One month of typesetting in Typst
Published on
I recently received my Master’s degree, which means that I defended and submitted my thesis to the library. As this may as well be the last time I’m tasked with typesetting a document formally, I decided to take it as an excuse and try out Typst as an alternative to the good old LaTeX.
The markup syntax–shown below here–resembles something like Markdown and Org, which is quite easy to get used to. It’s definitely a lot saner than LaTeX.
= Heading
This is a sentence in a paragraph with some _emphasis_ and a @citation.
- Bullet list item 1.
- Bullet list item 2.
$ E = mc^2 $
Typst also comes with an embedded scripting language for controlling formatting and advanced styling. Its syntax is like a mix of Python and the markup language, which is also (personally speaking) more palatable to LaTeX:
// "Set rules" for setting formatting options from now on.
#set par(justify: true)
// A variable bound to a function.
// Stuff in the square brackets is parsed as markup,
// and within markups "#" is parsed as the scripting language.
#let greeting(name) = [
Hello, #name! Today is #datetime.display(datetime.today()).
]
// Using the function within markups.
// This results in "Hey! Hello, kotatsuyaki! Today is 2024-10-06." Hey! #greeting[kotatsuyaki]
Writing and publishing a template for Typst–as I’ve done for my schools thesis format–is pleasant and easy. While creating the template, I have found some shortcomings:
Headings sometimes do not respect the orphan rules.Reportedly solved by PR 5017.- Adjacent headings are spaced out too far away. I worked around this by manually adding negative vertical spacing when the previous heading is close enough, but the way of querying the previous heading can see some improvement.
- CJK linebreaks are rendered as spaces. This is quite common in markup languages designed for latin scripts.
- There’s no way to indent the first line of the first paragraph.
Fortunately, the development happens quite actively, so I think those problems will eventually be resolved.
Writing a NTHU thesis in Typst
I have created a Typst template for NTHU thesis based on a LaTeX template handed down in my lab. The school doesn’t seem to care a lot about the formatting and the choice of typesetting software, as I didn’t have any problems submitting my thesis to the library. Still, consult your advisor before using non-standard software that’s still in beta to typeset your thesis.
For encrypting the PDF file for compliance required by the library, instead of using Acrobat Reader (which was discontinued for Linux ten years ago), one can use CLI tools such as pdftk or qpdf:
THESIS_PASSWORD=password
THESIS_PDF=thesis.pdf
THESIS_PROTECTED_PDF=thesis-protected.pdf
qpdf \
--encrypt \
--user-password="" \
--owner-password="$THESIS_PASSWORD" \
--bits=256 \
--accessibility=y \
--annotate=y \
--assemble=y \
--extract=n \
--form=y \
--modify-other=y \
--modify=assembly \
--print=full \
-- "$THESIS_PDF" "$THESIS_PROTECTED_PDF" \
--verbose
For use cases beyond basic typesetting such as diagram drawing, do check out other packages published on the Typst Universe.