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. 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
  • 1
    @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 Dec 2 '17 at 9:00
  • 1
    @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 Dec 2 '17 at 17:37

The documentation is a bit misleading and I think we can/should improve on that.

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.

  • Thank you for the clarification. By the way, is this kind of "documentation" problems allowed to be filed at GitHub issues? I once considered doing so and consulted the contribution guide, but I wasn't sure if GitHub was appropriate for such non-technical discussions.
    – yudai-nkt
    Dec 2 '17 at 15:51
  • @yudai-nkt well ... a) officially the github version is not yet live (we are just setting it up (perhaps there should be a big disclaimer but ...) but it will be soon. b) if phrased as a question like you did here the answer is "no" (for LaTeX2e at least). Questions are much better asked here with many people helping to get you answer. If it is clearly a bug (and especially you know the answer or direction) then the a documentation bug report is fine as an issue. But as you can see from the draft contribution guide and the template draft we really wish to limit the tracker for LaTeX2e. Dec 2 '17 at 23:00
  • Once we are ready with the github site I guess we will put out a question (and answer) here that discusses how and what to report there for LaTeX2e. Dec 2 '17 at 23:05
  • OK, I see. When I encounter a similar problem in the future, I'll ask here first and migrate the question to GitHub if it turns out to be worth the issue tracker (after the repository is set up of course).
    – yudai-nkt
    Dec 3 '17 at 4:53
  • yes please. It is just a question of resources: a handful of maintainers viz a whole site of people with knowledge ready to help (in case it is not a bug - or even if). and it helps keeping the Issue tracker relevant to actual bugs. Dec 3 '17 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.