diff options
| author | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-23 11:29:48 -0600 |
|---|---|---|
| committer | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-23 11:29:48 -0600 |
| commit | aacecb3a8593ec0a92809be15b12211befb9e9f5 (patch) | |
| tree | c1624ee690d7e2656ad04776fb5a4851e8422f87 /scripts | |
| parent | d711e2f0d6dbaa7c3491e6ead09c5a9ca60197af (diff) | |
| download | zash-aacecb3a8593ec0a92809be15b12211befb9e9f5.tar.gz | |
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.
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/spec-pdf.sh | 46 |
1 files changed, 46 insertions, 0 deletions
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 |
