blob: 88050d58fdc1b76bb7c077c76f40ed12ab7ba988 [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
Fred Drakeca6d6351998-11-30 20:30:26 +0000160 VALUE=`echo "$2" | sed 's/[$"@]/\\\\&/g'`
161 echo "\$$1 = \"$VALUE\";" >>$L2H_AUX_INIT_FILE
Fred Drake11300cc1998-08-05 04:48:18 +0000162 fi
163}
164
Fred Drake12f842e1998-04-17 02:52:12 +0000165cleanup() {
Fred Drake8cab5491998-07-23 19:13:52 +0000166 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 +0000167 rm -f mod$1.idx mod$1.ilg mod$1.ind
Fred Drake12f842e1998-04-17 02:52:12 +0000168 if [ ! "$BUILD_DVI" ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +0000169 rm -f $1.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000170 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000171 rm -rf $1.temp-html
Fred Drake8dbf46a1998-05-15 17:13:08 +0000172 rm -f $1/IMG* $1/*.pl $1/WARNINGS $1/index.dat $1/modindex.dat
Fred Drake566b6d51998-10-27 21:59:03 +0000173 # bibtex stuff
174 rm -f $1.bbl $1.blg
Fred Drakee2e904f1998-03-10 23:23:05 +0000175}
176
Fred Drakee1feb8f1998-08-28 20:21:04 +0000177parse_option() {
178 # When using a long option with a parameter separated by '=',
179 # generalize the parsing of the two:
180 OPTION="$1"
181 unset VALUE
182 STUFF=`echo "$1" | grep '^--[-a-zA-Z0-9]*='`
183 if [ "$STUFF" ] ; then
184 # This leaves OPTION=--option= and VALUE=value
185 OPTION=`echo "$STUFF" | sed 's/^\(--[-a-zA-Z0-9]*=\)\(.*\)$/\1/'`
186 VALUE=`echo "$STUFF" | sed 's/^\(--[-a-zA-Z0-9]*=\)\(.*\)$/\2/'`
187 fi
188}
189
Fred Drakee2e904f1998-03-10 23:23:05 +0000190# figure out what our targets are:
191while [ "$1" ] ; do
Fred Drakee1feb8f1998-08-28 20:21:04 +0000192 parse_option "$1"
193 case "$OPTION" in
Fred Drake9f6f0da1998-08-12 18:07:51 +0000194 --all|--al)
195 BUILD_PDF=true
196 BUILD_PS=true
197 BUILD_DVI=true
198 BUILD_HTML=true
199 BUILD_TEXT=true
200 USE_DEFAULT_FORMAT=false
201 shift 1
202 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000203 --pdf|--pd)
204 BUILD_PDF=true
205 USE_DEFAULT_FORMAT=false
206 shift 1
207 ;;
Fred Drake88053541998-04-24 21:57:12 +0000208 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000209 BUILD_PS=true
210 USE_DEFAULT_FORMAT=false
211 shift 1
212 ;;
213 --dvi|--dv|--d)
214 BUILD_DVI=true
215 USE_DEFAULT_FORMAT=false
216 shift 1
217 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000218 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000219 BUILD_HTML=true
220 USE_DEFAULT_FORMAT=false
221 shift 1
222 ;;
Fred Drake9940bd71998-08-06 20:15:20 +0000223 --text|--tex|--te|--t)
224 BUILD_TEXT=true
225 USE_DEFAULT_FORMAT=false
226 shift 1
227 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000228 -H|--help|--hel|--he)
229 usage 0
230 ;;
Fred Drake11300cc1998-08-05 04:48:18 +0000231 -i|--iconserver|--iconserve|--iconserv|--iconser|--iconse|--icons|--icon|--ico|--ic|--i)
232 ICONSERVER="$2"
233 shift 2
234 ;;
Fred Drakee1feb8f1998-08-28 20:21:04 +0000235 --iconserver=*|--iconserve=*|--iconserv=*|--iconser=*|--iconse=*|--icons=*|--icon=*|--ico=*|--ic=*|--i=*)
236 ICONSERVER="$VALUE"
237 shift 1
238 ;;
Fred Drake35049521998-05-11 19:04:06 +0000239 -a|--address|--addres|--addre|-addr|--add|--ad)
Fred Drakee2e904f1998-03-10 23:23:05 +0000240 ADDRESS="$2"
241 shift 2
242 ;;
Fred Drakee1feb8f1998-08-28 20:21:04 +0000243 --address=*|--addres=*|--addre=*|-addr=*|--add=*|--ad=*)
244 ADDRESS="$VALUE"
245 shift 1
246 ;;
Fred Drake35049521998-05-11 19:04:06 +0000247 --a4)
248 TEXINPUTS=$TOPDIR/paper-a4:$TEXINPUTS
249 shift 1
250 ;;
Fred Draked5d473f1998-05-11 20:40:24 +0000251 --letter|--lette|--lett|--let|--le)
252 shift 1
253 ;;
Fred Drake88053541998-04-24 21:57:12 +0000254 --link|--lin|--li)
255 LINK="$2"
Fred Drakeac8f91a1998-04-02 15:37:13 +0000256 shift 2
257 ;;
Fred Drakee1feb8f1998-08-28 20:21:04 +0000258 --link=*|--lin=*|--li=*)
259 LINK="$VALUE"
260 shift 1
261 ;;
Fred Drake88053541998-04-24 21:57:12 +0000262 -s|--split|--spli|--spl|--sp|--s)
263 MAX_SPLIT_DEPTH="$2"
264 shift 2
265 ;;
Fred Drakee1feb8f1998-08-28 20:21:04 +0000266 --split=|--spli=|--spl=|--sp=|--s=)
267 MAX_SPLIT_DEPTH="$VALUE"
268 shift 1
269 ;;
Fred Drake88053541998-04-24 21:57:12 +0000270 -l|--logging|--loggin|--loggi|--logg|--log|--lo)
Fred Drakedbc879e1998-03-11 15:33:44 +0000271 LOGGING=true
272 shift 1
273 ;;
274 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
275 DEBUGGING=true
276 shift 1
277 ;;
278 -k|--keep|--kee|--ke|--k)
279 DISCARD_TEMPS=''
280 shift 1
281 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000282 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000283 QUIET=true
284 shift 1
285 ;;
Fred Drake88053541998-04-24 21:57:12 +0000286 --)
Fred Drakec9b8a571998-04-29 21:28:25 +0000287 shift 1
Fred Drake88053541998-04-24 21:57:12 +0000288 break
289 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000290 -*)
Fred Drakee1feb8f1998-08-28 20:21:04 +0000291 usage 2 "Unknown option: ${VALUE%=}"
Fred Drakee2e904f1998-03-10 23:23:05 +0000292 ;;
293 *)
294 break;;
295 esac
296done
297
298if [ $# = 0 ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +0000299 # check for a single .tex file in .
300 COUNT=`ls -1 *.tex | wc -l | sed 's/[ ]//g'`
301 if [ "$COUNT" -eq 1 ] ; then
302 set -- `ls -1 *.tex`
Fred Drake9f6f0da1998-08-12 18:07:51 +0000303 elif [ "$COUNT" -gt 1 ] ; then
304 usage 2 "Could not deduce which file(s) to process as HOWTO documents."
Fred Drake9940bd71998-08-06 20:15:20 +0000305 else
Fred Drake9f6f0da1998-08-12 18:07:51 +0000306 usage 2 "No file to process."
Fred Drake9940bd71998-08-06 20:15:20 +0000307 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000308fi
309
310if [ $USE_DEFAULT_FORMAT = true ] ; then
311 eval "BUILD_$DEFAULT_FORMAT=true"
312fi
313
Fred Drake664b36f1998-03-11 15:41:21 +0000314if [ "$QUIET" ] ; then
315 exec >/dev/null
316fi
317
Fred Drake9940bd71998-08-06 20:15:20 +0000318if [ "$DEBUGGING" ] ; then
319 set -x
320fi
321
Fred Drake11300cc1998-08-05 04:48:18 +0000322echo '# auxillary init file for latex2html' >$L2H_AUX_INIT_FILE
Fred Drakea5de7301998-10-19 19:14:42 +0000323echo '# generated by mkhowto.sh -- do not edit' >>$L2H_AUX_INIT_FILE
Fred Drakee1feb8f1998-08-28 20:21:04 +0000324if [ "$ICONSERVER" ] ; then
325 ICONSERVER="${ICONSERVER%/}"
326fi
Fred Drake11300cc1998-08-05 04:48:18 +0000327l2hoption ICONSERVER "$ICONSERVER"
328l2hoption ADDRESS "$ADDRESS"
329l2hoption MAX_LINK_DEPTH "$MAX_LINK_DEPTH"
330l2hoption MAX_SPLIT_DEPTH "$MAX_SPLIT_DEPTH"
331echo '1;' >>$L2H_AUX_INIT_FILE
Fred Drakef4fc4761998-05-14 20:03:14 +0000332
Fred Drakee2e904f1998-03-10 23:23:05 +0000333for FILE in $@ ; do
Fred Drakedf825a11998-05-14 20:36:49 +0000334 FILEDIR=`dirname $FILE`
Fred Drakee1feb8f1998-08-28 20:21:04 +0000335 FILE=`basename $FILE .tex`
Fred Drakef4fc4761998-05-14 20:03:14 +0000336 #
337 # Put the directory the .tex file is in is also the first directory in
338 # TEXINPUTS, to allow files there to override files in the common area.
339 #
Fred Drake11300cc1998-08-05 04:48:18 +0000340 TEXINPUTS=$FILEDIR:$TOPDIR/texinputs:$TEXINPUTS
Fred Drakef4fc4761998-05-14 20:03:14 +0000341 export TEXINPUTS
342 #
Fred Drakee2e904f1998-03-10 23:23:05 +0000343 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000344 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000345 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000346 fi
347 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000348 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000349 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000350 fi
351 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000352 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000353 fi
354 if [ "$BUILD_HTML" ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +0000355 if [ ! "$HAVE_TEMPS" ] ; then
Fred Drakee2e904f1998-03-10 23:23:05 +0000356 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000357 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000358 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000359 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000360 build_html $FILE $FILE 2>&1 | tee -a $LOGFILE
Fred Drakea5de7301998-10-19 19:14:42 +0000361 if [ "$ICONSERVER" = "." ] ; then
362 cp $TOPDIR/icons/*.gif $FILE/
363 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000364 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000365 if [ "$BUILD_TEXT" ] ; then
366 if [ ! "$HAVE_TEMPS" ] ; then
367 # need to get aux file
368 build_dvi $FILE 2>&1 | tee -a $LOGFILE
369 HAVE_TEMPS=true
370 fi
371 # this is why building text really has to be last:
372 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
373 echo '# re-hack this file for --text:' >>$L2H_AUX_INIT_FILE
374 l2hoption MAX_SPLIT_DEPTH 1
375 echo '1;' >>$L2H_AUX_INIT_FILE
376 TEMPDIR=$FILE.temp-html
377 build_html $FILE $TEMPDIR 2>&1 | tee -a $LOGFILE
378 else
379 TEMPDIR=$FILE
380 fi
381 build_text $FILE $TEMPDIR 2>&1 | tee -a $LOGFILE
382 fi
383
Fred Drakedbc879e1998-03-11 15:33:44 +0000384 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000385 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000386 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000387 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000388 if [ "$LOGGING" ] ; then
389 cp $LOGFILE $FILE.how
390 fi
391 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000392done
Fred Drake11300cc1998-08-05 04:48:18 +0000393
Fred Drakeb0b19001998-10-07 16:41:40 +0000394if [ ! "$DEBUGGING" ] ; then
395 rm -f $L2H_AUX_INIT_FILE
396fi