[texhax] Curious behavior of \cite
Michael Barr
mbarr at math.mcgill.ca
Sat Sep 16 18:03:04 CEST 2006
Here is some curious behavior of \cite. The definition of \@citex (the
macro that does the work), from latex.ltx is
\def\@citex[#1]#2{\leavevmode
\let\@citea\@empty
\@cite{\@for\@citeb:=#2\do
{\@citea\def\@citea{,\penalty\@m\ }%
\edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
\if at filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
\@ifundefined{b@\@citeb}{\hbox{\reset at font\bfseries ?}%
\G at refundefinedtrue
\@latex at warning
{Citation `\@citeb' on page \thepage \space undefined}}%
{\@cite at ofmt{\csname b@\@citeb\endcsname}}}}{#1}}
It is the last line that actually inserts the citation and I will
concentrate on that. First, \@cite at ofmt is actually a synonym of \hbox
and I really don't see why a synonym is needed, but maybe some change is
anticipated in the future. At any rate, the effect of the \hbox is to
prevent the citation from breaking. But since I generally use the
[Author (year)] style of citations, this causes all sorts of problems.
So I tried changing the last line to
{\csname b@\@citeb\endcsname}}}{#1}}
This appeared to work fine, until I used \emph{et al.} in a citation.
To see the effect, run this file:
\documentclass{article}
\makeatletter
\def\@citex[#1]#2{\leavevmode
\let\@citea\@empty
\@cite{\@for\@citeb:=#2\do
{\@citea\def\@citea{,\penalty\@m\ }%
\edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
\if at filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
\@ifundefined{b@\@citeb}{\hbox{\reset at font\bfseries ?}%
\G at refundefinedtrue
\@latex at warning
{Citation `\@citeb' on page \thepage \space undefined}}%
{\csname b@\@citeb\endcsname}}}{#1}}
\makeatother
\begin{document}
Here is an example of a citation that can cause
problems: \cite{A}
\begin{thebibliography}{xxx}
\bibitem[A \emph{et al.}]{A}
\end{thebibliography}
\end{document}
Of course, this happened to me with real citations, but I have reduced
it to the minimum. What happens is that the citation has the form [A
\emph{et al.},] with an unwonted--not to mention unwanted--comma at the
end. Eventually, I discovered that adding an extra pair of braces to
the last line:
{{\csname b@\@citeb\endcsname}}}}{#1}}
cures the problem while still allowing breaks. I cannot explain any of
this, but I did want to call the attention of texhaxxers to this
phenomenon.
Michael Barr
More information about the texhax
mailing list