7772
|
1 |
#!/bin/bash
|
|
2 |
#
|
|
3 |
# $Id$
|
|
4 |
#
|
7794
|
5 |
# DESCRIPTION: run LaTeX (and related tools)
|
7772
|
6 |
|
|
7 |
|
|
8 |
PRG=$(basename $0)
|
|
9 |
|
|
10 |
function usage()
|
|
11 |
{
|
|
12 |
echo
|
7794
|
13 |
echo "Usage: $PRG [OPTIONS] [FILE]"
|
7772
|
14 |
echo
|
|
15 |
echo " Options are:"
|
7815
|
16 |
echo " -o FORMAT specify output format: dvi (default), dvi.gz, ps, ps.gz,"
|
8564
|
17 |
echo " pdf, bbl, png, sty"
|
7772
|
18 |
echo
|
7857
|
19 |
echo " Run LaTeX (and related tools) on FILE (default root.tex),"
|
|
20 |
echo " producing the specified output format."
|
7772
|
21 |
echo
|
|
22 |
exit 1
|
|
23 |
}
|
|
24 |
|
|
25 |
function fail()
|
|
26 |
{
|
|
27 |
echo "$1" >&2
|
|
28 |
exit 2
|
|
29 |
}
|
|
30 |
|
|
31 |
|
|
32 |
## process command line
|
|
33 |
|
|
34 |
# options
|
|
35 |
|
|
36 |
OUTFORMAT=dvi
|
|
37 |
|
|
38 |
while getopts "o:" OPT
|
|
39 |
do
|
|
40 |
case "$OPT" in
|
|
41 |
o)
|
|
42 |
OUTFORMAT="$OPTARG"
|
|
43 |
;;
|
|
44 |
\?)
|
|
45 |
usage
|
|
46 |
;;
|
|
47 |
esac
|
|
48 |
done
|
|
49 |
|
|
50 |
shift $(($OPTIND - 1))
|
|
51 |
|
|
52 |
|
|
53 |
# args
|
|
54 |
|
7794
|
55 |
FILE="root.tex"
|
7772
|
56 |
[ $# -ge 1 ] && { FILE="$1"; shift; }
|
|
57 |
|
7794
|
58 |
[ $# -ne 0 ] && usage
|
7772
|
59 |
|
|
60 |
|
|
61 |
## main
|
|
62 |
|
8564
|
63 |
# root file
|
7815
|
64 |
|
7772
|
65 |
DIR=$(dirname "$FILE")
|
7777
|
66 |
if [ "$DIR" = . ]; then
|
7772
|
67 |
FILEBASE=$(basename "$FILE" .tex)
|
|
68 |
else
|
7777
|
69 |
FILEBASE=$DIR/$(basename "$FILE" .tex)
|
7772
|
70 |
fi
|
|
71 |
|
8564
|
72 |
function check_root () { [ -f "$FILEBASE.tex" ] || fail "Bad file '$FILE'" }
|
7794
|
73 |
|
7815
|
74 |
|
|
75 |
# operations
|
|
76 |
|
|
77 |
function run_latex () { $ISABELLE_LATEX "\\nonstopmode\\input{$FILEBASE.tex}"; }
|
|
78 |
function run_pdflatex () { $ISABELLE_PDFLATEX "\\nonstopmode\\input{$FILEBASE.tex}"; }
|
|
79 |
function run_bibtex () { $ISABELLE_BIBTEX </dev/null "$FILEBASE"; }
|
|
80 |
function run_dvips () { $ISABELLE_DVIPS -o "$FILEBASE.ps" "$FILEBASE.dvi"; }
|
7865
|
81 |
function run_thumbpdf () { [ -n "$ISABELLE_THUMBPDF" ] && $ISABELLE_THUMBPDF "$FILEBASE"; }
|
7815
|
82 |
|
8564
|
83 |
function update_styles ()
|
|
84 |
{
|
|
85 |
for NAME in $ISABELLE_HOME/lib/texinputs/*.sty
|
|
86 |
do
|
|
87 |
BNAME=$(basename "$NAME")
|
|
88 |
if [ ! -e "$BNAME" -o "$NAME" -nt "$BNAME" ]; then
|
|
89 |
echo "updating $BNAME"
|
|
90 |
cp -f "$NAME" "$BNAME"
|
|
91 |
fi
|
|
92 |
done
|
|
93 |
}
|
7815
|
94 |
|
7772
|
95 |
case "$OUTFORMAT" in
|
|
96 |
dvi)
|
8564
|
97 |
check_root && \
|
7815
|
98 |
run_latex
|
7794
|
99 |
RC=$?
|
7772
|
100 |
;;
|
|
101 |
dvi.gz)
|
8564
|
102 |
check_root && \
|
7815
|
103 |
run_latex && \
|
7772
|
104 |
gzip -f "$FILEBASE.dvi"
|
7794
|
105 |
RC=$?
|
7772
|
106 |
;;
|
|
107 |
ps)
|
8564
|
108 |
check_root && \
|
7815
|
109 |
run_latex && \
|
|
110 |
run_dvips &&
|
7794
|
111 |
RC=$?
|
7772
|
112 |
;;
|
|
113 |
ps.gz)
|
8564
|
114 |
check_root && \
|
7815
|
115 |
run_latex && \
|
|
116 |
run_dvips &&
|
7772
|
117 |
gzip -f "$FILEBASE.ps"
|
7794
|
118 |
RC=$?
|
7772
|
119 |
;;
|
|
120 |
pdf)
|
8564
|
121 |
check_root && \
|
7815
|
122 |
run_pdflatex
|
|
123 |
RC=$?
|
|
124 |
;;
|
|
125 |
bbl)
|
8564
|
126 |
check_root && \
|
7815
|
127 |
run_bibtex
|
7794
|
128 |
RC=$?
|
7772
|
129 |
;;
|
7865
|
130 |
png)
|
8564
|
131 |
check_root && \
|
7865
|
132 |
run_thumbpdf
|
|
133 |
RC=$?
|
|
134 |
;;
|
8564
|
135 |
sty)
|
|
136 |
update_styles
|
|
137 |
RC=$?
|
|
138 |
;;
|
7772
|
139 |
*)
|
|
140 |
fail "Bad output format '$OUTFORMAT'"
|
|
141 |
;;
|
|
142 |
esac
|
7794
|
143 |
|
|
144 |
exit $RC
|