zettelkasten

Search IconIcon to open search
Dark ModeDark Mode

Typesetting with Typst?

Date: 3 Sep 2023

#post #typesetting

LaTeX is okay—very powerful, but not necessarily friendly… arguably not the most ergonomic without substantial investment to build a template and set up a workflow. Local TeX, if needed, eats up tons of storage as well.

Markdown is easy if not enjoyable to work with, but often there isn’t a syntax for formatting something complicated. It’s quite useful for web-based rendering, but probably not the best for typesetting actual documents.

At the end of the day, I mostly default back to handwriting notes if only given these two options.

Typst might actually be a promising middle ground, supposedly a modern, fast, and more friendly latex alternative. Indeed, LaTeX is old and complicated. I would welcome a successor, be it Typst or not. For the time being, Typst seems powerful enough to take notes I need but also ergonomic enough that taking notes doesn’t become wrangling with LaTeX.

H2 Equations

Take this equation as an example:

$$\arg \max_y \sum_{y=1}^{T_y} \log P\left(y^{} \mid x, y^{<1>}, \ldots, y^{}\right)$$

The LaTeX way… that’s a lot of backslash and braces.

\begin{equation*}
	\arg \max_y \sum_{y=1}^{T_y} \log P\left(y^{<t>} \mid x, y^{<1>}, \ldots, y^{<t-1>}\right)
\end{equation*}

And Typst… no more backslashes, writing symbols almost become just typing their name.

$
arg max_y sum_(y=1)^(T_y) log P(y^(<t>) | x, y^(<1>), ... , y^(<t-1>))
$

H2 Programmability

Similarly, one can define functions that turn input into content. It’s doable in LaTeX with \newcommand, but Typst functions seem more fun to work with.

H3 Content Block

= Introduction
#lorem(60)

#let definition(body) = {
  box(
    stroke: 1pt + rgb("#ddc7ff"),
    width: 100%,
    fill: rgb("#ddc7ff55"),
    inset: (x: 8pt, y: 8pt),
    [ *Definition* \
      #body
    ]
  )
}

#definition([
    Let $p in ZZ$. $p$ is *ring theoretically prime* if $|p| > 0$ and $forall a,b in ZZ, p | a b => (a | a or p | b)$. 
    
    $p$ is *irreducible prime* if $|p| > 0$ and $forall a,b in ZZ, p = a b => (a = ± 1 or b = ± 1)$. Alternatively, $forall a in ZZ, a | p => (a = ± 1 or a = ± p)$.
])

== In this paper
#lorem(20)

Results in

CleanShot 2023-09-03 at 10.46.38.jpg

Beautiful.

H3 Symbol Alias

#let eeq = $#sym.tilde.equiv$
#let neeq = $#sym.tilde.equiv.not$
#let stepsTo = $#sym.arrow.r.double.long$
#let stepsToIn(n) = {$attach(#sym.arrow.r.double.long, tr: #n)$}

`#eeq` etc. works in text #eeq and $"in math mode too" f eeq x neeq y stepsTo s stepsToIn(3) v$.

Results in

CleanShot 2023-09-03 at 11.05.46.jpg

H2 Limitations

Of course, Typst is still under development. Who knows what will happen… It has missing features many may need from LaTeX, but work is in progress. Its recently added support for packages may open up many opportunities. Things like algorithm is already possible, but CSL support is still on the roadmap. Will Typst become mainstream? Don’t know, but glad to see something trying to fix some of LaTeX’s problems.

For now, LaTeX still has a larger ecosystem: templates, packages, etc. For anything more formal than notes, probably LaTeX is still a better option.