Last active
September 10, 2022 16:39
-
-
Save GaPhil/4f50ed56232c556e6be456b1a41d165f to your computer and use it in GitHub Desktop.
Compile LaTex with or without (cross) references for improved performance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Setting defaults | |
FILE="./main" | |
mkdir -p "./out" | |
OUT_DIR="./out" | |
REFS=false | |
CROSS_REFS=false | |
function usage() { | |
echo "Usage: $(basename "$0") [-cr] [-i input_file] [-o output_dir]" 2>&1 | |
echo ' -c Compiles cross references.' | |
echo ' -i Specifies the input file.' | |
echo ' -o Specifies the output directory.' | |
echo ' -r Compiles references.' | |
echo 'If no options are set, main.tex will be compiled without references into the ./out/ directory.' | |
} | |
while getopts "ci::o::r" flag; do | |
case "${flag}" in | |
c) | |
CROSS_REFS=true | |
;; | |
i) # | |
REFS=true | |
FILE=${OPTARG} | |
;; | |
o) | |
REFS=true | |
rmdir "./out" | |
mkdir -p "${OPTARG}" | |
OUT_DIR=${OPTARG} | |
;; | |
r) | |
REFS=true | |
;; | |
?) | |
usage | |
rmdir "./out" 2>/dev/null | |
exit 1 | |
;; | |
esac | |
done | |
# Fast compile | |
pdflatex -output-directory="${OUT_DIR}" "${FILE}.tex" | |
# Compile references | |
if [ "${CROSS_REFS}" = true ] || [ "${REFS}" = true ]; then | |
cp ./*.bib "${OUT_DIR}" | |
bibtex "${OUT_DIR}/${FILE}" | |
pdflatex -output-directory="${OUT_DIR}" "${FILE}.tex" | |
# Compile cross references | |
if [ "${CROSS_REFS}" = true ]; then | |
pdflatex -output-directory="${OUT_DIR}" "${FILE}.tex" | |
fi | |
rm "${OUT_DIR}/"*.bib | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment