blob: 851e1020e4d9cb6600d7d10767c4182a6eb04e9c [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 Drakedbc879e1998-03-11 15:33:44 +000018LOGFILE=/usr/tmp/mkhowto-$LOGNAME-$$.how
19LOGGING=''
20
Fred Drakee2e904f1998-03-10 23:23:05 +000021usage() {
Fred Drakeac8f91a1998-04-02 15:37:13 +000022 MYNAME=`basename $0`
23 echo "usage: $MYNAME [options...] file ..."
24 cat <<EOF
25
26Options specifying formats to build:
27 --html HyperText Markup Language
28 --pdf Portable Document Format (default)
29 --ps PostScript
30 --dvi "DeVice Indepentent" format from TeX
31
32 More than one output format may be specified.
33
34HTML options:
35 --address, -a Specify an address for page footers.
Fred Drake88053541998-04-24 21:57:12 +000036 --link Specify the number of levels to include on each page.
Fred Drakeac8f91a1998-04-02 15:37:13 +000037 --split, -s Specify a section level for page splitting.
38
39Other options:
Fred Drake1a3541c1998-05-11 19:04:56 +000040 --a4 Format for A4 paper.
Fred Draked5d473f1998-05-11 20:40:24 +000041 --letter Format for US letter paper (the default).
Fred Drakeac8f91a1998-04-02 15:37:13 +000042 --help, -H Show this text.
43 --logging, -l Log stdout and stderr to a file (*.how).
44 --debugging, -D Echo commands as they are executed.
45 --keep, -k Keep temporary files around.
46 --quiet, -q Do not print command output to stdout.
47 (stderr is also lost, sorry; see *.how for errors)
48
49EOF
50
51 exit $1
Fred Drakee2e904f1998-03-10 23:23:05 +000052}
53
Fred Drake88053541998-04-24 21:57:12 +000054# These are LaTeX2HTML controls; they reflect l2h variables of the same name.
55# The values here are the defaults after modification by perl/l2hinit.perl.
56#
57ADDRESS=''
58MAX_LINK_DEPTH=3
59MAX_SPLIT_DEPTH=8
60
Fred Drakee2e904f1998-03-10 23:23:05 +000061build_html() {
Fred Drake19c7c841998-05-07 21:20:39 +000062 TEXFILE=`kpsewhich $1.tex`
Fred Drake88053541998-04-24 21:57:12 +000063 if [ "$ADDRESS" ] ; then
64 latex2html -init_file $L2H_INIT_FILE \
65 -address "$ADDRESS" \
66 -link $MAX_LINK_DEPTH -split $MAX_SPLIT_DEPTH \
67 $1 || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +000068 else
Fred Drake88053541998-04-24 21:57:12 +000069 latex2html -init_file $L2H_INIT_FILE \
70 -link $MAX_LINK_DEPTH -split $MAX_SPLIT_DEPTH \
Fred Drake19c7c841998-05-07 21:20:39 +000071 -dir $1 $TEXFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +000072 fi
Fred Drake88053541998-04-24 21:57:12 +000073 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +000074 (cd $1; $MYDIR/node2label.pl *.html) || exit $?
Fred Drakeac8f91a1998-04-02 15:37:13 +000075 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000076}
77
Fred Drake12f842e1998-04-17 02:52:12 +000078use_latex() {
79 # two args: <file> <latextype>
80 MYFILE=$1
81 MYLATEX=$2
82 #
83 # We really have to do it three times to get all the page numbers right,
84 # since the length of the ToC makes a real difference.
85 #
86 $MYDIR/newind.py >$MYFILE.ind
87 $MYDIR/newind.py modindex >mod$MYFILE.ind
88 $MYLATEX $MYFILE || exit $?
89 if [ -f mod$MYFILE.idx ] ; then
90 makeindex mod$MYFILE.idx
Fred Drakee2e904f1998-03-10 23:23:05 +000091 fi
Fred Drake12f842e1998-04-17 02:52:12 +000092 if [ -f $MYFILE.idx ] ; then
93 $MYDIR/fix_hack $MYFILE.idx
94 makeindex $MYFILE.idx
95 $MYDIR/indfix.py $MYFILE.ind
96 fi
97 $MYLATEX $MYFILE || exit $?
98 if [ -f mod$MYFILE.idx ] ; then
99 makeindex mod$MYFILE.idx
100 fi
101 if [ -f $MYFILE.idx ] ; then
102 $MYDIR/fix_hack $MYFILE.idx || exit $?
103 makeindex -s $TOPDIR/texinputs/myindex.ist $MYFILE.idx || exit $?
104 fi
Fred Drakef4fc4761998-05-14 20:03:14 +0000105 if [ -f $MYFILE.toc -a $MYLATEX = pdflatex ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000106 $MYDIR/toc2bkm.py -c section $MYFILE
107 fi
108 $MYLATEX $MYFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +0000109}
110
Fred Drake12f842e1998-04-17 02:52:12 +0000111build_dvi() {
112 use_latex $1 latex
Fred Drakee2e904f1998-03-10 23:23:05 +0000113}
114
115build_pdf() {
Fred Drake12f842e1998-04-17 02:52:12 +0000116 use_latex $1 pdflatex
117}
118
119build_ps() {
Fred Drake79842561998-04-17 20:06:16 +0000120 dvips -N0 -o $1.ps $1 || exit $?
Fred Drake12f842e1998-04-17 02:52:12 +0000121}
122
123cleanup() {
Fred Drakec9b8a571998-04-29 21:28:25 +0000124 rm -f $1.aux $1.log $1.out $1.toc $1.bkm $1.idx $1.ilg $1.ind
125 rm -f mod$1.idx mod$1.ilg mod$1.ind
Fred Drake12f842e1998-04-17 02:52:12 +0000126 if [ ! "$BUILD_DVI" ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +0000127 rm -f $1.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000128 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000129}
130
131# figure out what our targets are:
132while [ "$1" ] ; do
133 case "$1" in
134 --pdf|--pd)
135 BUILD_PDF=true
136 USE_DEFAULT_FORMAT=false
137 shift 1
138 ;;
Fred Drake88053541998-04-24 21:57:12 +0000139 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000140 BUILD_PS=true
141 USE_DEFAULT_FORMAT=false
142 shift 1
143 ;;
144 --dvi|--dv|--d)
145 BUILD_DVI=true
146 USE_DEFAULT_FORMAT=false
147 shift 1
148 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000149 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000150 BUILD_HTML=true
151 USE_DEFAULT_FORMAT=false
152 shift 1
153 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000154 -H|--help|--hel|--he)
155 usage 0
156 ;;
Fred Drake35049521998-05-11 19:04:06 +0000157 -a|--address|--addres|--addre|-addr|--add|--ad)
Fred Drakee2e904f1998-03-10 23:23:05 +0000158 ADDRESS="$2"
159 shift 2
160 ;;
Fred Drake35049521998-05-11 19:04:06 +0000161 --a4)
162 TEXINPUTS=$TOPDIR/paper-a4:$TEXINPUTS
163 shift 1
164 ;;
Fred Draked5d473f1998-05-11 20:40:24 +0000165 --letter|--lette|--lett|--let|--le)
166 shift 1
167 ;;
Fred Drake88053541998-04-24 21:57:12 +0000168 --link|--lin|--li)
169 LINK="$2"
Fred Drakeac8f91a1998-04-02 15:37:13 +0000170 shift 2
171 ;;
Fred Drake88053541998-04-24 21:57:12 +0000172 -s|--split|--spli|--spl|--sp|--s)
173 MAX_SPLIT_DEPTH="$2"
174 shift 2
175 ;;
176 -l|--logging|--loggin|--loggi|--logg|--log|--lo)
Fred Drakedbc879e1998-03-11 15:33:44 +0000177 LOGGING=true
178 shift 1
179 ;;
180 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
181 DEBUGGING=true
182 shift 1
183 ;;
184 -k|--keep|--kee|--ke|--k)
185 DISCARD_TEMPS=''
186 shift 1
187 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000188 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000189 QUIET=true
190 shift 1
191 ;;
Fred Drake88053541998-04-24 21:57:12 +0000192 --)
Fred Drakec9b8a571998-04-29 21:28:25 +0000193 shift 1
Fred Drake88053541998-04-24 21:57:12 +0000194 break
195 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000196 -*)
Fred Drakeac8f91a1998-04-02 15:37:13 +0000197 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000198 ;;
199 *)
200 break;;
201 esac
202done
203
204if [ $# = 0 ] ; then
Fred Drakeac8f91a1998-04-02 15:37:13 +0000205 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000206fi
207
208if [ $USE_DEFAULT_FORMAT = true ] ; then
209 eval "BUILD_$DEFAULT_FORMAT=true"
210fi
211
Fred Drakedbc879e1998-03-11 15:33:44 +0000212if [ "$DEBUGGING" ] ; then
213 set -x
214fi
215
Fred Drake664b36f1998-03-11 15:41:21 +0000216if [ "$QUIET" ] ; then
217 exec >/dev/null
218fi
219
Fred Drakef4fc4761998-05-14 20:03:14 +0000220COMMONTEXINPUTS=$TOPDIR/texinputs:$TEXINPUTS
221
Fred Drakee2e904f1998-03-10 23:23:05 +0000222for FILE in $@ ; do
Fred Drakedf825a11998-05-14 20:36:49 +0000223 FILEDIR=`dirname $FILE`
Fred Drake19c7c841998-05-07 21:20:39 +0000224 FILE=`basename ${FILE%.tex}`
Fred Drakef4fc4761998-05-14 20:03:14 +0000225 #
226 # Put the directory the .tex file is in is also the first directory in
227 # TEXINPUTS, to allow files there to override files in the common area.
228 #
Fred Drakef4fc4761998-05-14 20:03:14 +0000229 TEXINPUTS=$FILEDIR:$COMMONTEXINPUTS
230 export TEXINPUTS
Fred Drakedf825a11998-05-14 20:36:49 +0000231 echo TEXINPUTS is $TEXINPUTS
Fred Drakef4fc4761998-05-14 20:03:14 +0000232 #
Fred Drakee2e904f1998-03-10 23:23:05 +0000233 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000234 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000235 fi
236 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000237 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000238 fi
239 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000240 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000241 fi
242 if [ "$BUILD_HTML" ] ; then
243 if [ ! "$BUILD_DVI" -o ! "$BUILD_PDF" ] ; then
244 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000245 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000246 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000247 build_html $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000248 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000249 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000250 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000251 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000252 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000253 if [ "$LOGGING" ] ; then
254 cp $LOGFILE $FILE.how
255 fi
256 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000257done