blob: 4b0f63231eaaf7c34bbdf61547571deeecc8311c [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 Drakeac8f91a1998-04-02 15:37:13 +000046 --help, -H Show this text.
47 --logging, -l Log stdout and stderr to a file (*.how).
48 --debugging, -D Echo commands as they are executed.
49 --keep, -k Keep temporary files around.
50 --quiet, -q Do not print command output to stdout.
51 (stderr is also lost, sorry; see *.how for errors)
52
53EOF
54
55 exit $1
Fred Drakee2e904f1998-03-10 23:23:05 +000056}
57
Fred Drake88053541998-04-24 21:57:12 +000058# These are LaTeX2HTML controls; they reflect l2h variables of the same name.
59# The values here are the defaults after modification by perl/l2hinit.perl.
60#
61ADDRESS=''
62MAX_LINK_DEPTH=3
63MAX_SPLIT_DEPTH=8
64
Fred Drakee2e904f1998-03-10 23:23:05 +000065build_html() {
Fred Drake19c7c841998-05-07 21:20:39 +000066 TEXFILE=`kpsewhich $1.tex`
Fred Drake88053541998-04-24 21:57:12 +000067 if [ "$ADDRESS" ] ; then
68 latex2html -init_file $L2H_INIT_FILE \
69 -address "$ADDRESS" \
70 -link $MAX_LINK_DEPTH -split $MAX_SPLIT_DEPTH \
71 $1 || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +000072 else
Fred Drake88053541998-04-24 21:57:12 +000073 latex2html -init_file $L2H_INIT_FILE \
74 -link $MAX_LINK_DEPTH -split $MAX_SPLIT_DEPTH \
Fred Drake19c7c841998-05-07 21:20:39 +000075 -dir $1 $TEXFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +000076 fi
Fred Drake88053541998-04-24 21:57:12 +000077 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +000078 (cd $1; $MYDIR/node2label.pl *.html) || exit $?
Fred Drakeac8f91a1998-04-02 15:37:13 +000079 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000080}
81
Fred Drake12f842e1998-04-17 02:52:12 +000082use_latex() {
83 # two args: <file> <latextype>
84 MYFILE=$1
85 MYLATEX=$2
86 #
87 # We really have to do it three times to get all the page numbers right,
88 # since the length of the ToC makes a real difference.
89 #
90 $MYDIR/newind.py >$MYFILE.ind
91 $MYDIR/newind.py modindex >mod$MYFILE.ind
92 $MYLATEX $MYFILE || exit $?
93 if [ -f mod$MYFILE.idx ] ; then
94 makeindex mod$MYFILE.idx
Fred Drakee2e904f1998-03-10 23:23:05 +000095 fi
Fred Drake12f842e1998-04-17 02:52:12 +000096 if [ -f $MYFILE.idx ] ; then
97 $MYDIR/fix_hack $MYFILE.idx
98 makeindex $MYFILE.idx
99 $MYDIR/indfix.py $MYFILE.ind
100 fi
101 $MYLATEX $MYFILE || exit $?
102 if [ -f mod$MYFILE.idx ] ; then
103 makeindex mod$MYFILE.idx
104 fi
105 if [ -f $MYFILE.idx ] ; then
106 $MYDIR/fix_hack $MYFILE.idx || exit $?
107 makeindex -s $TOPDIR/texinputs/myindex.ist $MYFILE.idx || exit $?
108 fi
109 if [ -f $MYFILE.toc ] ; then
110 $MYDIR/toc2bkm.py -c section $MYFILE
111 fi
112 $MYLATEX $MYFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +0000113}
114
Fred Drake12f842e1998-04-17 02:52:12 +0000115build_dvi() {
116 use_latex $1 latex
Fred Drakee2e904f1998-03-10 23:23:05 +0000117}
118
119build_pdf() {
Fred Drake12f842e1998-04-17 02:52:12 +0000120 use_latex $1 pdflatex
121}
122
123build_ps() {
Fred Drake79842561998-04-17 20:06:16 +0000124 dvips -N0 -o $1.ps $1 || exit $?
Fred Drake12f842e1998-04-17 02:52:12 +0000125}
126
127cleanup() {
Fred Drakec9b8a571998-04-29 21:28:25 +0000128 rm -f $1.aux $1.log $1.out $1.toc $1.bkm $1.idx $1.ilg $1.ind
129 rm -f mod$1.idx mod$1.ilg mod$1.ind
Fred Drake12f842e1998-04-17 02:52:12 +0000130 if [ ! "$BUILD_DVI" ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +0000131 rm -f $1.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000132 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000133}
134
135# figure out what our targets are:
136while [ "$1" ] ; do
137 case "$1" in
138 --pdf|--pd)
139 BUILD_PDF=true
140 USE_DEFAULT_FORMAT=false
141 shift 1
142 ;;
Fred Drake88053541998-04-24 21:57:12 +0000143 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000144 BUILD_PS=true
145 USE_DEFAULT_FORMAT=false
146 shift 1
147 ;;
148 --dvi|--dv|--d)
149 BUILD_DVI=true
150 USE_DEFAULT_FORMAT=false
151 shift 1
152 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000153 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000154 BUILD_HTML=true
155 USE_DEFAULT_FORMAT=false
156 shift 1
157 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000158 -H|--help|--hel|--he)
159 usage 0
160 ;;
Fred Drake35049521998-05-11 19:04:06 +0000161 -a|--address|--addres|--addre|-addr|--add|--ad)
Fred Drakee2e904f1998-03-10 23:23:05 +0000162 ADDRESS="$2"
163 shift 2
164 ;;
Fred Drake35049521998-05-11 19:04:06 +0000165 --a4)
166 TEXINPUTS=$TOPDIR/paper-a4:$TEXINPUTS
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 Drakee2e904f1998-03-10 23:23:05 +0000221for FILE in $@ ; do
Fred Drake19c7c841998-05-07 21:20:39 +0000222 FILE=`basename ${FILE%.tex}`
Fred Drakee2e904f1998-03-10 23:23:05 +0000223 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000224 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000225 fi
226 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000227 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000228 fi
229 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000230 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000231 fi
232 if [ "$BUILD_HTML" ] ; then
233 if [ ! "$BUILD_DVI" -o ! "$BUILD_PDF" ] ; then
234 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000235 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000236 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000237 build_html $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000238 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000239 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000240 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000241 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000242 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000243 if [ "$LOGGING" ] ; then
244 cp $LOGFILE $FILE.how
245 fi
246 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000247done