[texhax] \directlua in LuaLaTeX

Arno Trautmann Arno.Trautmann at gmx.de
Mon Feb 8 13:57:47 CET 2010

Ulrike Fischer wrote:
> Am Thu, 04 Feb 2010 23:33:25 +0100 schrieb Arno Trautmann:
>> I was playing around a bit with LuaLaTeX (from TeXlive2009) and tried to
>> execute TeX code in a \directlua{tex.print()}.
>> The LuaTeX manual shows the following example (of course without the
>> LaTeX-stuff, only line 3):
>> \documentclass{minimal}
>> \begin{document}
>> before\directlua{tex.sprint("\\relax")tex.sprint(" inbetween")}after
>> \end{document}
>> But if I compile this with lualatex, I get a big heap of errors starting
>> with
>> ! Undefined control sequence.
>> \\  ->\let \reserved at e
>>                        \relax \let \reserved at f \relax \@ifstar {\let
>> \reserv...
>> l.4 before\directlua{tex.sprint("\\
>>                                    relax")tex.sprint(" inbetween")}after
>> So … I don’t understand where the problem comes from and how to
>> interpret these errors. I assume there is a problem that \directlua
>> expands all the TeX code directly and that this might clash anyhow with
>> a \protect. But no idea why this is evil …
>> Can anybody help me understanding this behaviour?
> The following
> seems to work (but my luatex is rather old, version 0.39)
> \documentclass{minimal}
> \begin{document}
> before\directlua{tex.sprint("\string\\relax")tex.sprint("
> inbetween")}after

Thank you very much for this, it does work for me (\string\\color{red}
is fine, too, as I want to change the color this way).

> before\directlua{tex.sprint("\luaescapestring{\relax}")tex.sprint("
> inbetween")}after
> \end{document}

This does work, too, but not with \color:


raises the error:

) (/home/texlive09/texmf-dist/tex/context/base/supp-pdf.mkii
! TeX capacity exceeded, sorry [input stack size=5000].
\@@mpstopdf@@unprotect ... \@@mpstopdf@@unprotect
                                                  \unprotect \let
l.34     \def\unprotect

Again, I have no idea what causes the problem …
Is there any possibility to pass code from lua to TeX without expanding
it right away? I think that could solve some problems.


More information about the texhax mailing list