In Expandable full expansion of tokens that preserves catcodes, Joseph Wright presents the following code:
\long\def\fullyexpand#1{%
\csname donothing\fullyexpandauxi{#1}{}%
}
\long\def\fullyexpandauxi#1{%
\expandafter\fullyexpandauxii\romannumeral -`0#1\fullyexpandend
}
\long\def\fullyexpandauxii#1#2\fullyexpandend#3{%
\ifx\donothing#2\donothing
\expandafter\fullyexpandend
\else
\expandafter\fullyexpandloop
\fi
{#1}{#2}{#3}%
}
\long\def\fullyexpandend#1#2#3{\endcsname#3#1}
\long\def\fullyexpandloop#1#2#3{%
\fullyexpandauxi{#2}{#3#1}%
}
\def\donothing{}
Of which he says:
I'd also note that the above code needs some guards adding for a blank (empty or all space) argument, as currently things fail in these cases.
And this is true enough, if not exactly grammatical. Unfortunately, I'm not up to scratch on my TeX, so I'm not sure how to add such guards. Any takers?
(For my application, anything that will work in pdfTeX is fine.)
