Skip to content

Instantly share code, notes, and snippets.

@alexnederlof
Created September 6, 2013 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexnederlof/6461356 to your computer and use it in GitHub Desktop.
Save alexnederlof/6461356 to your computer and use it in GitHub Desktop.
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