Serie: Machine Learning
bash
49 righe
· Aggiornato 2026-06-19
build.sh
Machine_Learning/build.sh
#!/usr/bin/env bash
# Build all curriculum PDFs with XeLaTeX.
# Usage: ./build.sh # build everything
# ./build.sh phase0 # build a single source stem in src/
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SRC="$ROOT/src"
OUT="$ROOT/pdf"
BUILD="$ROOT/.build"
mkdir -p "$OUT" "$BUILD"
export TEXINPUTS=".:$ROOT/style:$ROOT/src:${TEXINPUTS:-}"
compile () {
local stem="$1"
local tex="$SRC/$stem.tex"
[ -f "$tex" ] || { echo "!! missing $tex"; return 1; }
echo "==> Building $stem"
# Two passes for TOC / refs / bookmarks.
for pass in 1 2; do
xelatex -interaction=nonstopmode -halt-on-error \
-output-directory="$BUILD" "$tex" > "$BUILD/$stem.pass$pass.log" 2>&1 || {
echo "!! XeLaTeX failed on $stem (pass $pass). Tail of log:";
tail -n 40 "$BUILD/$stem.pass$pass.log";
return 1;
}
done
cp "$BUILD/$stem.pdf" "$OUT/$stem.pdf"
echo " -> $OUT/$stem.pdf ($(du -h "$OUT/$stem.pdf" | cut -f1))"
}
if [ "$#" -ge 1 ]; then
compile "$1"
else
for tex in "$SRC"/*.tex; do
compile "$(basename "$tex" .tex)"
done
# Merge into a single volume (in reading order) if pdfunite is available.
if command -v pdfunite >/dev/null 2>&1; then
order=(00_overview phase0_math_tooling phase1_core_ml phase2_dl_foundations \
phase3_computer_vision phase4_nlp_transformers phase5_generative_models \
phase6_reinforcement_learning phase7_mlops_deployment phase8_capstones)
parts=(); for s in "${order[@]}"; do [ -f "$OUT/$s.pdf" ] && parts+=("$OUT/$s.pdf"); done
pdfunite "${parts[@]}" "$OUT/ML_DL_Curriculum_complete.pdf" \
&& echo " -> $OUT/ML_DL_Curriculum_complete.pdf (combined volume)"
fi
fi
echo "All done. PDFs in $OUT"