[luatex] Expansion of TeX macros

Dirk Laurie dirk.laurie at gmail.com
Thu May 31 23:36:24 CEST 2012


2012/5/31 Paul Isambert <zappathustra at free.fr>:

>>
>> use it this way:
>>
>>   \[ \mat{\string\\mathbf{x},0,0;0,1,2} \]
>>
>> you have to escape the backslash
>
> That or you can redefine \mat as:
>
> \newcommand\mat[1]{%
>  \directlua{tex.print(tomatrix("\luatexluaescapestring{\detokenize{#1}}"))}%
>  }
>
Thanks, that is what I was looking for.  Simplest possible syntax
in the user-level file.

> Also, the following lines in the Lua code:
>
>  str = str:gsub("%;",[[\\]])
>  str= str:gsub("%,",[[&]])
>
> have unnecessary "%" (meant to escape magic characters; the comma and
> semi-colon aren't magic).
Point taken; I was too lazy to RTFM.

> They can be rewritten as:
>
>  str = str:gsub ("[,;]", {[","] = "&",
>                           [";"] = [[\\]]} )
>
I don't like this.  It requires a table access on every hit.
I've tested it with this standalone code:

str=string.rep(",;",1000000)
for k=1,10 do
   local t
   t=str:gsub("%,",[[&]]); t=t:gsub("%;",[[\\]])
--   t=str:gsub("[,;]", {[","] = "&",[";"] = [[\\]]})
   end

This way, `luatex test.lua` runs in 2.9s on my laptop.
Moving the comment to the other "t=" line runs in 4.3s.
Granted, for the matrix size in my TeX source it's not
going to matter.



More information about the luatex mailing list