Control sequences with optional arguments inside optional arguments must
be "hidden" with braces.
Using the abntex2cite
package to handle my citations, I often want to write:
\begin{teor}[{\cite[p.~42]{johndoe1999}}]
$2+2=4$.
\end{teor}
That doesn't work, however; I need to write:
\begin{teor}[\leavevmode{\cite[p.~42]{johndoe1999}}]
$2+2=4$.
\end{teor}
instead.
\cite
and \citeonline
behave exactly the same in this regard.
Besides \leavevmode
, a \strut
or just a space/end-of-line also work
(except the space looks weird/ugly).
That is, LaTeX needs something to start a line right before the citation macro between braces.
I thought that maybe this happens because the macros \cite
and \citeonline
had to start with \leavevmode
, but don't;
however, the source of abntex2cite
shows that the very first line of \citeonline
IS \leavevmode
!
So my questions are:
- Why is another
\leavevmode
before\citeonline
(or\cite
) necessary, even though\citeonline
starts with\leavevmode
? - Is there a way to redefine
\cite
and\citeonline
such that I don't need space/\strut
/\leavevmode
before the braced citation macro?
(Files to showcase what I described)
Contents of sample.tex
:
\documentclass{article}
\usepackage{ntheorem}
\newtheorem{teor}{Teorema}
\newcommand*{\page}[1]{p.~#1}
\usepackage[alf]{abntex2cite}
\begin{document}
Regular ``external'' citation according to the ABNT (Brazilian) standard:
\cite{johndoe1999}.
Regular ``inline'' citation according to the ABNT (Brazilian) standard:
\citeonline{johndoe1999}.
So far, so good; no extra braces needed.
Whithin the optional argument of an environment, however,
extra braces are needed:
\begin{teor}[This works
{\cite[\page{25}]{johndoe1999}}%<-- notice the extra braces!
]
Notice the extra braces in the optional argument.
\end{teor}
\begin{teor}[Also works
{\citeonline[\page{25}]{johndoe1999}}%<-- notice the extra braces!
]
Notice the extra braces in the optional argument.
\end{teor}
And the next one works, but it requires
(besides the extra braces)
something to start a line before \verb|\cite| or \verb|\citeonline|:
it can be a space, a \verb|\strut| or \verb|\leavevmode|.
I think that's annoying and error-prone;
is there another way?
\begin{teor}[% avoid extraneous space here
\leavevmode{\citeonline[\page{25}]{johndoe1999}}%<-- \leavevmode + extra braces!
]
This one requires both
extra braces AND ``something to start a line''
in the optional argument.
\end{teor}
\bibliography{bibfile}
% this is how a chapter of a book is supposed to look in the ABNT style...
\end{document}
% -- the following won't compile!
% erase the previous 2 macros to generate errors
\begin{teor}[% lacks \leavevmode AND extra braces
\citeonline[\page{25}]{johndoe1999}%
]
\fbox{content}
\end{teor}
\begin{teor}[% lacks extra braces: {\citeonline...}
\leavevmode\citeonline[\page{25}]{johndoe1999}%
]
\fbox{content}
\end{teor}
\begin{teor}[% lacks \leavevmode (or \strut)
{\citeonline[\page{25}]{johndoe1999}}%
]
\fbox{content}
\end{teor}
\bibliography{bibfile}
\end{document}
Contents of bibfile.bib
:
% Encoding: UTF-8
@InCollection{johndoe1999,
author = {Doe, John},
booktitle = {Handbook of Foobar},
publisher = {Barbaz},
title = {Interesting chapter},
year = {1999},
address = {Earth},
editor = {{Mc}Editor, Editor},
pages = {283--342},
}
\newtheorem
and friends to see if something there might be responsible for disabling\leavevmode
if the first thing within the optional argument is an open brace. (After all, when the optional argument starts with text, it works.)