# Definition of \protect in \edef

Update: With the release of LaTeX2e 2018-04-01 Patch level 2, the following sentence has been added in the paragraph cited below to make the documentation clearer:

More precisely, whenever the content of an \edef or \xdef etc. can contain arbitrary user input not under the direct control of the programmer, one should use \proetected@edef instead of \edef, etc., so that \protect has a suitable definition and the user input will not break if it contains fragile commands.

In an attempt to post this answer, I noticed source2e.pdf says in Section 11.4

The method LaTeX uses for making fragile commands robust is to precede them with \protect. This can have one of five possible values:

• [...]
• \@unexpandable@protect, for writing a moving argument to a file. So \protect\foo will write \protect\foo followed by a space. This value is also used inside \edefs, \marks and other commands which evaluate their arguments fully.

However, I don't understand what "This value is also used inside \edefs" means here. \protect is \let to be \@unexpandable@protect inside a \protected@edef as noted in the aforementioned answer, but I don't think one can alter the definition of \protect inside an \edef.

What's the point of this statement? Do I have some misunderstanding?

• I interpret it to mean that if \def\a{xyz}, then after \edef\tmp{\protect\a}, the macro \tmp will contain the tokens \protect xyz, so that \protect remains as \protect. – Steven B. Segletes Dec 2 '17 at 1:25
• @StevenB.Segletes Ah got it. I misread "This value" as \protect, but it should obviously refer to \@unexpandable@protect. It makes perfect sense. – yudai-nkt Dec 2 '17 at 3:37
• Should I close/delete this question as the confusion is purely due to my poor English comprehension and my question is off-topic here? – yudai-nkt Dec 2 '17 at 3:39
• @yudai-nkt it isn't your bad understanding, it's our bad english:-) I think actually most of that wording is older than \protected@edef so what it means was "you should set \protect to this value (\@unexpandable@protect) before using \edef or \mark, although it could now be worded as saying, use \protected@edef not \edef as it sets up \protect to mean \@onexpandable@protect – David Carlisle Dec 2 '17 at 9:00
• @yudai-nkt "new" as in when we made latex2e in 1993-1994 :-) the \protect mechanism itself goes back to latex2.09 but the more systematic use of it, and that documentation comes from that time – David Carlisle Dec 2 '17 at 17:37

Better would be something stating that LaTeX internally doesn't use \edef unless the input is known to be always "safe" but instead uses \protected@edef which sets \protect to \unexpandable@protect so that any command "protecting" itself is not expanded but survives the \edef expansion unaltered.