[luatex] lua script on the run

Arno Trautmann Arno.Trautmann at gmx.de
Thu Jan 6 13:10:21 CET 2011


Philipp Stephani wrote:
> 
> Am 06.01.2011 um 11:41 schrieb Arno Trautmann:
> 
>> Philipp Stephani wrote:
>>>
>>> […]
>>>> \texperanto{Alportu ^caron de sopiro!}
>>>>
>>>> And LuaTeX actually typesets "Alportu ĉaron de sopiro!"
>>>
>>> If you only need simple textual replacements, you can get quite far with Lua's built-in functions:
>>>
>>> \documentclass{minimal}
>>> \usepackage{fontspec}
>>> \usepackage{luacode}
>>> \begin{luacode*}
>>> function texperanto(text)
>>>   tex.sprint((text:gsub("%^c", "ĉ")))
>>> end
>>> \end{luacode*}
>>> \newcommand*{\texperanto}[1]{\luadirect{texperanto([[#1]])}}
>>> \setmainfont{DejaVu Sans}
>>> \begin{document}
>>> \texperanto{Alportu ^caron de sopiro!}
>>> \end{document}
>>
>> These solutions (Patrick's, Paul's and yours) are nice, but how would
>> one apply it to a whole document?
> 
> \documentclass{article}
> \usepackage{fontspec}
> \usepackage{luatextra}
> \begin{luacode*}
>   local function texperanto(text)
>     result = text:gsub("%^c", "ĉ")
>     return result
>   end
>   luatexbase.add_to_callback("process_input_buffer", texperanto, "texperanto")

nice :)
I totallay forgot about that callback … (ok, I've only once read that it
exists …)

> \end{luacode*}
> \setmainfont{DejaVu Sans}
> \begin{document}
> Alportu ^caron de sopiro!
> Warning: This is a literal translation of the whole input, including math,
> macros, \string^\string^-escapes, and everything else, so the following doesn’t
> work any more: $b^c$—use $b\sp c$ or $b\luatexUsuperscript c$ instead.
> \end{document}

Can this anyhow be constrained to text-only input? E.g. scanning for
math tokens in the texperanto function to ignore math input?

cheers
Arno

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <http://tug.org/pipermail/luatex/attachments/20110106/c9bd48f1/attachment.bin>


More information about the luatex mailing list