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