author | wenzelm |
Wed, 22 Nov 2000 21:41:39 +0100 | |
changeset 10511 | efb3428c9879 |
parent 9788 | df671fa2562a |
child 10555 | 2323ec838401 |
permissions | -rwxr-xr-x |
8212 | 1 |
#!/bin/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 |
||
8211 | 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 |
7814 | 87 |
if [ -f root.bib ] |
88 |
then |
|
9788 | 89 |
"$ISATOOL" latex -o "$FMT" && \ |
90 |
"$ISATOOL" latex -o bbl && \ |
|
91 |
"$ISATOOL" latex -o "$FMT" |
|
7814 | 92 |
else |
9788 | 93 |
"$ISATOOL" latex -o "$FMT" |
7814 | 94 |
fi |
95 |
} |
|
96 |
||
8211 | 97 |
( |
98 |
cd "$DIR" || fail "Bad directory '$DIR'" |
|
99 |
||
8654 | 100 |
[ -n "$CLEAN" ] && rm -f "../document.$OUTFORMAT" |
101 |
||
8211 | 102 |
if [ -f IsaMakefile ]; then |
9788 | 103 |
"$ISATOOL" make "$OUTFORMAT" |
104 |
RC="$?" |
|
8211 | 105 |
elif [ "$OUTFORMAT" = pdf ]; then |
106 |
pre_latex pdf && \ |
|
9788 | 107 |
"$ISATOOL" latex -o pdf && \ |
8211 | 108 |
{ if [ -n "$ISABELLE_THUMBPDF" ]; then |
9788 | 109 |
"$ISATOOL" latex -o png && \ |
110 |
"$ISATOOL" latex -o pdf |
|
8211 | 111 |
fi; } |
9788 | 112 |
RC="$?" |
8211 | 113 |
else |
114 |
pre_latex dvi && \ |
|
9788 | 115 |
"$ISATOOL" latex -o "$OUTFORMAT" |
116 |
RC="$?" |
|
8211 | 117 |
fi |
118 |
||
119 |
[ "$RC" -eq 0 -a -f "root.$OUTFORMAT" ] && \ |
|
120 |
cp -f "root.$OUTFORMAT" "../document.$OUTFORMAT" |
|
121 |
||
8217 | 122 |
exit "$RC" |
8211 | 123 |
) |
9788 | 124 |
RC="$?" |
7793 | 125 |
|
126 |
||
7814 | 127 |
# install |
7793 | 128 |
|
8211 | 129 |
[ "$RC" -ne 0 ] && fail "Failed to prepare document in directory '$DIR'" |
130 |
||
131 |
#beware! |
|
132 |
[ -n "$CLEAN" ] && rm -rf "$DIR" |
|
133 |
||
134 |
exit "$RC" |