#!/usr/bin/env bash u1=$(date +"%s") # epoch time of program start echo -e "\nShellscript (bash) $0" echo "(checks LaTeX code, without PDF output)" # assert that you may run the program pdflatex if [ ! -x "/usr/bin/pdflatex" ] ; then echo "FEHLER 1: Programm pdflatex fehlt !" exit 1 fi # path to latex file (either given or default) if [ $# -eq 0 ]; then # not given, use default pfad="/home/ahg/latex/myfi.tex" # default elif [ $# -eq 1 ]; then pfad=$1 # given file if [[ ! $pfad == *.tex ]] ; then echo "FEHLER 2: Ohne Dateiendung .tex !" exit 2 fi else echo "FEHLER 3: Zu viele Argumente (>1) !" exit 3 fi # exit with error if file datei does not exist if [ ! -f $pfad ] ; then echo "FEHLER 4: Die Datei gibt es nicht !" exit 4 fi # extract directory and file name without .tex vrz=$(dirname "${pfad}") # directory dat=$(basename "${pfad}") # file datohne="${dat%.*}" # file name without .tex # call pdflatex echo -e "\npdflatex auf Fehlersuche:" aux="${vrz}/${datohne}.log" pdflatex -output-directory ${vrz} -draftmode \ -interaction=batchmode ${pfad} 2>&1 > /dev/null # show shortened result of pdflatex if [ $? = 0 ] ; then echo -e "\nOhne Fehler !" cat ${aux} | grep "Warning" else echo -e "\nFehler! (l. = line number)" cat ${aux} | grep -m 1 -A 2 "^!" fi # delete all auxiliary files aux="${vrz}/${datohne}.aux" if [ -f "${aux}" ] ; then rm "${aux}" ; fi aux="${vrz}/${datohne}.bcf" if [ -f "${aux}" ] ; then rm "${aux}" ; fi aux="${vrz}/${datohne}.idx" if [ -f "${aux}" ] ; then rm "${aux}" ; fi aux="${vrz}/${datohne}.log" if [ -f "${aux}" ] ; then rm "${aux}" ; fi aux="${vrz}/${datohne}.out" if [ -f "${aux}" ] ; then rm "${aux}" ; fi aux="${vrz}/${datohne}.run.xml" if [ -f "${aux}" ] ; then rm "${aux}" ; fi aux="${vrz}/${datohne}.toc" if [ -f "${aux}" ] ; then rm "${aux}" ; fi u2=$(date +"%s") # epoch time of program stop echo -e "\nEnd after $(expr $u2 - $u1) seconds."