3 ms·
It appears the largest benefits is embedding Lua code into TeX (found at [1] in "Programmability"). The example they present from that page: \documentclas
by skierscott 9y ago
It appears the largest benefits is embedding Lua code into TeX (found at [1] in "Programmability").
The example they present from that page:
\documentclass{article}
\usepackage{luacode}
\begin{document}
\pagestyle{empty}
\begin{luacode*}
function esn (n)
return (1 + 1/n)^n
end
function etn (n)
tex.print(string.format('%5d & %1.8f \\\\', n, esn(n)))
end
\end{luacode*}
Convergence to $e$:
\begin{tabular}{ll}
\rule[-2mm]{0pt}{4mm}$n$ & $(1 + \frac{1}{n})^n$ \\
\hline
\luadirect{
for n = 10, 110, 10 do
tex.print(etn(n))
end
}
\hline
\end{tabular}
\end{document}
which allows a pretty table to be printed in the document.
- leephillips 9y agoThis is from my 2015 article at https://lwn.net/Articles/657157/ https://lwn.net/Articles/657157/
- skierscott 9y agoWhoops -- thanks for that! I forgot to give that link but meant to.
- svat 9y agoThat one simply inserts Lua code into TeX, and it's definitely a benefit (alternative to complicated macros). IMO an even bigger benefit (not yet widely used) are the various hooks and callbacks that LuaTeX provides -- you can influence the operation of TeX by writing some callback code in Lua at the right layer, instead of having to write everything in the input layer as macros to be expanded so that things are set up for later when TeX rolls around to do the thing you care about. This also results in cleaner code (even beyond Lua being more readable than TeX macros), and smaller/faster code as you don't have to account for as many different kinds of things in your "input". The "fade lines" callback example in the linked article is a good one. Here's another example of mine (not a great one) where you can influence TeX's linebreaking algorithm to avoid short words at line boundaries: https://tex.stackexchange.com/questions/378704/how-to-avoid-line-breaks-that-result-in-short-words-at-line-edges/379802#379802 https://tex.stackexchange.com/questions/378704/how-to-avoid-... -- the solution with macros is not so great.
- leephillips 9y agoThat's brilliant - thanks for sharing that.