TeX and Typst: Layout Models (2024)
laurmaedje.github.io
laurmaedje.github.io
* TeX's boxes-and-glue-and-penalties model is remarkably simple and flexible, as the author says. I've long been planning to write a post about this; the Knuth–Plass paper has some beautiful examples of how much you can cleverly achieve with such simple primitives. Really a model of elegance.
* This simplicity allows some ingenious solutions. With TeX (especially LuaTeX) one can do things that require knowledge of where on what page a paragraph is on: see for example this "demo" of mine: https://tex.stackexchange.com/a/403353 — of course one is fighting the system to some extent, but it is possible.
* Of the three “Challenges” it discusses, the first two “Varying container width” and “Side-floating elements” are both examples of things that are possible in TeX with caveats (parshape and wrapfig), but currently not possible in Typst — would be nice to see those limitations removed in Typst in a clean way.
* In the TeX world, note that there is Martin Ruckert's ongoing HINT project, which moves some of the TeX layout to the client (custom viewer), and thus supports arbitrarily varying widths (really cool to read a hint "book" on a phone): https://hint.userweb.mwn.de/#:~:text=TEX-,HINT,-%2C%20follow... (demo videos here: https://hint.userweb.mwn.de/hint/video/ and articles in TUGboat: https://tug.org/TUGboat/Contents/listauthor.html#Ruckert,Mar... )
On the whole, happy to see this post and that more attention is getting paid to text layout.
The margin calculations can definitely be improved, but in order to swap typesetting systems I need to be able to do at least this much (including the TikZ/PGF rendering for the images).
One of the other easy ways to overcome it is to provide as many templates as possible for journals. I’ve used LaTeX for years, but would by no means consider myself an expert in LaTeX, as I’ve almost exclusively been able to grab a template from a journal or from my university, and then just draft in the relevant blocks, write equations, add figures, and, rarely, add a package. I would guess that there are a huge amount of LaTeX users like me out there. I do all my drafting on Overleaf. I love TeX (and curse my PI whenever he requires that we use Word/365 instead of LaTeX/Overleaf)… but so much of the benefit, for me at least, comes from the fact that templates are readily available for any journal I would want to submit to; my masters thesis was built in a template provided by my university; etc. I don’t have to deal with any of the cognitive overhead of styling and formatting (except for flowing the occasional figure) and can just focus on drafting.
For me to even consider typst, it’s pretty much a requirement that there is some degree of template parity actively being worked on. The most natural way to approach that would be to just sort every journal by impact factor and start working top to bottom; given that so many journals share templates due to being within elsevier, springer etc, it should be straightforward to reach a reasonable degree of parity relatively quickly.
Getting the major publishers to support and offer their Typst templates would make me try it out immediately for what it’s worth.
Don't forget that many LaTeX packages exist solely because TeX and LaTeX suck and they are very underengineered save-the-day type of languages. They survived since everybody else asked money for their better typesetting systems. It is quite similar to how Unix and Unix-like systems survived despite the mountains of OS research and many new, more secure (usually paid) OS implementations.
One wonders why LaTeX has many users?Larger userbase can easily explained by being free. Students and PhDs usually don't have extra money to buy or nowadays rent Indesign but LaTeX is there for free. It doesn't mean it is technically superior or nice to use.
It does if one is doing typesetting math-heavy documents. Nothing really matches TeX quality or flexibility in math typesetting, not even typst (yet, at least).
But if there is no available template for the venues where I publish (in my case mostly conferences, although also some journals) it's not feasible for me to replace it. Maybe I could for slide presentations, posters or other documents that I design from scratch, but I'd say that's no more than 20% of the time I spend with LaTeX. The majority of the time I'm working with conference or journal templates.
> I want to use this post to explore these differences, to identify the benefits and limitations of both models, and to present my thinking on the future of Typst’s layout engine.
Which immediately made me think the author of the post was involved in Typst development.
That used to be the way blogs work, just written for a broad, unknown audience, but these days most blogs are written with a specific audience in mind, often one that knows the author reasonably well. Sometimes the blog is even just a secondary place to have an archive of the post, the main intended place being a post on a close-knit forum.
Once you take away the assumption that you're the intended audience, it's much easier to see the article - and the things it says and doesn't explicitly say - in a clearer light.
PDF has recently implemented a limited reflow feature by marking up text elements with metadata tags originally introduced to add accessibility features, hints for text to speech...
Meanwhile, Amazon has moved new books and user-submitted documents from its own Kindle format to ePub.
ePub is the e-book standard format that extends a subset of HTML.
Web browser teams have been hurling themselves against the walls of nearly-intractable layout cases for decades now.
We take it for granted: on your Kindle e-ink reader, change the font size. Boom: the whole book has to re-compute its layout.
Typst is far more computationally efficient, even elegant, but as yet it can't flow text around embedded sidebars or images.
As for myself I've completely abandoned LaTeX for Typst and couldn't be happier. My life will be better if I never have to touch LaTeX again. (Have written almost a dozen books with LaTeX.)
Interestingly, classical CSS had a similar limitation, that height is determined by content size, leading practitioners to search for the Holy Grail [1].
For documents whose source is likely to be shared or handed over to other people, writing in TeX rather than expecting them to learn a new language is still good citizenship.
The big differences for me are:
(1) TeX has the feeling of separating the author and editor, I get to write my stuff and someone else (Elsevier etc.) handles the template and layout. This is a good thing when the two are actually different people, but when I'm asked to do both ("write this up in the style of that") there's a whole lot of Yak Shaving to get it right. For Typst it's much more intuitive to say here's the page layout, this is the font to use. (yes XeTeX exists, but that has other problems over here)
(2) TeX ends up in dependency hell sooner or later where package X is incompatible with Y when you've also loaded Z. There's a lot in the comprehensive LaTeX symbol list where you just want to load some symbol to draw a triangle and you end up fighting the Type1/Type3 fonts thing and getting stmaryrd to play nice. I still don't have a clean solution for making some basic shapes (circle, triangles pointing in several directions, square, diamond) that come in outline and filled versions and take up space exactly from the baseline to the cap line (I could probably live with just the x-height instead).
Conversely, my entire interest in Typst is have an input format more efficiently read by AI. We've passed the inflection point where one can responsibly only write for humans.
Typst is Markdown-adjacent, while PreTeXT is XML-adjacent. More characters but even easier for AI to process. I'd switch for the HTML and ePub support, but no syntax coloring for code blocks?
Do you really want to wait for humans to reprogram air traffic control software unassisted, with no formal correctness guarantees?
Your attitude is fine if you plan to walk everywhere.
I view Typst on the high-end of software that can encourage more people who are into the "arts" or "humanities" into coding.
I used it once to typeset a booklet and had a lot of fun. One of the benefits of it being new and having an engaged community and being just fun to use is that I got to explore different workarounds to achieve certain layouts, learning more about how it works along the way.
Troff is lots of fun too.