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 "" "."`
87 # Argument processing.
92 shift; INPUT_TEX=$1 ;;
94 shift; OUTPUT_PDF="$1" ;;
96 shift; WORKING_DIR="$1" ;;
98 shift; TEXINPUTS=`cons_inputs "$TEXINPUTS" "$1"` ;;
100 shift; BIBINPUTS=`cons_inputs "$BIBINPUTS" "$1"` ;;
108 if [ -z "$INPUT_TEX" ] ; then usage ; fi
109 if [ -z "$WORKING_DIR" ] ; then usage ; fi
110 if [ -z "$OUTPUT_PDF" ] ; then usage ; fi
113 # Calculate all the other stuff we need.
115 INPUT_DIR=`dirname "$INPUT_TEX"`
116 INPUT_BASE=`basename "$INPUT_TEX" .tex`
117 TEXINPUTS=`cons_inputs "$TEXINPUTS" "$INPUT_DIR"`
118 BIBINPUTS=`cons_inputs "$BIBINPUTS" "$INPUT_DIR"`
123 # We use a different jobname due to parallel Make paranoia: it's a
124 # good idea if the output file that we really care out only appears as
125 # the last step of the build. This also allows us to specify
126 # different directories for the final PDF file and the intermediate
127 # working files, something (apparently) not possible within pdflatex.
129 JOB_NAME="${INPUT_BASE}.tmp"
130 # the man page for bibtex specifically reads
131 # "the filename on the command line must be given without the .aux extension"
132 AUX_FILE_WITHOUT_AUX="$WORKING_DIR/${JOB_NAME}"
133 AUX_FILE="$WORKING_DIR/${JOB_NAME}.aux"
134 HST_FILE="$WORKING_DIR/${JOB_NAME}.hst"
135 LOG_FILE="$WORKING_DIR/${JOB_NAME}.log"
136 TOC_FILE="$WORKING_DIR/${JOB_NAME}.toc"
137 BBL_FILE="$WORKING_DIR/${JOB_NAME}.bbl"
138 BLG_FILE="$WORKING_DIR/${JOB_NAME}.blg"
139 VER_FILE="$WORKING_DIR/${JOB_NAME}.ver"
140 PDF_FILE="$WORKING_DIR/${JOB_NAME}.pdf"
143 # And, finally, do what the old Makefile used to do.
145 # bibtex on cygwin can be miktex which always 0 exit code
147 if [ -n "$HAS_BIB" ]; then (bibtex $AUX_FILE_WITHOUT_AUX && test -r $BBL_FILE) || exit; echo run_latex; fi
148 if [ -e "$TOC_FILE" -o -e "$BBL_FILE" -o -e "$VER_FILE" ]; then run_latex; fi
149 if egrep Rerun "$LOG_FILE" ; then run_latex ; fi
150 if egrep Rerun "$LOG_FILE" ; then run_latex ; fi
151 if egrep Rerun "$LOG_FILE" ; then run_latex ; fi
152 rm -f "$AUX_FILE" "$HST_FILE" "$LOG_FILE" "$TOC_FILE" "$BBL_FILE"
153 rm -f "$BLG_FILE" "$VER_FILE"
154 mv "$PDF_FILE" "$OUTPUT_PDF"
155 echo "Output file is in $OUTPUT_PDF"