[texhax] Question about cwebmac.tex
Philip Taylor
P.Taylor at Rhul.Ac.Uk
Mon Feb 1 23:22:18 CET 2016
Igor Liferenko wrote:
> Is it possible that the following macros from cwebmac.tex makes \toksE
> contain no expandable tokens at all?
Pass.
> \newtoks\toksE
> \toksE{\foo}
> \def\foo{bar}
> \pdfoutline goto num 2 \expandafter{\directlua{toutf16("\the\toksE")}}
> x
> \pdfoutline goto num 3 {\directlua{toutf16("\the\toksE")}}
> x
It looks to me as if "\expandafter" is far too early; it forces
expansion of the token after the /next/ token (in your case, the "{"
that immediately precedes "\directlua"), whereas it actually needs to
appear immediately before the '"' that immediately precedes "\the
\toksE". However, if expansion is not taking place when the
\expandafter is read, it will have no effect, which I very much suspect
would be the case were you to place it as suggested above.
I would recommend looking at the e-TeX primitives that allow greater
control over expansion, and/or using "\edef" (coupled with "\noexpand"
as required) to create a control sequence that will expand to
\pdfoutline goto num 2 {\directlua{toutf16("\the\toksE")}}
with \the \toksE already expanded.
Philip Taylor
More information about the texhax
mailing list