[tex-eplain] \@optionalarg in \footnote
Oleg Katsitadze
olegkat at gmail.com
Fri Jun 15 18:00:39 CEST 2007
On Fri, Jun 15, 2007 at 04:09:01PM +0200, Stefan Becuwe wrote:
> construction, since "\@optionalarg" is printed as a footnote, not the
> "value" of \@optionalarg which is correctly displayed by \message...
[...]
> \else\message{[\@optionalarg]}\writenumberedtocentry{chapter}{#1\footnote{\@optionalarg}}{\expandchapter}%
This is because \writenumberedtocentry (unlike \message) does not
expand its second argument, and it's actually good that it does not,
otherwise the result would generally be unusable when it is read back
in. What you need here is _partial_ expansion, something like this:
\toks@={#1}%
\toks2=\expandafter{\@optionalarg}% Expands \@optionalarg *only once*.
\edef\@wr{\noexpand\writenumberedtocentry{chapter}{\the\toks@ \noexpand\footnote{\the\toks2}}}%
\@wr
The key to the above is that when \edef expands tokens, it will expand
\the\toksN only once, that is, get the contents of the register
without expanding any tokens _within_ the contents. And to avoid
expanding other macros, we add \noexpand in front of them -- \edef
removes \noexpand's and avoids expanding the following macro. Final
note -- use \toks2 as the scratch register, not \toks1, because we
make non-global assignment to it (by convention, global assignments
should only be made to registers 1, 3,..., 9, to avoid so-called save
stack overflow).
HTH,
Oleg
P.S. There is a missing closing \fi in your snippet, but maybe you
just overlooked it when cutting and pasting.
More information about the tex-eplain
mailing list