blob: 26deac9bff314c571cf7ab334e1371b401befd49 [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
Fred Drake78b8c3d1998-08-12 17:52:16 +000041 --text ASCII text
Fred Drakeac8f91a1998-04-02 15:37:13 +000042
43 More than one output format may be specified.
44
45HTML options:
46 --address, -a Specify an address for page footers.
Fred Drake88053541998-04-24 21:57:12 +000047 --link Specify the number of levels to include on each page.
Fred Drakeac8f91a1998-04-02 15:37:13 +000048 --split, -s Specify a section level for page splitting.
Fred Drake11300cc1998-08-05 04:48:18 +000049 --iconserver, -i Specify location of icons (default: ../).
Fred Drakeac8f91a1998-04-02 15:37:13 +000050
51Other options:
Fred Drake1a3541c1998-05-11 19:04:56 +000052 --a4 Format for A4 paper.
Fred Draked5d473f1998-05-11 20:40:24 +000053 --letter Format for US letter paper (the default).
Fred Drakeac8f91a1998-04-02 15:37:13 +000054 --help, -H Show this text.
55 --logging, -l Log stdout and stderr to a file (*.how).
56 --debugging, -D Echo commands as they are executed.
57 --keep, -k Keep temporary files around.
58 --quiet, -q Do not print command output to stdout.
59 (stderr is also lost, sorry; see *.how for errors)
60
61EOF
Fred Drake11300cc1998-08-05 04:48:18 +000062
Fred Drakeac8f91a1998-04-02 15:37:13 +000063 exit $1
Fred Drakee2e904f1998-03-10 23:23:05 +000064}
65
Fred Drake88053541998-04-24 21:57:12 +000066# These are LaTeX2HTML controls; they reflect l2h variables of the same name.
67# The values here are the defaults after modification by perl/l2hinit.perl.
68#
69ADDRESS=''
70MAX_LINK_DEPTH=3
71MAX_SPLIT_DEPTH=8
72
Fred Drakee2e904f1998-03-10 23:23:05 +000073build_html() {
Fred Drake19c7c841998-05-07 21:20:39 +000074 TEXFILE=`kpsewhich $1.tex`
Fred Drake9940bd71998-08-06 20:15:20 +000075 BUILDDIR=${2:-$1}
Fred Drake11300cc1998-08-05 04:48:18 +000076 latex2html \
77 -init_file $L2H_INIT_FILE \
78 -init_file $L2H_AUX_INIT_FILE \
Fred Drake9940bd71998-08-06 20:15:20 +000079 -dir $BUILDDIR $TEXFILE || exit $?
Fred Drake88053541998-04-24 21:57:12 +000080 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +000081 (cd $BUILDDIR; $MYDIR/node2label.pl *.html) || exit $?
Fred Drakeac8f91a1998-04-02 15:37:13 +000082 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000083}
84
Fred Drake12f842e1998-04-17 02:52:12 +000085use_latex() {
86 # two args: <file> <latextype>
87 MYFILE=$1
88 MYLATEX=$2
89 #
90 # We really have to do it three times to get all the page numbers right,
91 # since the length of the ToC makes a real difference.
92 #
93 $MYDIR/newind.py >$MYFILE.ind
94 $MYDIR/newind.py modindex >mod$MYFILE.ind
95 $MYLATEX $MYFILE || exit $?
96 if [ -f mod$MYFILE.idx ] ; then
97 makeindex mod$MYFILE.idx
Fred Drakee2e904f1998-03-10 23:23:05 +000098 fi
Fred Drake12f842e1998-04-17 02:52:12 +000099 if [ -f $MYFILE.idx ] ; then
100 $MYDIR/fix_hack $MYFILE.idx
101 makeindex $MYFILE.idx
102 $MYDIR/indfix.py $MYFILE.ind
103 fi
Fred Drake8cab5491998-07-23 19:13:52 +0000104 if [ -f $MYFILE.syn ] ; then
105 # This hack is due to a bug with the module synopsis support that
106 # causes the last module synopsis to be written out twice in
107 # howto documents (not present for manuals). Repeated below.
108 uniq $MYFILE.syn >TEMP.syn && mv TEMP.syn $MYFILE.syn || exit $?
109 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000110 $MYLATEX $MYFILE || exit $?
111 if [ -f mod$MYFILE.idx ] ; then
112 makeindex mod$MYFILE.idx
113 fi
114 if [ -f $MYFILE.idx ] ; then
115 $MYDIR/fix_hack $MYFILE.idx || exit $?
116 makeindex -s $TOPDIR/texinputs/myindex.ist $MYFILE.idx || exit $?
117 fi
Fred Drakef4fc4761998-05-14 20:03:14 +0000118 if [ -f $MYFILE.toc -a $MYLATEX = pdflatex ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000119 $MYDIR/toc2bkm.py -c section $MYFILE
120 fi
Fred Drake8cab5491998-07-23 19:13:52 +0000121 if [ -f $MYFILE.syn ] ; then
122 uniq $MYFILE.syn >TEMP.syn && mv TEMP.syn $MYFILE.syn || exit $?
123 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000124 $MYLATEX $MYFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +0000125}
126
Fred Drake12f842e1998-04-17 02:52:12 +0000127build_dvi() {
128 use_latex $1 latex
Fred Drakee2e904f1998-03-10 23:23:05 +0000129}
130
131build_pdf() {
Fred Drake12f842e1998-04-17 02:52:12 +0000132 use_latex $1 pdflatex
133}
134
135build_ps() {
Fred Drake79842561998-04-17 20:06:16 +0000136 dvips -N0 -o $1.ps $1 || exit $?
Fred Drake12f842e1998-04-17 02:52:12 +0000137}
138
Fred Drake9940bd71998-08-06 20:15:20 +0000139build_text() {
140 lynx -nolist -dump $2/index.html >$1.txt
141}
142
Fred Drake11300cc1998-08-05 04:48:18 +0000143l2hoption() {
144 if [ "$2" ] ; then
145 echo "\$$1 = \"$2\";" >>$L2H_AUX_INIT_FILE
146 fi
147}
148
Fred Drake12f842e1998-04-17 02:52:12 +0000149cleanup() {
Fred Drake8cab5491998-07-23 19:13:52 +0000150 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 +0000151 rm -f mod$1.idx mod$1.ilg mod$1.ind
Fred Drake12f842e1998-04-17 02:52:12 +0000152 if [ ! "$BUILD_DVI" ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +0000153 rm -f $1.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000154 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000155 rm -rf $1.temp-html
Fred Drake8dbf46a1998-05-15 17:13:08 +0000156 rm -f $1/IMG* $1/*.pl $1/WARNINGS $1/index.dat $1/modindex.dat
Fred Drakee2e904f1998-03-10 23:23:05 +0000157}
158
159# figure out what our targets are:
160while [ "$1" ] ; do
161 case "$1" in
162 --pdf|--pd)
163 BUILD_PDF=true
164 USE_DEFAULT_FORMAT=false
165 shift 1
166 ;;
Fred Drake88053541998-04-24 21:57:12 +0000167 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000168 BUILD_PS=true
169 USE_DEFAULT_FORMAT=false
170 shift 1
171 ;;
172 --dvi|--dv|--d)
173 BUILD_DVI=true
174 USE_DEFAULT_FORMAT=false
175 shift 1
176 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000177 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000178 BUILD_HTML=true
179 USE_DEFAULT_FORMAT=false
180 shift 1
181 ;;
Fred Drake9940bd71998-08-06 20:15:20 +0000182 --text|--tex|--te|--t)
183 BUILD_TEXT=true
184 USE_DEFAULT_FORMAT=false
185 shift 1
186 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000187 -H|--help|--hel|--he)
188 usage 0
189 ;;
Fred Drake11300cc1998-08-05 04:48:18 +0000190 -i|--iconserver|--iconserve|--iconserv|--iconser|--iconse|--icons|--icon|--ico|--ic|--i)
191 ICONSERVER="$2"
192 shift 2
193 ;;
Fred Drake35049521998-05-11 19:04:06 +0000194 -a|--address|--addres|--addre|-addr|--add|--ad)
Fred Drakee2e904f1998-03-10 23:23:05 +0000195 ADDRESS="$2"
196 shift 2
197 ;;
Fred Drake35049521998-05-11 19:04:06 +0000198 --a4)
199 TEXINPUTS=$TOPDIR/paper-a4:$TEXINPUTS
200 shift 1
201 ;;
Fred Draked5d473f1998-05-11 20:40:24 +0000202 --letter|--lette|--lett|--let|--le)
203 shift 1
204 ;;
Fred Drake88053541998-04-24 21:57:12 +0000205 --link|--lin|--li)
206 LINK="$2"
Fred Drakeac8f91a1998-04-02 15:37:13 +0000207 shift 2
208 ;;
Fred Drake88053541998-04-24 21:57:12 +0000209 -s|--split|--spli|--spl|--sp|--s)
210 MAX_SPLIT_DEPTH="$2"
211 shift 2
212 ;;
213 -l|--logging|--loggin|--loggi|--logg|--log|--lo)
Fred Drakedbc879e1998-03-11 15:33:44 +0000214 LOGGING=true
215 shift 1
216 ;;
217 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
218 DEBUGGING=true
219 shift 1
220 ;;
221 -k|--keep|--kee|--ke|--k)
222 DISCARD_TEMPS=''
223 shift 1
224 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000225 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000226 QUIET=true
227 shift 1
228 ;;
Fred Drake88053541998-04-24 21:57:12 +0000229 --)
Fred Drakec9b8a571998-04-29 21:28:25 +0000230 shift 1
Fred Drake88053541998-04-24 21:57:12 +0000231 break
232 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000233 -*)
Fred Drakeac8f91a1998-04-02 15:37:13 +0000234 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000235 ;;
236 *)
237 break;;
238 esac
239done
240
241if [ $# = 0 ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +0000242 # check for a single .tex file in .
243 COUNT=`ls -1 *.tex | wc -l | sed 's/[ ]//g'`
244 if [ "$COUNT" -eq 1 ] ; then
245 set -- `ls -1 *.tex`
246 else
247 usage 2
248 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000249fi
250
251if [ $USE_DEFAULT_FORMAT = true ] ; then
252 eval "BUILD_$DEFAULT_FORMAT=true"
253fi
254
Fred Drake664b36f1998-03-11 15:41:21 +0000255if [ "$QUIET" ] ; then
256 exec >/dev/null
257fi
258
Fred Drake9940bd71998-08-06 20:15:20 +0000259if [ "$DEBUGGING" ] ; then
260 set -x
261fi
262
Fred Drake11300cc1998-08-05 04:48:18 +0000263echo '# auxillary init file for latex2html' >$L2H_AUX_INIT_FILE
264echo '# generated by mkhowto.sh -- do no edit' >>$L2H_AUX_INIT_FILE
265l2hoption ICONSERVER "$ICONSERVER"
266l2hoption ADDRESS "$ADDRESS"
267l2hoption MAX_LINK_DEPTH "$MAX_LINK_DEPTH"
268l2hoption MAX_SPLIT_DEPTH "$MAX_SPLIT_DEPTH"
269echo '1;' >>$L2H_AUX_INIT_FILE
Fred Drakef4fc4761998-05-14 20:03:14 +0000270
Fred Drakee2e904f1998-03-10 23:23:05 +0000271for FILE in $@ ; do
Fred Drakedf825a11998-05-14 20:36:49 +0000272 FILEDIR=`dirname $FILE`
Fred Drake19c7c841998-05-07 21:20:39 +0000273 FILE=`basename ${FILE%.tex}`
Fred Drakef4fc4761998-05-14 20:03:14 +0000274 #
275 # Put the directory the .tex file is in is also the first directory in
276 # TEXINPUTS, to allow files there to override files in the common area.
277 #
Fred Drake11300cc1998-08-05 04:48:18 +0000278 TEXINPUTS=$FILEDIR:$TOPDIR/texinputs:$TEXINPUTS
Fred Drakef4fc4761998-05-14 20:03:14 +0000279 export TEXINPUTS
280 #
Fred Drakee2e904f1998-03-10 23:23:05 +0000281 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000282 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000283 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000284 fi
285 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000286 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000287 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000288 fi
289 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000290 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000291 fi
292 if [ "$BUILD_HTML" ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +0000293 if [ ! "$HAVE_TEMPS" ] ; then
Fred Drakee2e904f1998-03-10 23:23:05 +0000294 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000295 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000296 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000297 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000298 build_html $FILE $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000299 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000300 if [ "$BUILD_TEXT" ] ; then
301 if [ ! "$HAVE_TEMPS" ] ; then
302 # need to get aux file
303 build_dvi $FILE 2>&1 | tee -a $LOGFILE
304 HAVE_TEMPS=true
305 fi
306 # this is why building text really has to be last:
307 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
308 echo '# re-hack this file for --text:' >>$L2H_AUX_INIT_FILE
309 l2hoption MAX_SPLIT_DEPTH 1
310 echo '1;' >>$L2H_AUX_INIT_FILE
311 TEMPDIR=$FILE.temp-html
312 build_html $FILE $TEMPDIR 2>&1 | tee -a $LOGFILE
313 else
314 TEMPDIR=$FILE
315 fi
316 build_text $FILE $TEMPDIR 2>&1 | tee -a $LOGFILE
317 fi
318
Fred Drakedbc879e1998-03-11 15:33:44 +0000319 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000320 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000321 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000322 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000323 if [ "$LOGGING" ] ; then
324 cp $LOGFILE $FILE.how
325 fi
326 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000327done
Fred Drake11300cc1998-08-05 04:48:18 +0000328
329rm -f $L2H_AUX_INIT_FILE