Files
digital-garden-flo/snippets/typst-local-automation.md
T
2026-10-14 12:04:10 +01:00

2.1 KiB

Typst Local Development Loop

I truly enjoy Typst, but having a really dependency free experience I use this method to get live reloading of the pdf file I am currently working on. I use Justfile, but anything will do, just fire the commands in the cli.

Workflow

So for like live updating or recompiling the pdf document with a justfile that looks like this in one terminal window (Sorry, this Justfile a bit clumpsy, but I hope the point gets across).

# Watch Typst document with language parameter
watch-cv-typst doc lang="da":
	typst watch --input lang={{ lang }} {{ doc }}.typ ./output/{{ doc }}-{{ lang }}.pdf

# Watch generated PDF output
watch-cv-pdf doc lang="da":
	watch-pdf ./output/{{ doc }}-{{ lang }}.pdf

# Build CV in all three languages (English, Danish, Faroese)
build-cv:
	typst compile --input lang=en ./cv.typ ./output/cv-en.pdf
	typst compile --input lang=da ./cv.typ ./output/cv-da.pdf
	typst compile --input lang=fo ./cv.typ ./output/cv-fo.pdf

# Build cover letter from YAML input 
build-letter yaml output:
	typst compile --input cover-letter={{ yaml }} letter.typ {{ output }}

# Live watch mode for cover letter compilation
watch-letter-typst yaml output:
	typst watch --input cover-letter={{ yaml }} letter.typ {{ output }}

watch-letter-pdf doc:
	watch-pdf {{ doc }}.pdf

While the machine having the watch-pdf script available in PATH

#!/usr/bin/env bash
set -euo pipefail     

[[ -z "$1" ]] && { echo "ERROR: No PDF filename provided"; exit 1; }
PDF_PATH="$1"

if [[ ! -f "${PDF_PATH}" ]]; then
  echo "ERROR: ${PDF_PATH} is not a regular file"
  exit 1
fi

command -v evince &> /dev/null || { echo "❌ evince not found. Install: sudo apt-get install evince"; exit 1; }

echo "=== Reload Watcher Started ==="
echo "Monitoring ${PDF_PATH} for writes…"

while IFS= read -r change_file; do
  [[ "${change_file}" == "${PDF_PATH}" ]] || continue
  echo "[$(date '+%Y-%m-%d %H:%M:%S')] ${PDF_PATH} modified → opening evince"
  evince "${PDF_PATH}" &
done < <(inotifywait -mr --format '%w%f' -e close_write "${PDF_PATH}")

echo "Watcher stopped."