102

Possible Duplicate:
What is the difference between Fragile and Robust commands?

I've never understood the purpose of the command \protect? When and why should it be used?

gablin
  • 17,006

1 Answers1

53

To understand how to use \protect you need to understand the concept of fragile commands and to understand this concept, you need to understand what a moving argument is. Some commands called fragile commands causes an error when they use a moving argument. It's a command that expands into illegal TeX code during the save process. Some arguments are called moving arguments because they may be "moved" to other places in the document. A fragile command that appears in a moving argument must be preceded by a \protect command. For example,

  • sectioning commands
  • arguments of \caption commands
  • commands that produce page headings

An example :

\caption{Beautiful picture from \protect \citeauthor{allan}
  \protect \shortcite{allan}}
Alain Matthes
  • 95,075
  • 60
    "[A fragile command is a command that] expands into illegal TeX code during the save process." - What does this mean? What is the "save" process? How does a command that expands into illegal TeX successfully compile? Are there circumstances wherein a so-called "fragile command" expands into legal TeX? – Jake Aug 05 '16 at 06:17
  • 8
    I'm with @Jake here. While the answer technically answers the question, it leaves open a lot of questions. However this question is a duplicate anyway and the answer on the other question as linked on top is far more detailed. – Sunday Dec 07 '17 at 10:18
  • 6
    This technically isn't even an answer to the question.It didn't answer what is the purpose of the \protect command?, it just lists a few cases where I need one.This doesn't explain why LaTeX can't just put the protect in for me or what it actually does. – EntangledLoops May 14 '20 at 05:01
  • 1
    The information here https://latexref.xyz/_005cprotect.html seems elucidative. – LEo Feb 10 '21 at 13:43