5 ms·
LuaTeX is what TeX should have been from the start (and would have been, if the technology of the time had permitted it). Apart from modern font-handling and Un
by svat 5y ago
LuaTeX is what TeX should have been from the start (and would have been, if the technology of the time had permitted it). Apart from modern font-handling and Unicode, the main thing IMO is the hooks it provides (in the form of callbacks).
With other TeX engines (mainly: pdfTeX, XeTeX, or the original Knuth TeX), the only "programming" facility is in the form of macros, which were originally added by Knuth only for some simple text substitution to save typing. He never intended to add programming features into TeX, but of course, it doesn't take much to become "accidentally Turing-complete", and that's what TeX macros became. (There's also some rudimentary support for counters/registers, which IIRC Knuth added after he found users were (ab)using macros to encode numbers using unary or Church numerals.) So the only way to influence anything TeX does automatically, whether it's hyphenation or line-breaking or page-breaking or whatever, is to set up some macros whose blind expansion will ultimately—at a remove of several steps—result in the outcome you want, without affecting anything else (e.g. even an accidental space might get typeset, with undesirable results). This of course is cumbersome and error-prone.
With LuaTeX you can program these things at the level you actually intend, e.g. while you can still use macros (or use the `process_input_buffer` callback in Lua), you can now also directly, say, influence the page layout, in a Lua callback that is actually aware of data at the relevant level of abstraction (the vboxes on the page, say), rather than trying to do everything at the lowest (text expansion) level.
Knuth has said that he never intended for TeX macros to be used as a full-fledged programming language (he expected people would directly edit the SAIL/Pascal code of the TeX program for anything nontrivial), and that he dislikes each tool coming with its own Turing-complete programming language, and that if a standard embeddable programming language had been available he'd of course have used it in TeX — I think Lua would count.
You can see "TeX without TeX" page on the LuaTeX wiki for an example of the power of LuaTeX, typesetting with TeX while completely bypassing TeX syntax: http://wiki.luatex.org/index.php/TeX_without_TeX http://wiki.luatex.org/index.php/TeX_without_TeX — a more elaborate production system is Speedata Publisher: https://github.com/speedata/publisher https://github.com/speedata/publisher
As for myself, here is the most fancy thing I did with LuaTeX: https://tex.stackexchange.com/questions/401604/book-on-a-single-poster-page/403353#403353 https://tex.stackexchange.com/questions/401604/book-on-a-sin... (a "poster" of Kafka's Metamorphosis done just for that answer, never "productionized" into a package or whatever). Also, something possibly illuminating is this TeX-vs-LuaTeX comparison of something hyphenation-related (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-...), and in this answer (https://tex.stackexchange.com/questions/398310/why-in-2017-does-latex-not-use-tree-like-structures/398372#398372 https://tex.stackexchange.com/questions/398310/why-in-2017-d...) I link to some other times I used LuaTeX, though some of them just use the Lua part of LuaTeX rather than LuaTeX hooks, such as computing digits of pi for generating pretty pictures (https://tex.stackexchange.com/questions/367902/tikz-color-option-for-edges-without-effect/367905#367905 https://tex.stackexchange.com/questions/367902/tikz-color-op...).
- nsajko 5y ago> if a standard embeddable programming language had been available he'd of course have used it in TeX — I think Lua would count I agree with your general idea, but it is really a shame that Lua was chosen as the language to embed in TeX, instead of something sane like a Scheme, Common Lisp or at least Python (today, maybe Julia). Furthermore, the effort to rewrite as much of the TeX implementation as possible in Lua is perplexing.
- leephillips 5y agoJulia is a wildly inappropriate choice for embedding, and Python is not much better. Some implementation of Scheme might make more sense (isn’t that what Guile is about?). Except that most people are put off by s-expressions; Lua is comparatively “normal”.
- BeFlatXIII 5y agoIf you're not chasing market share for commercial purposes, do you really want to cater to those who are put off by s-expressions if you personally enjoy them?
- leephillips 5y agoProbably not. But I’m guessing that the people who created LuaTeX prefer Lua. And maybe, if you wanted to create a scriptable TeX that would be usable by the typical TeX user, a language like Lua makes more sense than a Lisp. Those users tend to be scientists and mathematicians, and just anyone who needs to make good-looking documents; most are not familiar with Lisp and would find it more difficult to learn than Lua.
- bccdee 5y agoIf you're making a tool for people to use, it's probably best to use a syntax that most people are comfortable with. UX doesn't only matter to corporations.
- chriswarbo 5y ago