I'm trying to understand the precise semantics of \protect as described in the beginning of section 11.4 Robust commands and protect of the source2e document, the annotated source code of the LaTeX2e format, on pp. 42-43 (I have substituted numbers below for bullet points in source2e):
[...] there are (at least) three different occasions when these commands [i.e.
LaTeXcommands --Evan Aad] are not safe. These are called 'moving arguments' byLaTeX, and consist of:
- writing information to a file, such as indexes or tables of contents.
- writing information to the screen.
- inside an
\edef,\message,\mark, or other command which evaluates its argument fully.The method
LaTeXuses for making fragile commands robust is to precede them with\protect. This can have one of five possible values:
\relax, for normal typesetting. So\protect\foowill execute\foo.\string, for writing to the screen. So\protect\foowill write\foo.\noexpand, for writing to a file. So\protect\foowill write\foofollowed by a space.\@unexpandable@protect, for writing a moving argument to a file. So\protect\foowill write\protect\foofollowed by a space. This value is also used inside\edefs,\marks and other commands which evaluate their arguments fully.\@unexpandable@noexpand, for performing a deferred write inside an\edef. So\protect\foowill write\foofollowed by a space. If you want\protect\footo be written, you should use\@unexpandable@protect. (Removed as never used.)
I struggle with the following issues.
- Item 4: The term 'moving argument' is used in a way that is inconsistent with the way it was defined before. In the opening paragraph it was defined as one of three occasions when the use of commands is risky, whereas in item 4 it designates a chunk of the input that is written to a file. So what exactly is a moving argument?
- Item 4: There's a mismatch between items 3 and 4: Item 3 says 'for writing to a file' and item 4 says 'for writing a moving argument to a file'. So the condition expressed in item 3 subsumes the one expressed in item 4, yet the actions specified in each case are different. How is it possible?
- Item 5: What's a 'deferred write'?
- Item 5: At the end of the item there's a comment that reads 'Removed as never used.` What does it mean?
This question is related to this one.