Skip to content

Instantly share code, notes, and snippets.

@paschalis-mpeis
Created January 19, 2022 12:40
Show Gist options
  • Save paschalis-mpeis/4612e9d0ee053c97dbb4e5a631800d7c to your computer and use it in GitHub Desktop.
Save paschalis-mpeis/4612e9d0ee053c97dbb4e5a631800d7c to your computer and use it in GitHub Desktop.
Latex compile wrapper on OSX
#!/bin/bash
# Convenience script that puts all intermediate files in ./out dir
# PDF is generated at: ./out/main.pdf
# It is the structured used by [Hannah-Sten/TeXiFy-IDEA](https://github.com/Hannah-Sten/TeXiFy-IDEA)
# Sample structure:
# .
# ├── compile.sh
# ├── project.iml
# ├── out
# └── src
SRC=src
OUT=out
CCPDF=pdflatex
MAIN=main.tex
SHOW_OUTPUT=0
SHOW_ERRORS=0
##########################################
###
# Wrapper for showing/hiding std outputs
###
run() {
if [[ "$SHOW_OUTPUT" -eq 1 ]]; then
echo "show all"
"$@"
elif [[ "$SHOW_ERRORS" -eq 1 ]]; then
"$@" > /dev/null
else
hide=$("$@")
fi
}
function compile_pdf() {
echo -n "- PDF: "
mkdir -p $OUT
cd $SRC
run $CCPDF -file-line-error \
-interaction=nonstopmode \
-synctex=1 \
-output-format=pdf \
-output-directory=../$OUT $MAIN
cd ../
echo " DONE"
}
function compile_bib() {
echo -n "- BIB: "
if [ ! -d $OUT ]; then
echo "ERROR: no output dir: $OUT"
echo -e " Have you run $CCPDF first?"
exit 1
fi
# export vars to work with custom out dir
srcDir=$(pwd)/src
export BIBINPUTS="$srcDir"
export BSTINPUTS="$srcDir":
cd $OUT
run bibtex main
cd ../
echo " DONE"
}
if [ -f $OUT/main.bbl ]; then
echo "Compiling:"
echo -n "1/2 | "; compile_bib
echo -n "2/2 | "; compile_pdf
else
echo "Compiling from Scratch:"
echo -n "1/4 | "; compile_pdf
echo -n "2/4 | "; compile_bib
echo -n "3/4 | "; compile_pdf
echo -n "4/4 | "; compile_pdf
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment