author | wenzelm |
Sat, 21 Mar 2009 20:00:23 +0100 | |
changeset 30627 | fb9e73c01603 |
parent 29143 | 72c960b2b83e |
child 40893 | 7d88ebdce380 |
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:" |
|
7815 | 16 |
echo " -o FORMAT specify output format: dvi (default), dvi.gz, ps, ps.gz," |
26908 | 17 |
echo " pdf, bbl, idx, sty, syms" |
7772 | 18 |
echo |
7857 | 19 |
echo " Run LaTeX (and related tools) on FILE (default root.tex)," |
20 |
echo " producing the specified output format." |
|
7772 | 21 |
echo |
22 |
exit 1 |
|
23 |
} |
|
24 |
||
25 |
function fail() |
|
26 |
{ |
|
27 |
echo "$1" >&2 |
|
28 |
exit 2 |
|
29 |
} |
|
30 |
||
31 |
||
32 |
## process command line |
|
33 |
||
34 |
# options |
|
35 |
||
36 |
OUTFORMAT=dvi |
|
37 |
||
38 |
while getopts "o:" OPT |
|
39 |
do |
|
40 |
case "$OPT" in |
|
41 |
o) |
|
42 |
OUTFORMAT="$OPTARG" |
|
43 |
;; |
|
44 |
\?) |
|
45 |
usage |
|
46 |
;; |
|
47 |
esac |
|
48 |
done |
|
49 |
||
50 |
shift $(($OPTIND - 1)) |
|
51 |
||
52 |
||
53 |
# args |
|
54 |
||
7794 | 55 |
FILE="root.tex" |
9788 | 56 |
[ "$#" -ge 1 ] && { FILE="$1"; shift; } |
7772 | 57 |
|
9788 | 58 |
[ "$#" -ne 0 ] && usage |
7772 | 59 |
|
60 |
||
61 |
## main |
|
62 |
||
8564 | 63 |
# root file |
7815 | 64 |
|
7772 | 65 |
DIR=$(dirname "$FILE") |
9788 | 66 |
FILEBASE=$(basename "$FILE" .tex) |
67 |
[ "$DIR" = . ] || FILEBASE="$DIR/$FILEBASE" |
|
7772 | 68 |
|
8568 | 69 |
function check_root () { [ -f "$FILEBASE.tex" ] || fail "Bad file '$FILE'"; } |
7794 | 70 |
|
7815 | 71 |
|
72 |
# operations |
|
73 |
||
74 |
function run_latex () { $ISABELLE_LATEX "\\nonstopmode\\input{$FILEBASE.tex}"; } |
|
75 |
function run_pdflatex () { $ISABELLE_PDFLATEX "\\nonstopmode\\input{$FILEBASE.tex}"; } |
|
76 |
function run_bibtex () { $ISABELLE_BIBTEX </dev/null "$FILEBASE"; } |
|
14344 | 77 |
function run_makeindex () { $ISABELLE_MAKEINDEX </dev/null "$FILEBASE"; } |
11845 | 78 |
function run_dvips () { $ISABELLE_DVIPS -q -o "$FILEBASE.ps" "$FILEBASE.dvi"; } |
16064 | 79 |
function copy_styles () |
80 |
{ |
|
16161 | 81 |
for STYLEFILE in "$ISABELLE_HOME/lib/texinputs"/*.sty |
82 |
do |
|
16874 | 83 |
TARGET="$DIR"/$(basename "$STYLEFILE") |
26576 | 84 |
perl -p -e 's/\$[I]d:?(?:\s)*([^\$]*)\$//g' "$STYLEFILE" > "$TARGET" |
16161 | 85 |
done |
16064 | 86 |
} |
7815 | 87 |
|
14921 | 88 |
function extract_syms () |
89 |
{ |
|
26576 | 90 |
perl -n \ |
14970
8159ade98144
more generous treatment of packages in draft prints;
wenzelm
parents:
14921
diff
changeset
|
91 |
-e '(!m,%requires, || m,%requires latin1, || m,%requires amssymb, || m,%requires textcomp,) && m,\\newcommand\{\\isasym(\w+)\}, && print "$1\n";' \ |
14921 | 92 |
"$ISABELLE_HOME/lib/texinputs/isabellesym.sty" > "$DIR/syms.lst" |
26576 | 93 |
perl -n \ |
14921 | 94 |
-e 'm,\\newcommand\{\\isactrl(\w+)\}, && print "$1\n";' \ |
95 |
"$ISABELLE_HOME/lib/texinputs/isabelle.sty" > "$DIR/ctrls.lst" |
|
96 |
} |
|
97 |
||
7772 | 98 |
case "$OUTFORMAT" in |
99 |
dvi) |
|
8564 | 100 |
check_root && \ |
7815 | 101 |
run_latex |
9788 | 102 |
RC="$?" |
7772 | 103 |
;; |
104 |
dvi.gz) |
|
8564 | 105 |
check_root && \ |
7815 | 106 |
run_latex && \ |
7772 | 107 |
gzip -f "$FILEBASE.dvi" |
9788 | 108 |
RC="$?" |
7772 | 109 |
;; |
110 |
ps) |
|
8564 | 111 |
check_root && \ |
7815 | 112 |
run_latex && \ |
26954
3a3816ca44bb
proper handling of the return code for the ps-format (fixes a bug)
urbanc
parents:
26908
diff
changeset
|
113 |
run_dvips |
9788 | 114 |
RC="$?" |
7772 | 115 |
;; |
116 |
ps.gz) |
|
8564 | 117 |
check_root && \ |
7815 | 118 |
run_latex && \ |
26979
c58778bdf146
fixed improper handling of return code (pdf and ps.gz formats)
urbanc
parents:
26954
diff
changeset
|
119 |
run_dvips && \ |
7772 | 120 |
gzip -f "$FILEBASE.ps" |
9788 | 121 |
RC="$?" |
7772 | 122 |
;; |
123 |
pdf) |
|
8564 | 124 |
check_root && \ |
7815 | 125 |
run_pdflatex |
9788 | 126 |
RC="$?" |
7815 | 127 |
;; |
128 |
bbl) |
|
8564 | 129 |
check_root && \ |
7815 | 130 |
run_bibtex |
9788 | 131 |
RC="$?" |
7772 | 132 |
;; |
14344 | 133 |
idx) |
134 |
check_root && \ |
|
135 |
run_makeindex |
|
136 |
RC="$?" |
|
137 |
;; |
|
8564 | 138 |
sty) |
12846
0fce95478e19
copy_styles replaces overly conservative update_styles;
wenzelm
parents:
11845
diff
changeset
|
139 |
copy_styles |
9788 | 140 |
RC="$?" |
8564 | 141 |
;; |
14921 | 142 |
syms) |
143 |
extract_syms |
|
144 |
RC="$?" |
|
145 |
;; |
|
7772 | 146 |
*) |
147 |
fail "Bad output format '$OUTFORMAT'" |
|
148 |
;; |
|
149 |
esac |
|
7794 | 150 |
|
9788 | 151 |
exit "$RC" |