Writing maths documents with Typst

Today I want to talk about a rather recent tool that aims to replace $\LaTeX$ as the main way to write mathematical documents. I tried it out, and spoiler: I loved it! Let me explain why I think it is indeed a serious challenger to $\LaTeX$.

My experience with $\LaTeX$

A lot of friction

So if you had to write a maths document after leaving high school, you probably heard of $\LaTeX$. If you decided to pursue a career in mathematics, you certainly wrote several (not to say a lot of) documents with $\LaTeX$. I myself started to use $\LaTeX$ to write my maths homework during my first year as an undergrad, during a Covid lockdown. And I consider myself lucky that there was a lockdown, because starting $\LaTeX$ is highly time-consuming. Every little thing I wanted to do that was not “typing text” I had to check on the internet, and there was no AI to ask at the time! Let me take the opportunity to recommend the website detexify, which allows you to draw a symbol with your mouse and outputs the corresponding command as well as the package needed. I wish I had known about it when I started.

But apart from this steep learning curve at the beginning, there are several aspects of $\LaTeX$ that I dislike. The most basic one is that you need to write a lot of commands, especially in math mode. And commands in $\LaTeX$ start with \. I don’t know about you, but on my keyboard (French Mac) I need to do Opt+Shift+\. And curly braces {} are not exactly the most straightforward thing to type either. Some people will probably explain to me that I can bind my keys differently are whatever, but I find this highly unergonomic, compared to usual programming languages where we use, I don’t know, brackets ()? More generally, it seems to me that programming in $\LaTeX$ is something of a hell. I am not much of a programmer myself, but I have done several programming projects that I would consider nontrivial. And from the few glimpses I had of some $\LaTeX$ code, it seems horrible. Maybe this is due to how old it is, I don’t know, but it is scary. Creating my own .sty file with some macros and basic environments, along with a .cwl completion file, was all I dared to do (which is not programming).

An amazing tool

After all of this, you may think that I am a sort of $\LaTeX$ hater. Wrong! I actually love $\LaTeX$. Clearly there are drawbacks, but overall I really enjoyed learning it and still enjoy using it. The satisfaction of reading my nicely written homework after several hours of coding was clearly worth all the effort. Discovering $\LaTeX$ after years of Word and PowerPoint was a real pleasure.

And I would say that it is quite fortunate that I enjoy it, because it is somewhat everywhere in maths nowadays. Now I am no expert in $\LaTeX$ history, but from my point of view there are three main reasons why $\LaTeX$ is preferred above any other tools in maths.

  • First, somewhat obvious but needs to be said, it allows to write maths very nicely and extensively. I don’t know of any other tool that permits to write pretty equations and with such a variety of symbols. In fact all the tools that I know which permit to write equations allow the user to use $\LaTeX$ for this purpose.
  • Second, it is entirely cusotmizable. You can control every single aspect of what you write (provided that you know how to do so of course), each journal or conference can have its own completely different template to display things exactly as it wants. This of course is also one of the reasons it is hard to learn $\LaTeX$: there are so many things you that can do you can quickly get lost, and documentation is loooooooong. The best illustration of that is how hard it is to draw pictures with tikz.
  • Third, there is nothing like it. Invented in the early 80s (and based on $\TeX$ which was created in 1978) to permit nice printing, it established itself as the only tool that permits this level of customization and so much possibilities for scientific documents. Regarding other programming languages, there is of course Markdown which has a much lighter syntax and produces nice documents, but lacks personalization. Word is much easier to use, but not open source and (in my opinion) not as nice.

Here comes a new challenger

Ok, after this long introduction, we can finally get to the point I am interested in: $\LaTeX$ is no longer alone in its category. Here comes a new challenger as they say: Typst. Typst aims to be a mixture of $\LaTeX$ and Markodwn I would say: as customizable as $\LaTeX$ but with much lighter syntax like Markdown.

Why it is so great

Let me start by briefly listing here a few features that I really like about it. You can write complicated programs with it, and its syntax is much closer to what we are used to in other programming languages than the syntax in $\LaTeX$. There are also several shortcuts for functions that one uses often: = creates a section title, == for a subsection etc. + will start a numbered list, - will start an unnumbered one. Inside the document, functions start with # rather than \, and in a programming environment they do not need a prefix (as in a usual programming language). The star feature are probably the show rules that allow you to select specific elements to change their style, somewhat similarly to what a CSS sheet would do. Another really cool feature: compilation is instantaneous, when you type something it directly appears on the preview file. Finally, there is much more built-in stuff in the language, so that all the packages you use rely on the same mechanisms inside. This prevents from some cryptic error messages that one sees sometimes in $\LaTeX$ because of a weird implementation in a certain package. I find it hard to describe Typst and its differences with $\LaTeX$ precisely, and rather point you to the tutorial. But I can share my feeling: after an hour with Typst, I felt much more at ease with customization and programming in Typst than I have ever felt with $\LaTeX$.

But THE feature that made me fall in love with Typst above all, is this: writing maths. It is so much easier and pleasant than with $\LaTeX$. For instance, to write a fraction, you can type $a/b$ and it will render as

\[\frac a b\]

automatically, no need for the more painful $\frac{a}{b}$. Parentheses are dealt with dynamically, which is also fantastic. How do you write $\frac{a+b}{c}$? In $\LaTeX$ it is $\frac{a+b}{c}$, curly braces and so on, and things get quickly hard to read if a, b or c are complicated as well. In Typst, you simply write $(a+b)/c$. Yes, Typst understands that the parentheses are only there for parsing and does not print them! But it understands also if they have to be printed, so if you write $(a (b + c)) / d$, it will render as

\[\frac{a (b+c)}{d}.\]

The first pair is omitted, but not the second. This feature is amazing, because you can write everything with parentheses ($a_{b+c}$ is written with $a_(b+c)$ for instance) and Typst will render exactly as you want, it is much more pleasant than using curly braces everywhere. Also, delimiters are automatically adjusted to the size of the content, so $(a/b)$ renders as

\[\left(\frac a b\right),\]

not as the horrible

\[(\frac a b).\]

There are also several built-in commands for maths, that you can write without the #. This means however that if you want to write the product of $a$ and $b$ you need to write $a b$ rather than $ab$, otherwise Typst will think you are using an unknown command ab. This may seem annoying, I personally don’t mind it. If you want to write greek letters for instance you simply write $sigma, Sigma$ for $\sigma, \Sigma$. You can also write $RR$ for $\mathbb{R}$ and similar for other blackboard letters. More generally the bb function gives blackboard symbols, for instance $bb(1)$ prints the blackboard $1$ (while $\mathbb{1}$ in $\LaTeX$ will not produce what you think, except if you use the bbold package which changes how blackboard letters are printed, and I don’t like how it looks). I cannot insist enough on how nice it feels to be able to use parentheses for everything instead of curly braces.

The impossible challenge

To finish on why I love Typst, let me give you a concrete example of something I never managed to do with $\LaTeX$ but that I managed to achieve in Typst ten minutes after I discovered it. When I was writing my maths homework, my teachers always asked us to put our final answer to a question inside a red rectangle. And when I say they “asked us”, I actually mean that if we did not do it, we would not get points. Naturally I wanted to do the same in my $\LaTeX$ homework. Here is the catch: I never managed to do it.

What I wanted was to be able to write some centered text, with possibly displayed equations, all put inside a red rectangle whose borders would adjust perfectly to the content. In short, something like this:

Unfortunately, the closest I managed to get (without any programming of course, only using already existing packages) was this:

(I actually had a way of changing the size, but it was not automatic so I had to write the width by hand everytime, which was not an option). It was ok for my purpose, but I was highly frustrated that I did not manage to get it right. If you know how to do that in $\LaTeX$, please email me!

Now spoiler: the screenshots I showed above were made with Typst, so yes I managed to make it work with Typst. And as I said, this was just after reading part of the tutorial! Here is the function I created:

#let answer(content) = block(width: 100%)[
  #align(center)[
    #rect(stroke: red, inset: 7pt)[
      #align(center, content)
    ]
  ]
]

This was enough to convince me that Typst had the power to overthrow $\LaTeX$ as the dominating tool to write mathematics.

Can Typst overthrow $\LaTeX$?

After all of this, I hope I intrigued you enough so that you will take a look at Typst, and maybe try and follow the tutorial or type some of your favorite equations to see how you like it. You can try it online (see the main page). I personally use it in VSCode thanks to the Tinymist plugin. If you like it and want to get better at it, then I can only recommend you to try and write full documents and see what difficulties you encounter. I personally trained by writing solutions to the maths homework of my cousin (Yes, maths homeworks are a good way to learn that kind of tool). There is a forum where you can ask your questions.

So what do we do now? Throw away $\LaTeX$ as an old-fashioned technology and move everything to Typst? Not so fast! I am pretty sure $\LaTeX$ still has a few years ahead of it, and it is not even clear to me that it will one day be replaced by Typst. I could personally throw away $\LaTeX$ right now and never look back. But for all the advantages that Typst has, there are also drawbacks that I think will need some fixing. First of all, Typst is really young. This means that it can relies on much younger technology, but that’s a small consolation compared to this: the community is underdeveloped. As I mentioned previously, Typst comes with much more built-in functions than $\LaTeX$: basic maths, tables, grids, figures etc. You can do a lot without importing any packages. But if you encounter some nontrivial thing that you want to do, you are likely to hit a wall: nobody needed that before you, and so nobody did it. So you either have to wait for someone to do it, or try and program it yourself. Of course I am guessing that $\LaTeX$ had the same issue at the beginning, but nowadays there are $\LaTeX$ packages for nearly everything, with lots of options to allow for user-friendly customization. This is fundamental in the success of $\LaTeX$: as programming with it is so complicated, the community needed a few people motivated enough to build blocks that others could reuse. Although there are already packages for most important stuff in Typst, like dealing with theorems, an elaborate graphic package etc., there are still a lot to do. One positive thing about that is that it is much easier for someone to contribute to Typst as programming is much easier than in $\LaTeX$. But this will obviously take time.

The second drawback I want to mention is maybe the most critical: people are not using it. If there are no people using it, there won’t be a need for developing new tools and packages (see the previous paragraph), so people will feel like it is not as powerful as $\LaTeX$, and they will keep on using $\LaTeX$. People may also be reluctant to move away from the tool they have been using for years. I think there is a chance that we may move over to Typst because it is so much more pleasant to use than $\LaTeX$, but if it happens it will take a lot of time and persuasion (and I am writing this post for that purpose too to be honest). So I will conclude like this: if you sometimes feel like $\LaTeX$ is complicated, if you are tired of typing \ or {}, please, try Typst! Have a go at it! Use it to write a small document, maybe a proof you like or whatever. If you feel like it is worth it, get used to it, talk about it around you. If you work for a journal or conference, allow authors to submit with Typst. Collectively, we may just be able to revolutionize the way maths are written, and I think that would be great.