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