[texhax] Force double expansion ?

Uwe Lueck uwe.lueck at web.de
Wed Jul 16 22:43:57 CEST 2014


Phil Taylor writes:
> When peeking ahead using \futurelet, the expansion of the token to be 
> peeked at can be forced using a simple chain of \expandafters, as in :
> 
> \expandafter \futurelet
>     \expandafter \nexttok
>         \expandafter\analysenexttok
>
> such that if (for example) the following token were \whatever,
> and if its expansion were \csname, then \analysenexttok would identify 
> \nexttok as \csname and not as \whatever.  But suppose that that were 
> not sufficient :  suppose that one wanted \nexttok to be \futurelet not 
> to \csname, but rather to the /expansion/ of \csname ...\endcsname 
> (assuming that the following code were well-formed).  Then how might 
> that be forced ?  It is important to note that that only the first-level 
> expansion of \csname ...\endcsname is required, so \edef (for example) 
> is not an option.

Are you really asking for the simple

  \expandafter\expandafter\expandafter \futurelet
      \expandafter\expandafter\expandafter \nexttok
          \expandafter\expandafter\expandafter \analysenexttok

? An advantage of latex.ltx over plain.tex may be that it has several 
examples to teach this. I think I have even seen expanding thrice etc. 
by \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
(maybe in something own), ams... has used \@xp for better readability 
of such things, also abbreviations for three \expandafter's may help ...

Cheers,

    Uwe.



More information about the texhax mailing list