spb/traite-evaluation-qc
Public
1#!/usr/bin/env bash2# Compile un chapitre (ou une annexe) seul, avec le préambule complet du livre.3# Usage : tools/compile_chapter.sh 16 -> build/ch16/ch16.pdf4# tools/compile_chapter.sh glossaire -> build/app-glossaire/app-glossaire.pdf5set -uo pipefail6ROOT="$(cd "$(dirname "$0")/.." && pwd)"7ARG="${1:?numero de chapitre (16) ou nom d annexe}"8if [[ "$ARG" =~ ^[0-9]+$ ]]; then9 N=$(printf "%02d" "$ARG"); SRC="chapters/ch$N.tex"; JOB="ch$N"; SOL="../solutions/ch$N.tex"; PREV=$((10#$N - 1))10else11 SRC="appendices/$ARG.tex"; JOB="app-$ARG"; SOL=""; PREV=012fi13OUT="$ROOT/build/$JOB"; mkdir -p "$OUT"14WRAP="$ROOT/manuscript/_wrap_$JOB.tex"15{16 printf '%s\n' '\providecommand{\BUILDVARIANT}{uqo}\providecommand{\BUILDMEDIA}{numerique}'17 printf '%s\n' '\documentclass[10pt,twoside,openright]{book}'18 printf '%s\n' '\newif\ifLogoAutorise\LogoAutorisefalse\def\PALETTE{uqo}'19 printf '%s\n' '\usepackage{traite-qc}'20 printf '%s\n' '\input{../manuscript/frontmatter/metadata.tex}'21 printf '\\input{%s}\n' "$OUT/_labels.tex"22 printf '%s\n' '\begin{document}'23 printf '\\setcounter{chapter}{%d}\n' "$PREV"24 printf '\\input{%s}\n' "$SRC"25 if [[ -n "$SOL" ]]; then printf '\\appendix\\chapter{Solutions du chapitre}\\input{%s}\n' "$SOL"; fi26 printf '%s\n' '\printbibliography'27 printf '%s\n' '\end{document}'28} > "$WRAP"29python3 "$ROOT/tools/make_labels.py" "$OUT/_labels.tex"30cd "$ROOT/manuscript"; export TEXINPUTS="../styles:${TEXINPUTS:-}"31latexmk -g -lualatex -interaction=nonstopmode -halt-on-error -file-line-error -bibtex -e "\$biber=q{$ROOT/tools/biber %O %S};" -output-directory="$OUT" "$WRAP" >"$OUT/latexmk.out" 2>&132RC=$?33rm -f "$WRAP"34LOG="$OUT/_wrap_$JOB.log"35if [[ $RC -ne 0 ]]; then36 echo "ECHEC de compilation ($JOB). Premieres erreurs :"37 grep -nE '^.*:[0-9]+: |^! ' "$LOG" | head -2038 exit 139fi40mv -f "$OUT/_wrap_$JOB.pdf" "$OUT/$JOB.pdf"41PAGES=$(grep -oE 'Output written on .*\(([0-9]+) pages' "$LOG" | tail -1 | grep -oE '[0-9]+ pages')42WARN=$(grep -cE 'LaTeX Warning: (Reference|Citation) .* undefined' "$LOG")43OVF=$(grep -c 'Overfull \\hbox' "$LOG")44echo "OK $JOB : $PAGES, $WARN references/citations non definies, $OVF overfull hbox -> $OUT/$JOB.pdf"45grep -E 'LaTeX Warning: (Reference|Citation) .* undefined' "$LOG" | sed 's/LaTeX Warning: //' | sort -u | head -1546exit 047