Skip to content

Instantly share code, notes, and snippets.

@Dragonink
Last active May 27, 2025 17:23
Show Gist options
  • Save Dragonink/2c50e4b9ed8ba071060f15b1977aa05c to your computer and use it in GitHub Desktop.
Save Dragonink/2c50e4b9ed8ba071060f15b1977aa05c to your computer and use it in GitHub Desktop.
How to Typst + PanDiff

How to Typst + PanDiff

  1. Prepare a diff.typ source file as shown in this Gist.
  2. Provided you have two Typst SOURCE files named a.typ and b.typ, execute:
    pandiff --from typst --to typst a.typ b.typ > diff.content.typ
  3. Compile the diff.typ file:
    typst compile diff.typ
#let diff-box(color, contents) = box(
outset: 0.25em,
fill: color.transparentize(85%),
text(fill: color, contents),
)
#let INSERT_RE = regex(`\{\+{2}(.+?)\+{2}\}`.text)
#show INSERT_RE: this => {
let (contents,) = this.text.match(INSERT_RE).captures
diff-box(green, underline(contents))
}
#let DELETE_RE = regex(`\{(?:-{2}|–)(.+?)(?:-{2}|–)\}`.text)
#show DELETE_RE: this => {
let (contents,) = this.text.match(DELETE_RE).captures
diff-box(red, strike(contents))
}
#let REPLACE_RE = regex(`\{(?:~{2})(.+?)~>(.+?)(?:~{2})\}`.text)
#show REPLACE_RE: this => {
let (old, new) = this.text.match(REPLACE_RE).captures
diff-box(orange)[
#strike(old)
#underline(new)
]
}
#include "diff.content.typ"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment