Typst Quick Start Guide: A Modern Alternative to LaTeX
Typst is an emerging typesetting system designed to address some long-standing issues with LaTeX, such as complex syntax, lengthy compilation times, and steep learning curves. As a modern alternative to LaTeX, Typst offers more concise syntax, real-time preview, and friendlier error messages while maintaining high-quality typesetting output, especially for mathematical formulas.
Comparison Between Typst and LaTeX
Typst was designed to retain LaTeX's typesetting quality while solving its pain points. Here is a comparison of their main features:
Feature | Typst | LaTeX |
---|---|---|
Compilation Speed | Millisecond-level, real-time preview | May take seconds to minutes |
Syntax Complexity | Concise, similar to Markdown | Complex, self-contained system |
Error Messages | Clear, friendly, precise location | Often difficult to understand, vague location |
Learning Curve | Gentle, easy to get started | Steep, difficult for beginners |
Ecosystem | Emerging but rapidly developing | Mature, with abundant existing resources |
Customization Ability | Implemented through functions, modern programming-oriented | Implemented through macros, special syntax |
Mathematical Typesetting | Powerful, more concise syntax | Extremely powerful, de facto standard |
Installation and Environment Setup
Typst offers multiple usage methods to meet different users' needs:
Online Editor: No installation required, simply visit Typst Web Version to start using it
Local Installation:
Windows System:
# Using Scoop scoop install typst # Or using Winget winget install --id Typst.Typst
macOS System:
# Using Homebrew brew install typst
Linux System:
# Using Cargo (Rust package manager) cargo install --git https://github.com/typst/typst
Editor Plugins:
- VS Code: Install the official Typst plugin
- Vim/Neovim: Use the typst.vim plugin
- Other editors also have corresponding plugin support
Typst Basic Syntax
Typst's syntax combines the simplicity of Markdown with the expressiveness of LaTeX, making it very intuitive to use.
Document Structure
A basic Typst document structure looks like this:
#set document(title: "My First Typst Document")
#set page(numbering: "1", number-align: center)
#set text(font: "Times New Roman", lang: "en", size: 11pt)
= Document Title
== First Chapter
This is a paragraph, you can input text directly. *This is bold text*, _This is italic text_.
=== Section
- This is an unordered list item
- Another unordered list item
- Nested list item
1. This is an ordered list
2. Another ordered list item
Mathematical Formula Typesetting
Typst's mathematical formula syntax is similar to LaTeX but more concise:
Inline Formula: Surrounded by $...$
This is an inline formula: $E = mc^2$, it will be embedded within the text line.
Display Formula: Use $ ... $
and make it a separate paragraph
This is a display formula:
$ F = G \frac{m_1 m_2}{r^2} $
It will be centered.
Mathematical Formula Examples:
// Fractions
$ f(x) = \frac{1}{1 + x^2} $
// Summation
$ \sum_{i=1}^{n} i = \frac{n(n+1)}{2} $
// Integration
$ \int_{a}^{b} f(x) \derivative{x} $
// Matrix
$ A = \matrix(
1, 2, 3;
4, 5, 6;
7, 8, 9
) $
// Piecewise function
$ f(x) = \cases(
x^2 &if x > 0,
-x^2 &if x \le 0
) $
Advanced Features and Techniques
Charts and Images
#figure(
image("path/to/image.jpg", width: 80%),
caption: "Image title"
)
References and Bibliography
// Insert references in the document
As @smith2023 states...
// Add bibliography at the end of the document
#bibliography("references.bib")
Custom Functions and Templates
Typst allows you to define functions to create custom components:
#let theorem(body, name: none) = {
let title = "Theorem"
if name != none {
title += " (" + name + ")"
}
block(
fill: rgb(240, 240, 250),
inset: 10pt,
radius: 4pt,
width: 100%,
)[
#text(weight: "bold")[#title]
#body
]
}
// Using the custom function
#theorem[
There are infinitely many prime numbers.
][Euclid]
Tips for Migrating from LaTeX to Typst
If you previously used LaTeX, here are some practical suggestions for migrating to Typst:
Document Structure Changes:
- LaTeX's
\section{}
becomes= Title
in Typst - LaTeX's
\begin{environment}...\end{environment}
becomes function calls in Typst
- LaTeX's
Mathematical Symbol Correspondence:
- Most LaTeX mathematical symbols can be used directly in Typst
- LaTeX's
\frac{a}{b}
is\frac{a}{b}
in Typst (the same) - LaTeX's
\begin{matrix}...\end{matrix}
is\matrix(...)
in Typst
Package and Function Correspondence:
- Package functions in LaTeX are usually provided by built-in functions in Typst
- For example, the
graphicx
package in LaTeX is not needed in Typst; use theimage()
function directly
Compilation Process Differences:
- Typst supports real-time preview, eliminating LaTeX's multi-compilation process
- Typst directly outputs PDF without generating intermediate files
Using SimpleTex to Assist Typst Document Creation
Although Typst simplifies formula input, manually writing code for complex mathematical formulas is still time-consuming. SimpleTex can help you:
- Recognize existing mathematical formulas and convert them to Typst-compatible code
- Convert handwritten or printed mathematical formulas to digital format
- Convert LaTeX mathematical formula code to Typst format, assisting the migration process
Using SimpleTex for formula recognition and then importing the results into Typst documents can greatly improve document creation efficiency.
Conclusion
As a modern alternative to LaTeX, Typst brings a whole new experience to document typesetting. It simplifies syntax, speeds up compilation, and maintains high-quality typesetting output, making it especially suitable for situations requiring frequent editing and previewing. For academic writing and mathematical document creation, Typst provides a more powerful option than Markdown and a friendlier one than LaTeX.
If you are already a LaTeX user, Typst is worth trying; if you are a typesetting novice, Typst might be an easier starting point than LaTeX. As the Typst community continues to develop, we can expect it to become an important choice for academic document typesetting in the future.