From aacecb3a8593ec0a92809be15b12211befb9e9f5 Mon Sep 17 00:00:00 2001 From: Sean Kurtz Date: Mon, 23 Nov 2026 11:29:48 -0600 Subject: formal: typeset the spec from a script, and with the new cover formal/zash-spec.pdf could not be rebuilt from anything in the tree. scripts/spec-pdf.sh does it: the typst CLI when present, the Python package otherwise, with the repository root as typst's root so the cover can reach ../packaging/zash-logo.svg. `make spec` runs it. The PDF is rebuilt from the same source, so the cover carries the new logo; the page count is unchanged at 27. --- scripts/spec-pdf.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 scripts/spec-pdf.sh (limited to 'scripts') diff --git a/scripts/spec-pdf.sh b/scripts/spec-pdf.sh new file mode 100755 index 0000000..6870654 --- /dev/null +++ b/scripts/spec-pdf.sh @@ -0,0 +1,46 @@ +#!/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 -- cgit