6

How to remove brackets around a specific citation in the text:

See [1] and [2], but 3 is what I need, and [4] is ok.

Here, what command would give 3 and not [3] as \cite gives? For the other citations in the same document, brackets like [1] are OK.

This is not a duplicate of "Remove brackets from a single citation" because the command \citenum recommended there needs an additional package (probably natbib).

My motivation is citing two papers, each with page numbers. It seems it is impossible using normal citing commands:

See [1, p 12] and [2, p 23], but [3, p 34; 5, p 45] is what I need, and [4, p 56] is ok

so I expect to simulate it with commands like

See \cite[p 12]{A} and \cite[p 23]{B}, 
but [\citeNoBrackets[p 34]{C}; \citeNoBrackets[p 45]{E}] is what I need, 
and \cite[p 56]{D} is ok.

For this, I need a command like \citeNoBrackets that behaves as \cite but does not add brackets. How do I do it?

Note: \def\@biblabel#1{#1} does just the opposite: it changes the References list, but does not change how citations appear in the text.

MWE:

\documentclass{article}
\begin{document}
    See \cite[p 12]{A} and \cite[p 23]{B}, 
    but [\cite[p 34]{C}; \cite[p 45]{E}] is what I need, 
    and \cite[p 56]{D} is ok.
\bibliographystyle{plain}
\bibliography{test}
\end{document}

test.bib:

@Article{A, author = {A}, title = {A}, journal = {A}, year = {A}}
@Article{B, author = {B}, title = {B}, journal = {B}, year = {B}}
@Article{C, author = {C}, title = {C}, journal = {C}, year = {C}}
@Article{D, author = {D}, title = {D}, journal = {D}, year = {D}}
@Article{E, author = {E}, title = {E}, journal = {E}, year = {E}}

which produces

See [1, p 12] and [2, p 23], but [[3, p 34]; [5, p 45]] is what I need, and [4, p 56] is ok.

with unwanted double brackets.

  • 1
    Why do you not want to use natbib? It is very widely used and accepted by publishers. – Michael Palmer Aug 04 '17 at 12:34
  • natbib was created to do what you want. Where is the problem? – Johannes_B Aug 04 '17 at 12:42
  • 1
    I am not sure if it will not alter a given style. In addition, I cannot get it working with the particular style I have to use, svjour3.cls. – Alexander Gelbukh Aug 04 '17 at 12:42
  • A minimal working example with bibliography (MWEB), that illustrates your problem would help a lot. – Bobyandbob Aug 04 '17 at 12:51
  • 3
    The svjour3.cls has a natbib option, so it's definitely compatible with natbib. You're asking people to reinvent the wheel. – Alan Munn Aug 04 '17 at 13:00
  • Alan is right. The template that comes with that class has \DeclareOption{natbib}{\AtEndOfClass{\RequirePackage{natbib} - so you just start your document with \documentclass[natbib]{svjour3}. This loads the natbib package, and you should be all set. – Michael Palmer Aug 04 '17 at 13:08
  • Yes, but in my case it gives an error Bibliography not compatible with author-year citations. I do not see how to give it an option [numbers]. (How to debug this would be another question.) But in any case, I thought there should be a trivial way to get rid of the brackets without more packages. – Alexander Gelbukh Aug 04 '17 at 13:12
  • In my MWE, just changing \documentclass{article} for \documentclass[natbib]{svjour3} here produces this error. Maybe it's a problem of configuration of my computer, not sure. – Alexander Gelbukh Aug 04 '17 at 13:21
  • It works if I add \usepackage{natbib} and copy all its parameters from the class, but this is hacking, not an intended use of the class. – Alexander Gelbukh Aug 04 '17 at 13:26
  • You're solving the wrong problem here. Load the svjour3 class with the natbib option, add \setcitestyle{numbers,square} and \bibliographystyle{plainnat} to your preamble. Then use regular natbib commands. If that doesn't work, edit your question with a minimal example showing this and then perhaps we can solve the problem. – Alan Munn Aug 04 '17 at 13:42
  • Yes, \setcitestyle{numbers} solved the svjour3 problem, thank you! But even with this, I would be interested (for the future, or for other readers) to know the answer to the original question, if somebody wants to provide it. – Alexander Gelbukh Aug 04 '17 at 13:51
  • The answer would just copy the code from natbib. It was already done. of course one could argue that to avoid natbib, one could just as well copy tge relevant code from the more modern biblatex package. – Johannes_B Aug 04 '17 at 13:54

1 Answers1

7

Lightly tested.

\documentclass[]{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}

@book{Knuth1984texbook,
    Author = {Knuth, D.E.},
    Publisher = {Addison-Wesley, Reading, Massachusetts,},
    Title = {The TEXbook, volume A of Computers and typesetting},
    Year = {1984}}

@book{Chomsky1965,
    Address = {Cambridge Mass.},
    Author = {Noam Chomsky},
    Publisher = {{MIT} Press},
    Title = {Aspects of the Theory of Syntax},
    Year = {1965}}
\end{filecontents*}

\bibliographystyle{plain}
\makeatletter
\newif\ifnobrackets
\renewcommand\@cite[2]{\ifnobrackets\else[\fi{#1\if@tempswa , #2\fi}\ifnobrackets\else]\fi\nobracketsfalse}
\newcommand\nbcite{\nobracketstrue\cite}
\makeatother


\begin{document}
[\nbcite[p.4]{Knuth1984texbook} and \nbcite[p.5]{Chomsky1965}] show that ...
\cite[p.4]{Knuth1984texbook} and \cite[p.5]{Chomsky1965} show that ...
\bibliography{\jobname}
\end{document}

output of code

Alan Munn
  • 218,180