How would you test whether we are in an expansion only context (i.e., \edef, \xdef, \write,...) or not? The only ways I could think of leave things behind (but the full expansion of that extra stuff is empty).
Is there a clean way of testing this?
\documentclass{article} \def\expiffalse{\expandafter\iffalse} \protected\def\mygobble#1{\ifx\iftrue#1\expiffalse\fi} \def\ifexpanding{\mygobble\iftrue\relax} \begin{document} We test that it sort of works: first, we are \ifexpanding expanding\else not expanding\fi. Then, we are% \edef\foo{\ifexpanding expanding\else not expanding\fi} \show\foo \foo. \end{document}
\let\voodoo\voodoowith\voodoostarting with \relax\relax and ignoring its first argument, which does pretty much the same thing, but would leave a \let\relax\relax in an expanding context. (The whole story can be found in nag.dtx. Ah, the days we were young...)\write, it should simply expand to the character. --- Since I have full control on what is going on, I can just keep track of things with a boolean, but I was lead to the question above.