3

Here is (almost) minimal example of the file, which gives the error.

\documentclass{article}
\usepackage{amsmath}
\usepackage[english]{babel}
\begin{document}
\section{Section name with varinjlim: $\varinjlim$}
\end{document}

Running pdflatex gives 4 identical errors of the form

minimal.tex:5: Illegal parameter number in definition of \reserved@a. [...{Section name with varinjlim: $\varinjlim$}]

Adding \tableofcontents gives 12 additional errors of the form

\minimal.toc:2: Only one # is allowed per tab. [...m \p@ \kern -\ex@ }\cr }}}}\nmlimits@ $}{1}]

Is there a way to avoid these, and still put \varinjlim in the section name?

fiktor
  • 1,953

1 Answers1

3

It's necessary to use \protect or to robustify the command.

However, other problems might appear, if hyperref is used, since pdftex will complete about invalid strings in bookmarks then. In this case, use \texorpdfstring as shown in the second version.

\documentclass{article}
\usepackage{amsmath}
\usepackage[english]{babel}
\usepackage{hyperref} % Not needed
\begin{document}
\section{Section name with varinjlim: $\protect\varinjlim$}
\section{Section name with varinjlim: \texorpdfstring{$\protect\varinjlm$}{limits}}
\end{document}

Another way is to use following code in the preamble:

\usepackage{etoolbox}

\robustify\varinjlim%

This way the \protect is not needed, however, it does not prevent the required \texorpdfstring.