Last active
December 19, 2015 00:39
-
-
Save mattiaslundberg/5869965 to your computer and use it in GitHub Desktop.
Autobuild latex files.
This file contains hidden or 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
#!/usr/bin/env bash | |
######################## | |
# Copyright (c) 2013, Mattias Lundberg | |
# All rights reserved. | |
# | |
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | |
# | |
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | |
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | |
# | |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
####################### | |
path=$(pwd)/ # Current directory. | |
line=$(head -n 1 $1.tex) | |
# Select main file | |
if [[ $line == \%main* ]]; then | |
file=$(echo $line | awk '{ print $2}') | |
else | |
file=$1 | |
fi | |
# Get the path | |
if [[ $file == \.\.* ]]; then | |
path=$(echo $path | awk '{$(NF-1)=$NF;NF--}1' FS='/' OFS='/') | |
file=$(echo $file | awk -F '/' '{ print $2 }') | |
fi | |
function clean() { | |
rm -f ${path}{,sections,appendices,chapters,chp,latex}/*.{out,aux,blg,toc,log,bbl,fdb_latexmk,synctex.gz,eps,dvi,nav,vrb,snm} | |
rm -f $1.pdf | |
} | |
# Always clean if beamer | |
if [[ $(grep -c beamer "${path}${file}.tex") > 0 ]]; then | |
clean ${path}${file} | |
fi | |
# Convert all .dia files to something useful | |
if [ -d ${path}dia ]; then | |
for f in ${path}dia/*.dia; do | |
dfile=$(echo $f | awk -F '.' '{ print $1 }') | |
if test ${dfile}.dia -nt ${dfile}.pdf ; then | |
echo ${dfile} | awk '{ print "dia -e " $f ".eps -t eps " $f ".dia ; epstopdf " $f ".eps " }' | sh | |
fi | |
done | |
fi | |
# latexmk -e "\$pdflatex = 'pdflatex %O -interaction=nonstopmode -synctex=1 %S'" -f -pdf ${path}${file} &> /dev/null | |
rubber --pdf ${path}${file} #&> /dev/null | |
out=$? | |
rubber-info --check ${path}${file} | |
if [ $out -eq 0 ]; then | |
evince "${path}${file}.pdf" &> /dev/null & | |
echo "Sucessfully done!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment