by mr-karan · 1y ago · 0 comments
Our previous pipeline was LaTeX-based (first pdflatex, then lualatex), but we were constantly fighting cryptic memory errors on large documents and huge Docker image sizes that slowed down boot times of our ephemeral workers.
Switching to Typst was a massive win for us. The single static binary resulted in tiny images and faster boot times. More importantly, the performance gains were huge. Overall compile times were ~3–4× faster than LaTeX. On really large documents (2000+ pages, mostly tables), Typst compiles in ~1 minute vs. ~18 minutes with lualatex.
Beyond performance, the better developer experience and good error messages was a nice bonus too.
We wrote a detailed post about the entire architecture - from the job orchestration with Nomad to the S3 optimizations and the Typst migration in particular. If you're curious, you can read it here: https://zerodha.tech/blog/1-5-million-pdfs-in-25-minutes
Here are my most important requirements: Multiple columns configurable for meaningful column and page breaks (minimum number of lines in a new column or page). Reliable automatic hyphenation for multiple languages (at least English and German, perhaps French, Italian and Spanish in the future). Pictures in columns with dynamic placing according to the available space. Complex tables and forms with sensible automatic page breaks. Background images. Different areas on the page which are treated like mini-pages. -- Is Typst capable of all that?
If anyone here hasn't messed with it, but thinks "I wonder, if LaTex could ruin my life, too", I suggest to start learning pandoc first (it can do various markup conversions, it's useful by itself). Get familiar with pandoc metadata headers on a RTFM basis. A LaTex intro is all you need after that, if you are up for a bit of trial and error. Or learn LaTex first, but not both at the same time, as the layered processing involved is a bit confusing (e.g. pandoc showing pdflatex errors). In any case, I strongly advice to bite the bullet and install the full LaTex package of your distro (no idea about macOS, or windows), as fighting dependencies is suuuper annoying. However, the trade-off is it's truly a behemoth, consequently frequent upgrades for a lot of packages you don't ever use. (I configured dnf to download upgrades automatically, so I can do a quick `dnf upgrade --cacheonly` when opportune.)
Speaking of... I wish pandoc could do Tex package management and dependency resolution.
I assume the original question is asking about programmatic document generation, in which case working with a real AST is probably also a productivity and reliability win as well.
I've migrated my invoicing (and all my other publishing/slides) to typst from latex and couldn't be more happy.
I've not tried a couple of things you mention (e.g. background images) but e.g. for dynamic placing there are libraries like https://typst.app/universe/package/meander
The core of Typst is a pretty featureful well-thought-out FP language. This makes expressing libraries for any piece of functionality very pleasant.
It’s always been some combination of MJML, inline DIY HTML, or PDFs generated with Puppeteer etc.
Do you think Typst would be a good fit there too?
I suppose it depends on how much web dev experience is on hand.
Weasyprint is quite wonderful, fast, and you can file upstream tickets and get good clarity on what's going on.
And you're writing your templates in CSS + HTML, which generally flows well.
At the end of the day the problems are rarely "CSS + HTML vs Latex vs Typst", but more just about making decisions about how you want something to be laid out when you have dynamic input.
"What should happen when I have a huge blob of text here" is often a non-trivial question. "What should I do on a page break here" is a non-trivial question. And they often involve having to, at the high level, make decisions. People whine about CSS, sometimes you just gotta read the spec and figure things out (rather than stop at your intuition for how certain fields work).
Nice thing about CSS + HTML is you can open up your output in a browser and futz about with it very easily.
Personally I think ConTeXt is a far superior tool, though its documentation is always trailing quite a distance behind its current capabilities.
Some people might say that writing in XML is annoying, but it isn't if you have a decent XML editor. In my case, it is Emacs nXML mode. Customisation is possible with DITA-OT [1] and plugins, and yes, it is also based on XSLT. Overall, I think DITA is an industry-proven XML powerhouse. It may be boring, but it has huge potential for anyone with advanced documentation requirements.
[0] https://dita-lang.org/dita/archspec/base/introduction-to-dit...
LaTeX notation works well for this and can be easily converted to both web and PDF formats.
But compilation speed definitely needs improvement.
On the other hand, how often do you actually need to compile thousands of pages into a single document? That’s really an edge case.
https://www.pandoc.org/demo/example33/2.4-creating-a-pdf.htm...