1 ##########################################################################
2 # Copyright (c) 2010, ETH Zurich.
5 # This file is distributed under the terms in the attached LICENSE file.
6 # If you do not find this file, copies can be found by writing to:
7 # ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
8 ##########################################################################
10 # run-pdflatex.sh: helper script to build Barrelfish technical notes
12 # This script wraps up pdflatex into something that can be entirely
13 # controlled by command-line options, making it considerably easier to
14 # invoke from a Makefile or Hakefile.
16 # In some ways this is a poor relation to rubber, but it doesn't
17 # require any support packages (not even Python), and is specifically
18 # tailored to the kinds of filesystem naming games that Hake likes to
19 # play. That said, it's completely independent of Hake, and usable
28 --input-tex <filename>
30 --output-pdf <filename>
39 # Shorthand for running pdflatex. This is nicer than using a single
40 # shell variable as it always gets the quoting right.
43 # echo "dirs: $WORKING_DIR, $JOB_NAME, $INPUT_TEX, $TEXINPUTS, $BIBINPUTS" \
45 -interaction=nonstopmode \
47 -output-directory "$WORKING_DIR" \
48 -jobname "$JOB_NAME" \
53 # Work out how to construct TEXINPUTS and BIBINPUTS paths, according
56 case "`which pdflatex`" in
57 /cygdrive/*) _ISCYGWIN=Yes ;;
61 if [ -z "$_ISCYGWIN" ] ; then
69 # Initial values for input arguments
71 if [ -z "$TEXINPUTS" ]; then
72 TEXINPUTS=`cons_inputs "" "."`
74 TEXINPUTS=`cons_inputs "$TEXINPUTS" "."`
77 # echo "TEXinputs is $TEXINPUTS"
80 BIBINPUTS=`cons_inputs "" "."`
88 # Argument processing.
93 shift; INPUT_TEX=$1 ;;
95 shift; OUTPUT_PDF="$1" ;;
97 shift; WORKING_DIR="$1" ;;
99 shift; TEXINPUTS=`cons_inputs "$TEXINPUTS" "$1"` ;;
101 shift; BIBINPUTS=`cons_inputs "$BIBINPUTS" "$1"` ;;
111 if [ -z "$INPUT_TEX" ] ; then usage ; fi
112 if [ -z "$WORKING_DIR" ] ; then usage ; fi
113 if [ -z "$OUTPUT_PDF" ] ; then usage ; fi
116 # Calculate all the other stuff we need.
118 INPUT_DIR=`dirname "$INPUT_TEX"`
119 INPUT_BASE=`basename "$INPUT_TEX" .tex`
120 TEXINPUTS=`cons_inputs "$TEXINPUTS" "$INPUT_DIR"`
121 BIBINPUTS=`cons_inputs "$BIBINPUTS" "$INPUT_DIR"`
126 # We use a different jobname due to parallel Make paranoia: it's a
127 # good idea if the output file that we really care out only appears as
128 # the last step of the build. This also allows us to specify
129 # different directories for the final PDF file and the intermediate
130 # working files, something (apparently) not possible within pdflatex.
132 JOB_NAME="${INPUT_BASE}.tmp"
133 # the man page for bibtex specifically reads
134 # "the filename on the command line must be given without the .aux extension"
135 AUX_FILE_WITHOUT_AUX="$WORKING_DIR/${JOB_NAME}"
136 AUX_FILE="$WORKING_DIR/${JOB_NAME}.aux"
137 HST_FILE="$WORKING_DIR/${JOB_NAME}.hst"
138 LOG_FILE="$WORKING_DIR/${JOB_NAME}.log"
139 TOC_FILE="$WORKING_DIR/${JOB_NAME}.toc"
140 BBL_FILE="$WORKING_DIR/${JOB_NAME}.bbl"
141 BLG_FILE="$WORKING_DIR/${JOB_NAME}.blg"
142 VER_FILE="$WORKING_DIR/${JOB_NAME}.ver"
143 GLO_FILE="$WORKING_DIR/${JOB_NAME}.glo"
144 ACN_FILE="$WORKING_DIR/${JOB_NAME}.acn"
145 IST_FILE="$WORKING_DIR/${JOB_NAME}.ist"
146 PDF_FILE="$WORKING_DIR/${JOB_NAME}.pdf"
149 # And, finally, do what the old Makefile used to do.
151 # bibtex on cygwin can be miktex which always 0 exit code
153 if [ -n "$HAS_BIB" ]; then (bibtex $AUX_FILE_WITHOUT_AUX && test -r $BBL_FILE) || exit; echo run_latex; fi
154 if [ -n "$HAS_GLO" ]; then (makeglossaries -s $IST_FILE $GLO_FILE && makeglossaries -s $IST_FILE $ACN_FILE && test -r $GLO_FILE) || exit; echo run_latex; fi
155 if [ -e "$TOC_FILE" -o -e "$BBL_FILE" -o -e "$VER_FILE" -o -e "$GLO_FILE" -o -e "$ACN_FILE" ]; then run_latex; fi
156 while egrep Rerun "$LOG_FILE"; do run_latex; done
157 rm -f "$AUX_FILE" "$HST_FILE" "$LOG_FILE" "$TOC_FILE" "$BBL_FILE"
158 rm -f "$BLG_FILE" "$VER_FILE"
159 rm -f "$GLO_FILE" "$ACN_FILE" "$IST_FILE"
160 mv "$PDF_FILE" "$OUTPUT_PDF"
161 echo "Output file is in $OUTPUT_PDF"