[luatex] lua script on the run
Paul Isambert
zappathustra at free.fr
Thu Jan 6 22:42:07 CET 2011
Le 06/01/2011 22:23, Philipp Stephani a écrit :
> Am 06.01.2011 um 21:05 schrieb Paul Isambert:
>
>> 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,
> In this example it is necessary because otherwise you get errors (but only because I used ^b and other unmodified sequences to test the functions)
>
Indeed, I didn't see that, sorry.
>>>> 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.
> But making ^ active disables ^^-escapes:
>
> \def\normalcircumflex{^}
> \edef\twonormalcircumflexes{\normalcircumflex\normalcircumflex}
> \catcode`\^=\active
> \def^{\futurelet\next\dotexperanto}
> \def\dotexperanto{%
> \ifx\next g%
> \let\next\dodotexperanto
> \else
> \ifx\next^%
> \let\next\twonormalcircumflexes
> \else
> \let\next\normalcircumflex
> \fi
> \fi
> \next
> }
> \def\dodotexperanto#1{\^#1}
> g ^g h
> ^^J
> \bye
Oh yes, that is a very bad idea to change the catcode of "^" that way.
What I meant was enclosing it in the \texperanto macro.
Best,
Paul
More information about the luatex
mailing list