| author | wenzelm | 
| Fri, 17 Jul 2015 21:40:47 +0200 | |
| changeset 60749 | f727b99faaf7 | 
| parent 52746 | eec610972763 | 
| child 67263 | 449a989f42cd | 
| permissions | -rwxr-xr-x | 
| 10555 | 1  | 
#!/usr/bin/env bash  | 
| 7772 | 2  | 
#  | 
| 9788 | 3  | 
# Author: Markus Wenzel, TU Muenchen  | 
| 7772 | 4  | 
#  | 
| 7794 | 5  | 
# DESCRIPTION: run LaTeX (and related tools)  | 
| 7772 | 6  | 
|
7  | 
||
| 10511 | 8  | 
PRG="$(basename "$0")"  | 
| 7772 | 9  | 
|
10  | 
function usage()  | 
|
11  | 
{
 | 
|
12  | 
echo  | 
|
| 28650 | 13  | 
echo "Usage: isabelle $PRG [OPTIONS] [FILE]"  | 
| 7772 | 14  | 
echo  | 
15  | 
echo " Options are:"  | 
|
| 52746 | 16  | 
echo " -o FORMAT specify output format: pdf (default), dvi, bbl, idx, sty, syms"  | 
| 7772 | 17  | 
echo  | 
| 7857 | 18  | 
echo " Run LaTeX (and related tools) on FILE (default root.tex),"  | 
19  | 
echo " producing the specified output format."  | 
|
| 7772 | 20  | 
echo  | 
21  | 
exit 1  | 
|
22  | 
}  | 
|
23  | 
||
24  | 
function fail()  | 
|
25  | 
{
 | 
|
26  | 
echo "$1" >&2  | 
|
27  | 
exit 2  | 
|
28  | 
}  | 
|
29  | 
||
30  | 
||
31  | 
## process command line  | 
|
32  | 
||
33  | 
# options  | 
|
34  | 
||
| 52746 | 35  | 
OUTFORMAT=pdf  | 
| 7772 | 36  | 
|
37  | 
while getopts "o:" OPT  | 
|
38  | 
do  | 
|
39  | 
case "$OPT" in  | 
|
40  | 
o)  | 
|
41  | 
OUTFORMAT="$OPTARG"  | 
|
42  | 
;;  | 
|
43  | 
\?)  | 
|
44  | 
usage  | 
|
45  | 
;;  | 
|
46  | 
esac  | 
|
47  | 
done  | 
|
48  | 
||
49  | 
shift $(($OPTIND - 1))  | 
|
50  | 
||
51  | 
||
52  | 
# args  | 
|
53  | 
||
| 7794 | 54  | 
FILE="root.tex"  | 
| 9788 | 55  | 
[ "$#" -ge 1 ] && { FILE="$1"; shift; }
 | 
| 7772 | 56  | 
|
| 9788 | 57  | 
[ "$#" -ne 0 ] && usage  | 
| 7772 | 58  | 
|
59  | 
||
60  | 
## main  | 
|
61  | 
||
| 8564 | 62  | 
# root file  | 
| 7815 | 63  | 
|
| 48515 | 64  | 
DIR="$(dirname "$FILE")"  | 
65  | 
FILEBASE="$(basename "$FILE" .tex)"  | 
|
| 9788 | 66  | 
[ "$DIR" = . ] || FILEBASE="$DIR/$FILEBASE"  | 
| 7772 | 67  | 
|
| 8568 | 68  | 
function check_root () { [ -f "$FILEBASE.tex" ] || fail "Bad file '$FILE'"; }
 | 
| 7794 | 69  | 
|
| 7815 | 70  | 
|
71  | 
# operations  | 
|
72  | 
||
73  | 
function run_latex () { $ISABELLE_LATEX "\\nonstopmode\\input{$FILEBASE.tex}"; }
 | 
|
74  | 
function run_pdflatex () { $ISABELLE_PDFLATEX "\\nonstopmode\\input{$FILEBASE.tex}"; }
 | 
|
75  | 
function run_bibtex () { $ISABELLE_BIBTEX </dev/null "$FILEBASE"; }
 | 
|
| 14344 | 76  | 
function run_makeindex () { $ISABELLE_MAKEINDEX </dev/null "$FILEBASE"; }
 | 
| 16064 | 77  | 
function copy_styles ()  | 
78  | 
{
 | 
|
| 16161 | 79  | 
for STYLEFILE in "$ISABELLE_HOME/lib/texinputs"/*.sty  | 
80  | 
do  | 
|
| 16874 | 81  | 
TARGET="$DIR"/$(basename "$STYLEFILE")  | 
| 26576 | 82  | 
perl -p -e 's/\$[I]d:?(?:\s)*([^\$]*)\$//g' "$STYLEFILE" > "$TARGET"  | 
| 16161 | 83  | 
done  | 
| 16064 | 84  | 
}  | 
| 7815 | 85  | 
|
| 14921 | 86  | 
function extract_syms ()  | 
87  | 
{
 | 
|
| 26576 | 88  | 
perl -n \  | 
| 
40893
 
7d88ebdce380
isabellesym.sty: eliminated dependency on latin1, to allow documents using utf8 instead;
 
wenzelm 
parents: 
29143 
diff
changeset
 | 
89  | 
    -e '(!m,%requires, || m,%requires amssymb, || m,%requires textcomp,) && m,\\newcommand\{\\isasym(\w+)\}, && print "$1\n";' \
 | 
| 14921 | 90  | 
"$ISABELLE_HOME/lib/texinputs/isabellesym.sty" > "$DIR/syms.lst"  | 
| 26576 | 91  | 
perl -n \  | 
| 14921 | 92  | 
    -e 'm,\\newcommand\{\\isactrl(\w+)\}, && print "$1\n";' \
 | 
93  | 
"$ISABELLE_HOME/lib/texinputs/isabelle.sty" > "$DIR/ctrls.lst"  | 
|
94  | 
}  | 
|
95  | 
||
| 7772 | 96  | 
case "$OUTFORMAT" in  | 
| 52746 | 97  | 
pdf)  | 
98  | 
check_root && \  | 
|
99  | 
run_pdflatex  | 
|
100  | 
RC="$?"  | 
|
101  | 
;;  | 
|
| 7772 | 102  | 
dvi)  | 
| 8564 | 103  | 
check_root && \  | 
| 7815 | 104  | 
run_latex  | 
| 9788 | 105  | 
RC="$?"  | 
| 7772 | 106  | 
;;  | 
| 7815 | 107  | 
bbl)  | 
| 8564 | 108  | 
check_root && \  | 
| 7815 | 109  | 
run_bibtex  | 
| 9788 | 110  | 
RC="$?"  | 
| 7772 | 111  | 
;;  | 
| 14344 | 112  | 
idx)  | 
113  | 
check_root && \  | 
|
114  | 
run_makeindex  | 
|
115  | 
RC="$?"  | 
|
116  | 
;;  | 
|
| 8564 | 117  | 
sty)  | 
| 
12846
 
0fce95478e19
copy_styles replaces overly conservative update_styles;
 
wenzelm 
parents: 
11845 
diff
changeset
 | 
118  | 
copy_styles  | 
| 9788 | 119  | 
RC="$?"  | 
| 8564 | 120  | 
;;  | 
| 14921 | 121  | 
syms)  | 
122  | 
extract_syms  | 
|
123  | 
RC="$?"  | 
|
124  | 
;;  | 
|
| 7772 | 125  | 
*)  | 
126  | 
fail "Bad output format '$OUTFORMAT'"  | 
|
127  | 
;;  | 
|
128  | 
esac  | 
|
| 7794 | 129  | 
|
| 9788 | 130  | 
exit "$RC"  |