I get the error
! Argument of \@item has an extra }.
<inserted text>
\par
l.135 \emph{class} \bfcode{C}}
when translating a LaTeX file generated by Sphinx documentation system.
I've managed to reduce it to the following self-contained example:
\documentclass{article}
\usepackage{hyperref}
\newcommand{\pysigline}[1]{\item[#1]\nopagebreak}
\newenvironment{fulllineitems}{
\begin{list}{}{\labelwidth \leftmargin \labelsep 0pt
\rightmargin 0pt \topsep -\parskip \partopsep \parskip
\itemsep -\parsep}
}{\end{list}}
\begin{document}
\begin{fulllineitems}
\pysigline{\phantomsection\label{index:project0class_c}\item[] template \textless{}typename T\textgreater{}
\emph{class} \bfcode{C}}
Test class.
\end{fulllineitems}
\end{document}
As you can see the '{' and '}' are balanced.
What does this error mean and how can I fix it?
Best Answer
A LaTeX optional argument ends at the first
]
(unless it is inside a{}
group. It does not match[ ]
(unless you use the declarations provided byxparse
) so inthe argument of
\item
is not...\foo[] ...
but...\foo[
and things go wrong.\pysigline
puts its argument in an optional argument so useto hide the
[]
Or better (if you have access to the definition in your real case) fix the definition to add the extra
{}
in all cases:now a stray
]
in the argument to\pysigline
is protected from terminating the optional argument of the inner\item