Skip to content
sou1118Public

About

A diff tool for Typst documents, similar to latexdiff for LaTeX

Topics

Resources

Stars

81 stars

Watchers

1 watching

Forks

Latest commit

 

History

34 Commits

Folders and files

Repository files navigation

typdiff

A diff tool for Typst documents, similar to latexdiff for LaTeX.

typdiff compares two Typst source files and generates a new Typst document that visually highlights the differences — added text in blue with underline and deleted text in red with strikethrough.

Example

Given an old document:

= Introduction

This is the old text.

- First item
- Second item

== Details

The quick brown fox jumps over the lazy dog.

And a new document:

= Background

This is the new text.

- First item
- Third item
- Fourth item

== Details

The quick red fox leaps over the lazy cat.

Running typdiff old.typ new.typ produces:

= #diff-deleted[Introduction]

= #diff-added[Background]

This is the #diff-deleted[old]#diff-added[new] text.

- First item

- #diff-deleted[Second]#diff-added[Third] item

- #diff-added[Fourth item]

== Details

The quick #diff-deleted[brown]#diff-added[red] fox #diff-deleted[jumps]#diff-added[leaps] over the lazy #diff-deleted[dog]#diff-added[cat].

Compile the output with typst compile to get a PDF with visual diff markup.

Installation

With mise (recommended)

mise 2026.9.2 or later installs the appropriate prebuilt binary for your platform from the release's signed packslip manifest, verifying the signature and the archive's digest before unpacking it.

mise use -g packslip:github.com/sou1118/typdiff

Releases before v0.1.4 have no packslip manifest. To install one of them, or with an older mise, use the GitHub backend, which verifies GitHub Artifact Attestations when available:

mise use -g github:sou1118/typdiff

From crates.io

cargo install typdiff

From source (latest development version)

cargo install --git https://github.com/sou1118/typdiff

Usage

typdiff <OLD> <NEW> [-o <OUTPUT>]
Argument Description
<OLD> Path to the old Typst file
<NEW> Path to the new Typst file
-o, --output <OUTPUT> Output file path (defaults to stdout)

Examples

# Print diff to stdout
typdiff old.typ new.typ

# Save diff to a file
typdiff old.typ new.typ -o diff.typ

# Generate a PDF
typdiff old.typ new.typ -o diff.typ && typst compile diff.typ

Features

  • Block-level diffing — Detects structural changes in headings, paragraphs, list items, enum items, and term list items
  • Word-level diffing — Shows fine-grained changes within modified blocks
  • CJK support — Character-level granularity for Chinese, Japanese, and Korean text
  • Atomic blocks — Raw blocks, equations, and function calls are treated as indivisible units
  • Safe output — Escapes references, labels, and special syntax in deleted content to prevent compilation errors

How it works

  1. Parse — Both Typst files are parsed into block-level elements (headings, paragraphs, list items, etc.) using typst-syntax
  2. Diff — Blocks are compared using the Patience diff algorithm, with similarity-based matching for modified regions
  3. Render — The diff result is rendered back to Typst source with #diff-added[...] and #diff-deleted[...] markup

License

Apache-2.0

About

A diff tool for Typst documents, similar to latexdiff for LaTeX

Topics

Resources

Stars

81 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages