Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A bash script to clean LaTeX temporary files, compiling, and glossaries.
#!/bin/bash
# USAGE: ./script FILE --clean --glossary
extensions_to_delete=(gz fls fdb_latexmk blg bbl log aux out nav toc snm glg glo xdy)
compile_and_open() {
argument="$1"
auxname="${argument%.tex}.aux"
errors=$(pdflatex -shell-escape -interaction=nonstopmode -file-line-error "$argument" | grep ".*:[0-9]*:.*")
if [[ -n $errors ]]; then
echo "$1 Errors Detected"
echo "$errors" | less
else
open_file $1
echo "$1 Compile Successful"
fi
}
open_file() {
filename=`echo "$1" | cut -d'.' -f1`
open "$filename.pdf"
echo "$filename Opened"
}
# http://tex.stackexchange.com/questions/6845/compile-latex-with-bibtex-and-glossaries
glossary() {
compile $1
makeglossaries $1
compile $1
compile $1
}
clean() {
for file in $(dirname $1)/*; do
filename=$(basename "$file")
extension="${filename##*.}"
filename="${filename%.*}"
for bad_extensions in "${extensions_to_delete[@]}" ; do
if [[ $bad_extensions = $extension ]]; then
rm $file
echo "$file Deleted"
fi
done
done
}
main() {
compile_and_open $1
if [ "$3" = "--glossary" ]; then
glossary $1
fi
if [ "$2" = "--clean" ]; then
clean $1
fi
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment