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' by
LaTeX, and consist of:
- writing information to a file, such as indexes or tables of contents.
- writing information to the screen.
- inside an
\mark, or other command which evaluates its argument fully.
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
\string, for writing to the screen. So
\noexpand, for writing to a file. So
\foofollowed by a space.
\@unexpandable@protect, for writing a moving argument to a file. So
\protect\foofollowed by a space. This value is also used inside
\marks and other commands which evaluate their arguments fully.
\@unexpandable@noexpand, for performing a deferred write inside an
\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.