author | wenzelm |
Thu, 14 Jul 2005 19:28:31 +0200 | |
changeset 16847 | 8fc160b12e73 |
parent 14981 | e73f8140af78 |
child 17049 | ee573216713a |
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" |
7866
3ccaa11b6df9
pdf: generate thumbnails if ISABELLE_THUMBPDF set;
wenzelm
parents:
7857
diff
changeset
|
18 |
echo " -o FORMAT specify output format: dvi (default), dvi.gz, ps," |
3ccaa11b6df9
pdf: generate thumbnails if ISABELLE_THUMBPDF set;
wenzelm
parents:
7857
diff
changeset
|
19 |
echo " ps.gz, pdf" |
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="" |
7793 | 39 |
OUTFORMAT=dvi |
40 |
||
11844 | 41 |
while getopts "co:" OPT |
7793 | 42 |
do |
43 |
case "$OPT" in |
|
8211 | 44 |
c) |
45 |
CLEAN=true |
|
46 |
;; |
|
7793 | 47 |
o) |
48 |
OUTFORMAT="$OPTARG" |
|
49 |
;; |
|
50 |
\?) |
|
51 |
usage |
|
52 |
;; |
|
53 |
esac |
|
54 |
done |
|
55 |
||
56 |
shift $(($OPTIND - 1)) |
|
57 |
||
58 |
||
59 |
# args |
|
60 |
||
8211 | 61 |
DIR="document" |
9788 | 62 |
[ "$#" -ge 1 ] && { DIR="$1"; shift; } |
7793 | 63 |
|
9788 | 64 |
[ "$#" -ne 0 ] && usage |
7793 | 65 |
|
66 |
||
67 |
## main |
|
68 |
||
7814 | 69 |
# check format |
70 |
||
71 |
case "$OUTFORMAT" in |
|
72 |
dvi | dvi.gz | ps | ps.gz | pdf) |
|
73 |
;; |
|
74 |
*) |
|
75 |
fail "Bad output format '$OUTFORMAT'" |
|
76 |
;; |
|
77 |
esac |
|
78 |
||
79 |
||
80 |
# prepare document |
|
7793 | 81 |
|
7814 | 82 |
function pre_latex () |
83 |
{ |
|
84 |
local FMT="$1" |
|
14367
0b1447d37161
remove more files (index, log files) for -c option
kleing
parents:
14344
diff
changeset
|
85 |
[ -n "$CLEAN" ] && rm -f *.aux *.out *.ind *.idx *.ilg *.bbl *.blg *.log |
12688 | 86 |
"$ISATOOL" latex -o sty && \ |
11948 | 87 |
"$ISATOOL" latex -o "$FMT" && \ |
88 |
{ [ ! -f root.bib ] || "$ISATOOL" latex -o bbl; } && \ |
|
14936 | 89 |
{ [ ! -f root.idx ] || "$ISATOOL" latex -o idx; } && \ |
90 |
"$ISATOOL" latex -o "$FMT" |
|
7814 | 91 |
} |
92 |
||
8211 | 93 |
( |
94 |
cd "$DIR" || fail "Bad directory '$DIR'" |
|
95 |
||
8654 | 96 |
[ -n "$CLEAN" ] && rm -f "../document.$OUTFORMAT" |
97 |
||
8211 | 98 |
if [ -f IsaMakefile ]; then |
9788 | 99 |
"$ISATOOL" make "$OUTFORMAT" |
100 |
RC="$?" |
|
8211 | 101 |
elif [ "$OUTFORMAT" = pdf ]; then |
102 |
pre_latex pdf && \ |
|
9788 | 103 |
"$ISATOOL" latex -o pdf && \ |
8211 | 104 |
{ if [ -n "$ISABELLE_THUMBPDF" ]; then |
9788 | 105 |
"$ISATOOL" latex -o png && \ |
106 |
"$ISATOOL" latex -o pdf |
|
8211 | 107 |
fi; } |
9788 | 108 |
RC="$?" |
8211 | 109 |
else |
110 |
pre_latex dvi && \ |
|
9788 | 111 |
"$ISATOOL" latex -o "$OUTFORMAT" |
112 |
RC="$?" |
|
8211 | 113 |
fi |
114 |
||
11581 | 115 |
if [ "$RC" -eq 0 -a -f "root.$OUTFORMAT" ]; then |
11844 | 116 |
cp -f "root.$OUTFORMAT" "../document.$OUTFORMAT" |
11581 | 117 |
fi |
8211 | 118 |
|
8217 | 119 |
exit "$RC" |
8211 | 120 |
) |
9788 | 121 |
RC="$?" |
7793 | 122 |
|
123 |
||
7814 | 124 |
# install |
7793 | 125 |
|
8211 | 126 |
[ "$RC" -ne 0 ] && fail "Failed to prepare document in directory '$DIR'" |
127 |
||
128 |
#beware! |
|
129 |
[ -n "$CLEAN" ] && rm -rf "$DIR" |
|
130 |
||
131 |
exit "$RC" |