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.)
\def\fullyexpandblank#1#2{ }otherwise I get an undefined command error if there are any spaces in the original arg, I was trying to see if spaces can be preserved (rather than stripped) but that seems a little tricky to do via expansion only as the primitive argument grabber has a tendency to eat space – David Carlisle Mar 09 '12 at 20:32\fullyexpand{\gobble{1}}, due to the way it loops over the input one token at a time, so you end up with\gobbleand1instead of nothing :-(. – SamB Mar 11 '12 at 01:42\edef, I'm accepting it ;-). – SamB Mar 11 '12 at 17:25