blob: 393e419392a1fdbb4f39822a801166adf2d93c54 [file] [log] [blame]
Fred Drake11300cc1998-08-05 04:48:18 +00001#! /usr/bin/env bash
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 Drakeac8f91a1998-04-02 15:37:13 +000025L2H_INIT_FILE=$TOPDIR/perl/l2hinit.perl
Fred Drake11300cc1998-08-05 04:48:18 +000026L2H_AUX_INIT_FILE=/usr/tmp/mkhowto-$LOGNAME-$$.perl
Fred Drakeac8f91a1998-04-02 15:37:13 +000027
Fred Drakedbc879e1998-03-11 15:33:44 +000028LOGFILE=/usr/tmp/mkhowto-$LOGNAME-$$.how
29LOGGING=''
30
Fred Drakee2e904f1998-03-10 23:23:05 +000031usage() {
Fred Drakeac8f91a1998-04-02 15:37:13 +000032 MYNAME=`basename $0`
33 echo "usage: $MYNAME [options...] file ..."
34 cat <<EOF
35
36Options specifying formats to build:
37 --html HyperText Markup Language
38 --pdf Portable Document Format (default)
39 --ps PostScript
40 --dvi "DeVice Indepentent" format from TeX
41
42 More than one output format may be specified.
43
44HTML options:
45 --address, -a Specify an address for page footers.
Fred Drake88053541998-04-24 21:57:12 +000046 --link Specify the number of levels to include on each page.
Fred Drakeac8f91a1998-04-02 15:37:13 +000047 --split, -s Specify a section level for page splitting.
Fred Drake11300cc1998-08-05 04:48:18 +000048 --iconserver, -i Specify location of icons (default: ../).
Fred Drakeac8f91a1998-04-02 15:37:13 +000049
50Other options:
Fred Drake1a3541c1998-05-11 19:04:56 +000051 --a4 Format for A4 paper.
Fred Draked5d473f1998-05-11 20:40:24 +000052 --letter Format for US letter paper (the default).
Fred Drakeac8f91a1998-04-02 15:37:13 +000053 --help, -H Show this text.
54 --logging, -l Log stdout and stderr to a file (*.how).
55 --debugging, -D Echo commands as they are executed.
56 --keep, -k Keep temporary files around.
57 --quiet, -q Do not print command output to stdout.
58 (stderr is also lost, sorry; see *.how for errors)
59
60EOF
Fred Drake11300cc1998-08-05 04:48:18 +000061
Fred Drakeac8f91a1998-04-02 15:37:13 +000062 exit $1
Fred Drakee2e904f1998-03-10 23:23:05 +000063}
64
Fred Drake88053541998-04-24 21:57:12 +000065# These are LaTeX2HTML controls; they reflect l2h variables of the same name.
66# The values here are the defaults after modification by perl/l2hinit.perl.
67#
68ADDRESS=''
69MAX_LINK_DEPTH=3
70MAX_SPLIT_DEPTH=8
71
Fred Drakee2e904f1998-03-10 23:23:05 +000072build_html() {
Fred Drake19c7c841998-05-07 21:20:39 +000073 TEXFILE=`kpsewhich $1.tex`
Fred Drake9940bd71998-08-06 20:15:20 +000074 BUILDDIR=${2:-$1}
Fred Drake11300cc1998-08-05 04:48:18 +000075 latex2html \
76 -init_file $L2H_INIT_FILE \
77 -init_file $L2H_AUX_INIT_FILE \
Fred Drake9940bd71998-08-06 20:15:20 +000078 -dir $BUILDDIR $TEXFILE || exit $?
Fred Drake88053541998-04-24 21:57:12 +000079 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +000080 (cd $BUILDDIR; $MYDIR/node2label.pl *.html) || exit $?
Fred Drakeac8f91a1998-04-02 15:37:13 +000081 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000082}
83
Fred Drake12f842e1998-04-17 02:52:12 +000084use_latex() {
85 # two args: <file> <latextype>
86 MYFILE=$1
87 MYLATEX=$2
88 #
89 # We really have to do it three times to get all the page numbers right,
90 # since the length of the ToC makes a real difference.
91 #
92 $MYDIR/newind.py >$MYFILE.ind
93 $MYDIR/newind.py modindex >mod$MYFILE.ind
94 $MYLATEX $MYFILE || exit $?
95 if [ -f mod$MYFILE.idx ] ; then
96 makeindex mod$MYFILE.idx
Fred Drakee2e904f1998-03-10 23:23:05 +000097 fi
Fred Drake12f842e1998-04-17 02:52:12 +000098 if [ -f $MYFILE.idx ] ; then
99 $MYDIR/fix_hack $MYFILE.idx
100 makeindex $MYFILE.idx
101 $MYDIR/indfix.py $MYFILE.ind
102 fi
Fred Drake8cab5491998-07-23 19:13:52 +0000103 if [ -f $MYFILE.syn ] ; then
104 # This hack is due to a bug with the module synopsis support that
105 # causes the last module synopsis to be written out twice in
106 # howto documents (not present for manuals). Repeated below.
107 uniq $MYFILE.syn >TEMP.syn && mv TEMP.syn $MYFILE.syn || exit $?
108 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000109 $MYLATEX $MYFILE || exit $?
110 if [ -f mod$MYFILE.idx ] ; then
111 makeindex mod$MYFILE.idx
112 fi
113 if [ -f $MYFILE.idx ] ; then
114 $MYDIR/fix_hack $MYFILE.idx || exit $?
115 makeindex -s $TOPDIR/texinputs/myindex.ist $MYFILE.idx || exit $?
116 fi
Fred Drakef4fc4761998-05-14 20:03:14 +0000117 if [ -f $MYFILE.toc -a $MYLATEX = pdflatex ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000118 $MYDIR/toc2bkm.py -c section $MYFILE
119 fi
Fred Drake8cab5491998-07-23 19:13:52 +0000120 if [ -f $MYFILE.syn ] ; then
121 uniq $MYFILE.syn >TEMP.syn && mv TEMP.syn $MYFILE.syn || exit $?
122 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000123 $MYLATEX $MYFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +0000124}
125
Fred Drake12f842e1998-04-17 02:52:12 +0000126build_dvi() {
127 use_latex $1 latex
Fred Drakee2e904f1998-03-10 23:23:05 +0000128}
129
130build_pdf() {
Fred Drake12f842e1998-04-17 02:52:12 +0000131 use_latex $1 pdflatex
132}
133
134build_ps() {
Fred Drake79842561998-04-17 20:06:16 +0000135 dvips -N0 -o $1.ps $1 || exit $?
Fred Drake12f842e1998-04-17 02:52:12 +0000136}
137
Fred Drake9940bd71998-08-06 20:15:20 +0000138build_text() {
139 lynx -nolist -dump $2/index.html >$1.txt
140}
141
Fred Drake11300cc1998-08-05 04:48:18 +0000142l2hoption() {
143 if [ "$2" ] ; then
144 echo "\$$1 = \"$2\";" >>$L2H_AUX_INIT_FILE
145 fi
146}
147
Fred Drake12f842e1998-04-17 02:52:12 +0000148cleanup() {
Fred Drake8cab5491998-07-23 19:13:52 +0000149 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 +0000150 rm -f mod$1.idx mod$1.ilg mod$1.ind
Fred Drake12f842e1998-04-17 02:52:12 +0000151 if [ ! "$BUILD_DVI" ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +0000152 rm -f $1.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000153 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000154 rm -rf $1.temp-html
Fred Drake8dbf46a1998-05-15 17:13:08 +0000155 rm -f $1/IMG* $1/*.pl $1/WARNINGS $1/index.dat $1/modindex.dat
Fred Drakee2e904f1998-03-10 23:23:05 +0000156}
157
158# figure out what our targets are:
159while [ "$1" ] ; do
160 case "$1" in
161 --pdf|--pd)
162 BUILD_PDF=true
163 USE_DEFAULT_FORMAT=false
164 shift 1
165 ;;
Fred Drake88053541998-04-24 21:57:12 +0000166 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000167 BUILD_PS=true
168 USE_DEFAULT_FORMAT=false
169 shift 1
170 ;;
171 --dvi|--dv|--d)
172 BUILD_DVI=true
173 USE_DEFAULT_FORMAT=false
174 shift 1
175 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000176 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000177 BUILD_HTML=true
178 USE_DEFAULT_FORMAT=false
179 shift 1
180 ;;
Fred Drake9940bd71998-08-06 20:15:20 +0000181 --text|--tex|--te|--t)
182 BUILD_TEXT=true
183 USE_DEFAULT_FORMAT=false
184 shift 1
185 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000186 -H|--help|--hel|--he)
187 usage 0
188 ;;
Fred Drake11300cc1998-08-05 04:48:18 +0000189 -i|--iconserver|--iconserve|--iconserv|--iconser|--iconse|--icons|--icon|--ico|--ic|--i)
190 ICONSERVER="$2"
191 shift 2
192 ;;
Fred Drake35049521998-05-11 19:04:06 +0000193 -a|--address|--addres|--addre|-addr|--add|--ad)
Fred Drakee2e904f1998-03-10 23:23:05 +0000194 ADDRESS="$2"
195 shift 2
196 ;;
Fred Drake35049521998-05-11 19:04:06 +0000197 --a4)
198 TEXINPUTS=$TOPDIR/paper-a4:$TEXINPUTS
199 shift 1
200 ;;
Fred Draked5d473f1998-05-11 20:40:24 +0000201 --letter|--lette|--lett|--let|--le)
202 shift 1
203 ;;
Fred Drake88053541998-04-24 21:57:12 +0000204 --link|--lin|--li)
205 LINK="$2"
Fred Drakeac8f91a1998-04-02 15:37:13 +0000206 shift 2
207 ;;
Fred Drake88053541998-04-24 21:57:12 +0000208 -s|--split|--spli|--spl|--sp|--s)
209 MAX_SPLIT_DEPTH="$2"
210 shift 2
211 ;;
212 -l|--logging|--loggin|--loggi|--logg|--log|--lo)
Fred Drakedbc879e1998-03-11 15:33:44 +0000213 LOGGING=true
214 shift 1
215 ;;
216 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
217 DEBUGGING=true
218 shift 1
219 ;;
220 -k|--keep|--kee|--ke|--k)
221 DISCARD_TEMPS=''
222 shift 1
223 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000224 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000225 QUIET=true
226 shift 1
227 ;;
Fred Drake88053541998-04-24 21:57:12 +0000228 --)
Fred Drakec9b8a571998-04-29 21:28:25 +0000229 shift 1
Fred Drake88053541998-04-24 21:57:12 +0000230 break
231 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000232 -*)
Fred Drakeac8f91a1998-04-02 15:37:13 +0000233 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000234 ;;
235 *)
236 break;;
237 esac
238done
239
240if [ $# = 0 ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +0000241 # check for a single .tex file in .
242 COUNT=`ls -1 *.tex | wc -l | sed 's/[ ]//g'`
243 if [ "$COUNT" -eq 1 ] ; then
244 set -- `ls -1 *.tex`
245 else
246 usage 2
247 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000248fi
249
250if [ $USE_DEFAULT_FORMAT = true ] ; then
251 eval "BUILD_$DEFAULT_FORMAT=true"
252fi
253
Fred Drake664b36f1998-03-11 15:41:21 +0000254if [ "$QUIET" ] ; then
255 exec >/dev/null
256fi
257
Fred Drake9940bd71998-08-06 20:15:20 +0000258if [ "$DEBUGGING" ] ; then
259 set -x
260fi
261
Fred Drake11300cc1998-08-05 04:48:18 +0000262echo '# auxillary init file for latex2html' >$L2H_AUX_INIT_FILE
263echo '# generated by mkhowto.sh -- do no edit' >>$L2H_AUX_INIT_FILE
264l2hoption ICONSERVER "$ICONSERVER"
265l2hoption ADDRESS "$ADDRESS"
266l2hoption MAX_LINK_DEPTH "$MAX_LINK_DEPTH"
267l2hoption MAX_SPLIT_DEPTH "$MAX_SPLIT_DEPTH"
268echo '1;' >>$L2H_AUX_INIT_FILE
Fred Drakef4fc4761998-05-14 20:03:14 +0000269
Fred Drakee2e904f1998-03-10 23:23:05 +0000270for FILE in $@ ; do
Fred Drakedf825a11998-05-14 20:36:49 +0000271 FILEDIR=`dirname $FILE`
Fred Drake19c7c841998-05-07 21:20:39 +0000272 FILE=`basename ${FILE%.tex}`
Fred Drakef4fc4761998-05-14 20:03:14 +0000273 #
274 # Put the directory the .tex file is in is also the first directory in
275 # TEXINPUTS, to allow files there to override files in the common area.
276 #
Fred Drake11300cc1998-08-05 04:48:18 +0000277 TEXINPUTS=$FILEDIR:$TOPDIR/texinputs:$TEXINPUTS
Fred Drakef4fc4761998-05-14 20:03:14 +0000278 export TEXINPUTS
279 #
Fred Drakee2e904f1998-03-10 23:23:05 +0000280 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000281 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000282 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000283 fi
284 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000285 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000286 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000287 fi
288 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000289 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000290 fi
291 if [ "$BUILD_HTML" ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +0000292 if [ ! "$HAVE_TEMPS" ] ; then
Fred Drakee2e904f1998-03-10 23:23:05 +0000293 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000294 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000295 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000296 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000297 build_html $FILE $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000298 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000299 if [ "$BUILD_TEXT" ] ; then
300 if [ ! "$HAVE_TEMPS" ] ; then
301 # need to get aux file
302 build_dvi $FILE 2>&1 | tee -a $LOGFILE
303 HAVE_TEMPS=true
304 fi
305 # this is why building text really has to be last:
306 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
307 echo '# re-hack this file for --text:' >>$L2H_AUX_INIT_FILE
308 l2hoption MAX_SPLIT_DEPTH 1
309 echo '1;' >>$L2H_AUX_INIT_FILE
310 TEMPDIR=$FILE.temp-html
311 build_html $FILE $TEMPDIR 2>&1 | tee -a $LOGFILE
312 else
313 TEMPDIR=$FILE
314 fi
315 build_text $FILE $TEMPDIR 2>&1 | tee -a $LOGFILE
316 fi
317
Fred Drakedbc879e1998-03-11 15:33:44 +0000318 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000319 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000320 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000321 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000322 if [ "$LOGGING" ] ; then
323 cp $LOGFILE $FILE.how
324 fi
325 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000326done
Fred Drake11300cc1998-08-05 04:48:18 +0000327
328rm -f $L2H_AUX_INIT_FILE