# Use of \noexpand in the implementation of \TextOrMath for eTeX

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
{#1}{#2}}


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
{#1}{#2}}


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}

\edef\TextOrMath#1#2{%
\expandafter\noexpand\csname TextOrMath\space\endcsname
{#1}{#2}}

% My simpler way of doing the same (?)
\edef\altTextOrMath#1#2{%
\csname TextOrMath\space\endcsname
{#1}{#2}}

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

\ifx\TextOrMath\altTextOrMath
identical
\else
different
\fi

\vfill
\eject
\bye


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!

• 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