\
protect
\
cmd
” tells LaTeX to save \
cmd
as
\
cmd
, without expanding it at all.
So, what is a ‘fragile command’? — it’s a command that expands into
illegal TeX code during the save process.
What is a ‘robust command’? — it’s a command that expands into legal
TeX code during the save process.
Lamport’s book says in its description of every LaTeX command whether
it is ‘robust’ or ‘fragile’; it also says that every command with an
optional argument is fragile. The list isn’t reliable, and neither
is the assertion about optional arguments; the statements may have
been true in early versions of LaTeX2e but are not any longer
necessarily so:
\
cite
, have been made robust
in later revisions of LaTeX.
\
end
and \
nocite
, are fragile
even though they have no optional arguments.
\
newcommand
or \
newcommand*
) now always
creates a robust command (though macros without optional arguments
may still be fragile if they do things that are themselves fragile).
\
cite
command commonly suffers this treatment).
\
fred
is fragile, and you write:
\newcommand{\jim}{\fred}
then \
jim
is fragile too. There is, however, the
\
newcommand
-replacement \
DeclareRobustCommand
, which
always creates a robust command (whether or not it has optional
arguments). The syntax of \
DeclareRobustCommand
is substantially
identical to that of \
newcommand
, and if you do the wrapping
trick above as:
\DeclareRobustCommand{\jim}{\fred}
then \
jim
is robust.
\
MakeRobustCommand
to convert a command to be robust. With the
package, the “wrapping” above can simply be replaced by:
\MakeRobustCommand\fred
Whereafter, \
fred
is robust. Using the package may be reasonable
if you have lots of fragile commands that you need to use in moving
arguments.
\
protect
ion.
This question on the Web: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=protect