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

Paul Isambert zappathustra at free.fr
Mon Apr 4 10:25:03 CEST 2011


Le 04/04/2011 10:10, luigi scarso a écrit :
> On Mon, Apr 4, 2011 at 9:37 AM, Paul Isambert<zappathustra at free.fr>  wrote:
>> Le 04/04/2011 09:26, luigi scarso a écrit :
>>> On Mon, Apr 4, 2011 at 9:03 AM, Dirk Laurie<dpl at sun.ac.za>    wrote:
>>>> I've managed quite well for several months by writing and debugging
>>>> my Lua code separately and using only "dofile" inside \directlua.
>>>> Now I'm trying to do it all inside LuaTeX.
>>>>
>>>> It comes as a shock that
>>>>
>>>> \directlua{ tex.print("\\TeX") }
>>>>
>>>> does not work.  TeX grabs the double-quote and tries to make some
>>>> accented character.  I've read to about page 25 of the LuaTeX manual
>>>> and it's already way over my head.  The answer, apart from working
>>>> with dofile, may be in there but I'm not going to find it soon.
>>>>
>>>> Help please!
>>>>
>>>> Dirk
>>>>
>>> what about
>>> \directlua{ tex.print([=[\TeX]=]) }
>>> ?
>>
>> It won't work properly either. Let's not forget that \directlua expands its
>> argument. In both cases there lacks a \noexpand.
>> Using \directlua is good for snippets only, otherwise it's not very
>> convenient, and you have to change catcodes. Everything (I hope) is
>> explained in the Wiki:
>> http://wiki.luatex.org/index.php/Writing_Lua_in_TeX
> hm,
>
> \directlua{ tex.print([=[\TeX]=]) }
> \directlua{ tex.print(string.char(92,84,101,88)) }
> \directlua{ tex.print(string.char(92).."TeX") }
>
> produce correctly the same \TeX logo with luatex fmt from minimals.

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.

> But I must admit that as context user I seldom give attention to this
> low level questions.
> I was surprised by the mail of Dirk, because I have not  accented
> characters, but an error
>
> ! Argument of \\ has an extra }.

That's what I have too. Don't know where Dirk's accent comes from, I 
suspect there's a misunderstanding.

> \directlua{ tex.print("\TeX") }
> gives  the meaning of
> the \TeX macro, i.e
> Tkern -.1667emlower .5exhbox Ekern -.125emX

Yes, that's what I've said above, but here escape characters aren't 
ignored (as in your version with [=[...]=]), so Lua processes a string 
with things like "\k", which doesn't make sense (unlike e.g. "\n"), and 
is apparently normalized to "k".

Best,
Paul


More information about the luatex mailing list