blob: f9a84a7f651cb3e044d68374220806174780b8d1 [file] [log] [blame]
Fred Drakee2e904f1998-03-10 23:23:05 +00001#! /depot/gnu/plat/bin/bash
2
3MYDIR=`dirname $0`
Fred Drakef558e311998-03-24 17:48:20 +00004WORKDIR=`pwd`
5cd $MYDIR
6MYDIR=`pwd`
Fred Drakeac8f91a1998-04-02 15:37:13 +00007cd ..
8TOPDIR=`pwd`
Fred Drakef558e311998-03-24 17:48:20 +00009cd $WORKDIR
Fred Drakee2e904f1998-03-10 23:23:05 +000010
11# DEFAULT_FORMAT must be upper case...
12DEFAULT_FORMAT=PDF
13USE_DEFAULT_FORMAT=true
Fred Drakedbc879e1998-03-11 15:33:44 +000014DISCARD_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +000015
Fred Drakeac8f91a1998-04-02 15:37:13 +000016L2H_INIT_FILE=$TOPDIR/perl/l2hinit.perl
17
Fred Drakee2e904f1998-03-10 23:23:05 +000018# This is needed to support kpathsea based TeX installations. Others are
19# not supported. ;-)
Fred Drakedbc879e1998-03-11 15:33:44 +000020TEXINPUTS=`dirname $MYDIR`/texinputs:$TEXINPUTS
Fred Drakee2e904f1998-03-10 23:23:05 +000021export TEXINPUTS
22
Fred Drakedbc879e1998-03-11 15:33:44 +000023LOGFILE=/usr/tmp/mkhowto-$LOGNAME-$$.how
24LOGGING=''
25
Fred Drakee2e904f1998-03-10 23:23:05 +000026usage() {
Fred Drakeac8f91a1998-04-02 15:37:13 +000027 MYNAME=`basename $0`
28 echo "usage: $MYNAME [options...] file ..."
29 cat <<EOF
30
31Options specifying formats to build:
32 --html HyperText Markup Language
33 --pdf Portable Document Format (default)
34 --ps PostScript
35 --dvi "DeVice Indepentent" format from TeX
36
37 More than one output format may be specified.
38
39HTML options:
40 --address, -a Specify an address for page footers.
Fred Drake88053541998-04-24 21:57:12 +000041 --link Specify the number of levels to include on each page.
Fred Drakeac8f91a1998-04-02 15:37:13 +000042 --split, -s Specify a section level for page splitting.
43
44Other options:
45 --help, -H Show this text.
46 --logging, -l Log stdout and stderr to a file (*.how).
47 --debugging, -D Echo commands as they are executed.
48 --keep, -k Keep temporary files around.
49 --quiet, -q Do not print command output to stdout.
50 (stderr is also lost, sorry; see *.how for errors)
51
52EOF
53
54 exit $1
Fred Drakee2e904f1998-03-10 23:23:05 +000055}
56
Fred Drake88053541998-04-24 21:57:12 +000057# These are LaTeX2HTML controls; they reflect l2h variables of the same name.
58# The values here are the defaults after modification by perl/l2hinit.perl.
59#
60ADDRESS=''
61MAX_LINK_DEPTH=3
62MAX_SPLIT_DEPTH=8
63
Fred Drakee2e904f1998-03-10 23:23:05 +000064build_html() {
Fred Drake19c7c841998-05-07 21:20:39 +000065 TEXFILE=`kpsewhich $1.tex`
Fred Drake88053541998-04-24 21:57:12 +000066 if [ "$ADDRESS" ] ; then
67 latex2html -init_file $L2H_INIT_FILE \
68 -address "$ADDRESS" \
69 -link $MAX_LINK_DEPTH -split $MAX_SPLIT_DEPTH \
70 $1 || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +000071 else
Fred Drake88053541998-04-24 21:57:12 +000072 latex2html -init_file $L2H_INIT_FILE \
73 -link $MAX_LINK_DEPTH -split $MAX_SPLIT_DEPTH \
Fred Drake19c7c841998-05-07 21:20:39 +000074 -dir $1 $TEXFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +000075 fi
Fred Drake88053541998-04-24 21:57:12 +000076 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +000077 (cd $1; $MYDIR/node2label.pl *.html) || exit $?
Fred Drakeac8f91a1998-04-02 15:37:13 +000078 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000079}
80
Fred Drake12f842e1998-04-17 02:52:12 +000081use_latex() {
82 # two args: <file> <latextype>
83 MYFILE=$1
84 MYLATEX=$2
85 #
86 # We really have to do it three times to get all the page numbers right,
87 # since the length of the ToC makes a real difference.
88 #
89 $MYDIR/newind.py >$MYFILE.ind
90 $MYDIR/newind.py modindex >mod$MYFILE.ind
91 $MYLATEX $MYFILE || exit $?
92 if [ -f mod$MYFILE.idx ] ; then
93 makeindex mod$MYFILE.idx
Fred Drakee2e904f1998-03-10 23:23:05 +000094 fi
Fred Drake12f842e1998-04-17 02:52:12 +000095 if [ -f $MYFILE.idx ] ; then
96 $MYDIR/fix_hack $MYFILE.idx
97 makeindex $MYFILE.idx
98 $MYDIR/indfix.py $MYFILE.ind
99 fi
100 $MYLATEX $MYFILE || exit $?
101 if [ -f mod$MYFILE.idx ] ; then
102 makeindex mod$MYFILE.idx
103 fi
104 if [ -f $MYFILE.idx ] ; then
105 $MYDIR/fix_hack $MYFILE.idx || exit $?
106 makeindex -s $TOPDIR/texinputs/myindex.ist $MYFILE.idx || exit $?
107 fi
108 if [ -f $MYFILE.toc ] ; then
109 $MYDIR/toc2bkm.py -c section $MYFILE
110 fi
111 $MYLATEX $MYFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +0000112}
113
Fred Drake12f842e1998-04-17 02:52:12 +0000114build_dvi() {
115 use_latex $1 latex
Fred Drakee2e904f1998-03-10 23:23:05 +0000116}
117
118build_pdf() {
Fred Drake12f842e1998-04-17 02:52:12 +0000119 use_latex $1 pdflatex
120}
121
122build_ps() {
Fred Drake79842561998-04-17 20:06:16 +0000123 dvips -N0 -o $1.ps $1 || exit $?
Fred Drake12f842e1998-04-17 02:52:12 +0000124}
125
126cleanup() {
Fred Drakec9b8a571998-04-29 21:28:25 +0000127 rm -f $1.aux $1.log $1.out $1.toc $1.bkm $1.idx $1.ilg $1.ind
128 rm -f mod$1.idx mod$1.ilg mod$1.ind
Fred Drake12f842e1998-04-17 02:52:12 +0000129 if [ ! "$BUILD_DVI" ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +0000130 rm -f $1.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000131 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000132}
133
134# figure out what our targets are:
135while [ "$1" ] ; do
136 case "$1" in
137 --pdf|--pd)
138 BUILD_PDF=true
139 USE_DEFAULT_FORMAT=false
140 shift 1
141 ;;
Fred Drake88053541998-04-24 21:57:12 +0000142 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000143 BUILD_PS=true
144 USE_DEFAULT_FORMAT=false
145 shift 1
146 ;;
147 --dvi|--dv|--d)
148 BUILD_DVI=true
149 USE_DEFAULT_FORMAT=false
150 shift 1
151 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000152 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000153 BUILD_HTML=true
154 USE_DEFAULT_FORMAT=false
155 shift 1
156 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000157 -H|--help|--hel|--he)
158 usage 0
159 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000160 -a|--address|--addres|--addre|-addr|--add|--ad|--a)
161 ADDRESS="$2"
162 shift 2
163 ;;
Fred Drake88053541998-04-24 21:57:12 +0000164 --link|--lin|--li)
165 LINK="$2"
Fred Drakeac8f91a1998-04-02 15:37:13 +0000166 shift 2
167 ;;
Fred Drake88053541998-04-24 21:57:12 +0000168 -s|--split|--spli|--spl|--sp|--s)
169 MAX_SPLIT_DEPTH="$2"
170 shift 2
171 ;;
172 -l|--logging|--loggin|--loggi|--logg|--log|--lo)
Fred Drakedbc879e1998-03-11 15:33:44 +0000173 LOGGING=true
174 shift 1
175 ;;
176 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
177 DEBUGGING=true
178 shift 1
179 ;;
180 -k|--keep|--kee|--ke|--k)
181 DISCARD_TEMPS=''
182 shift 1
183 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000184 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000185 QUIET=true
186 shift 1
187 ;;
Fred Drake88053541998-04-24 21:57:12 +0000188 --)
Fred Drakec9b8a571998-04-29 21:28:25 +0000189 shift 1
Fred Drake88053541998-04-24 21:57:12 +0000190 break
191 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000192 -*)
Fred Drakeac8f91a1998-04-02 15:37:13 +0000193 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000194 ;;
195 *)
196 break;;
197 esac
198done
199
200if [ $# = 0 ] ; then
Fred Drakeac8f91a1998-04-02 15:37:13 +0000201 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000202fi
203
204if [ $USE_DEFAULT_FORMAT = true ] ; then
205 eval "BUILD_$DEFAULT_FORMAT=true"
206fi
207
Fred Drakedbc879e1998-03-11 15:33:44 +0000208if [ "$DEBUGGING" ] ; then
209 set -x
210fi
211
Fred Drake664b36f1998-03-11 15:41:21 +0000212if [ "$QUIET" ] ; then
213 exec >/dev/null
214fi
215
Fred Drakee2e904f1998-03-10 23:23:05 +0000216for FILE in $@ ; do
Fred Drake19c7c841998-05-07 21:20:39 +0000217 FILE=`basename ${FILE%.tex}`
Fred Drakee2e904f1998-03-10 23:23:05 +0000218 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000219 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000220 fi
221 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000222 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000223 fi
224 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000225 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000226 fi
227 if [ "$BUILD_HTML" ] ; then
228 if [ ! "$BUILD_DVI" -o ! "$BUILD_PDF" ] ; then
229 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000230 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000231 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000232 build_html $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000233 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000234 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000235 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000236 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000237 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000238 if [ "$LOGGING" ] ; then
239 cp $LOGFILE $FILE.how
240 fi
241 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000242done