#!/bin/sh # shellcheck shell=sh # # spec-pdf.sh - typeset formal/zash-spec.typ into formal/zash-spec.pdf # # usage: spec-pdf.sh [-v] [out.pdf] # # Run from anywhere inside the repository. The root passed to typst is the # repository root, because the spec reads ../packaging/zash-logo.svg and # typst refuses files outside its root. # # Uses the typst CLI if it is on PATH, otherwise the Python package # (pip install typst), which is how the PDF was first built. set -eu verbose=0 if [ "${1-}" = -v ]; then verbose=1 shift fi root=$(cd "$(dirname "$0")/.." && pwd) src=$root/formal/zash-spec.typ out=${1:-$root/formal/zash-spec.pdf} [ -f "$src" ] || { echo "spec-pdf.sh: $src: not found" >&2; exit 1; } if command -v typst >/dev/null 2>&1; then [ "$verbose" = 1 ] && echo "typst CLI: $(typst --version)" >&2 typst compile --root "$root" "$src" "$out" elif python3 -c 'import typst' 2>/dev/null; then [ "$verbose" = 1 ] && echo "typst Python package" >&2 python3 - "$src" "$out" "$root" <<'EOF' import sys import typst src, out, root = sys.argv[1:] typst.compile(src, output=out, root=root) EOF else echo "spec-pdf.sh: need typst (CLI) or 'pip install typst'" >&2 exit 1 fi [ "$verbose" = 1 ] && echo "wrote $out" >&2 exit 0