In latexrelease 2015/01/01, there are two implementations of \TextOrMath: one for regular TeX, the other one for eTeX-like engines (more precisely: those which support \protected). My question concerns the latter:

\protected\expandafter\def\csname TextOrMath\space\endcsname{%
  (...) } % no problem here
\edef\TextOrMath#1#2{% from latex.ltx
  \expandafter\noexpand\csname TextOrMath\space\endcsname

I think I understand well these definitions, however I can't figure out why the \edef isn't simply written this way:

\edef\TextOrMath#1#2{% from me
  \csname TextOrMath\space\endcsname

Since the internal \TextOrMath<space> macro is \protected, what is the point of preceding it with \noexpand inside the \edef? Is it because the author feared that \protected might be deficient?..

I made a test like this (ran with pdfTeX):

% From latex.ltx (or p. 153 of source2e.pdf)
\protected\expandafter\def\csname TextOrMath\space\endcsname{%
  \ifmmode  \expandafter\@secondoftwo
  \else     \expandafter\@firstoftwo  \fi}

  \expandafter\noexpand\csname TextOrMath\space\endcsname

% My simpler way of doing the same (?)
  \csname TextOrMath\space\endcsname

\show\TextOrMath    % \TextOrMath=macro:#1#2->\TextOrMath  {#1}{#2}.
\show\altTextOrMath % \altTextOrMath=ditto



This test prints 'identical' and seems to indicate that my definition is equivalent to the one in latex.ltx (but slightly simpler). Did I miss something?


  • thanks I suppose we could change that:-) – David Carlisle Apr 2 at 20:24
  • Many thanks for your insight into this, I was really puzzled! – frougon Apr 2 at 20:26

No you didn't miss anything, just old habits die hard as we gradually add these modern post 1992 features into the sources....

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.