blob: 61083303851f55ced6f03a4c49cb2e78c098f394 [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 Drakee2e904f1998-03-10 23:23:05 +000018# This is needed to support kpathsea based TeX installations. Others are
19# not supported. ;-)
Fred Drake35049521998-05-11 19:04:06 +000020TEXINPUTS=$TOPDIR/texinputs:$TEXINPUTS
Fred Drakee2e904f1998-03-10 23:23:05 +000021export TEXINPUTS
22
Fred Drakedbc879e1998-03-11 15:33:44 +000023LOGFILE=/usr/tmp/mkhowto-$LOGNAME-$$.how
24LOGGING=''
25
Fred Drakee2e904f1998-03-10 23:23:05 +000026usage() {
Fred Drakeac8f91a1998-04-02 15:37:13 +000027 MYNAME=`basename $0`
28 echo "usage: $MYNAME [options...] file ..."
29 cat <<EOF
30
31Options specifying formats to build:
32 --html HyperText Markup Language
33 --pdf Portable Document Format (default)
34 --ps PostScript
35 --dvi "DeVice Indepentent" format from TeX
36
37 More than one output format may be specified.
38
39HTML options:
40 --address, -a Specify an address for page footers.
Fred Drake88053541998-04-24 21:57:12 +000041 --link Specify the number of levels to include on each page.
Fred Drakeac8f91a1998-04-02 15:37:13 +000042 --split, -s Specify a section level for page splitting.
43
44Other options:
Fred Drake1a3541c1998-05-11 19:04:56 +000045 --a4 Format for A4 paper.
Fred Draked5d473f1998-05-11 20:40:24 +000046 --letter Format for US letter paper (the default).
Fred Drakeac8f91a1998-04-02 15:37:13 +000047 --help, -H Show this text.
48 --logging, -l Log stdout and stderr to a file (*.how).
49 --debugging, -D Echo commands as they are executed.
50 --keep, -k Keep temporary files around.
51 --quiet, -q Do not print command output to stdout.
52 (stderr is also lost, sorry; see *.how for errors)
53
54EOF
55
56 exit $1
Fred Drakee2e904f1998-03-10 23:23:05 +000057}
58
Fred Drake88053541998-04-24 21:57:12 +000059# These are LaTeX2HTML controls; they reflect l2h variables of the same name.
60# The values here are the defaults after modification by perl/l2hinit.perl.
61#
62ADDRESS=''
63MAX_LINK_DEPTH=3
64MAX_SPLIT_DEPTH=8
65
Fred Drakee2e904f1998-03-10 23:23:05 +000066build_html() {
Fred Drake19c7c841998-05-07 21:20:39 +000067 TEXFILE=`kpsewhich $1.tex`
Fred Drake88053541998-04-24 21:57:12 +000068 if [ "$ADDRESS" ] ; then
69 latex2html -init_file $L2H_INIT_FILE \
70 -address "$ADDRESS" \
71 -link $MAX_LINK_DEPTH -split $MAX_SPLIT_DEPTH \
72 $1 || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +000073 else
Fred Drake88053541998-04-24 21:57:12 +000074 latex2html -init_file $L2H_INIT_FILE \
75 -link $MAX_LINK_DEPTH -split $MAX_SPLIT_DEPTH \
Fred Drake19c7c841998-05-07 21:20:39 +000076 -dir $1 $TEXFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +000077 fi
Fred Drake88053541998-04-24 21:57:12 +000078 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +000079 (cd $1; $MYDIR/node2label.pl *.html) || exit $?
Fred Drakeac8f91a1998-04-02 15:37:13 +000080 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000081}
82
Fred Drake12f842e1998-04-17 02:52:12 +000083use_latex() {
84 # two args: <file> <latextype>
85 MYFILE=$1
86 MYLATEX=$2
87 #
88 # We really have to do it three times to get all the page numbers right,
89 # since the length of the ToC makes a real difference.
90 #
91 $MYDIR/newind.py >$MYFILE.ind
92 $MYDIR/newind.py modindex >mod$MYFILE.ind
93 $MYLATEX $MYFILE || exit $?
94 if [ -f mod$MYFILE.idx ] ; then
95 makeindex mod$MYFILE.idx
Fred Drakee2e904f1998-03-10 23:23:05 +000096 fi
Fred Drake12f842e1998-04-17 02:52:12 +000097 if [ -f $MYFILE.idx ] ; then
98 $MYDIR/fix_hack $MYFILE.idx
99 makeindex $MYFILE.idx
100 $MYDIR/indfix.py $MYFILE.ind
101 fi
102 $MYLATEX $MYFILE || exit $?
103 if [ -f mod$MYFILE.idx ] ; then
104 makeindex mod$MYFILE.idx
105 fi
106 if [ -f $MYFILE.idx ] ; then
107 $MYDIR/fix_hack $MYFILE.idx || exit $?
108 makeindex -s $TOPDIR/texinputs/myindex.ist $MYFILE.idx || exit $?
109 fi
110 if [ -f $MYFILE.toc ] ; then
111 $MYDIR/toc2bkm.py -c section $MYFILE
112 fi
113 $MYLATEX $MYFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +0000114}
115
Fred Drake12f842e1998-04-17 02:52:12 +0000116build_dvi() {
117 use_latex $1 latex
Fred Drakee2e904f1998-03-10 23:23:05 +0000118}
119
120build_pdf() {
Fred Drake12f842e1998-04-17 02:52:12 +0000121 use_latex $1 pdflatex
122}
123
124build_ps() {
Fred Drake79842561998-04-17 20:06:16 +0000125 dvips -N0 -o $1.ps $1 || exit $?
Fred Drake12f842e1998-04-17 02:52:12 +0000126}
127
128cleanup() {
Fred Drakec9b8a571998-04-29 21:28:25 +0000129 rm -f $1.aux $1.log $1.out $1.toc $1.bkm $1.idx $1.ilg $1.ind
130 rm -f mod$1.idx mod$1.ilg mod$1.ind
Fred Drake12f842e1998-04-17 02:52:12 +0000131 if [ ! "$BUILD_DVI" ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +0000132 rm -f $1.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000133 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000134}
135
136# figure out what our targets are:
137while [ "$1" ] ; do
138 case "$1" in
139 --pdf|--pd)
140 BUILD_PDF=true
141 USE_DEFAULT_FORMAT=false
142 shift 1
143 ;;
Fred Drake88053541998-04-24 21:57:12 +0000144 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000145 BUILD_PS=true
146 USE_DEFAULT_FORMAT=false
147 shift 1
148 ;;
149 --dvi|--dv|--d)
150 BUILD_DVI=true
151 USE_DEFAULT_FORMAT=false
152 shift 1
153 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000154 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000155 BUILD_HTML=true
156 USE_DEFAULT_FORMAT=false
157 shift 1
158 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000159 -H|--help|--hel|--he)
160 usage 0
161 ;;
Fred Drake35049521998-05-11 19:04:06 +0000162 -a|--address|--addres|--addre|-addr|--add|--ad)
Fred Drakee2e904f1998-03-10 23:23:05 +0000163 ADDRESS="$2"
164 shift 2
165 ;;
Fred Drake35049521998-05-11 19:04:06 +0000166 --a4)
167 TEXINPUTS=$TOPDIR/paper-a4:$TEXINPUTS
168 shift 1
169 ;;
Fred Draked5d473f1998-05-11 20:40:24 +0000170 --letter|--lette|--lett|--let|--le)
171 shift 1
172 ;;
Fred Drake88053541998-04-24 21:57:12 +0000173 --link|--lin|--li)
174 LINK="$2"
Fred Drakeac8f91a1998-04-02 15:37:13 +0000175 shift 2
176 ;;
Fred Drake88053541998-04-24 21:57:12 +0000177 -s|--split|--spli|--spl|--sp|--s)
178 MAX_SPLIT_DEPTH="$2"
179 shift 2
180 ;;
181 -l|--logging|--loggin|--loggi|--logg|--log|--lo)
Fred Drakedbc879e1998-03-11 15:33:44 +0000182 LOGGING=true
183 shift 1
184 ;;
185 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
186 DEBUGGING=true
187 shift 1
188 ;;
189 -k|--keep|--kee|--ke|--k)
190 DISCARD_TEMPS=''
191 shift 1
192 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000193 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000194 QUIET=true
195 shift 1
196 ;;
Fred Drake88053541998-04-24 21:57:12 +0000197 --)
Fred Drakec9b8a571998-04-29 21:28:25 +0000198 shift 1
Fred Drake88053541998-04-24 21:57:12 +0000199 break
200 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000201 -*)
Fred Drakeac8f91a1998-04-02 15:37:13 +0000202 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000203 ;;
204 *)
205 break;;
206 esac
207done
208
209if [ $# = 0 ] ; then
Fred Drakeac8f91a1998-04-02 15:37:13 +0000210 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000211fi
212
213if [ $USE_DEFAULT_FORMAT = true ] ; then
214 eval "BUILD_$DEFAULT_FORMAT=true"
215fi
216
Fred Drakedbc879e1998-03-11 15:33:44 +0000217if [ "$DEBUGGING" ] ; then
218 set -x
219fi
220
Fred Drake664b36f1998-03-11 15:41:21 +0000221if [ "$QUIET" ] ; then
222 exec >/dev/null
223fi
224
Fred Drakee2e904f1998-03-10 23:23:05 +0000225for FILE in $@ ; do
Fred Drake19c7c841998-05-07 21:20:39 +0000226 FILE=`basename ${FILE%.tex}`
Fred Drakee2e904f1998-03-10 23:23:05 +0000227 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000228 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000229 fi
230 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000231 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000232 fi
233 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000234 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000235 fi
236 if [ "$BUILD_HTML" ] ; then
237 if [ ! "$BUILD_DVI" -o ! "$BUILD_PDF" ] ; then
238 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000239 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000240 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000241 build_html $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000242 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000243 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000244 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000245 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000246 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000247 if [ "$LOGGING" ] ; then
248 cp $LOGFILE $FILE.how
249 fi
250 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000251done