Serie: Game Theory
bash
60 righe
· Aggiornato 2026-08-03
build-chapter-pdfs.sh
Game Theory/build-chapter-pdfs.sh
#!/bin/bash
# Build one standalone high-quality PDF per chapter/appendix .tex file.
# Cross-chapter references are resolved against the full book (main.aux) via xr.
set -e
cd "$(dirname "$0")"
# Fresh main.aux so xr can resolve cross-references
latexmk -pdf -interaction=nonstopmode -halt-on-error main.tex >/dev/null
mkdir -p standalone build chapter-pdfs
# name : setup-code
entries=(
"preface|\\chapter*{Preface}"
"ch01-introduction|\\setcounter{chapter}{0}"
"ch02-rationality|\\setcounter{chapter}{1}"
"ch03-normal-form|\\setcounter{chapter}{2}"
"ch04-nash|\\setcounter{chapter}{3}"
"ch05-mixed|\\setcounter{chapter}{4}"
"ch06-extensive|\\setcounter{chapter}{5}"
"ch07-applications|\\setcounter{chapter}{6}"
"ch08-bargaining|\\setcounter{chapter}{7}"
"ch09-repeated|\\setcounter{chapter}{8}"
"ch10-bayesian|\\setcounter{chapter}{9}"
"ch11-dynamic-incomplete|\\setcounter{chapter}{10}"
"ch12-zerosum|\\setcounter{chapter}{11}"
"ch13-existence-refinements|\\setcounter{chapter}{12}"
"ch14-mechanism-design|\\setcounter{chapter}{13}"
"ch15-cooperative|\\setcounter{chapter}{14}"
"ch16-evolutionary|\\setcounter{chapter}{15}"
"ch17-algorithmic|\\setcounter{chapter}{16}"
"ch18-frontiers|\\setcounter{chapter}{17}"
"appendix-math|\\appendix\\setcounter{chapter}{0}"
"appendix-solutions|\\appendix\\setcounter{chapter}{1}"
"bibliography|\\backmatter"
)
for entry in "${entries[@]}"; do
name="${entry%%|*}"
setup="${entry#*|}"
wrapper="standalone/${name}.tex"
{ echo '\documentclass[11pt,a4paper]{book}'
echo '\input{preamble}'
echo '\usepackage{xr}'
echo '\externaldocument{main}'
echo '\begin{document}'
[ "$name" = "preface" ] || true
echo "$setup"
echo "\\input{chapters/${name}}"
echo '\end{document}'
} > "$wrapper"
echo "=== Building ${name}.pdf"
latexmk -pdf -interaction=nonstopmode -halt-on-error \
-output-directory=build "$wrapper" >/dev/null
mv "build/${name}.pdf" "chapter-pdfs/${name}.pdf"
done
echo "Done. PDFs in chapter-pdfs/:"
ls chapter-pdfs/