Fundamentals 9 min read

Quick Start Guide: Why Typst Beats LaTeX for Modern Document Typesetting

Typst is a markup‑based, easy‑to‑learn typesetting language that offers a modern alternative to TeX/LaTeX with concise syntax, programmable styling, CLI/Web/VS Code tools, flexible export formats, powerful code mode, query system, and robust math support, making high‑quality document creation far simpler.

21CTO
21CTO
21CTO
Quick Start Guide: Why Typst Beats LaTeX for Modern Document Typesetting

Typst is a simple yet powerful markup‑based document typesetting language designed for academic papers, technical manuals, books, and other complex publications, positioning itself as a modern alternative to TeX and LaTeX with concise syntax and programmable extensions.

1. A Half‑Century of Evolution: TeX, LaTeX, and Typst

TeX, created by Donald Knuth in 1978, and LaTeX, introduced in 1984, have long dominated academic publishing. Their longevity brings two persistent pain points: they were built for older computing environments, making their syntax feel cumbersome today, and LaTeX’s underlying complexity still results in high configuration and debugging barriers. Typst was created expressly to eliminate these historical burdens.

2. Development Ecosystem and Workflow

CLI : The open‑source Typst compiler can be integrated into CI/CD pipelines or automated build processes.

Web Playground (Typst App) : An official hosted web application that provides real‑time preview in the browser, ready to use out of the box.

VS Code Extension : The most popular extension, Tinymist Typst , offers code completion, live rendering, and preview capabilities.

For basic documents, Typst’s learning curve is low; its syntax mirrors Markdown: underscore ( _) for italics, asterisk ( *) for bold, and equals sign ( =) for headings of various levels.

3. Core Mechanism: Style Declarations and “Code Mode”

Typst’s programming ability shines when customizing layout. The #set directive lets you control page size, text size, margins, and more globally or locally. For example:

#set page(width: 5.25in, height: 8in, margin: 0.5in)
#set text(size: 11pt, font: "Libre Baskerville")
#set par(first-line-indent: 1.75em, justify: true)

The #set command affects all content that follows its position; invoking it again later overrides previous settings.

Typst distinguishes between markup mode and code mode using the hash symbol ( #). In code mode you can define macros and functions, such as:

#let inline_image(img) = {
  box(height: 8em, place(top+left, dx: 5pt, square(
    image(img, height: 100%, fit: "cover"))))
}

This defines a function inline_image that embeds an image inside an inline box. Statements end with line breaks, not semicolons.

4. Powerful Export and Query System

Typst natively exports to PDF, common image formats, and HTML. The target() function enables conditional rendering. For instance, when the export target is HTML, the following function inserts a <div> with a specific CSS class; otherwise it renders a built‑in divider:

#let sectionbreak(txt) = {
  context(
    if target() == "html" {
      html.elem("div", attrs: (class: "section-break"))[]
      return
    } else {
      divider()
    }
  )
}

Typst also provides a DOM‑like query system via the query function, allowing developers to retrieve specific elements such as headings, figures, or footnotes. Example:

// Query all level‑1 headings
query(heading.where(level: 1))

Package management eliminates TeX’s cumbersome global installation. Using the import statement, remote packages are automatically downloaded and made available.

5. Elegant Mathematical Typesetting

Typst’s math module inherits TeX’s aesthetic quality while simplifying syntax. Math expressions are wrapped in dollar signs ( $), e.g.: $ sum_(k=1)^n k = (n(n+1))/2 $ To output a literal dollar sign, escape it with \$. Users with existing TeX assets can employ third‑party tools like MiTex to convert TeX formulas to Typst syntax.

6. Ecosystem and Automation Extensions

Typst’s open‑source ecosystem is rapidly expanding. Although file‑path imports and local data reads are deliberately restricted for security, developers can use external languages for automation. For example, the Python typst library enables:

Automated multi‑file collaborative builds.

Reading data sources outside the project root before compilation.

Dynamic document generation using the query system.

With over 1,000 community packages already listed, Typst is becoming the preferred choice for developers, scholars, and publishing teams creating technical documentation.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CLITypstMarkup LanguageVS Code extensionDocument typesettingLaTeX alternativeMath typesettingQuery system
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.