TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

LuaTeX Comes of Age (2017)

134 pointsby goranmoominover 3 years ago

9 comments

svatover 3 years 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).<p>With other TeX engines (mainly: pdfTeX, XeTeX, or the original Knuth TeX), the only &quot;programming&quot; 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&#x27;t take much to become &quot;accidentally Turing-complete&quot;, and that&#x27;s what TeX macros became. (There&#x27;s also some rudimentary support for counters&#x2F;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&#x27;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.<p>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.<p>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&#x2F;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&#x27;d of course have used it in TeX — I think Lua would count.<p>You can see &quot;TeX without TeX&quot; page on the LuaTeX wiki for an example of the power of LuaTeX, typesetting with TeX while completely bypassing TeX syntax: <a href="http:&#x2F;&#x2F;wiki.luatex.org&#x2F;index.php&#x2F;TeX_without_TeX" rel="nofollow">http:&#x2F;&#x2F;wiki.luatex.org&#x2F;index.php&#x2F;TeX_without_TeX</a> — a more elaborate production system is Speedata Publisher: <a href="https:&#x2F;&#x2F;github.com&#x2F;speedata&#x2F;publisher" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;speedata&#x2F;publisher</a><p>As for myself, here is the most fancy thing I did with LuaTeX: <a href="https:&#x2F;&#x2F;tex.stackexchange.com&#x2F;questions&#x2F;401604&#x2F;book-on-a-single-poster-page&#x2F;403353#403353" rel="nofollow">https:&#x2F;&#x2F;tex.stackexchange.com&#x2F;questions&#x2F;401604&#x2F;book-on-a-sin...</a> (a &quot;poster&quot; of Kafka&#x27;s Metamorphosis done just for that answer, never &quot;productionized&quot; into a package or whatever). Also, something possibly illuminating is this TeX-vs-LuaTeX comparison of something hyphenation-related (<a href="https:&#x2F;&#x2F;tex.stackexchange.com&#x2F;questions&#x2F;378704&#x2F;how-to-avoid-line-breaks-that-result-in-short-words-at-line-edges&#x2F;379802#379802" rel="nofollow">https:&#x2F;&#x2F;tex.stackexchange.com&#x2F;questions&#x2F;378704&#x2F;how-to-avoid-...</a>), and in this answer (<a href="https:&#x2F;&#x2F;tex.stackexchange.com&#x2F;questions&#x2F;398310&#x2F;why-in-2017-does-latex-not-use-tree-like-structures&#x2F;398372#398372" rel="nofollow">https:&#x2F;&#x2F;tex.stackexchange.com&#x2F;questions&#x2F;398310&#x2F;why-in-2017-d...</a>) 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 (<a href="https:&#x2F;&#x2F;tex.stackexchange.com&#x2F;questions&#x2F;367902&#x2F;tikz-color-option-for-edges-without-effect&#x2F;367905#367905" rel="nofollow">https:&#x2F;&#x2F;tex.stackexchange.com&#x2F;questions&#x2F;367902&#x2F;tikz-color-op...</a>).
评论 #29715286 未加载
评论 #29715311 未加载
评论 #29718250 未加载
lou1306over 3 years ago
&quot;Modern&quot; TeX processors (LuaTeX or XeTeX) are sadly held back because publishers still cling to PDFLaTex. For instance, ArXiV &quot;fully supports and automatically recognizes PDFLaTeX&quot; and makes no mention of other backends [0].<p>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.<p>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...<p>[0]: <a href="https:&#x2F;&#x2F;arxiv.org&#x2F;help&#x2F;submit_tex" rel="nofollow">https:&#x2F;&#x2F;arxiv.org&#x2F;help&#x2F;submit_tex</a><p>[1]: <a href="https:&#x2F;&#x2F;tug.org&#x2F;pipermail&#x2F;luatex&#x2F;2016-September&#x2F;006201.html" rel="nofollow">https:&#x2F;&#x2F;tug.org&#x2F;pipermail&#x2F;luatex&#x2F;2016-September&#x2F;006201.html</a>
thangalinover 3 years ago
ConTeXt[1] has had Lua integrated since around 2009[2]. KeenWrite[3], the text editor that I&#x27;m developing, converts Markdown documents to XML, then can call ConTeXt with a given theme[4] to typeset the document. This allows for complete separation of content from presentation, as described in my Typesetting Markdown series, in which part 8 briefly touches upon Lua[5].<p>[1]: <a href="https:&#x2F;&#x2F;wiki.contextgarden.net&#x2F;Installation" rel="nofollow">https:&#x2F;&#x2F;wiki.contextgarden.net&#x2F;Installation</a><p>[2]: <a href="https:&#x2F;&#x2F;tug.org&#x2F;TUGboat&#x2F;tb40-1&#x2F;tb124hagen-lmtx.pdf" rel="nofollow">https:&#x2F;&#x2F;tug.org&#x2F;TUGboat&#x2F;tb40-1&#x2F;tb124hagen-lmtx.pdf</a><p>[3]: <a href="https:&#x2F;&#x2F;github.com&#x2F;DaveJarvis&#x2F;keenwrite" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;DaveJarvis&#x2F;keenwrite</a><p>[4]: <a href="https:&#x2F;&#x2F;github.com&#x2F;DaveJarvis&#x2F;keenwrite-themes&#x2F;" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;DaveJarvis&#x2F;keenwrite-themes&#x2F;</a><p>[5]: <a href="https:&#x2F;&#x2F;dave.autonoma.ca&#x2F;blog&#x2F;2020&#x2F;04&#x2F;28&#x2F;typesetting-markdown-part-8&#x2F;" rel="nofollow">https:&#x2F;&#x2F;dave.autonoma.ca&#x2F;blog&#x2F;2020&#x2F;04&#x2F;28&#x2F;typesetting-markdow...</a>
评论 #29716528 未加载
strenholmeover 3 years ago
The linked LWN article mentions that it’s difficult to put comments in inline LuaTeX macros because those macros remove newlines.<p>To add a comment to the middle of a line in Lua, use the --[[ comment ]] form:<p><pre><code> a = 1 --[[ Set a to 1 ]] print(a) </code></pre> If we have a comment that has ]] in it, we can do this instead:<p><pre><code> a = 1 --[=[ We love [[brackets]] a lot ]=] print(a) </code></pre> The --[[ (or --[=[ ) form also works for multi-line comments<p><pre><code> 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)</code></pre>
amichailover 3 years ago
Here&#x27;s something better that doesn&#x27;t use TeX and is fully WYSIWYG:<p><a href="http:&#x2F;&#x2F;texmacs.org&#x2F;tmweb&#x2F;home&#x2F;videos.en.html" rel="nofollow">http:&#x2F;&#x2F;texmacs.org&#x2F;tmweb&#x2F;home&#x2F;videos.en.html</a>
评论 #29713568 未加载
评论 #29714230 未加载
coliveiraover 3 years ago
LuaTeX is another way to create LaTeX macros, but using Lua as the language to manipulate text. I think it helps create macros that would be too complicated in TeX, but on the other hand it is another language for LaTeX users to learn. I haven&#x27;t see much advantage of their approach other than in specialized niches such as creating complex figures.
评论 #29714204 未加载
评论 #29714143 未加载
dangover 3 years ago
Discussed at the time:<p><i>LuaTeX Comes of Age</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=15146300" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=15146300</a> - Sept 2017 (28 comments)
dhosekover 3 years ago
LuaTeX has some small differences from TeX that are not present in pdfTeX or XeTeX that I find really annoying. Most notably, it will <i>not</i> break lines after – or — (whether entered as Unicode or with traditional TeX input using -- or ---). And the slowness is on pretty much all documents. It also does some weird mapping of character codes in generating the pdf files that should be invisible to most users but is evident if one digs into the output files. It could cause issues in malformed pdf readers although as far as I know this isn&#x27;t an issue. Unless someone specifically needs Lua, it&#x27;s hard to recommend LuaTeX over XeTeX.
评论 #29715129 未加载
OtomotOover 3 years ago
The article is from 2017.<p>Would be great if that could be added to the headline here.