[luatex] lua script on the run

Philipp Stephani st_philipp at yahoo.de
Thu Jan 6 13:05:05 CET 2011


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")
\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}


More information about the luatex mailing list