All LaTeX commands are either fragile or robust. A fragile command can break when it is used in the argument to certain other commands. Commands that contain data that LaTeX writes to an auxiliary file and re-reads later are fragile. This includes material that goes into a table of contents, list of figures, list of tables, etc. Fragile commands also include line breaks, any command that has an optional argument, and many more. To prevent such commands from breaking, one solution is to preceded them with the command \protect
.
For example, when LaTeX runs the \section{section
name}
command it writes the section name text to the .aux auxiliary file, moving it there for use elsewhere in the document such as in the table of contents. Any argument that is internally expanded by LaTeX without typesetting it directly is referred to as a moving argument. A command is fragile if it can expand during this process into invalid TeX code. Some examples of moving arguments are those that appear in the \caption{...}
command (see figure), in the \thanks{...}
command (see \maketitle), and in @-expressions in the tabular
and array
environments (see tabular).
If you get strange errors from commands used in moving arguments, try preceding it with \protect
. Every fragile commands must be protected with their own \protect
.
Although usually a \protect
command doesn’t hurt, length commands are robust and should not be preceded by a \protect
command. Nor can a \protect
command be used in the argument to \addtocounter
or \setcounter
command.
In this example the \caption
command gives a mysterious error about an extra curly brace. Fix the problem by preceding each \raisebox
command with \protect
.
\begin{figure} ... \caption{Company headquarters of A\raisebox{1pt}{B}\raisebox{-1pt}{C}} \end{figure}
In the next example the \tableofcontents
command gives an error because the \(..\)
in the section title expands to illegal TeX in the .toc file. You can solve this by changing \(..\)
to \protect\(..\protect\)
.
\begin{document} \tableofcontents ... \section{Einstein's \( e=mc^2 \)} ...
© 2007–2018 Karl Berry
Public Domain Software
http://latexref.xyz/_005cprotect.html