[luatex] lua script on the run

Philipp Stephani st_philipp at yahoo.de
Wed Jan 5 22:43:20 CET 2011


Am 05.01.2011 um 21:52 schrieb Luis Rivera:

> Hello!
> 
> I am new to LuaTeX; so please, don't bite me!!!
> 
> I was wondering if it was possible to use some Lua code to make text
> conversions on the fly. More precisely, I was thinking about setting
> up a macro that swallows some text written in some ascii
> transliteration scheme, but actually feeds the typesetter with the
> right utf8 string, There are lua scripts that make conversions to
> update files with older transliteration schemes (take mtx-babel.lua as
> an example); 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!"

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}




More information about the luatex mailing list