LuaTeX Comes of Age (2017)
lwn.net
lwn.net
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 — a more elaborate production system is 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-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-...), and in this answer (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-op...).
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.
Very little of the TeX implementation has been rewritten in Lua. (Assuming you're talking of LuaTeX itself and not the "TeX without TeX" wiki page, which is just for demonstration.) LuaTeX starts with the WEB (Pascal) code of TeX, manually translated into C (see e.g. https://tug.org/TUGboat/tb30-3/tb96hoekwater-pascal.pdf), and, additionally, hooks are added: callbacks that can be written in Lua, and which have access to the internal data structures.
(By the way, SILE is a separate typesetting system (unrelated to TeX) that is actually written in Lua, and re-implements some of the TeX algorithms in Lua, I think. You can see this talk by its author about it: https://www.youtube.com/watch?v=5BIP_N9qQm4 )
This triggered my obligatory rant that Lisp doesn't require s-expressions, there are a bunch of equivalent alternatives, and indeed the entire point of s-expressions is that they're trivial to generate, parse and manipulate automatically (if you don't want to write them manually).
I personally find Lua to be a completely sane and easy to program language. But, to each their own.
Let’s look at these options and some others:
Scheme/Lisp: It’s true that Scheme and Lisp-like languages are pretty compact and easy to embed, but the syntax of Lisp is, for most modern programmers, pretty esoteric. Asking today’s programmers to program in a Lisp is, for better or worse, like asking secretaries to use Vi to edit documents.
Python: Python is a big, bulky language and one which is not really suitable for embedding inside another program. See this recent discussion for more on this: https://news.ycombinator.com/item?id=29700947
Julia: A somewhat non-mainstream language, and, like Python, it doesn’t look to be a language designed for embedding the way Lua is.
Forth: Like Lisp dialects, Forth’s completely stack-based syntax is not intuitive for today’s generation of programmers.
Lua needs batteries, which I know is off putting to some programmers. It turned me off from Lua for a while until Roblox made me give Lua a second chance. Here is my own set of public domain Lua batteries: https://github.com/samboy/LUAstuff (stuff like a Lua copy.deepcopy(), sorted table/dictionary iteration, split strings based on a regex, etc.)
So, LuaTeX is perfectly fine for personal stuff that you can compile in-house, but basically nobody wants to risk using it in any scenarios where sources are to be sent to a 3rd party for compilation, only to find out that they need to make them PDFLaTeX-compatible.
And after all LuaTeX came out of beta in 2016 [1], which is pretty recent in TeX-years. So it kind of makes sense that publishers still prefer the quite battle-tested PDFLaTeX...
[0]: https://arxiv.org/help/submit_tex
[1]: https://tug.org/pipermail/luatex/2016-September/006201.html
[1]: https://wiki.contextgarden.net/Installation
[2]: https://tug.org/TUGboat/tb40-1/tb124hagen-lmtx.pdf
[3]: https://github.com/DaveJarvis/keenwrite
[4]: https://github.com/DaveJarvis/keenwrite-themes/
[5]: https://dave.autonoma.ca/blog/2020/04/28/typesetting-markdow...
To add a comment to the middle of a line in Lua, use the --[[ comment ]] form:
a = 1 --[[ Set a to 1 ]] print(a)
If we have a comment that has ]] in it, we can do this instead: a = 1 --[=[ We love [[brackets]] a lot ]=] print(a)
The --[[ (or --[=[ ) form also works for multi-line comments a = 1 --[[ Lorem ipsum dolor sit amet, consectetur
adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Dictum fusce ut placerat
orci nulla pellentesque dignissim. Quam viverra orci
sagittis eu volutpat odio facilisis mauris. ]] print (a)> That which can be asserted without evidence, can be dismissed without evidence.
Lua is a somewhat odd but perfectly sane language that you can pick up in a day. With a few hooks into TeX you can be writing complex programs that manipulate your document, insert the result of calculations into the text, etc. Writing these things in TeX is insanely difficult. I’ve been using TeX literally since it became available, and I wouldn’t dare try to write anything complicated in TeX the programming language. But Lua is a breeze.
Because of this I’m a bit surprised that I haven’t seen more. One big application is the layout algorithm for network diagrams in tikz.
On the other hand, if you're just manipulating text that doesn't interface with LaTeX, then you could really do that from outside LaTeX, using any kind of script language such as python or perl. That's why I think that Lua scripting is not being used outside of some niche areas.
My company is using their own LuaLaTeX class extensively to produce hundreds, if not thousands of reports per year, and features like automatically computing the CVSS base score of a CVSS vector will take a couple of minutes in lua, while it will cost you several days and a bunch of gray hairs to do in TeX. It's only the developer who has to know any lua though. It's completely transparent to the user.
LuaTeX Comes of Age - https://news.ycombinator.com/item?id=15146300 - Sept 2017 (28 comments)
\hsize 0pt
abc--def
\bye
I also don't know what kind of weird remapping you are talking about, if you are referring to the Unicode mapping then they are required to get proper copy&paste (and are also generated by other engines these days).Would be great if that could be added to the headline here.