Typst with Pandoc: A Modern, Fast Alternative to (Xe)LaTeX for PDF Generation
For years, I’ve been using XeLaTeX to generate professionally formatted PDFs. Either for scientific papers, or from Markdown sources using Pandoc for things like technical documentation or company-internal notes. I like XeLaTeX over “plain” LaTEx in particular for its native support of system fonts. But I’ve always been frustrated with LaTeX’s compilation speed. Even for medium-sized documents, waiting several seconds for each rebuild adds up quickly, especially when iterating on content where visual feedback is important.
Recently, I discovered that Pandoc supports Typst. I’d heard about Typst earlier, but never tried using it (for reasons I’ll get into). Typst is a modern typesetting system written in Rust that promises LaTeX-quality output with dramatically faster compilation times . After testing it out, I can confirm: if you’re using Pandoc to generate PDFs, you should seriously consider switching to Typst .
TL;DR: Pandoc supports Typst as a PDF engine. It’s orders of magnitude faster than XeLaTeX while producing equivalent quality output, has better error messages, and uses a cleaner template syntax.
The Problem with XeLaTeX
My typical workflow looked like this:
pandoc input.md \<br>--output=output.pdf \<br>--to=latex \<br>--from=markdown \<br>--template=template.tex \<br>--pdf-engine=xelatex
This works great, but like I mentioned earlier, the biggest pain point is compilation speed. The combination of Pandoc and XeLaTeX takes several seconds, even for simple documents. Add in references and citations, and the wait time increases significantly because you need to compile twice to get references right. Also, if you’ve ever come across a LaTeX error, you know how cryptic and difficult they can be to debug. Lastly, a full TeX Live installation is several Gigabytes, which is a heavy dependency… just to generate PDFs?
Welcome Typst!
Typst is a modern alternative to LaTeX that provides similar typographic quality while being significantly faster and more user-friendly. You can try it out here:
Try Typst in an online editor!
Best of all – and the reason I finally switched over to it – is that Pandoc has native Typst support. Why not just use Typst directly? Well, it’s yet another default syntax, and since Markdown is second nature to me, I didn’t want to learn another language. So I was initially skeptical to try it out unless I could feed it Markdown sources. But now that is possible with Pandoc!
Installing Typst is straightforward under macOS and Windows:
# macOS<br>brew install typst
# Windows<br>winget install --id=Typst.Typst
Linux users will have to decide whether they use:
A packaged source (notably it does not include Debian/Ubuntu)
A snap source
cargo install --locked typst-cli (requires Rust toolchain, e.g. apt install cargo on Debian/Ubuntu)
Or a standalone binary from the GitHub release page
Using Typst with Pandoc
The beauty of Pandoc’s Typst support is how simple the migration is. Instead of generating LaTeX and compiling with XeLaTeX, Pandoc generates Typst code and compiles with Typst:
# Generate a default template<br>pandoc --print-default-template=typst > template.typ
# Generate PDF using Typst<br>pandoc input.md \<br>--output=output.pdf \<br>--to=typst \<br>--from=markdown \<br>--template=template.typ \<br>--pdf-engine=typst
That’s it. Just change --to=latex to --to=typst and --pdf-engine=xelatex to --pdf-engine=typst, and point to a Typst template (.typ instead of .tex).
Of course, you are not going to be able to use Typst’s advanced features (like custom macros) directly from Markdown, but for standard documents, it works out of the box. You could build those complex features into the templates though, so let’s cover that in the next section.
Template Customization and Migration
In the above case, we’ve used Pandoc’s built-in default Typst template, but you can customize it as needed. You can find Typst templates in their offical GitHub repo, read their guide on how to write one, or browse their universe. Because Pandoc has special variables, it’s wise to start with the default template and modify it to your needs.
Note that with Typst, you might need to specify a root directory for file access (e.g., for images or includes that are part of your template):
pandoc input.md \<br>--output=output.pdf \<br>--to=typst \<br>--from=markdown \<br>--template=template.typ \<br>--pdf-engine=typst \<br>--pdf-engine-opt=--root=/path/to/project
If you have existing LaTeX templates, you’ll need to manually port them to Typst. I have been using the Eisvogel template for LaTeX, and have not yet found a good alternative, partly because the Eisvogel template has been around for such a long time. But the good news is that Typst’s template syntax is generally cleaner and more intuitive than LaTeX.
Typst templates use a modern scripting language with native functions, conditionals, and variables rather than LaTeX’s macro system. To get started with migrating,...