Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auto recompile Latex in the background on OS X
#!/bin/bash
###
# A Script that automatically recompiles your
# Latex in the background on Mac OS X.
###
# Options
BIN_PATH=/usr/texbin
FILE=thesis
WATCH_FILE=chapters
# The script
PREVIOUS=""
while [ true ] ; do
# Calculate any difference using crc32. CRC is nice and quick.
NOW=`crc32 $WATCH_FILE.tex`
if [ ! "$NOW" == "$PREVIOUS" ]; then
echo "Diff!"
PREVIOUS=$NOW
# Run first pdf comile
$BIN_PATH/pdflatex -halt-on-error $FILE.tex
if [ $? -eq 1 ]; then # If error code
echo -e "\033[31m Compilation error\033[0m"
# Stop and wait until changed again
continue
fi;
# Compile the bibtech.
for aux in `ls *.aux`; do
$BIN_PATH/bibtex $aux
done
# Compile latex twice. Just because its a stupid language.
$BIN_PATH/pdflatex -halt-on-error $FILE.tex > /dev/null
$BIN_PATH/pdflatex -halt-on-error $FILE.tex > /dev/null
#Open with Preview in the background
open -g $FILE.pdf
fi
sleep 1;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment