[luatex] lua script on the run

Paul Isambert zappathustra at free.fr
Thu Jan 6 21:05:54 CET 2011

Le 06/01/2011 20:50, Philipp Stephani a écrit :
> Am 06.01.2011 um 20:06 schrieb Luis Rivera:
>> "tables and functions". So how would you set a table for the six
>> special characters of esperanto (^c, ^g, ^h, ^j, ^s, ^u)?
> \catcode`\^=12
> \begingroup
> \catcode`\%=12
> \gdef\percentchar{%}
> \endgroup
> \directlua{%
>    local translate = {
>      c = "ĉ",
>      g = "ĝ",
>      h = "ĥ",
>      j = "ĵ",
>      s = "ŝ",
>      u = "û"
>    }
>    function texperanto(text)
>      result = text:gsub("\percentchar^(\percentchar a)", translate)
>      tex.sprint(result)
>    end
> }
> \def\texperanto#1{\directlua{texperanto([[#1]])}}
> \input luaotfload.sty
> \font\rm={name:DejaVu Sans:}\relax
> \rm
> \texperanto{^a ^b ^c ^d ^e ^f ^g ^h ^i ^j ^s ^u}
> \bye

A small simplification: again, the catcode change for "^" is 
unnecessary, and you could as well use \direclua in the group and use 
"%" as is (i.e. without \percentchar), since \directlua is immune to TeX 

>> I thought of a macro package independent solution. This one works for
>> LuaLaTeX, but Patrick's should also work for plain LuaTeX.
> of course that's possible, but a bit more awkward since you have to e.g. escape percent characters. "macro package independence" is even harder with LuaTeX than with pdfTeX, since you need lots of external packages to e.g. load fonts. Luaotfload works with LaTeX and plain, but probably not with ConTeXt, which is completely different anyway.

Luaotfload should work with ConTeXt, since the code is ConTeXt's code. 
And format-independance should be enforced as often as possible (a 
personal hobby): when it comes to Lua, it's rather easy, since Lua code 
doesn't give a damn about formats (unless you use format-dependant Lua 
function, that is).

>> What occurs to me is to use a babel-like solution: make ^ active in
>> textual context, and define it in terms of Lua functions so that it
>> may check the following character and apply a conversion on a match:
>> otherwise, typeset the original two character string.
> Never do this if you have LuaTeX, it is completely obsolete and causes many issues. If you are sure to run on LuaTeX, do everything in Lua, and avoid catcode changes and the like.

Indeed, the solution with catcodes would be ok with anything but LuaTeX, 
and you actually don't need any Lua function.


More information about the luatex mailing list