author | wenzelm |
Wed, 09 Jan 2002 17:36:34 +0100 | |
changeset 12688 | 4ad13c2f7196 |
parent 11948 | 9c812b21b2e8 |
child 14344 | 0f0a2148a099 |
permissions | -rwxr-xr-x |
10555 | 1 |
#!/usr/bin/env bash |
7793 | 2 |
# |
3 |
# $Id$ |
|
9788 | 4 |
# Author: Markus Wenzel, TU Muenchen |
5 |
# License: GPL (GNU GENERAL PUBLIC LICENSE) |
|
7793 | 6 |
# |
7 |
# DESCRIPTION: prepare theory session document |
|
8 |
||
9 |
||
10511 | 10 |
PRG="$(basename "$0")" |
7793 | 11 |
|
12 |
function usage() |
|
13 |
{ |
|
14 |
echo |
|
15 |
echo "Usage: $PRG [OPTIONS] [DIR]" |
|
16 |
echo |
|
17 |
echo " Options are:" |
|
8654 | 18 |
echo " -c cleanup -- be aggressive in removing old stuff" |
7866
3ccaa11b6df9
pdf: generate thumbnails if ISABELLE_THUMBPDF set;
wenzelm
parents:
7857
diff
changeset
|
19 |
echo " -o FORMAT specify output format: dvi (default), dvi.gz, ps," |
3ccaa11b6df9
pdf: generate thumbnails if ISABELLE_THUMBPDF set;
wenzelm
parents:
7857
diff
changeset
|
20 |
echo " ps.gz, pdf" |
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="" |
7793 | 40 |
OUTFORMAT=dvi |
41 |
||
11844 | 42 |
while getopts "co:" OPT |
7793 | 43 |
do |
44 |
case "$OPT" in |
|
8211 | 45 |
c) |
46 |
CLEAN=true |
|
47 |
;; |
|
7793 | 48 |
o) |
49 |
OUTFORMAT="$OPTARG" |
|
50 |
;; |
|
51 |
\?) |
|
52 |
usage |
|
53 |
;; |
|
54 |
esac |
|
55 |
done |
|
56 |
||
57 |
shift $(($OPTIND - 1)) |
|
58 |
||
59 |
||
60 |
# args |
|
61 |
||
8211 | 62 |
DIR="document" |
9788 | 63 |
[ "$#" -ge 1 ] && { DIR="$1"; shift; } |
7793 | 64 |
|
9788 | 65 |
[ "$#" -ne 0 ] && usage |
7793 | 66 |
|
67 |
||
68 |
## main |
|
69 |
||
7814 | 70 |
# check format |
71 |
||
72 |
case "$OUTFORMAT" in |
|
73 |
dvi | dvi.gz | ps | ps.gz | pdf) |
|
74 |
;; |
|
75 |
*) |
|
76 |
fail "Bad output format '$OUTFORMAT'" |
|
77 |
;; |
|
78 |
esac |
|
79 |
||
80 |
||
81 |
# prepare document |
|
7793 | 82 |
|
7814 | 83 |
function pre_latex () |
84 |
{ |
|
85 |
local FMT="$1" |
|
8654 | 86 |
[ -n "$CLEAN" ] && rm -f *.aux *.out |
12688 | 87 |
"$ISATOOL" latex -o sty && \ |
11948 | 88 |
"$ISATOOL" latex -o "$FMT" && \ |
89 |
{ [ ! -f root.bib ] || "$ISATOOL" latex -o bbl; } && \ |
|
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" |