alfin K

I plan to use this place to document my work, keep short notes for easy reference and write about things I might forget.

Typst Language

Getting to know the typst language and workflow

published » updated
written by Alfin · category Software ·

Typst is an open source typesetting language. I am looking into it because it is said to be much easier than Latex. I have used Latex before, but because I don't use it often, I end up spending more time reading package documentations than writing.

As of writing this, I am on Gentoo. So, installing Typst was easy since it is packaged in the GURU repository. This is already very nice compared to installing a huge Latex meta package. You can compile a .typ file to a PDF using this command:

$ typst compile input.typ output.pdf

You can also watch and compile on changes to a file using:

$ typst watch input.typ

A simple local live editing setup can be made if you open the output file in a PDF viewer which supports refreshing on changes. Now everytime you save the .typ file you see the changes immediately.

Functions#

Functions are the central mechanism behind all your formatting. Writing *bold text* is a syntax sugar for the function #strong[bold text]. Likewise = Heading is a shorthand for #heading[Heading]. You can find more functions in this list. These markup functions commonly evaluate to a content.

Content#

You rarely need to interact with these directly when writing. This is an internal tree structure which contains fields representing its properties. Essentially it contains information about how your document should be layered. These are commonly created when you enclose markup in square brackets. For example [*text*] produces a content. You can see how the internal structure looks like using the #repr() function which returns a string representation.

#repr(strong[hello]) \
#repr(heading[heading]) \
#repr([This is _emphasized_])
strong(body: [hello])
heading(body: [heading])
sequence([This is], [ ], emph(body: [emphasized]))
1

Notice how _emphasized_ was replaced by its corresponding container

Templates#

Looking at templates are a good way to see how things work in typst. Awesome-typst is a nice repo with a lot of templates.