[luatex] Newbie question: how to stop TeX trying to interpret Lua?

Paul Isambert zappathustra at free.fr
Mon Apr 4 15:36:40 CEST 2011



Le 04/04/2011 11:40, luigi scarso a écrit :
> On Mon, Apr 4, 2011 at 10:25 AM, Paul Isambert<zappathustra at free.fr>  wrote:
>
>> Yes, because \TeX expands to harmless primitives (\kern, etc.), so tex.print
>> actually sees is something like "T\kern-.1.667em....". Try replacing
>> tex.print with texio.write_nl and you'll see. In other cases, though,
>> expansion should be carefully controlled.
> True, in fact I though that one can replace
> <<text>>
> with
> \directlua{tex.print( [=[<<text>>]=])}
> assuming ASCII and the same catcode regime
> but it's not true, even if I don't understand clearly why.
>
>
> \bgroup
> \initcatcodetable1
> \catcode`\_=0
> _TeX\TeX
> \savecatcodetable1
> \egroup
>
> %% ok
> \directlua{tex.print(1, [=[_TeX\relax\TeX]=])}
>
> %% ok
> \directlua{tex.print(1, [=[_TeX{}\TeX]=])}
>
> %% ok
> \directlua{tex.print(1, [=[_TeX \TeX]=])}
>
>
> %% wrong
> %% \directlua{tex.print(1, [=[_TeX\TeX]=])}
> %% ! Undefined control sequence.
> %% l.1 _TeXT
> %%         \kern

Quite normal: \TeX is expanded in \directlua to "T\kern1.6667em etc.", 
so the string that is passed to the Lua interpreter and then back to TeX 
is "_TeXT\kern1.6667em etc." The underscore being an escape character 
here, _TeXT is an (unexisting) control sequence. Try:

\directlua{tex.print(1, [=[_TeX\noexpand\TeX]=])}

and \TeX will remain as it is, and the string passed back from Lua to 
TeX will be "_TeX\TeX", hence no error.

>
> %ok (32 is space)
> \directlua{ tex.print(1,string.char(95,84,101,88,
>                                      32,
>                                      92,84,101,88)) }
>
>
> %% ok ... why ??
> \directlua{ tex.print(1,string.char(95,84,101,88,
>                                      92,84,101,88)) }

Because nothing is expanded here. Instead, Lua passes to TeX a string 
made of _, T, e, X, \, T, e, X, and that's simply two control sequences 
in a row.

Best,
Paul


More information about the luatex mailing list