author | huffman |
Wed, 26 Mar 2008 22:38:17 +0100 | |
changeset 26407 | 562a1d615336 |
parent 17049 | ee573216713a |
child 26908 | 25fb7241f32e |
permissions | -rwxr-xr-x |
10555 | 1 |
#!/usr/bin/env bash |
7793 | 2 |
# |
3 |
# $Id$ |
|
9788 | 4 |
# Author: Markus Wenzel, TU Muenchen |
7793 | 5 |
# |
6 |
# DESCRIPTION: prepare theory session document |
|
7 |
||
8 |
||
10511 | 9 |
PRG="$(basename "$0")" |
7793 | 10 |
|
11 |
function usage() |
|
12 |
{ |
|
13 |
echo |
|
14 |
echo "Usage: $PRG [OPTIONS] [DIR]" |
|
15 |
echo |
|
16 |
echo " Options are:" |
|
8654 | 17 |
echo " -c cleanup -- be aggressive in removing old stuff" |
17049 | 18 |
echo " -n NAME specify document name (default 'document')" |
19 |
echo " -o FORMAT specify output format: dvi (default), dvi.gz, ps, ps.gz, pdf" |
|
20 |
echo " -t TAGS specify tagged region markup" |
|
7793 | 21 |
echo |
8211 | 22 |
echo " Prepare the theory session document in DIR (default 'document')" |
7857 | 23 |
echo " producing the specified output format." |
7793 | 24 |
echo |
25 |
exit 1 |
|
26 |
} |
|
27 |
||
28 |
function fail() |
|
29 |
{ |
|
30 |
echo "$1" >&2 |
|
31 |
exit 2 |
|
32 |
} |
|
33 |
||
34 |
||
35 |
## process command line |
|
36 |
||
37 |
# options |
|
38 |
||
8211 | 39 |
CLEAN="" |
17049 | 40 |
NAME="document" |
7793 | 41 |
OUTFORMAT=dvi |
17049 | 42 |
TAGS="" |
7793 | 43 |
|
17049 | 44 |
while getopts "cn:o:t:" OPT |
7793 | 45 |
do |
46 |
case "$OPT" in |
|
8211 | 47 |
c) |
48 |
CLEAN=true |
|
49 |
;; |
|
17049 | 50 |
n) |
51 |
NAME="$OPTARG" |
|
52 |
;; |
|
7793 | 53 |
o) |
54 |
OUTFORMAT="$OPTARG" |
|
55 |
;; |
|
17049 | 56 |
t) |
57 |
TAGS="$OPTARG" |
|
58 |
;; |
|
7793 | 59 |
\?) |
60 |
usage |
|
61 |
;; |
|
62 |
esac |
|
63 |
done |
|
64 |
||
65 |
shift $(($OPTIND - 1)) |
|
66 |
||
67 |
||
68 |
# args |
|
69 |
||
8211 | 70 |
DIR="document" |
9788 | 71 |
[ "$#" -ge 1 ] && { DIR="$1"; shift; } |
7793 | 72 |
|
9788 | 73 |
[ "$#" -ne 0 ] && usage |
7793 | 74 |
|
75 |
||
76 |
## main |
|
77 |
||
7814 | 78 |
# check format |
79 |
||
80 |
case "$OUTFORMAT" in |
|
81 |
dvi | dvi.gz | ps | ps.gz | pdf) |
|
82 |
;; |
|
83 |
*) |
|
84 |
fail "Bad output format '$OUTFORMAT'" |
|
85 |
;; |
|
86 |
esac |
|
87 |
||
88 |
||
17049 | 89 |
# tagged region markup |
90 |
||
91 |
function prep_tags () |
|
92 |
{ |
|
93 |
( |
|
94 |
IFS="," |
|
95 |
for TAG in $TAGS |
|
96 |
do |
|
97 |
case "$TAG" in |
|
98 |
/*) |
|
99 |
echo "\\isafoldtag{${TAG:1}}" |
|
100 |
;; |
|
101 |
-*) |
|
102 |
echo "\\isadroptag{${TAG:1}}" |
|
103 |
;; |
|
104 |
+*) |
|
105 |
echo "\\isakeeptag{${TAG:1}}" |
|
106 |
;; |
|
107 |
*) |
|
108 |
echo "\\isakeeptag{${TAG}}" |
|
109 |
;; |
|
110 |
esac |
|
111 |
done |
|
112 |
) > isabelletags.sty |
|
113 |
} |
|
114 |
||
115 |
||
7814 | 116 |
# prepare document |
7793 | 117 |
|
7814 | 118 |
function pre_latex () |
119 |
{ |
|
120 |
local FMT="$1" |
|
14367
0b1447d37161
remove more files (index, log files) for -c option
kleing
parents:
14344
diff
changeset
|
121 |
[ -n "$CLEAN" ] && rm -f *.aux *.out *.ind *.idx *.ilg *.bbl *.blg *.log |
12688 | 122 |
"$ISATOOL" latex -o sty && \ |
11948 | 123 |
"$ISATOOL" latex -o "$FMT" && \ |
124 |
{ [ ! -f root.bib ] || "$ISATOOL" latex -o bbl; } && \ |
|
14936 | 125 |
{ [ ! -f root.idx ] || "$ISATOOL" latex -o idx; } && \ |
126 |
"$ISATOOL" latex -o "$FMT" |
|
7814 | 127 |
} |
128 |
||
8211 | 129 |
( |
130 |
cd "$DIR" || fail "Bad directory '$DIR'" |
|
131 |
||
17049 | 132 |
[ -n "$CLEAN" ] && rm -f "../$NAME.$OUTFORMAT" |
133 |
||
134 |
prep_tags |
|
8654 | 135 |
|
8211 | 136 |
if [ -f IsaMakefile ]; then |
9788 | 137 |
"$ISATOOL" make "$OUTFORMAT" |
138 |
RC="$?" |
|
8211 | 139 |
elif [ "$OUTFORMAT" = pdf ]; then |
140 |
pre_latex pdf && \ |
|
9788 | 141 |
"$ISATOOL" latex -o pdf && \ |
8211 | 142 |
{ if [ -n "$ISABELLE_THUMBPDF" ]; then |
9788 | 143 |
"$ISATOOL" latex -o png && \ |
144 |
"$ISATOOL" latex -o pdf |
|
8211 | 145 |
fi; } |
9788 | 146 |
RC="$?" |
8211 | 147 |
else |
148 |
pre_latex dvi && \ |
|
9788 | 149 |
"$ISATOOL" latex -o "$OUTFORMAT" |
150 |
RC="$?" |
|
8211 | 151 |
fi |
152 |
||
11581 | 153 |
if [ "$RC" -eq 0 -a -f "root.$OUTFORMAT" ]; then |
17049 | 154 |
cp -f "root.$OUTFORMAT" "../$NAME.$OUTFORMAT" |
11581 | 155 |
fi |
8211 | 156 |
|
8217 | 157 |
exit "$RC" |
8211 | 158 |
) |
9788 | 159 |
RC="$?" |
7793 | 160 |
|
161 |
||
7814 | 162 |
# install |
7793 | 163 |
|
17049 | 164 |
[ "$RC" -ne 0 ] && fail "Document preparation failure in directory '$DIR'" |
8211 | 165 |
|
166 |
#beware! |
|
167 |
[ -n "$CLEAN" ] && rm -rf "$DIR" |
|
168 |
||
169 |
exit "$RC" |