47

When I try to cite a book in such a way

\begin{theorem}[\cite[p.~90]{bibitem}]
Theorem body.
\end{theorem}

I've got an error because of multiple use of [ and ]. Is it possible to cite in such a way in theorem argument? Would be great if it could be done without redefine of \cite command.

lockstep
  • 250,273
xen
  • 705

2 Answers2

53

If you need to pass a ] inside an optional argument, just enclose the argument in figure braces:

\begin{theorem}[{\cite[p.~90]{bibitem}}]
Theorem body.
\end{theorem}

Without this, it's the \cite[p.~90 (everything up to the first ]) that gets passed as the argument, while the remaining text is typeset afterwards.

Andrey Vihrov
  • 22,325
  • 15
    It may be worth pointing out why this happens. The [ and ] bracketing of optional arguments in LaTeX isn't as robust as the { ... } bracketing of TeX. In particular, [ is matched by the next ] that is in the same group (with regard to { ... } grouping) as it. It doesn't look to see if the ] should have matched an intervening [. The solution is (as Andrey says) to ensure that any intervening [ and ]s are in a different TeX group by enclosing them in braces. – Andrew Stacey Mar 21 '11 at 08:09
1

The answer by Andrey Vihrov perfectly addresses the OP, I just want to add a small note (which doesn't fit well in a comment): when using the package ntheorem and the \theoremstyle{plain} command, wrapping the citation in braces is not enough. This is basically due to the implementation of the theorem style, which is the following:

\newtheoremstyle{plain}%
  {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}%
  {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\ (##3)\theorem@separator]}

The \cite command will be the ##3 argument. If the \cite command comes with an optional parameter (as in the OP) this interferes with the \item brackets. The same issue occurs with the change, margin, nonumberplain, and empty theorem styles. As a workaround, you may either wrap the \cite command in double braces, e.g.

\begin{theorem}[{{\cite[p.~90]{bibitem}}}]
Theorem body.
\end{theorem}

or you may consider redefining the style wrapping the ##3 argument in braces. For example, you can redefine the plain style using

\renewtheoremstyle{plain}%
  {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]}%
  {\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\ ({##3})\theorem@separator]}
Manlio
  • 480
  • 3
  • 13