Statements about \noexpand in source3.pdf and in the TeXbook

expl3primitivestex-core

The LaTeX3 sources, released 2021-07-12, says in section "23.7 Description of all possible tokens" of "Chapter 23: The l3token package /Token manipulation":

  • Expanding \noexpand ⟨token⟩ (when the ⟨token⟩ is expandable) results in an internal token, displayed (temporarily) as \notexpanded: ⟨token⟩, whose shape coincides with the ⟨token⟩ and whose meaning differs from \relax.

Question 1: Why the statement that the meaning differs from \relax?

If I do

\expandafter\show\noexpand\TeX

, then I get:

> \TeX=\relax.
<recently read> \notexpanded: \TeX 

, which seems to imply that right after expanding \noexpand the meaning equals the meaning of the \relax-primitive.

If I do

\expandafter\let\expandafter\test\expandafter=\noexpand\TeX \show\test

, then I get:

> \test=\relax

, which seems to imply that right after expanding \noexpand the meaning equals the meaning of the \relax-primitive.

Besides this, TeXbook, "Chapter 20: Definitions (also called Macros)" says:

  • \noexpand ⟨token⟩. 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.

Btw: This brings up more questions:

On the one hand (source3.pdf) there is the statement of the expansion of \noexpand ⟨token⟩ yielding an internal token, displayed (temporarily) as \notexpanded: ⟨token⟩ whose shape coincides with the ⟨token⟩.

On the other hand (TeXbook) there is the statement of the expansion of \noexpand ⟨token⟩ yielding the ⟨token⟩ itself.

These are two different statements.

Question 2: Are both statements correct?

Question 3: Which of these two statements is more precise?

Best Answer

well...


\expandafter\show\noexpand\TeX

\expandafter\ifx\noexpand\TeX\relax \show Y\else\show N\fi

\expandafter\ifx\noexpand\TeX\TeX \show Y\else\show N\fi

\edef\zz{\ifnum0=0\else\fi}

\expandafter\expandafter\expandafter\ifx\expandafter\noexpand\expandafter\TeX\zz \show Y\else\show N\fi


\expandafter\expandafter\expandafter\ifx\expandafter\noexpand\expandafter\TeX\noexpand\LaTeX \show Y\else\show N\fi

\expandafter\expandafter\expandafter\ifx\expandafter\noexpand\expandafter\TeX\noexpand\TeX \show Y\else\show N\fi

\bye

produces

> \TeX=\relax.
<recently read> \notexpanded: \TeX 
                                   
l.2 \expandafter\show\noexpand\TeX
                                  
? 
> the letter N.
l.4 ...\ifx\noexpand\TeX\relax \show Y\else\show N
                                                  \fi
? 
> the letter N.
l.6 ...er\ifx\noexpand\TeX\TeX \show Y\else\show N
                                                  \fi
? 
> the letter N.
l.10 ...and\expandafter\TeX\zz \show Y\else\show N
                                                  \fi
? 
> the letter Y.
l.13 ...and\expandafter\TeX\noexpand\LaTeX \show Y
                                                  \else\show N\fi
? 
> the letter Y.
l.15 ...xpand\expandafter\TeX\noexpand\TeX \show Y
                                                  \else\show N\fi
? 

so although \show implies the token is \relax it is not \ifx equal to \relax or a frozen \relax or to the original token \TeX, but is \ifx equal to other \noexpand produced tokens.