# \cite[page]{book} inside \caption[…]{…}

Is it somehow possible to put a citation including page specification, as in \cite[page]{book}, inside the list-of-figures-relevant caption of a figure, i.e. \caption[*HERE*]{...}?

I can do

\caption[\protect\cite{book}]{other text}


but

\caption[\protect\cite[page]{book}]{other text}


yields book] other text as the caption in the first run and produces an error "Argument of \NAT@@cite has an extra }" in the second LaTeX run.

I'm using pdfLaTeX and natbib.

-
LaTeX mistakes the bracket after page for the closing bracket of the optional argument; \caption[{\protect\cite[page]{book}}]{other text} –  egreg Feb 28 '12 at 23:15
Oh wow, thanks, that was quick and easy! Could've thought of that myself... Care to post that as an answer so that I can accept it? –  Jan Pöschko Feb 28 '12 at 23:20
note that citations in lists-of-*, toc, etc., play havoc with unsrt-type biblio styles. i think there's a faq answer about that... –  wasteofspace Feb 28 '12 at 23:53

The scanning of an optional argument (in brackets, [ and ]) works in a slight different way than the scanning of a mandatory argument (in braces, { and }); TeX counts the braces, but doesn't do the same for brackets. So, with your input, the optional argument that is seen is

\protect\cite[page


that is, everything from [ to the first ] (which is balanced with respect to braces). In order to avoid this problem, brackets inside an optional argument must be "masked" with braces:

\caption[{\protect\cite[page]{book}}]{other text}


The argument cannot have unbalanced braces, so the bracket after page doesn't end it, in this case.

-
Nice, thanks! Out of curiosity: Do you know the reasoning behind the different behavior for optional vs mandatory arguments / [] vs {}? –  Jan Pöschko Feb 28 '12 at 23:41
The balancing of braces is built in in TeX; optional arguments in LaTeX are treated in a rather different way. –  egreg Feb 28 '12 at 23:45
@ egreg, I want to congratulate you for such a complete answer! Even though it seems something simple, this is the kind of question to be expected in Tex.SX –  henrique Feb 29 '12 at 1:07