blob: cd85ef078c263d19f54df36fd5c75f5042329aa3 [file] [log] [blame]
Fred Drake566b6d51998-10-27 21:59:03 +00001#! /usr/bin/env ksh
Fred Drakee2e904f1998-03-10 23:23:05 +00002
Fred Drakec794c381998-08-12 17:50:07 +00003# This script may be invoked by naming it directly or via a shell alias,
4# but NOT through a symbolic link. Perhaps a future version will allow
5# the use of a symbolic link.
6#
7# Using a symbolic link will cause the script to not be able to locate
8# its support files.
9
Fred Drakee2e904f1998-03-10 23:23:05 +000010MYDIR=`dirname $0`
Fred Drakef558e311998-03-24 17:48:20 +000011WORKDIR=`pwd`
12cd $MYDIR
13MYDIR=`pwd`
Fred Drakeac8f91a1998-04-02 15:37:13 +000014cd ..
15TOPDIR=`pwd`
Fred Drakef558e311998-03-24 17:48:20 +000016cd $WORKDIR
Fred Drakee2e904f1998-03-10 23:23:05 +000017
18# DEFAULT_FORMAT must be upper case...
19DEFAULT_FORMAT=PDF
20USE_DEFAULT_FORMAT=true
Fred Drakedbc879e1998-03-11 15:33:44 +000021DISCARD_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +000022
Fred Drake11300cc1998-08-05 04:48:18 +000023ICONSERVER=''
24
Fred Drakee1feb8f1998-08-28 20:21:04 +000025TEMPBASE=mkhowto-$LOGNAME-$$
Fred Drakeac8f91a1998-04-02 15:37:13 +000026
Fred Drakee1feb8f1998-08-28 20:21:04 +000027L2H_INIT_FILE=$TOPDIR/perl/l2hinit.perl
28L2H_AUX_INIT_FILE=/usr/tmp/$TEMPBASE.perl
29
30LOGFILE=/usr/tmp/$TEMPBASE.how
Fred Drakedbc879e1998-03-11 15:33:44 +000031LOGGING=''
32
Fred Drakee2e904f1998-03-10 23:23:05 +000033usage() {
Fred Drakeac8f91a1998-04-02 15:37:13 +000034 MYNAME=`basename $0`
Fred Drakeac8f91a1998-04-02 15:37:13 +000035 cat <<EOF
Fred Drakea5de7301998-10-19 19:14:42 +000036usage: $MYNAME [options...] file ...
Fred Drakeac8f91a1998-04-02 15:37:13 +000037
38Options specifying formats to build:
39 --html HyperText Markup Language
40 --pdf Portable Document Format (default)
41 --ps PostScript
42 --dvi "DeVice Indepentent" format from TeX
Fred Drakea5de7301998-10-19 19:14:42 +000043 --text ASCII text (requires lynx)
Fred Drakeac8f91a1998-04-02 15:37:13 +000044
Fred Drake9f6f0da1998-08-12 18:07:51 +000045 More than one output format may be specified, or --all.
Fred Drakeac8f91a1998-04-02 15:37:13 +000046
47HTML options:
48 --address, -a Specify an address for page footers.
Fred Drake88053541998-04-24 21:57:12 +000049 --link Specify the number of levels to include on each page.
Fred Drake437ff861998-10-07 16:46:54 +000050 --split, -s Specify a section level for page splitting, default: $MAX_SPLIT_DEPTH.
Fred Drake11300cc1998-08-05 04:48:18 +000051 --iconserver, -i Specify location of icons (default: ../).
Fred Drakeac8f91a1998-04-02 15:37:13 +000052
53Other options:
Fred Drake1a3541c1998-05-11 19:04:56 +000054 --a4 Format for A4 paper.
Fred Draked5d473f1998-05-11 20:40:24 +000055 --letter Format for US letter paper (the default).
Fred Drakeac8f91a1998-04-02 15:37:13 +000056 --help, -H Show this text.
57 --logging, -l Log stdout and stderr to a file (*.how).
58 --debugging, -D Echo commands as they are executed.
59 --keep, -k Keep temporary files around.
60 --quiet, -q Do not print command output to stdout.
61 (stderr is also lost, sorry; see *.how for errors)
62
63EOF
Fred Drake9f6f0da1998-08-12 18:07:51 +000064 if [ "$2" ] ; then
65 echo "$2"
66 echo
67 fi
Fred Drakeac8f91a1998-04-02 15:37:13 +000068 exit $1
Fred Drakee2e904f1998-03-10 23:23:05 +000069}
70
Fred Drake88053541998-04-24 21:57:12 +000071# These are LaTeX2HTML controls; they reflect l2h variables of the same name.
72# The values here are the defaults after modification by perl/l2hinit.perl.
73#
74ADDRESS=''
75MAX_LINK_DEPTH=3
Fred Drake437ff861998-10-07 16:46:54 +000076MAX_SPLIT_DEPTH=6
Fred Drake88053541998-04-24 21:57:12 +000077
Fred Drakee2e904f1998-03-10 23:23:05 +000078build_html() {
Fred Drake19c7c841998-05-07 21:20:39 +000079 TEXFILE=`kpsewhich $1.tex`
Fred Drakeb5210951998-10-16 17:34:34 +000080 TEXFILE="${TEXFILE#./}"
Fred Drake9940bd71998-08-06 20:15:20 +000081 BUILDDIR=${2:-$1}
Fred Drake11300cc1998-08-05 04:48:18 +000082 latex2html \
83 -init_file $L2H_INIT_FILE \
84 -init_file $L2H_AUX_INIT_FILE \
Fred Drake9940bd71998-08-06 20:15:20 +000085 -dir $BUILDDIR $TEXFILE || exit $?
Fred Drake88053541998-04-24 21:57:12 +000086 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +000087 (cd $BUILDDIR; $MYDIR/node2label.pl *.html) || exit $?
Fred Drakeac8f91a1998-04-02 15:37:13 +000088 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000089}
90
Fred Drake12f842e1998-04-17 02:52:12 +000091use_latex() {
92 # two args: <file> <latextype>
93 MYFILE=$1
94 MYLATEX=$2
95 #
96 # We really have to do it three times to get all the page numbers right,
97 # since the length of the ToC makes a real difference.
98 #
99 $MYDIR/newind.py >$MYFILE.ind
100 $MYDIR/newind.py modindex >mod$MYFILE.ind
101 $MYLATEX $MYFILE || exit $?
102 if [ -f mod$MYFILE.idx ] ; then
103 makeindex mod$MYFILE.idx
Fred Drakee2e904f1998-03-10 23:23:05 +0000104 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000105 if [ -f $MYFILE.idx ] ; then
106 $MYDIR/fix_hack $MYFILE.idx
107 makeindex $MYFILE.idx
108 $MYDIR/indfix.py $MYFILE.ind
109 fi
Fred Drake566b6d51998-10-27 21:59:03 +0000110 if [ `grep -c '^\\\\bibdata{' $MYFILE.aux` -ne 0 ] ; then
111 USE_BIBTEX=true
112 bibtex $MYFILE
113 else
114 USE_BIBTEX=''
115 fi
Fred Drake8cab5491998-07-23 19:13:52 +0000116 if [ -f $MYFILE.syn ] ; then
117 # This hack is due to a bug with the module synopsis support that
118 # causes the last module synopsis to be written out twice in
119 # howto documents (not present for manuals). Repeated below.
120 uniq $MYFILE.syn >TEMP.syn && mv TEMP.syn $MYFILE.syn || exit $?
121 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000122 $MYLATEX $MYFILE || exit $?
123 if [ -f mod$MYFILE.idx ] ; then
124 makeindex mod$MYFILE.idx
125 fi
126 if [ -f $MYFILE.idx ] ; then
127 $MYDIR/fix_hack $MYFILE.idx || exit $?
Fred Drakefbdddde1998-10-19 21:48:05 +0000128 makeindex -s $TOPDIR/texinputs/python.ist $MYFILE.idx || exit $?
Fred Drake12f842e1998-04-17 02:52:12 +0000129 fi
Fred Drakef4fc4761998-05-14 20:03:14 +0000130 if [ -f $MYFILE.toc -a $MYLATEX = pdflatex ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000131 $MYDIR/toc2bkm.py -c section $MYFILE
132 fi
Fred Drake8cab5491998-07-23 19:13:52 +0000133 if [ -f $MYFILE.syn ] ; then
134 uniq $MYFILE.syn >TEMP.syn && mv TEMP.syn $MYFILE.syn || exit $?
135 fi
Fred Drake566b6d51998-10-27 21:59:03 +0000136 if [ "$USE_BIBTEX" ] ; then
137 bibtex $MYFILE
138 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000139 $MYLATEX $MYFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +0000140}
141
Fred Drake12f842e1998-04-17 02:52:12 +0000142build_dvi() {
143 use_latex $1 latex
Fred Drakee2e904f1998-03-10 23:23:05 +0000144}
145
146build_pdf() {
Fred Drake12f842e1998-04-17 02:52:12 +0000147 use_latex $1 pdflatex
148}
149
150build_ps() {
Fred Drake79842561998-04-17 20:06:16 +0000151 dvips -N0 -o $1.ps $1 || exit $?
Fred Drake12f842e1998-04-17 02:52:12 +0000152}
153
Fred Drake9940bd71998-08-06 20:15:20 +0000154build_text() {
155 lynx -nolist -dump $2/index.html >$1.txt
156}
157
Fred Drake11300cc1998-08-05 04:48:18 +0000158l2hoption() {
159 if [ "$2" ] ; then
160 echo "\$$1 = \"$2\";" >>$L2H_AUX_INIT_FILE
161 fi
162}
163
Fred Drake12f842e1998-04-17 02:52:12 +0000164cleanup() {
Fred Drake8cab5491998-07-23 19:13:52 +0000165 rm -f $1.aux $1.log $1.out $1.toc $1.bkm $1.idx $1.ilg $1.ind $1.syn
Fred Drakec9b8a571998-04-29 21:28:25 +0000166 rm -f mod$1.idx mod$1.ilg mod$1.ind
Fred Drake12f842e1998-04-17 02:52:12 +0000167 if [ ! "$BUILD_DVI" ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +0000168 rm -f $1.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000169 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000170 rm -rf $1.temp-html
Fred Drake8dbf46a1998-05-15 17:13:08 +0000171 rm -f $1/IMG* $1/*.pl $1/WARNINGS $1/index.dat $1/modindex.dat
Fred Drake566b6d51998-10-27 21:59:03 +0000172 # bibtex stuff
173 rm -f $1.bbl $1.blg
Fred Drakee2e904f1998-03-10 23:23:05 +0000174}
175
Fred Drakee1feb8f1998-08-28 20:21:04 +0000176parse_option() {
177 # When using a long option with a parameter separated by '=',
178 # generalize the parsing of the two:
179 OPTION="$1"
180 unset VALUE
181 STUFF=`echo "$1" | grep '^--[-a-zA-Z0-9]*='`
182 if [ "$STUFF" ] ; then
183 # This leaves OPTION=--option= and VALUE=value
184 OPTION=`echo "$STUFF" | sed 's/^\(--[-a-zA-Z0-9]*=\)\(.*\)$/\1/'`
185 VALUE=`echo "$STUFF" | sed 's/^\(--[-a-zA-Z0-9]*=\)\(.*\)$/\2/'`
186 fi
187}
188
Fred Drakee2e904f1998-03-10 23:23:05 +0000189# figure out what our targets are:
190while [ "$1" ] ; do
Fred Drakee1feb8f1998-08-28 20:21:04 +0000191 parse_option "$1"
192 case "$OPTION" in
Fred Drake9f6f0da1998-08-12 18:07:51 +0000193 --all|--al)
194 BUILD_PDF=true
195 BUILD_PS=true
196 BUILD_DVI=true
197 BUILD_HTML=true
198 BUILD_TEXT=true
199 USE_DEFAULT_FORMAT=false
200 shift 1
201 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000202 --pdf|--pd)
203 BUILD_PDF=true
204 USE_DEFAULT_FORMAT=false
205 shift 1
206 ;;
Fred Drake88053541998-04-24 21:57:12 +0000207 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000208 BUILD_PS=true
209 USE_DEFAULT_FORMAT=false
210 shift 1
211 ;;
212 --dvi|--dv|--d)
213 BUILD_DVI=true
214 USE_DEFAULT_FORMAT=false
215 shift 1
216 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000217 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000218 BUILD_HTML=true
219 USE_DEFAULT_FORMAT=false
220 shift 1
221 ;;
Fred Drake9940bd71998-08-06 20:15:20 +0000222 --text|--tex|--te|--t)
223 BUILD_TEXT=true
224 USE_DEFAULT_FORMAT=false
225 shift 1
226 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000227 -H|--help|--hel|--he)
228 usage 0
229 ;;
Fred Drake11300cc1998-08-05 04:48:18 +0000230 -i|--iconserver|--iconserve|--iconserv|--iconser|--iconse|--icons|--icon|--ico|--ic|--i)
231 ICONSERVER="$2"
232 shift 2
233 ;;
Fred Drakee1feb8f1998-08-28 20:21:04 +0000234 --iconserver=*|--iconserve=*|--iconserv=*|--iconser=*|--iconse=*|--icons=*|--icon=*|--ico=*|--ic=*|--i=*)
235 ICONSERVER="$VALUE"
236 shift 1
237 ;;
Fred Drake35049521998-05-11 19:04:06 +0000238 -a|--address|--addres|--addre|-addr|--add|--ad)
Fred Drakee2e904f1998-03-10 23:23:05 +0000239 ADDRESS="$2"
240 shift 2
241 ;;
Fred Drakee1feb8f1998-08-28 20:21:04 +0000242 --address=*|--addres=*|--addre=*|-addr=*|--add=*|--ad=*)
243 ADDRESS="$VALUE"
244 shift 1
245 ;;
Fred Drake35049521998-05-11 19:04:06 +0000246 --a4)
247 TEXINPUTS=$TOPDIR/paper-a4:$TEXINPUTS
248 shift 1
249 ;;
Fred Draked5d473f1998-05-11 20:40:24 +0000250 --letter|--lette|--lett|--let|--le)
251 shift 1
252 ;;
Fred Drake88053541998-04-24 21:57:12 +0000253 --link|--lin|--li)
254 LINK="$2"
Fred Drakeac8f91a1998-04-02 15:37:13 +0000255 shift 2
256 ;;
Fred Drakee1feb8f1998-08-28 20:21:04 +0000257 --link=*|--lin=*|--li=*)
258 LINK="$VALUE"
259 shift 1
260 ;;
Fred Drake88053541998-04-24 21:57:12 +0000261 -s|--split|--spli|--spl|--sp|--s)
262 MAX_SPLIT_DEPTH="$2"
263 shift 2
264 ;;
Fred Drakee1feb8f1998-08-28 20:21:04 +0000265 --split=|--spli=|--spl=|--sp=|--s=)
266 MAX_SPLIT_DEPTH="$VALUE"
267 shift 1
268 ;;
Fred Drake88053541998-04-24 21:57:12 +0000269 -l|--logging|--loggin|--loggi|--logg|--log|--lo)
Fred Drakedbc879e1998-03-11 15:33:44 +0000270 LOGGING=true
271 shift 1
272 ;;
273 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
274 DEBUGGING=true
275 shift 1
276 ;;
277 -k|--keep|--kee|--ke|--k)
278 DISCARD_TEMPS=''
279 shift 1
280 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000281 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000282 QUIET=true
283 shift 1
284 ;;
Fred Drake88053541998-04-24 21:57:12 +0000285 --)
Fred Drakec9b8a571998-04-29 21:28:25 +0000286 shift 1
Fred Drake88053541998-04-24 21:57:12 +0000287 break
288 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000289 -*)
Fred Drakee1feb8f1998-08-28 20:21:04 +0000290 usage 2 "Unknown option: ${VALUE%=}"
Fred Drakee2e904f1998-03-10 23:23:05 +0000291 ;;
292 *)
293 break;;
294 esac
295done
296
297if [ $# = 0 ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +0000298 # check for a single .tex file in .
299 COUNT=`ls -1 *.tex | wc -l | sed 's/[ ]//g'`
300 if [ "$COUNT" -eq 1 ] ; then
301 set -- `ls -1 *.tex`
Fred Drake9f6f0da1998-08-12 18:07:51 +0000302 elif [ "$COUNT" -gt 1 ] ; then
303 usage 2 "Could not deduce which file(s) to process as HOWTO documents."
Fred Drake9940bd71998-08-06 20:15:20 +0000304 else
Fred Drake9f6f0da1998-08-12 18:07:51 +0000305 usage 2 "No file to process."
Fred Drake9940bd71998-08-06 20:15:20 +0000306 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000307fi
308
309if [ $USE_DEFAULT_FORMAT = true ] ; then
310 eval "BUILD_$DEFAULT_FORMAT=true"
311fi
312
Fred Drake664b36f1998-03-11 15:41:21 +0000313if [ "$QUIET" ] ; then
314 exec >/dev/null
315fi
316
Fred Drake9940bd71998-08-06 20:15:20 +0000317if [ "$DEBUGGING" ] ; then
318 set -x
319fi
320
Fred Drake11300cc1998-08-05 04:48:18 +0000321echo '# auxillary init file for latex2html' >$L2H_AUX_INIT_FILE
Fred Drakea5de7301998-10-19 19:14:42 +0000322echo '# generated by mkhowto.sh -- do not edit' >>$L2H_AUX_INIT_FILE
Fred Drakee1feb8f1998-08-28 20:21:04 +0000323if [ "$ICONSERVER" ] ; then
324 ICONSERVER="${ICONSERVER%/}"
325fi
Fred Drake11300cc1998-08-05 04:48:18 +0000326l2hoption ICONSERVER "$ICONSERVER"
327l2hoption ADDRESS "$ADDRESS"
328l2hoption MAX_LINK_DEPTH "$MAX_LINK_DEPTH"
329l2hoption MAX_SPLIT_DEPTH "$MAX_SPLIT_DEPTH"
330echo '1;' >>$L2H_AUX_INIT_FILE
Fred Drakef4fc4761998-05-14 20:03:14 +0000331
Fred Drakee2e904f1998-03-10 23:23:05 +0000332for FILE in $@ ; do
Fred Drakedf825a11998-05-14 20:36:49 +0000333 FILEDIR=`dirname $FILE`
Fred Drakee1feb8f1998-08-28 20:21:04 +0000334 FILE=`basename $FILE .tex`
Fred Drakef4fc4761998-05-14 20:03:14 +0000335 #
336 # Put the directory the .tex file is in is also the first directory in
337 # TEXINPUTS, to allow files there to override files in the common area.
338 #
Fred Drake11300cc1998-08-05 04:48:18 +0000339 TEXINPUTS=$FILEDIR:$TOPDIR/texinputs:$TEXINPUTS
Fred Drakef4fc4761998-05-14 20:03:14 +0000340 export TEXINPUTS
341 #
Fred Drakee2e904f1998-03-10 23:23:05 +0000342 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000343 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000344 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000345 fi
346 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000347 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000348 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000349 fi
350 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000351 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000352 fi
353 if [ "$BUILD_HTML" ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +0000354 if [ ! "$HAVE_TEMPS" ] ; then
Fred Drakee2e904f1998-03-10 23:23:05 +0000355 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000356 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000357 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000358 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000359 build_html $FILE $FILE 2>&1 | tee -a $LOGFILE
Fred Drakea5de7301998-10-19 19:14:42 +0000360 if [ "$ICONSERVER" = "." ] ; then
361 cp $TOPDIR/icons/*.gif $FILE/
362 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000363 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000364 if [ "$BUILD_TEXT" ] ; then
365 if [ ! "$HAVE_TEMPS" ] ; then
366 # need to get aux file
367 build_dvi $FILE 2>&1 | tee -a $LOGFILE
368 HAVE_TEMPS=true
369 fi
370 # this is why building text really has to be last:
371 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
372 echo '# re-hack this file for --text:' >>$L2H_AUX_INIT_FILE
373 l2hoption MAX_SPLIT_DEPTH 1
374 echo '1;' >>$L2H_AUX_INIT_FILE
375 TEMPDIR=$FILE.temp-html
376 build_html $FILE $TEMPDIR 2>&1 | tee -a $LOGFILE
377 else
378 TEMPDIR=$FILE
379 fi
380 build_text $FILE $TEMPDIR 2>&1 | tee -a $LOGFILE
381 fi
382
Fred Drakedbc879e1998-03-11 15:33:44 +0000383 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000384 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000385 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000386 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000387 if [ "$LOGGING" ] ; then
388 cp $LOGFILE $FILE.how
389 fi
390 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000391done
Fred Drake11300cc1998-08-05 04:48:18 +0000392
Fred Drakeb0b19001998-10-07 16:41:40 +0000393if [ ! "$DEBUGGING" ] ; then
394 rm -f $L2H_AUX_INIT_FILE
395fi