blob: 97d3cf91d7c1b877f9a589ec8a5024cc2d9dc03c [file] [log] [blame]
Fred Drakee2e904f1998-03-10 23:23:05 +00001#! /depot/gnu/plat/bin/bash
2
3MYDIR=`dirname $0`
4
5# DEFAULT_FORMAT must be upper case...
6DEFAULT_FORMAT=PDF
7USE_DEFAULT_FORMAT=true
8
9# This is needed to support kpathsea based TeX installations. Others are
10# not supported. ;-)
11TEXINPUTS=$MYDIR/../texinputs:
12export TEXINPUTS
13
14usage() {
15 echo "usage: $0 [options...] file ..."
16 exit 2
17}
18
19build_html() {
20 # This doesn't work; l2hinit.perl uses the current directory, not it's own
21 # location. Need a workaround for this.
22 if [ "$ADDRESS" ] ; then
23 latex2html -init_file $MYDIR/../perl/l2hinit.perl -address "$ADDRESS" \
24 $1 || exit $?
25 else
26 latex2html -init_file $MYDIR/../perl/l2hinit.perl $1 || exit $?
27 fi
28 (cd $FILE; $MYDIR/node2label.pl *.html) || exit $?
29}
30
31build_dvi() {
32 latex $1 || exit $?
33 if [ -f $1.idx ] ; then
34 `dirname $0`/fix_hack $1.idx || exit $?
35 makeindex $1.idx || exit $?
36 fi
37 latex $1 || exit $?
38}
39
40build_ps() {
41 dvips -N0 -f $1 >$1.ps || exit $?
42}
43
44build_pdf() {
45 # We really have to do it three times to get all the page numbers right,
46 # since the length of the ToC makes a real difference.
47 pdflatex $1 || exit $?
48 pdflatex $1 || exit $?
49 `dirname $0`/toc2bkm.py -c section $FILE || exit $?
50 if [ -f $1.idx ] ; then
51 `dirname $0`/fix_hack $1.idx || exit $?
52 makeindex $1.idx || exit $?
53 fi
54 pdflatex $1 || exit $?
55}
56
57# figure out what our targets are:
58while [ "$1" ] ; do
59 case "$1" in
60 --pdf|--pd)
61 BUILD_PDF=true
62 USE_DEFAULT_FORMAT=false
63 shift 1
64 ;;
65 --ps)
66 BUILD_PS=true
67 USE_DEFAULT_FORMAT=false
68 shift 1
69 ;;
70 --dvi|--dv|--d)
71 BUILD_DVI=true
72 USE_DEFAULT_FORMAT=false
73 shift 1
74 ;;
75 --html|--htm|--ht|--h)
76 BUILD_HTML=true
77 USE_DEFAULT_FORMAT=false
78 shift 1
79 ;;
80 -a|--address|--addres|--addre|-addr|--add|--ad|--a)
81 ADDRESS="$2"
82 shift 2
83 ;;
84 -*)
85 usage
86 ;;
87 *)
88 break;;
89 esac
90done
91
92if [ $# = 0 ] ; then
93 usage
94fi
95
96if [ $USE_DEFAULT_FORMAT = true ] ; then
97 eval "BUILD_$DEFAULT_FORMAT=true"
98fi
99
100for FILE in $@ ; do
101 FILE=${FILE%.tex}
102 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
103 build_dvi $FILE
104 fi
105 if [ "$BUILD_PDF" ] ; then
106 build_pdf $FILE
107 fi
108 if [ "$BUILD_PS" ] ; then
109 build_ps $FILE
110 fi
111 if [ "$BUILD_HTML" ] ; then
112 if [ ! "$BUILD_DVI" -o ! "$BUILD_PDF" ] ; then
113 # need to get aux file
114 build_dvi $FILE
115 fi
116 build_html $FILE
117 fi
118 rm -f $FILE.aux $FILE.log $FILE.out $FILE.toc $FILE.bkm
119 if [ ! "$BUILD_DVI" ] ; then
120 rm -f $FILE.dvi
121 fi
122done