tokenfabrikker/rapport/bygg.sh
Kjell Tore Guttormsen f271f11715
docs(rapport): appendices with the parameters and the change list, the reference list, and the two-page summary
Appendix B, appendix C and the reference list are generated from the frozen
parameter file, the pre-registration and the source bank. Citations link to
their item in the list. The two-page summary states only what the summary in
the report states. Draft PDFs of the report and the summary are in pdf/.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-14 21:24:36 +01:00

106 lines
3.7 KiB
Bash
Executable file

#!/bin/bash
# Build the report PDFs: main.pdf (pdflatex x3), notat.pdf (pdflatex x3), karusell.pdf (xelatex x2).
#
# Usage: rapport/bygg.sh [main] [notat] [karusell] (no argument: all three)
#
# Every LaTeX run has a hard time limit (TIDSGRENSE seconds, default 120): one pdflatex run has
# been seen to hang. The limit is set with perl's alarm, since macOS has no timeout command.
# The script first writes vedlegg_kart.tex with lag_vedlegg.py, generert/ (chapter 6) with
# lag_resultater.py, the appendices with the parameters and the change list, and the reference
# list (lag_vedlegg_parametere.py, lag_vedlegg_endringer.py, lag_referanser.py). It exits non-zero when the
# generator fails, a LaTeX run fails or times out, or the last run reports undefined references.
# Bash 3.2 and ASCII only. Build output stays in rapport/ and is ignored by git.
set -u
TIDSGRENSE="${TIDSGRENSE:-120}"
MAPPE="$(cd "$(dirname "$0")" && pwd)"
PATH="/Library/TeX/texbin:$PATH"
export PATH
cd "$MAPPE" || exit 1
na() {
perl -MTime::HiRes=time -e 'printf "%.1f", time'
}
sider() {
if command -v pdfinfo >/dev/null 2>&1; then
pdfinfo "$1" 2>/dev/null | awk '/^Pages:/ {print $2}'
else
echo "?"
fi
}
# One LaTeX run with the time limit. $1 = engine, $2 = file without .tex, $3 = run number.
kjor() {
motor="$1"
navn="$2"
nr="$3"
perl -e 'alarm shift @ARGV; exec @ARGV or die "exec: $!\n"' "$TIDSGRENSE" \
"$motor" -interaction=nonstopmode -halt-on-error -file-line-error "$navn.tex" \
</dev/null >"$navn-kjoring$nr.log" 2>&1
status=$?
if [ "$status" -eq 142 ]; then
echo "FEIL: $motor $navn.tex, kjoring $nr, stanset etter $TIDSGRENSE s (tidsgrense)" >&2
return 1
fi
if [ "$status" -ne 0 ]; then
echo "FEIL: $motor $navn.tex, kjoring $nr, avsluttet med status $status" >&2
grep -n -m 5 -E '^[^:]+:[0-9]+:|^! ' "$navn.log" >&2 2>/dev/null
echo " (se $MAPPE/$navn.log)" >&2
return 1
fi
return 0
}
# Build one document. $1 = engine, $2 = file without .tex, $3 = number of runs.
bygg() {
motor="$1"
navn="$2"
antall="$3"
start="$(na)"
i=1
while [ "$i" -le "$antall" ]; do
kjor "$motor" "$navn" "$i" || return 1
i=$((i + 1))
done
slutt="$(na)"
rm -f "$navn"-kjoring*.log
if grep -q -E "There were undefined references|Reference .* undefined|Citation .* undefined" "$navn.log"; then
echo "FEIL: $navn.pdf har udefinerte referanser (se $MAPPE/$navn.log)" >&2
return 1
fi
if grep -q -E "Rerun to get|Label\(s\) may have changed" "$navn.log"; then
echo "ADVARSEL: $navn.log ber om en ny kjoring etter $antall kjoringer" >&2
fi
tid="$(perl -e 'printf "%.1f", $ARGV[1] - $ARGV[0]' "$start" "$slutt")"
echo "OK: $navn.pdf, $(sider "$navn.pdf") sider, $tid s ($antall x $motor)"
return 0
}
if [ "$#" -eq 0 ]; then
set -- main notat karusell
fi
python3 lag_vedlegg.py || { echo "FEIL: lag_vedlegg.py" >&2; exit 1; }
python3 lag_resultater.py || { echo "FEIL: lag_resultater.py" >&2; exit 1; }
python3 lag_vedlegg_parametere.py || { echo "FEIL: lag_vedlegg_parametere.py" >&2; exit 1; }
python3 lag_vedlegg_endringer.py || { echo "FEIL: lag_vedlegg_endringer.py" >&2; exit 1; }
# Last: the reference list also reads the generated appendices.
python3 lag_referanser.py || { echo "FEIL: lag_referanser.py" >&2; exit 1; }
feil=0
for maal in "$@"; do
case "$maal" in
main) bygg pdflatex main 3 || feil=1 ;;
notat) bygg pdflatex notat 3 || feil=1 ;;
karusell) bygg xelatex karusell 2 || feil=1 ;;
*) echo "FEIL: ukjent maal '$maal' (main, notat, karusell)" >&2; feil=1 ;;
esac
done
if [ "$feil" -ne 0 ]; then
exit 1
fi
exit 0