SPB Git
2.2 KB · 45 lines shellscript
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 '%s\n' '\begin{document}'22  printf '\\setcounter{chapter}{%d}\n' "$PREV"23  printf '\\input{%s}\n' "$SRC"24  if [[ -n "$SOL" ]]; then printf '\\appendix\\chapter{Solutions du chapitre}\\input{%s}\n' "$SOL"; fi25  printf '%s\n' '\printbibliography'26  printf '%s\n' '\end{document}'27} > "$WRAP"28cd "$ROOT/manuscript"; export TEXINPUTS="../styles:${TEXINPUTS:-}"29latexmk -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>&130RC=$?31rm -f "$WRAP"32LOG="$OUT/_wrap_$JOB.log"33if [[ $RC -ne 0 ]]; then34  echo "ECHEC de compilation ($JOB). Premieres erreurs :"35  grep -nE '^.*:[0-9]+: |^! ' "$LOG" | head -2036  exit 137fi38mv -f "$OUT/_wrap_$JOB.pdf" "$OUT/$JOB.pdf"39PAGES=$(grep -oE 'Output written on .*\(([0-9]+) pages' "$LOG" | tail -1 | grep -oE '[0-9]+ pages')40WARN=$(grep -cE 'LaTeX Warning: (Reference|Citation) .* undefined' "$LOG")41OVF=$(grep -c 'Overfull \\hbox' "$LOG")42echo "OK $JOB : $PAGES, $WARN references/citations non definies, $OVF overfull hbox -> $OUT/$JOB.pdf"43grep -E 'LaTeX Warning: (Reference|Citation) .* undefined' "$LOG" | sed 's/LaTeX Warning: //' | sort -u | head -1544exit 045
Files · aec5b3ada91a3917afad185ea43ebf02faef3fbc
Menu

Theme