Log changes
[latex2e.git] / latex2e-20151001 / scripts / run-tex
blob4a81db5bf6722d6b5313bfda0c9ce581bd523864
1 #!/bin/sh
3 if [ $# -lt 2 -o $# -gt 3 ] ; then
4 echo >&2 Usage: run-tex format file [interaction_mode]
5 exit 1
6 fi
8 MAXRUNS=${MAXLATEXRUNS:-10}
10 FORMAT=`basename $1 .fmt`
11 FILE=$2
12 if [ $# -eq 3 ] ; then
13 MODE="\\$3 \\input"
16 # The following removes the directory part, the last dot and what follows it
17 JOBNAME=`basename ${FILE} | sed -e 's/\...*$//'`
19 # A function for computing a checksum
20 checksum () {
21 CHECKSUM="`sum $1 | cut -f1 -d' '`"
25 # A simple function for showing a command on the screen and running it
26 # If the command fails, the whole script exits,
27 run_command () {
28 echo $*
29 $* || exit
33 # A more complicated function for running LaTeX until the message
34 # `Rerun to get cross-references right.' does no longer show up.
35 # The number of runs is limited by MAXRUNS (default 10, if not set
36 # from environment variable MAXLATEXRUNS above.
37 run_tex () {
38 SUCCESS=0
39 RUNS=0
40 until [ ${SUCCESS} = 1 ] ; do
41 run_command pdfetex -efmt=${FORMAT} ${MODE} ${FILE}
42 fgrep -q "Rerun to get cross-references right." ${JOBNAME}.log || SUCCESS=1
43 RUNS=`expr ${RUNS} + 1`
44 if [ ${RUNS} -gt ${MAXRUNS} ] ; then
45 echo >&2 Maximum number of runs reached. Stop.
46 exit 1
48 checksum ${JOBNAME}.aux
49 done
52 # Initilizations
53 RERUN=0
54 CHECKSUM=""
55 OLD_CHECKSUM=""
57 # The rest is straightforward: run LaTeX....
58 run_tex
61 # Check if bibtex needs to be run....
62 if fgrep -q "\bibdata" ${JOBNAME}.aux ; then
63 run_command bibtex ${JOBNAME}
64 RERUN=1
67 # Check if makeindex needs to be run on the .idx file....
68 if [ -s ${JOBNAME}.idx ] ; then
69 if test -r ${JOBNAME}.ist ; then
70 run_command makeindex -s ${JOBNAME}.ist ${JOBNAME}
71 elif fgrep -q "=\verb!*+" ${JOBNAME}.idx ; then
72 run_command makeindex -s gind.ist ${JOBNAME}
73 else
74 run_command makeindex ${JOBNAME}
76 RERUN=1
79 # Check if makeindex needs to be run on the .glo file....
80 if [ -s ${JOBNAME}.glo ] ; then
81 if fgrep -q "=\verb!*+" ${JOBNAME}.glo ; then
82 run_command makeindex -s gglo.ist -o ${JOBNAME}.gls ${JOBNAME}.glo
83 else
84 run_command makeindex -o ${JOBNAME}.gls ${JOBNAME}.glo
86 RERUN=1
89 OLD_CHECKSUM=${CHECKSUM}
91 # ...if one of the above was necessary, rerun LaTeX.
92 if [ ${RERUN} = 1 ] ; then
93 run_tex
94 if [ "${OLD_CHECKSUM}" != "${CHECKSUM}" ] ; then
95 echo Checksum has changed. Running LaTeX again is recommended!
99 exit