#!/usr/bin/env bash # Compile un chapitre (ou une annexe) seul, avec le préambule complet du livre. # Usage : tools/compile_chapter.sh 16 -> build/ch16/ch16.pdf # tools/compile_chapter.sh glossaire -> build/app-glossaire/app-glossaire.pdf set -uo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" ARG="${1:?numero de chapitre (16) ou nom d annexe}" if [[ "$ARG" =~ ^[0-9]+$ ]]; then N=$(printf "%02d" "$ARG"); SRC="chapters/ch$N.tex"; JOB="ch$N"; SOL="../solutions/ch$N.tex"; PREV=$((10#$N - 1)) else SRC="appendices/$ARG.tex"; JOB="app-$ARG"; SOL=""; PREV=0 fi OUT="$ROOT/build/$JOB"; mkdir -p "$OUT" WRAP="$ROOT/manuscript/_wrap_$JOB.tex" { printf '%s\n' '\providecommand{\BUILDVARIANT}{uqo}\providecommand{\BUILDMEDIA}{numerique}' printf '%s\n' '\documentclass[10pt,twoside,openright]{book}' printf '%s\n' '\newif\ifLogoAutorise\LogoAutorisefalse\def\PALETTE{uqo}' printf '%s\n' '\usepackage{traite-qc}' printf '%s\n' '\input{../manuscript/frontmatter/metadata.tex}' printf '\\input{%s}\n' "$OUT/_labels.tex" printf '%s\n' '\begin{document}' printf '\\setcounter{chapter}{%d}\n' "$PREV" printf '\\input{%s}\n' "$SRC" if [[ -n "$SOL" ]]; then printf '\\appendix\\chapter{Solutions du chapitre}\\input{%s}\n' "$SOL"; fi printf '%s\n' '\printbibliography' printf '%s\n' '\end{document}' } > "$WRAP" python3 "$ROOT/tools/make_labels.py" "$OUT/_labels.tex" cd "$ROOT/manuscript"; export TEXINPUTS="../styles:${TEXINPUTS:-}" latexmk -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>&1 RC=$? rm -f "$WRAP" LOG="$OUT/_wrap_$JOB.log" if [[ $RC -ne 0 ]]; then echo "ECHEC de compilation ($JOB). Premieres erreurs :" grep -nE '^.*:[0-9]+: |^! ' "$LOG" | head -20 exit 1 fi mv -f "$OUT/_wrap_$JOB.pdf" "$OUT/$JOB.pdf" PAGES=$(grep -oE 'Output written on .*\(([0-9]+) pages' "$LOG" | tail -1 | grep -oE '[0-9]+ pages') WARN=$(grep -cE 'LaTeX Warning: (Reference|Citation) .* undefined' "$LOG") OVF=$(grep -c 'Overfull \\hbox' "$LOG") echo "OK $JOB : $PAGES, $WARN references/citations non definies, $OVF overfull hbox -> $OUT/$JOB.pdf" grep -E 'LaTeX Warning: (Reference|Citation) .* undefined' "$LOG" | sed 's/LaTeX Warning: //' | sort -u | head -15 exit 0