1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
#!/bin/bash
#
# Automate running LaTeX
program=`basename $0`
tex=latex
format=dvi
rerun='Rerun to get cross-references right'
maxruns=4
quiet=false
mkindexopts=
bibtexopts=
function texclean
{ rm -f *.idx *.ind *.ilg *.aux *.log *.lof *.out *.toc *.blg
}
# make runtex --clean work without GNU getopt
case "$1" in
--clean)
texclean
exit 0
;;
esac
appbase=`dirname $0`
case "$appbase" in
/*)
;;
.) appbase=`pwd`
;;
./*|../*)
appbase="`pwd`/$appbase"
clean=false
while [ $clean = false ]; do
b=`echo $appbase | sed -e 's@/\./@/@g' -e 's@/[a-z]*/\.\./@/@g'`
if [ "x$b" = "x$appbase" ]; then
clean=true
else
appbase="$b"
fi
done
;;
*) echo "ERROR: runtex must be called with relative or absolute path"
exit 1
;;
esac
function addinput
{ if [ -z "$TEXINPUTS" ]; then
export TEXINPUTS="$1::"
else
export TEXINPUTS=$TEXINPUTS:$1::
fi
}
function addbstinput
{ if [ -z "$BSTINPUTS" ]; then
export BSTINPUTS="$1::"
else
export BSTINPUTS=$BSTINPUTS:$1::
fi
}
function addbibinput
{ if [ -z "$BIBINPUTS" ]; then
export BIBINPUTS="$1::"
else
export BIBINPUTS=$BIBINPUTS:$1::
fi
}
function usage
{ echo "Usage:"
echo ""
echo " $program [options] file"
echo ""
echo "Options:"
echo ""
echo " --pdf Use pdflatex and make .pdf images"
echo " --dvi Use latex"
echo " --help Print this message"
echo " --maxruns=# Specify maximum # runs"
echo " --clean Just remove TeX temporary files"
}
if [ -d $appbase ]; then
addinput $appbase
addbstinput $appbase
addbibinput $appbase
fi
argp=true
while [ $argp = true ] ; do
case "$1" in
--pdf)
tex=pdflatex
format=pdf
shift ;;
--dvi)
tex=latex
format=dvi
shift ;;
--quiet)
quiet=true
mkindexopts=-q
bibtexopts=-terse
shift ;;
--maxruns=*)
maxruns="`echo $1 | sed 's/--maxruns=//'`"
shift ;;
--inputs=*)
addinput "`echo $1 | sed 's/--inputs=//'`"
shift ;;
--help)
usage
exit 0 ;;
--clean)
texclean
exit 0
;;
--*)
usage
exit 1 ;;
*)
argp=false;
;;
esac
done
if [ -z "$1" ]; then
usage
exit 1
fi
if [ $quiet = false ]; then
echo "runtex application base = $appbase"
fi
file="$1"
# ensure .tex suffix
if [ ${file%.tex} = $file ]; then
file=$file.tex
fi
doc=${file%.tex}
if [ -r Makefile ] && grep -q '^tex:' Makefile; then
make tex
fi
cont=yes
done=0
while [ $cont != "no" ]; do
cont=maybe
# fix index problems
if [ -r $doc.idx ]; then
cp $doc.idx $doc.idx.$$
if [ -r $appbase/correctindex ]; then
perl -pi $appbase/correctindex $doc.idx
fi
if [ -r $appbase/makeindex.ist ]; then
makeindex $mkindexopts -s $appbase/makeindex.ist $doc.idx
else
makeindex $mkindexopts $doc.idx
fi
fi
if test -r $doc.aux && grep -qw bibdata $doc.aux; then
if [ -f $doc.bbl ]; then cp $doc.bbl $doc.bbl$$; fi
if [ $quiet == false ]; then
echo "%%% Running Bibtex"
fi
bibtex $bibtexopts $doc
if [ -r $doc.bbl -a -r $doc.bbl.$$ ]; then
if cmp -s $doc.bbl $doc.bbl.$$; then
true
else
cont=yes
if [ $quiet == false ]; then
echo "*** Bibtex output changed. Rerunning $tex ***"
fi
fi
fi
rm -f $doc.bbl$$
fi
if [ `basename $tex` = pdflatex -a -r $appbase/Makefile.pdf ]; then
make --quiet -f $appbase/Makefile.pdf
fi
rm -f $doc.log
if [ $quiet == true ]; then
$tex $doc -file-line-error -halt-on-error >/dev/null
else
$tex $doc
fi
if [ $? != 0 ]; then
rm -f $doc.idx.$$
exit $?;
fi
if grep -q "$rerun" $doc.log; then
if [ $quiet == false ]; then
echo "*** Cross-references changed. Rerunning $tex ***"
fi
cont=yes
else
if [ -r $doc.idx -a -r $doc.idx.$$ ]; then
if cmp -s $doc.idx $doc.idx.$$; then
true
else
ls -l $doc.idx $doc.idx.$$
cont=yes
if [ $quiet == false ]; then
echo "*** Index changed. Rerunning $tex ***"
fi
fi
fi
fi
rm -f $doc.idx.$$
done=$(($done+1))
if [ $done = $maxruns ]; then cont=no; fi
if [ $cont = maybe ]; then cont=no; fi
done
if grep -q Warning $doc.log; then
echo ""
echo "*****************************"
echo "The following warnings remain"
echo "*****************************"
grep Warning $doc.log
fi
|