[luatex] lua script on the run

Paul Isambert zappathustra at free.fr
Wed Jan 5 22:28:35 CET 2011


Le 05/01/2011 22:19, Patrick Gundlach a écrit :
>
>> but I was thinking about defining a command like, say,
>> \texperanto, which performs a conversion of its argument on the fly,
>> so that I may write
>>
>> \texperanto{Alportu ^caron de sopiro!}
>>
>> And LuaTeX actually typesets "Alportu ĉaron de sopiro!"
> ------------------------------------------------
> \def\texperanto#1{\directlua{
>    local str = string.gsub("#1","\%^c","ĉ")
>    tex.print(str)
> }}
>
> \catcode`\^=11
>
> \texperanto{Alportu ^caron de sopiro!}
>
> \bye

As indicated by Patrick's code (where the catcode change is 
unnecessary), your task is no big deal: string.gsub can indeed handle 
it, and you want to read the Lua manual on string manipulation 
(http://www.lua.org/manual/5.1/manual.html#5.4). Two things are worth 
noting: string.gsub can also take (as its third arguments) tables and 
functions, which makes it much more powerful; and magic characters 
should be taken care of ("^" is one of them).

Best,
Paul


More information about the luatex mailing list