[Dev-luatex] The explanation of \directlua in the manual

Javier Múgica de Rivera javieraritz.ribadeo at gmail.com
Thu Oct 20 11:23:30 CEST 2011


>> Note that the expansion of \directlua is a sequence of characters, not
>> of tokens, contrary to all TeX commands. So formally speaking its
>> expansion is null, but places material on a pseudo-file to be
>> immediately read by TeX, as etex's \scantokens.
>>
>> For a description of print functions look at section 4.13.10.

>Is that really true? When you assign catcodes (catcode tables) to the print functions, >TeX's behavior is different from scantokens. I have never used scantokens, so I am >not 100% sure. Take for example:
>
>tex.print(-2, "\\def\\foo{abc}")
>
>will not define \foo. While you have referenced the section with the print commands, I >think that the description is misleading.
>
>Patrick

The section on print commands says:

"The arguments to these three functions are all stored in an in-memory
virtual file that is fed to the TEX scanner as the result of the
expansion of \directlua."

An so what is fed to TEX are characters, no tokens. Your example,
indeed, is a good one to exhibit that behaviour. The fact that you can
change the catcodes and read the string again shows that TEX reads
characters, tokenizing them. If it where not and the expansion were a
sequence of tokens then \foo would get defined. Your example is like

\def\scanasothers#1{
<set up catcodes as the value -2 for the first argument of tex.print does>
\scantokens{#1}
<reset catcodes>
}

\scanasothers{def\foo{abc}}

This actual example suffices:

\def\scanasothers#1{
\catcode`\\=12
\scantokens{#1}
\catcode`\\=0
}

\scanasothers{\def\foo{abc}}
\show\foo
\end

Which reports

> \foo=undefined.
l.8 \show\foo

and the dvi output includes the \'s output as " (the character in the
font at the position of \).

Javier


More information about the dev-luatex mailing list