blob: ac06cebf8be57c54d6cd208c7abd759fb38a05cf [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 \
Fred Drake8dbf46a1998-05-15 17:13:08 +000067 -dir $1 $TEXFILE || 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 Drake8dbf46a1998-05-15 17:13:08 +0000129 rm -f $1/IMG* $1/*.pl $1/WARNINGS $1/index.dat $1/modindex.dat
Fred Drakee2e904f1998-03-10 23:23:05 +0000130}
131
132# figure out what our targets are:
133while [ "$1" ] ; do
134 case "$1" in
135 --pdf|--pd)
136 BUILD_PDF=true
137 USE_DEFAULT_FORMAT=false
138 shift 1
139 ;;
Fred Drake88053541998-04-24 21:57:12 +0000140 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000141 BUILD_PS=true
142 USE_DEFAULT_FORMAT=false
143 shift 1
144 ;;
145 --dvi|--dv|--d)
146 BUILD_DVI=true
147 USE_DEFAULT_FORMAT=false
148 shift 1
149 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000150 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000151 BUILD_HTML=true
152 USE_DEFAULT_FORMAT=false
153 shift 1
154 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000155 -H|--help|--hel|--he)
156 usage 0
157 ;;
Fred Drake35049521998-05-11 19:04:06 +0000158 -a|--address|--addres|--addre|-addr|--add|--ad)
Fred Drakee2e904f1998-03-10 23:23:05 +0000159 ADDRESS="$2"
160 shift 2
161 ;;
Fred Drake35049521998-05-11 19:04:06 +0000162 --a4)
163 TEXINPUTS=$TOPDIR/paper-a4:$TEXINPUTS
164 shift 1
165 ;;
Fred Draked5d473f1998-05-11 20:40:24 +0000166 --letter|--lette|--lett|--let|--le)
167 shift 1
168 ;;
Fred Drake88053541998-04-24 21:57:12 +0000169 --link|--lin|--li)
170 LINK="$2"
Fred Drakeac8f91a1998-04-02 15:37:13 +0000171 shift 2
172 ;;
Fred Drake88053541998-04-24 21:57:12 +0000173 -s|--split|--spli|--spl|--sp|--s)
174 MAX_SPLIT_DEPTH="$2"
175 shift 2
176 ;;
177 -l|--logging|--loggin|--loggi|--logg|--log|--lo)
Fred Drakedbc879e1998-03-11 15:33:44 +0000178 LOGGING=true
179 shift 1
180 ;;
181 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
182 DEBUGGING=true
183 shift 1
184 ;;
185 -k|--keep|--kee|--ke|--k)
186 DISCARD_TEMPS=''
187 shift 1
188 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000189 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000190 QUIET=true
191 shift 1
192 ;;
Fred Drake88053541998-04-24 21:57:12 +0000193 --)
Fred Drakec9b8a571998-04-29 21:28:25 +0000194 shift 1
Fred Drake88053541998-04-24 21:57:12 +0000195 break
196 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000197 -*)
Fred Drakeac8f91a1998-04-02 15:37:13 +0000198 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000199 ;;
200 *)
201 break;;
202 esac
203done
204
205if [ $# = 0 ] ; then
Fred Drakeac8f91a1998-04-02 15:37:13 +0000206 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000207fi
208
209if [ $USE_DEFAULT_FORMAT = true ] ; then
210 eval "BUILD_$DEFAULT_FORMAT=true"
211fi
212
Fred Drakedbc879e1998-03-11 15:33:44 +0000213if [ "$DEBUGGING" ] ; then
214 set -x
215fi
216
Fred Drake664b36f1998-03-11 15:41:21 +0000217if [ "$QUIET" ] ; then
218 exec >/dev/null
219fi
220
Fred Drakef4fc4761998-05-14 20:03:14 +0000221COMMONTEXINPUTS=$TOPDIR/texinputs:$TEXINPUTS
222
Fred Drakee2e904f1998-03-10 23:23:05 +0000223for FILE in $@ ; do
Fred Drakedf825a11998-05-14 20:36:49 +0000224 FILEDIR=`dirname $FILE`
Fred Drake19c7c841998-05-07 21:20:39 +0000225 FILE=`basename ${FILE%.tex}`
Fred Drakef4fc4761998-05-14 20:03:14 +0000226 #
227 # Put the directory the .tex file is in is also the first directory in
228 # TEXINPUTS, to allow files there to override files in the common area.
229 #
Fred Drakef4fc4761998-05-14 20:03:14 +0000230 TEXINPUTS=$FILEDIR:$COMMONTEXINPUTS
231 export TEXINPUTS
232 #
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