#!/usr/bin/env bash
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PAPER_DIR="$HERE/../paper"
OUT_DIR="$HERE/build"
mkdir -p "$OUT_DIR"
cp "$PAPER_DIR/"*.tex "$OUT_DIR/"
cp "$PAPER_DIR/"*.bib "$OUT_DIR/"
cd "$OUT_DIR"
if ! command -v pdflatex >/dev/null 2>&1; then
  echo "pdflatex not found. Compile locally with:"
  echo "  pdflatex sft_form_theory.tex"
  echo "  bibtex sft_form_theory"
  echo "  pdflatex sft_form_theory.tex"
  echo "  pdflatex sft_form_theory.tex"
  exit 0
fi
pdflatex -interaction=nonstopmode sft_form_theory.tex || true
if command -v bibtex >/dev/null 2>&1; then
  bibtex sft_form_theory || true
fi
pdflatex -interaction=nonstopmode sft_form_theory.tex || true
pdflatex -interaction=nonstopmode sft_form_theory.tex || true
echo "Build output in $OUT_DIR"
