Files
2026-09-25 13:33:30 +02:00

72 lines
2.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build the three language books of this single-source project:
# _book/ English (default profile -- also what the preview renders)
# _book/fr/ French
# _book/de/ German
# Html and pdf for every language; the pdf is offered as a download in the
# html sidebar (book: downloads: [pdf] in _quarto.yml).
#
# ./render-all.sh build
# ./render-all.sh --serve [port] build, then serve _book/ on localhost (8000)
#
# The figures are built first: figures/build-figures.py turns each drawing in
# figures/src/ into figures/<name>-{en,fr,de}.svg (html) and .pdf (latex).
# A chapter refers to one without an extension, so each output format picks the
# file it can use. The web version also animates the message flow through the
# mailboxes; that layer is figures/flow-player.html and needs no build step.
#
# English goes first on purpose: its full render empties _book/, which holds
# the other two. Stop `quarto preview` before running this, for the same
# reason: preview keeps re-rendering English. After one run, the language menu also works in the VS Code
# preview, since that serves _book/ -- but fr/ and de/ only change when this
# script runs again.
#
# A fr/de PDF loads its language from babel's bundled .ini files (babeloptions:
# provide=* in the profiles), so no extra TeX packages are needed. A missing
# .ini is detected up front and that PDF is skipped instead.
set -uo pipefail
cd "$(dirname "$0")"
serve=""
if [ "${1:-}" = "--serve" ]; then serve="${2:-8000}"; fi
declare -A LDF=( [en]="" [fr]=babel-fr.ini [de]=babel-de.ini )
declare -A PKG=( [en]="" [fr]=texlive-basic [de]=texlive-basic )
problems=()
echo "==> figures"
python3 figures/build-figures.py || problems+=("figures: build failed")
for l in en fr de; do
# One render per language, both formats at once. Rendering them separately
# does not work: `--to pdf` afterwards prunes the html-only libraries
# (bootstrap, quarto-nav, quarto-search, ...) out of that language's
# site_libs/, because they are not among the pdf's dependencies -- and
# --no-clean does not stop it. The pages then load without styles or
# scripts. Asking for both formats in one command tells Quarto both
# dependency sets are live.
if [ -n "${LDF[$l]}" ] && [ -z "$(kpsewhich "${LDF[$l]}" 2>/dev/null)" ]; then
echo "==> $l: html (pdf skipped)"
quarto render --profile "$l" --to html || problems+=("$l: html failed")
problems+=("$l: pdf skipped, missing ${LDF[$l]} -> sudo pacman -S ${PKG[$l]}")
else
echo "==> $l: html + pdf"
quarto render --profile "$l" || problems+=("$l: render failed")
fi
done
echo
if [ ${#problems[@]} -eq 0 ]; then
echo "all three books built."
else
printf '%s\n' "${problems[@]}"
fi
if [ -n "$serve" ]; then
echo
echo "serving _book/ on http://localhost:$serve/ (Ctrl+C to stop)"
exec python3 -m http.server "$serve" --bind 127.0.0.1 --directory _book
fi
[ ${#problems[@]} -eq 0 ]