Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
5  
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
add comment

1 Answer 1

up vote 12 down vote accepted

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.

share|improve this answer
    
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
4  
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
1  
@ 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.