#! /bin/bash usage="$0 TEXFILE" # Runs bibtex ${TEXFILE:r} and latex ${TEXFILE} repeatedly until # the ".aux" and ".bbl" files are stable. if [[ $# -ne 1 ]]; then echo "usage: ${usage}" 1>&2; exit 1 fi name="$1"; shift; source "${STOLFIHOME}/lib/latex-parse-name.sh" echo "run-latex: name = ${name} ext = ${ext}" 1>&2 auxiliaries=( aux bbl toc lof lot ) # Make sure that the auxiliary targets exist: echo "run-latex: making sure that auxiliary files exist" 1>&2 for ext in ${auxiliaries[@]} ; do target="${name}.${ext}" if [[ ! -r ${target} ]]; then touch ${target}; fi done # Loop until convergence: while [[ 1 ]]; do # Save current version of files: for ext in ${auxiliaries[@]} ; do target="${name}.${ext}" /bin/cp -v ${target} ${target}~~ done # Run bibtex and latex bibtex ${name} bibfailed=$? echo "run-latex: status = $bibfailed" 1>&2 which latex latex ${name} > ${name}.errs texfailed=$? echo "run-latex: status = $texfailed" 1>&2 if [[ ${texfailed} ]]; then break; fi # Check if any of the result files changed: changed=0 for ext in ${auxiliaries[@]} ; do target="${name}.${ext}" if ! { cmp -s ${target} ${target}~~; } ; then echo "run-latex: ${target} changed" 1>&2 changed=1 ( ls -l ${target}~~ ${target} ; \ diff ${target}~~ ${target} \ | prettify-diff-output z \ | head -10 z \ ) \ | sed -e 's/^/ | /' fi done if [[ ! ${changed} ]]; then break; fi done # Either bibtex/latex failed or the process converged. # Print the error messages cat ${name}.errs | tex-error-filter # cat ${name}.errs echo "run-latex: done" 1>&2 exit ${texfailed}