Skip to main content

yuce.me

Typst Workflow on OpenBSD

Typst on OpenBSD

Recently I had to write a paper with scientific vibes. Of course, the first tool that comes to mind for writing papers is LaTeX. I used quite a bit of LaTeX in the distant past, but the problem is I forgot everything about it! I could probably re-learn it easily, but I decided to search for alternatives first. The first tool that sprang up was Typst with over 40000 Github stars!

Typst is an open source project written in Rust. It provides a nice CLI tool with a single binary, and it has a pretty nice language. The example they put out on their Github is very convincing (good sign for an open source project). I decided it to give it a try, and after a short time I was already feeling quite a bit of comfortable with it!

I used Typst for a couple of weeks now, and there’s absolutely no friction using it. These are what I like about it in no particular order:

  1. The language is nice and consistent. To be frank, my first reaction was, “Nooo, not another markup language!”. But I like it quite a bit now!
  2. Their documentation is very good.
  3. It has a fairly big community. There was never a situation I needed help but couldn’t find it. Up until now, any questions I had were already asked and answered.
  4. Although it’s still a 0.x project, their CLI tool is very robust. I didn’t encounter any bugs.
  5. The error messages are very accurate and descriptive. It was trivial to fix the few mistakes I did.

A few days ago, I read an article about the TK method: TK, or the secret to effortless writing. If I am not sure about how to write the next sentence, I would usually just write XXX or maybe TODO, or even TBC. But using TK consistently makes much more sense! I decided to add a #TK() command to my Typst manuscript. Here is what I came up with first:

#let TK() = {
    highlight[TK]
}

This just writes a highlighted TK in yellow, whenever I use #TK() in text:

= Section 1

I'll continue with #TK()

I ended up with just a bit of a more complex TK function which makes the text stand out more and allow me mention what’s missing:

#let TK(..what) = {
  underline[
    #highlight[
      #text(weight: "bold", fill: red, [TK])
      #text(
        weight: "bold",
        what.pos().join(", ")
      )
    ]
  ]
}

This is how I use it in my manuscript:

= Section 1

I'll continue with #TK("something", "ref")

Here’s a screenshot from the resulting PDF: Sample TK usage

Anyway, I was using Typst on Linux by compiling it myself. I write the manuscript using Visual Studio Code + the extension from their Github (under typst/tools/support directory). The extension provides only syntax highlighting, which is sufficient to me.

These days I enjoy OpenBSD a bit more than I do Linux, so I decided to use Typst on my OpenBSD laptop. (Unsurprisingly) it’s trivial to get going on OpenBSD. It’s just:

$ doas pkg_add typst

The latest version of Typst, together with a Vim plugin is installed, and everything works as expected. OpenBSD package maintainers always do a great job, kudos!

Here’s how I use Typst on OpenBSD:

  1. I use a two window layout with i3. On one-side there’s Vim with the Typst manuscript. On the other-side I have MuPDF (installed with doas pkg_add mupdf) running with the output PDF.
  2. I make changes in the manuscript and run :make in Vim. I have set autowrite in my ~/.vimrc, so the :make command automatically saves the file (the Vim plugin knows how to build the manuscript).
  3. Once the PDF is built (at most a second), I switch to the MuPDF window and press r which reloads the PDF. It would be great if MuPDF supported auto-reloading (like KDE’s Okular), but typing a single letter is not too bad. (MuPDF also supports the SIGHUP signal for a reload, but I didn’t yet bother to write a script to build the manuscript and raise that signal.)

That’s all! If you are looking for a tool to produce nice documents without frictions, I would highly recommend Typst.