Created
September 6, 2013 09:04
-
-
Save alexnederlof/6461356 to your computer and use it in GitHub Desktop.
Auto recompile Latex in the background on OS X
This file contains 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 | |
### | |
# 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