LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Forum View

Use Proportional Font
Show HTML Part by Default
Show All Mail Headers

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

Print Reply
Subject:
From:
Heiko Oberdiek <[log in to unmask]>
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Date:
Tue, 19 Aug 2014 19:21:00 +0200
Content-Type:
text/plain
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 `~':

\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

ATOM RSS1 RSS2