# practical use of \noexpand outside\edef(\xdef) and \write(\messge)?

After reading (and searching through) TeXbyTopic.pdf I have the impression that practical use of \noexpand falls into one of the following three cases,

1. Inside \edef or \xdef, including the cases where macros are defined so that they are used in the context of \edef, such as

\def\protect{\noexpand\protect\noexpand}

2. Inside \write and \message, including the case of movable texts in LaTeX

3. In the special construction \if\noexpand#1\relax

Are there any other practical uses of \noexpand? Are there any practical use of \noexpand that is not in the expansion-only context, except for #3 listed above? I am new to plain and hope to understand plain better (especailly, the expansion-only context) by understanding various usages of \noexpand.

• Thank you for your quick reply. I am just wondering whether there are more cases like #3 in the question. Basically I am trying to summarize the usages of \noexpand and if you think you can rephrase the question so that it does not seem so "no"-leading, feel free to edit. – Weijun Zhou Apr 8 at 10:17

There are lots of tex primitives that expand tokens looking for arguments like \if and \ifcat. \noexpand would have a similar effect with any of them but whether or not that is useful is harder to say.

for example

\def\zz{hello}

\input s\noexpand\zz

\bye


inputs the file s.tex and then typesets hello whereas

\def\zz{hello}

\input s\zz

\bye


produces

! I can't find file shello'.


But you could more easily have used a space after s than \noexpand to stop the scan for a filename.

As indicated by Henri in comments there is also the use to nullify the end of file token in input or \scantokens

\edef\zz{\scantokens{z}}


is the error

! File ended while scanning definition of \zz.


but

\edef\zz{\scantokens{z\noexpand}}


or

\everyeof{\noexpand}
\edef\zz{\scantokens{z}}
`

are error free.