tokenfabrikker/rapport/bygg.sh
Kjell Tore Guttormsen 339161df18
docs(rapport): LaTeX skeleton of the report, the summary and the carousel, with placeholders for every result
Foreword, chapters 1, 2 and 8 and the appendix from equation to code are
written from the pre-registration, the review log and the map; the rest are
stubs. bygg.sh builds with a time limit per LaTeX run. Not yet read against
the sources by the session.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-14 09:29:57 +01:00

99 lines
3.1 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. 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; }
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