Subject: | |
From: | |
Reply To: | |
Date: | Tue, 19 Aug 2014 19:21:00 +0200 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
On 19.08.2014 19:00, Stephan Hennig wrote:
> Hi,
>
> I'm observing differences in the handling of \directlua between LaTeX2e
> and LaTeX3 (in LaTeX2e). Compiling this example
>
> \listfiles
> \documentclass{article}
> \usepackage{expl3}
> \newcommand*{\mymacro}{Hello World!}
> \directlua{
> local myarg = '\mymacro'
> texio.write_nl('l2: argument is ' .. tostring(myarg))
> }
> \ExplSyntaxOn
> \directlua{
> local myarg = '\mymacro'
> texio.write_nl('l3: argument is ' .. tostring(myarg))
> }
> \ExplSyntaxOff
> \begin{document}
> \end{document}
>
> with lualatex, the output is
>
> l2: argument is Hello World!
> l3:argumentisnil
>
> First, spaces are gone in Lua code. Though, spaces are significant in Lua.
`\ExplSyntaxOn' says that spaces are gone, that's the purpose of this
command. Explicit spaces are available via `~':
\directlua{
local~myarg = '\mymacro'
texio.write_nl('l3:~argument~is~' .. tostring(myarg))
}
> Second, variable myarg is nil with \ExplSyntaxOn. (I don't understand why.)
Without spaces you get:
localmyarg='\mymacro'
This defines "localmyarg" globally instead of "myarg".
BTW, this is quite a risky way to pass the contents of user variables ot
Lua code. Consider syntax errors, if "\mymacro" contains ', or
"\mymacro" could even contain containing something like:
'; very evil code; local dummy='
There is \luaescapestring/\luatexluaescapestring:
'\luatexluaescapestring{\mymacro}'
Yours sincerely
Heiko Oberdiek
|
|
|