\
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:
then\newcommand{\jim}{\fred}
\
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:
then\DeclareRobustCommand{\jim}{\fred}
\
jim
is robust.
Finally, we have the makerobust package, which defines
\
MakeRobustCommand
to convert a command to be robust. With the
package, the “wrapping” above can simply be replaced by:
Whereafter,\MakeRobustCommand\fred
\
fred
is robust. Using the package may be reasonable
if you have lots of fragile commands that you need to use in moving
arguments.
In short, the situation is confusing. No-one believes this is
satisfactory; the LaTeX team have removed the need for
protection of some things, but the techniques available in
current LaTeX mean that this is an expensive exercise. It remains
a long-term aim of the team to remove all need for \
protect
ion.
This answer last edited: 2011-06-01
This question on the Web: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=protect