S SmartDocs
シリーズ: mathematics bash 29 行 · 更新日 2026-08-17

build.sh

mathematics/Statistics/build.sh

#!/bin/bash
# 編譯《機率與統計:從入門到精通》全部章節
# 用法:./build.sh          編譯全部
#       ./build.sh 第03章*  只編譯符合樣式的檔案
set -u
cd "$(dirname "$0")"

shopt -s nullglob
if [ $# -gt 0 ]; then
  files=( "$@" )
else
  files=( 第*.tex 附錄*.tex )
fi

fail=0
for tex in "${files[@]}"; do
  echo "==> 編譯 $tex"
  if xelatex -interaction=nonstopmode -halt-on-error "$tex" > /dev/null 2>&1 \
     && xelatex -interaction=nonstopmode -halt-on-error "$tex" > /dev/null 2>&1; then
    echo "    完成:${tex%.tex}.pdf"
  else
    echo "    失敗:請查看 ${tex%.tex}.log"
    fail=1
  fi
done

# 清理輔助檔
rm -f ./*.aux ./*.out ./*.toc 2>/dev/null
exit $fail