The TeXbook (20th printing, Addison-Wesley 1991) describes how the primitive \noexpand<token>
is expanded (p. 213):
The expansion is the token itself; but that token is interpreted as if its meaning were ‘
\relax
’ if it is a control sequence that would ordinarily be expanded by TeX’s expansion rules.
In light of this I expect the following plain TeX manuscript to typeset "yes". In fact, it typesets "no". Why?
\def\foo{bar}%
\expandafter\ifx\noexpand\foo\relax yes\else no\fi%
\bye
\expandafter\meaning\noexpand\foo
is just like\meaning\foo
and should therefore typeset "macro:->bar", but in fact it typesets "\relax".\foo
in this context is not a control sequence that would ordinarily be expanded by TeX’s expansion rules. For\ifx
does not expand; it only checks whether two tokens mean the same. Unfortunately, this “explanation” does not explain the difference between\ifx
and\meaning
: The latter does not expand its argument either. I suppose it boils down to reading the TeX source code (which I never tried).