[luatex] % character in \directlua

Wolfgang Schuster schuster.wolfgang at googlemail.com
Sat Feb 19 11:41:41 CET 2011


Am 19.02.2011 um 01:10 schrieb Yannis Haralambous:

> Hi everybody, and sorry for my mailer: it gives me only two choices, either "text" (my current choice, believe it or not) or "rtf".
> 
> I'm writing to ask whether there is a more elegant way to use a % in a \directlua argument (I need the Lua modulo operator)
> besides changing the catcode of % to 12 around the \directlua command:
> 
> \begingroup
> \catcode`\%=12
> \directlua{texio.write(5 % 2)}
> \endgroup
> 
> I have tried \%, \string%, nothing works besides the code above.


As plain TeX user you can write your own command:

\def\luacode
  {\begingroup
   \catcode`\%=12
   \doluacode}

\def\doluacode#1%
  {\endgroup
   \directlua{#1}}

\luacode{tex.sprint(string.format("%.2f",math.pi))}

\bye

ConTeXt already provides a command with the name \ctxluacode which does the same.

Wolfgang




More information about the luatex mailing list