[Tex/LaTex] Practical use of Lua

lua

Although I always use LuaLaTeX to compile my documents, I don't really use Lua that often. Sometimes I even forget about it.

In my last document I used it to write a random word generator, which picks a word from a pool of words. Which can be really helpful in many different documents and circumstances. I came up with this code in another question, but I will repost it here, if someone wants to use it.

So today I asked myself, what are some other good uses for Lua in TeX documents? And here we go, now it's your turn to post your ideas.


Thanks for all the great answers. There are some great ideas, and I certainly can put them to good use in my own documents (and other users aswell, I guess 🙂 ). In my opinion, every answer deserves the check mark, so I guess I will let the community decide and choose the one with the most upvotes.

That of course doesn't mean you have to stop posting your awesome ideas 😉

Best Answer

LaTeX can not do all things you might want to typeset. Sometimes you might need the power of another (scripting) language. You are free to use Perl, PHP, bash scripts or what ever. But the main advantage of Lua is very simple - it's available. On all supported platforms. No need for the user to install anything else!

In my getmap package, I use a Lua script to connect web servers to download maps:

enter image description here

% compile with pdflatex -shell-escape
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{graphicx}
\usepackage{filecontents}
% use overwrite while optimizing the image
\usepackage[overwrite,mode=gm]{getmap}
\begin{document}
\begin{filecontents*}{berlin.epl}
&path=weight:5|color:purple|enc:_xq_IcgrpA?AFE@?^BFE@A^U@CLQXEZU?gCR?B?DBF@@?vA?D?D?BAHE@JBN@JLGFCG[DC~C?@?F?R?vA?p@iB@i@Fe@JWRSTOf@Gh@C^A?e@?gE?w@r@?lB@hA?`@??M?aA?]dI??O?O?Cn@cBfBeF|AeEHNVNBc@H@H_AEwA?OAMNA@N
\end{filecontents*}
\getmap[file=berlin, language=de, xsize=400, ysize=600,
        markers={&markers=size:mid|label:H|color:green|Berlin, Hbf
                 &markers=label:B|color:blue|Brandenburger Tor, Berlin},
        pathfile={berlin.epl}]{}
\includegraphics[width=6cm]{berlin}
\end{document}

The route was exported into a gpx file and converted to encoded polylines (Google's route format) by the very same Lua script:

getmapdl -m gpx2epl -G berlin.gpx

So, from my point of view, the embedded Lua interpreter opens new horizons!

Related Question