LATEX-L Archives

Mailing list for the LaTeX3 project


Options: Use Classic View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender: Mailing list for the LaTeX3 project <[log in to unmask]>
Date: Tue, 19 Aug 2014 19:21:00 +0200
Reply-To: Mailing list for the LaTeX3 project <[log in to unmask]>
Message-ID: <[log in to unmask]>
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
In-Reply-To: <[log in to unmask]>
Content-Type: text/plain; charset=ISO-8859-1
From: Heiko Oberdiek <[log in to unmask]>
Parts/Attachments: text/plain (58 lines)
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 `~':

  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:


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:


Yours sincerely
  Heiko Oberdiek