1 | #! /bin/sh
|
---|
2 | # texi2dvi --- produce DVI (or PDF) files from Texinfo (or LaTeX) sources.
|
---|
3 | # $Id: texi2dvi,v 1.14 2003/02/05 00:42:33 karl Exp $
|
---|
4 | #
|
---|
5 | # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001,
|
---|
6 | # 2002, 2003 Free Software Foundation, Inc.
|
---|
7 | #
|
---|
8 | # This program is free software; you can redistribute it and/or modify
|
---|
9 | # it under the terms of the GNU General Public License as published by
|
---|
10 | # the Free Software Foundation; either version 2, or (at your option)
|
---|
11 | # any later version.
|
---|
12 | #
|
---|
13 | # This program is distributed in the hope that it will be useful,
|
---|
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | # GNU General Public License for more details.
|
---|
17 | #
|
---|
18 | # You should have received a copy of the GNU General Public License
|
---|
19 | # along with this program; if not, you can either send email to this
|
---|
20 | # program's maintainer or write to: The Free Software Foundation,
|
---|
21 | # Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
|
---|
22 | #
|
---|
23 | # Original author: Noah Friedman <friedman@gnu.org>.
|
---|
24 | #
|
---|
25 | # Please send bug reports, etc. to bug-texinfo@gnu.org.
|
---|
26 | # If possible, please send a copy of the output of the script called with
|
---|
27 | # the `--debug' option when making a bug report.
|
---|
28 |
|
---|
29 | # This string is expanded by rcs automatically when this file is checked out.
|
---|
30 | rcs_revision='$Revision: 1.14 $'
|
---|
31 | rcs_version=`set - $rcs_revision; echo $2`
|
---|
32 | program=`echo $0 | sed -e 's!.*/!!'`
|
---|
33 | version="texi2dvi (GNU Texinfo 4.5) $rcs_version
|
---|
34 |
|
---|
35 | Copyright (C) 2003 Free Software Foundation, Inc.
|
---|
36 | There is NO warranty. You may redistribute this software
|
---|
37 | under the terms of the GNU General Public License.
|
---|
38 | For more information about these matters, see the files named COPYING."
|
---|
39 |
|
---|
40 | usage="Usage: $program [OPTION]... FILE...
|
---|
41 |
|
---|
42 | Run each Texinfo or LaTeX FILE through TeX in turn until all
|
---|
43 | cross-references are resolved, building all indices. The directory
|
---|
44 | containing each FILE is searched for included files. The suffix of FILE
|
---|
45 | is used to determine its language (LaTeX or Texinfo).
|
---|
46 |
|
---|
47 | Makeinfo is used to perform Texinfo macro expansion before running TeX
|
---|
48 | when needed.
|
---|
49 |
|
---|
50 | Operation modes:
|
---|
51 | -b, --batch no interaction
|
---|
52 | -c, --clean remove all auxiliary files
|
---|
53 | -D, --debug turn on shell debugging (set -x)
|
---|
54 | -h, --help display this help and exit successfully
|
---|
55 | -o, --output=OFILE leave output in OFILE (implies --clean);
|
---|
56 | Only one input FILE may be specified in this case
|
---|
57 | -q, --quiet no output unless errors (implies --batch)
|
---|
58 | -s, --silent same as --quiet
|
---|
59 | -v, --version display version information and exit successfully
|
---|
60 | -V, --verbose report on what is done
|
---|
61 |
|
---|
62 | TeX tuning:
|
---|
63 | -@ use @input instead of \input; for preloaded Texinfo
|
---|
64 | -e, -E, --expand force macro expansion using makeinfo
|
---|
65 | -I DIR search DIR for Texinfo files
|
---|
66 | -l, --language=LANG specify the LANG of FILE (LaTeX or Texinfo)
|
---|
67 | -p, --pdf use pdftex or pdflatex for processing
|
---|
68 | -t, --texinfo=CMD insert CMD after @setfilename in copy of input file
|
---|
69 | multiple values accumulate
|
---|
70 |
|
---|
71 | The values of the BIBTEX, LATEX (or PDFLATEX), MAKEINDEX, MAKEINFO,
|
---|
72 | TEX (or PDFTEX), and TEXINDEX environment variables are used to run
|
---|
73 | those commands, if they are set.
|
---|
74 |
|
---|
75 | Email bug reports to <bug-texinfo@gnu.org>,
|
---|
76 | general questions and discussion to <help-texinfo@gnu.org>.
|
---|
77 | Texinfo home page: http://www.gnu.org/software/texinfo/"
|
---|
78 |
|
---|
79 | # Initialize variables for option overriding and otherwise.
|
---|
80 | # Don't use `unset' since old bourne shells don't have this command.
|
---|
81 | # Instead, assign them an empty value.
|
---|
82 | batch=false # eval for batch mode
|
---|
83 | clean=
|
---|
84 | debug=
|
---|
85 | escape='\'
|
---|
86 | expand= # t for expansion via makeinfo
|
---|
87 | miincludes= # makeinfo include path
|
---|
88 | oformat=dvi
|
---|
89 | oname= # --output
|
---|
90 | quiet= # by default let the tools' message be displayed
|
---|
91 | set_language=
|
---|
92 | textra=
|
---|
93 | tmpdir=${TMPDIR:-/tmp}/t2d$$ # avoid collisions on 8.3 filesystems.
|
---|
94 | txincludes= # TEXINPUTS extensions, with trailing colon
|
---|
95 | txiprereq=19990129 # minimum texinfo.tex version to have macro expansion
|
---|
96 | verbose=false # echo for verbose mode
|
---|
97 |
|
---|
98 | orig_pwd=`pwd`
|
---|
99 |
|
---|
100 | # Systems which define $COMSPEC or $ComSpec use semicolons to separate
|
---|
101 | # directories in TEXINPUTS.
|
---|
102 | if test -n "$COMSPEC$ComSpec"; then
|
---|
103 | path_sep=";"
|
---|
104 | else
|
---|
105 | path_sep=":"
|
---|
106 | fi
|
---|
107 |
|
---|
108 | # Pacify verbose cds.
|
---|
109 | CDPATH=${ZSH_VERSION+.}$path_sep
|
---|
110 |
|
---|
111 | # In case someone crazy insists on using grep -E.
|
---|
112 | : ${EGREP=egrep}
|
---|
113 |
|
---|
114 | # Save this so we can construct a new TEXINPUTS path for each file.
|
---|
115 | TEXINPUTS_orig="$TEXINPUTS"
|
---|
116 | # Unfortunately makeindex does not read TEXINPUTS.
|
---|
117 | INDEXSTYLE_orig="$INDEXSTYLE"
|
---|
118 | export TEXINPUTS INDEXSTYLE
|
---|
119 |
|
---|
120 | # Push a token among the arguments that will be used to notice when we
|
---|
121 | # ended options/arguments parsing.
|
---|
122 | # Use "set dummy ...; shift" rather than 'set - ..." because on
|
---|
123 | # Solaris set - turns off set -x (but keeps set -e).
|
---|
124 | # Use ${1+"$@"} rather than "$@" because Digital Unix and Ultrix 4.3
|
---|
125 | # still expand "$@" to a single argument (the empty string) rather
|
---|
126 | # than nothing at all.
|
---|
127 | arg_sep="$$--$$"
|
---|
128 | set dummy ${1+"$@"} "$arg_sep"; shift
|
---|
129 |
|
---|
130 | # |
---|
131 |
|
---|
132 | # Parse command line arguments.
|
---|
133 | while test x"$1" != x"$arg_sep"; do
|
---|
134 |
|
---|
135 | # Handle --option=value by splitting apart and putting back on argv.
|
---|
136 | case "$1" in
|
---|
137 | --*=*)
|
---|
138 | opt=`echo "$1" | sed -e 's/=.*//'`
|
---|
139 | val=`echo "$1" | sed -e 's/[^=]*=//'`
|
---|
140 | shift
|
---|
141 | set dummy "$opt" "$val" ${1+"$@"}; shift
|
---|
142 | ;;
|
---|
143 | esac
|
---|
144 |
|
---|
145 | # This recognizes --quark as --quiet. So what.
|
---|
146 | case "$1" in
|
---|
147 | -@ ) escape=@;;
|
---|
148 | # Silently and without documentation accept -b and --b[atch] as synonyms.
|
---|
149 | -b | --b*) batch=eval;;
|
---|
150 | -q | -s | --q* | --s*) quiet=t; batch=eval;;
|
---|
151 | -c | --c*) clean=t;;
|
---|
152 | -D | --d*) debug=t;;
|
---|
153 | -e | -E | --e*) expand=t;;
|
---|
154 | -h | --h*) echo "$usage"; exit 0;;
|
---|
155 | -I | --I*)
|
---|
156 | shift
|
---|
157 | miincludes="$miincludes -I $1"
|
---|
158 | txincludes="$txincludes$1$path_sep"
|
---|
159 | ;;
|
---|
160 | -l | --l*) shift; set_language=$1;;
|
---|
161 | -o | --o*)
|
---|
162 | shift
|
---|
163 | clean=t
|
---|
164 | case "$1" in
|
---|
165 | /* | ?:/*) oname=$1;;
|
---|
166 | *) oname="$orig_pwd/$1";;
|
---|
167 | esac;;
|
---|
168 | -p | --p*) oformat=pdf;;
|
---|
169 | -t | --t*) shift; textra="$textra\\
|
---|
170 | $1";;
|
---|
171 | -v | --vers*) echo "$version"; exit 0;;
|
---|
172 | -V | --verb*) verbose=echo;;
|
---|
173 | --) # What remains are not options.
|
---|
174 | shift
|
---|
175 | while test x"$1" != x"$arg_sep"; do
|
---|
176 | set dummy ${1+"$@"} "$1"; shift
|
---|
177 | shift
|
---|
178 | done
|
---|
179 | break;;
|
---|
180 | -*)
|
---|
181 | echo "$0: Unknown or ambiguous option \`$1'." >&2
|
---|
182 | echo "$0: Try \`--help' for more information." >&2
|
---|
183 | exit 1;;
|
---|
184 | *) set dummy ${1+"$@"} "$1"; shift;;
|
---|
185 | esac
|
---|
186 | shift
|
---|
187 | done
|
---|
188 | # Pop the token
|
---|
189 | shift
|
---|
190 |
|
---|
191 | # Interpret remaining command line args as filenames.
|
---|
192 | case $# in
|
---|
193 | 0)
|
---|
194 | echo "$0: Missing file arguments." >&2
|
---|
195 | echo "$0: Try \`--help' for more information." >&2
|
---|
196 | exit 2
|
---|
197 | ;;
|
---|
198 | 1) ;;
|
---|
199 | *)
|
---|
200 | if test -n "$oname"; then
|
---|
201 | echo "$0: Can't use option \`--output' with more than one argument." >&2
|
---|
202 | exit 2
|
---|
203 | fi
|
---|
204 | ;;
|
---|
205 | esac
|
---|
206 |
|
---|
207 | # Prepare the temporary directory. Remove it at exit, unless debugging.
|
---|
208 | if test -z "$debug"; then
|
---|
209 | trap "cd / && rm -rf $tmpdir" 0 1 2 15
|
---|
210 | fi
|
---|
211 |
|
---|
212 | # Create the temporary directory with strict rights
|
---|
213 | (umask 077 && mkdir $tmpdir) || exit 1
|
---|
214 |
|
---|
215 | # Prepare the tools we might need. This may be extra work in some
|
---|
216 | # cases, but improves the readibility of the script.
|
---|
217 | utildir=$tmpdir/utils
|
---|
218 | mkdir $utildir || exit 1
|
---|
219 |
|
---|
220 | # A sed script that preprocesses Texinfo sources in order to keep the
|
---|
221 | # iftex sections only. We want to remove non TeX sections, and
|
---|
222 | # comment (with `@c texi2dvi') TeX sections so that makeinfo does not
|
---|
223 | # try to parse them. Nevertheless, while commenting TeX sections,
|
---|
224 | # don't comment @macro/@end macro so that makeinfo does propagate
|
---|
225 | # them. Unfortunately makeinfo --iftex --no-ifhtml --no-ifinfo
|
---|
226 | # doesn't work well enough (yet) to use that, so work around with sed.
|
---|
227 | comment_iftex_sed=$utildir/comment.sed
|
---|
228 | cat <<EOF >$comment_iftex_sed
|
---|
229 | /^@tex/,/^@end tex/{
|
---|
230 | s/^/@c texi2dvi/
|
---|
231 | }
|
---|
232 | /^@iftex/,/^@end iftex/{
|
---|
233 | s/^/@c texi2dvi/
|
---|
234 | /^@c texi2dvi@macro/,/^@c texi2dvi@end macro/{
|
---|
235 | s/^@c texi2dvi//
|
---|
236 | }
|
---|
237 | }
|
---|
238 | /^@html/,/^@end html/{
|
---|
239 | s/^/@c (texi2dvi)/
|
---|
240 | }
|
---|
241 | /^@ifhtml/,/^@end ifhtml/{
|
---|
242 | s/^/@c (texi2dvi)/
|
---|
243 | }
|
---|
244 | /^@ifnottex/,/^@end ifnottex/{
|
---|
245 | s/^/@c (texi2dvi)/
|
---|
246 | }
|
---|
247 | /^@ifinfo/,/^@end ifinfo/{
|
---|
248 | /^@node/p
|
---|
249 | /^@menu/,/^@end menu/p
|
---|
250 | t
|
---|
251 | s/^/@c (texi2dvi)/
|
---|
252 | }
|
---|
253 | s/^@ifnotinfo/@c texi2dvi@ifnotinfo/
|
---|
254 | s/^@end ifnotinfo/@c texi2dvi@end ifnotinfo/
|
---|
255 | EOF
|
---|
256 | # Uncommenting is simple: Remove any leading `@c texi2dvi'.
|
---|
257 | uncomment_iftex_sed=$utildir/uncomment.sed
|
---|
258 | cat <<EOF >$uncomment_iftex_sed
|
---|
259 | s/^@c texi2dvi//
|
---|
260 | EOF
|
---|
261 |
|
---|
262 | # A shell script that computes the list of xref files.
|
---|
263 | # Takes the filename (without extension) of which we look for xref
|
---|
264 | # files as argument. The index files must be reported last.
|
---|
265 | get_xref_files=$utildir/get_xref.sh
|
---|
266 | cat <<\EOF >$get_xref_files
|
---|
267 | #! /bin/sh
|
---|
268 |
|
---|
269 | # Get list of xref files (indexes, tables and lists).
|
---|
270 | # Find all files having root filename with a two-letter extension,
|
---|
271 | # saves the ones that are really Texinfo-related files. .?o? catches
|
---|
272 | # many files: .toc, .log, LaTeX tables and lists, FiXme's .lox, maybe more.
|
---|
273 | for this_file in "$1".?o? "$1".aux "$1".?? "$1".idx; do
|
---|
274 | # If file is empty, skip it.
|
---|
275 | test -s "$this_file" || continue
|
---|
276 | # If the file is not suitable to be an index or xref file, don't
|
---|
277 | # process it. The file can't be if its first character is not a
|
---|
278 | # backslash or single quote.
|
---|
279 | first_character=`sed -n '1s/^\(.\).*$/\1/p;q' $this_file`
|
---|
280 | if test "x$first_character" = "x\\" \
|
---|
281 | || test "x$first_character" = "x'"; then
|
---|
282 | xref_files="$xref_files ./$this_file"
|
---|
283 | fi
|
---|
284 | done
|
---|
285 | echo "$xref_files"
|
---|
286 | EOF
|
---|
287 | chmod 500 $get_xref_files
|
---|
288 |
|
---|
289 | # File descriptor usage:
|
---|
290 | # 0 standard input
|
---|
291 | # 1 standard output (--verbose messages)
|
---|
292 | # 2 standard error
|
---|
293 | # 3 some systems may open it to /dev/tty
|
---|
294 | # 4 used on the Kubota Titan
|
---|
295 | # 5 tools output (turned off by --quiet)
|
---|
296 |
|
---|
297 | # Tools' output. If quiet, discard, else redirect to the message flow.
|
---|
298 | if test "$quiet" = t; then
|
---|
299 | exec 5>/dev/null
|
---|
300 | else
|
---|
301 | exec 5>&1
|
---|
302 | fi
|
---|
303 |
|
---|
304 | # Enable tracing
|
---|
305 | test "$debug" = t && set -x
|
---|
306 |
|
---|
307 | # |
---|
308 |
|
---|
309 | # TeXify files.
|
---|
310 |
|
---|
311 | for command_line_filename in ${1+"$@"}; do
|
---|
312 | $verbose "Processing $command_line_filename ..."
|
---|
313 |
|
---|
314 | # If the COMMAND_LINE_FILENAME is not absolute (e.g., --debug.tex),
|
---|
315 | # prepend `./' in order to avoid that the tools take it as an option.
|
---|
316 | echo "$command_line_filename" | $EGREP '^(/|[A-z]:/)' >/dev/null \
|
---|
317 | || command_line_filename="./$command_line_filename"
|
---|
318 |
|
---|
319 | # See if the file exists. If it doesn't we're in trouble since, even
|
---|
320 | # though the user may be able to reenter a valid filename at the tex
|
---|
321 | # prompt (assuming they're attending the terminal), this script won't
|
---|
322 | # be able to find the right xref files and so forth.
|
---|
323 | if test ! -r "$command_line_filename"; then
|
---|
324 | echo "$0: Could not read $command_line_filename, skipping." >&2
|
---|
325 | continue
|
---|
326 | fi
|
---|
327 |
|
---|
328 | # Get the name of the current directory. We want the full path
|
---|
329 | # because in clean mode we are in tmp, in which case a relative
|
---|
330 | # path has no meaning.
|
---|
331 | filename_dir=`echo $command_line_filename | sed 's!/[^/]*$!!;s!^$!.!'`
|
---|
332 | filename_dir=`cd "$filename_dir" >/dev/null && pwd`
|
---|
333 |
|
---|
334 | # Strip directory part but leave extension.
|
---|
335 | filename_ext=`basename "$command_line_filename"`
|
---|
336 | # Strip extension.
|
---|
337 | filename_noext=`echo "$filename_ext" | sed 's/\.[^.]*$//'`
|
---|
338 | ext=`echo "$filename_ext" | sed 's/^.*\.//'`
|
---|
339 |
|
---|
340 | # _src. Use same basename since we want to generate aux files with
|
---|
341 | # the same basename as the manual. If --expand, then output the
|
---|
342 | # macro-expanded file to here, else copy the original file.
|
---|
343 | tmpdir_src=$tmpdir/src
|
---|
344 | filename_src=$tmpdir_src/$filename_noext.$ext
|
---|
345 |
|
---|
346 | # _xtr. The file with the user's extra commands.
|
---|
347 | tmpdir_xtr=$tmpdir/xtr
|
---|
348 | filename_xtr=$tmpdir_xtr/$filename_noext.$ext
|
---|
349 |
|
---|
350 | # _bak. Copies of the previous xref files (another round is run if
|
---|
351 | # they differ from the new one).
|
---|
352 | tmpdir_bak=$tmpdir/bak
|
---|
353 |
|
---|
354 | # Make all those directories and give up if we can't succeed.
|
---|
355 | mkdir $tmpdir_src $tmpdir_xtr $tmpdir_bak || exit 1
|
---|
356 |
|
---|
357 | # Source file might include additional sources.
|
---|
358 | # We want `.:$orig_pwd' before anything else. (We'll add `.:' later
|
---|
359 | # after all other directories have been turned into absolute paths.)
|
---|
360 | # `.' goes first to ensure that any old .aux, .cps,
|
---|
361 | # etc. files in ${directory} don't get used in preference to fresher
|
---|
362 | # files in `.'. Include orig_pwd in case we are in clean mode, where
|
---|
363 | # we've cd'd to a temp directory.
|
---|
364 | common="$orig_pwd$path_sep$filename_dir$path_sep$txincludes"
|
---|
365 | TEXINPUTS="$common$TEXINPUTS_orig"
|
---|
366 | INDEXSTYLE="$common$INDEXSTYLE_orig"
|
---|
367 |
|
---|
368 | # Convert relative paths to absolute paths, so we can run in another
|
---|
369 | # directory (e.g., in --clean mode, or during the macro-support
|
---|
370 | # detection.)
|
---|
371 | #
|
---|
372 | # Empty path components are meaningful to tex. We rewrite them
|
---|
373 | # as `EMPTY' so they don't get lost when we split on $path_sep.
|
---|
374 | TEXINPUTS=`echo $TEXINPUTS |sed 's/^:/EMPTY:/;s/:$/:EMPTY/;s/::/:EMPTY:/g'`
|
---|
375 | INDEXSTYLE=`echo $INDEXSTYLE |sed 's/^:/EMPTY:/;s/:$/:EMPTY/;s/::/:EMPTY:/g'`
|
---|
376 | save_IFS=$IFS
|
---|
377 | IFS=$path_sep
|
---|
378 | set x $TEXINPUTS; shift
|
---|
379 | TEXINPUTS=.
|
---|
380 | for dir
|
---|
381 | do
|
---|
382 | case $dir in
|
---|
383 | EMPTY)
|
---|
384 | TEXINPUTS=$TEXINPUTS$path_sep
|
---|
385 | ;;
|
---|
386 | [\\/]* | ?:[\\/]*) # Absolute paths don't need to be expansed.
|
---|
387 | TEXINPUTS=$TEXINPUTS$path_sep$dir
|
---|
388 | ;;
|
---|
389 | *)
|
---|
390 | abs=`cd "$dir" && pwd` && TEXINPUTS=$TEXINPUTS$path_sep$abs
|
---|
391 | ;;
|
---|
392 | esac
|
---|
393 | done
|
---|
394 | set x $INDEXSTYLE; shift
|
---|
395 | INDEXSTYLE=.
|
---|
396 | for dir
|
---|
397 | do
|
---|
398 | case $dir in
|
---|
399 | EMPTY)
|
---|
400 | INDEXSTYLE=$INDEXSTYLE$path_sep
|
---|
401 | ;;
|
---|
402 | [\\/]* | ?:[\\/]*) # Absolute paths don't need to be expansed.
|
---|
403 | INDEXSTYLE=$INDEXSTYLE$path_sep$dir
|
---|
404 | ;;
|
---|
405 | *)
|
---|
406 | abs=`cd "$dir" && pwd` && INDEXSTYLE=$INDEXSTYLE$path_sep$abs
|
---|
407 | ;;
|
---|
408 | esac
|
---|
409 | done
|
---|
410 | IFS=$save_IFS
|
---|
411 |
|
---|
412 | # If the user explicitly specified the language, use that.
|
---|
413 | # Otherwise, if the first line is \input texinfo, assume it's texinfo.
|
---|
414 | # Otherwise, guess from the file extension.
|
---|
415 | if test -n "$set_language"; then
|
---|
416 | language=$set_language
|
---|
417 | elif sed 1q "$command_line_filename" | grep 'input texinfo' >/dev/null; then
|
---|
418 | language=texinfo
|
---|
419 | else
|
---|
420 | language=
|
---|
421 | fi
|
---|
422 |
|
---|
423 | # Get the type of the file (latex or texinfo) from the given language
|
---|
424 | # we just guessed, or from the file extension if not set yet.
|
---|
425 | case ${language:-$filename_ext} in
|
---|
426 | [lL]a[tT]e[xX] | *.ltx | *.tex)
|
---|
427 | # Assume a LaTeX file. LaTeX needs bibtex and uses latex for
|
---|
428 | # compilation. No makeinfo.
|
---|
429 | bibtex=${BIBTEX:-bibtex}
|
---|
430 | makeinfo= # no point in running makeinfo on latex source.
|
---|
431 | texindex=${MAKEINDEX:-makeindex}
|
---|
432 | if test $oformat = dvi; then
|
---|
433 | tex=${LATEX:-latex}
|
---|
434 | else
|
---|
435 | tex=${PDFLATEX:-pdflatex}
|
---|
436 | fi
|
---|
437 | ;;
|
---|
438 |
|
---|
439 | *)
|
---|
440 | # Assume a Texinfo file. Texinfo files need makeinfo, texindex and tex.
|
---|
441 | bibtex=
|
---|
442 | texindex=${TEXINDEX:-texindex}
|
---|
443 | if test $oformat = dvi; then
|
---|
444 | tex=${TEX:-tex}
|
---|
445 | else
|
---|
446 | tex=${PDFTEX:-pdftex}
|
---|
447 | fi
|
---|
448 | # Unless required by the user, makeinfo expansion is wanted only
|
---|
449 | # if texinfo.tex is too old.
|
---|
450 | if test "$expand" = t; then
|
---|
451 | makeinfo=${MAKEINFO:-makeinfo}
|
---|
452 | else
|
---|
453 | # Check if texinfo.tex performs macro expansion by looking for
|
---|
454 | # its version. The version is a date of the form YEAR-MO-DA.
|
---|
455 | # We don't need to use [0-9] to match the digits since anyway
|
---|
456 | # the comparison with $txiprereq, a number, will fail with non
|
---|
457 | # digits.
|
---|
458 | txiversion_tex=txiversion.tex
|
---|
459 | echo '\input texinfo.tex @bye' >$tmpdir/$txiversion_tex
|
---|
460 | # Run in the tmpdir to avoid leaving files.
|
---|
461 | eval `cd $tmpdir >/dev/null &&
|
---|
462 | $tex $txiversion_tex 2>/dev/null |
|
---|
463 | sed -n 's/^.*\[\(.*\)version \(....\)-\(..\)-\(..\).*$/txiformat=\1 txiversion="\2\3\4"/p'`
|
---|
464 | $verbose "texinfo.tex preloaded as \`$txiformat', version is \`$txiversion' ..."
|
---|
465 | if test "$txiprereq" -le "$txiversion" >/dev/null 2>&1; then
|
---|
466 | makeinfo=
|
---|
467 | else
|
---|
468 | makeinfo=${MAKEINFO:-makeinfo}
|
---|
469 | fi
|
---|
470 | # As long as we had to run TeX, offer the user this convenience
|
---|
471 | if test "$txiformat" = Texinfo; then
|
---|
472 | escape=@
|
---|
473 | fi
|
---|
474 | fi
|
---|
475 | ;;
|
---|
476 | esac
|
---|
477 |
|
---|
478 | # Expand macro commands in the original source file using Makeinfo.
|
---|
479 | # Always use `end' footnote style, since the `separate' style
|
---|
480 | # generates different output (arguably this is a bug in -E).
|
---|
481 | # Discard main info output, the user asked to run TeX, not makeinfo.
|
---|
482 | if test -n "$makeinfo"; then
|
---|
483 | $verbose "Macro-expanding $command_line_filename to $filename_src ..."
|
---|
484 | sed -f $comment_iftex_sed "$command_line_filename" \
|
---|
485 | | $makeinfo --footnote-style=end -I "$filename_dir" $miincludes \
|
---|
486 | -o /dev/null --macro-expand=- \
|
---|
487 | | sed -f $uncomment_iftex_sed >"$filename_src"
|
---|
488 | filename_input=$filename_src
|
---|
489 | fi
|
---|
490 |
|
---|
491 | # If makeinfo failed (or was not even run), use the original file as input.
|
---|
492 | if test $? -ne 0 \
|
---|
493 | || test ! -r "$filename_src"; then
|
---|
494 | $verbose "Reverting to $command_line_filename ..."
|
---|
495 | filename_input=$filename_dir/$filename_ext
|
---|
496 | fi
|
---|
497 |
|
---|
498 | # Used most commonly for @finalout, @smallbook, etc.
|
---|
499 | if test -n "$textra"; then
|
---|
500 | $verbose "Inserting extra commands: $textra"
|
---|
501 | sed '/^@setfilename/a\
|
---|
502 | '"$textra" "$filename_input" >$filename_xtr
|
---|
503 | filename_input=$filename_xtr
|
---|
504 | fi
|
---|
505 |
|
---|
506 | # If clean mode was specified, then move to the temporary directory.
|
---|
507 | if test "$clean" = t; then
|
---|
508 | $verbose "cd $tmpdir_src"
|
---|
509 | cd "$tmpdir_src" || exit 1
|
---|
510 | fi
|
---|
511 |
|
---|
512 | while :; do # will break out of loop below
|
---|
513 | orig_xref_files=`$get_xref_files "$filename_noext"`
|
---|
514 |
|
---|
515 | # Save copies of originals for later comparison.
|
---|
516 | if test -n "$orig_xref_files"; then
|
---|
517 | $verbose "Backing up xref files: `echo $orig_xref_files | sed 's|\./||g'`"
|
---|
518 | cp $orig_xref_files $tmpdir_bak
|
---|
519 | fi
|
---|
520 |
|
---|
521 | # Run bibtex on current file.
|
---|
522 | # - If its input (AUX) exists.
|
---|
523 | # - If AUX contains both `\bibdata' and `\bibstyle'.
|
---|
524 | # - If some citations are missing (LOG contains `Citation').
|
---|
525 | # or the LOG complains of a missing .bbl
|
---|
526 | #
|
---|
527 | # We run bibtex first, because I can see reasons for the indexes
|
---|
528 | # to change after bibtex is run, but I see no reason for the
|
---|
529 | # converse.
|
---|
530 | #
|
---|
531 | # Don't try to be too smart. Running bibtex only if the bbl file
|
---|
532 | # exists and is older than the LaTeX file is wrong, since the
|
---|
533 | # document might include files that have changed. Because there
|
---|
534 | # can be several AUX (if there are \include's), but a single LOG,
|
---|
535 | # looking for missing citations in LOG is easier, though we take
|
---|
536 | # the risk to match false messages.
|
---|
537 | if test -n "$bibtex" \
|
---|
538 | && test -r "$filename_noext.aux" \
|
---|
539 | && test -r "$filename_noext.log" \
|
---|
540 | && (grep '^\\bibdata[{]' "$filename_noext.aux" \
|
---|
541 | && grep '^\\bibstyle[{]' "$filename_noext.aux" \
|
---|
542 | && (grep 'Warning:.*Citation.*undefined' "$filename_noext.log" \
|
---|
543 | || grep 'No file .*\.bbl\.' "$filename_noext.log")) \
|
---|
544 | >/dev/null 2>&1; \
|
---|
545 | then
|
---|
546 | $verbose "Running $bibtex $filename_noext ..."
|
---|
547 | if $bibtex "$filename_noext" >&5; then :; else
|
---|
548 | echo "$0: $bibtex exited with bad status, quitting." >&2
|
---|
549 | exit 1
|
---|
550 | fi
|
---|
551 | fi
|
---|
552 |
|
---|
553 | # What we'll run texindex on -- exclude non-index files.
|
---|
554 | # Since we know index files are last, it is correct to remove everything
|
---|
555 | # before .aux and .?o?. But don't really do <anything>o<anything>
|
---|
556 | # -- don't match whitespace as <anything>.
|
---|
557 | # Otherwise, if orig_xref_files contains something like
|
---|
558 | # foo.xo foo.whatever
|
---|
559 | # the space after the o will get matched.
|
---|
560 | index_files=`echo "$orig_xref_files" \
|
---|
561 | | sed "s!.*\.aux!!g;
|
---|
562 | s!./$filename_noext\.[^ ]o[^ ]!!g;
|
---|
563 | s/^[ ]*//;s/[ ]*$//"`
|
---|
564 | # Run texindex (or makeindex) on current index files. If they
|
---|
565 | # already exist, and after running TeX a first time the index
|
---|
566 | # files don't change, then there's no reason to run TeX again.
|
---|
567 | # But we won't know that if the index files are out of date or
|
---|
568 | # nonexistent.
|
---|
569 | if test -n "$texindex" && test -n "$index_files"; then
|
---|
570 | $verbose "Running $texindex $index_files ..."
|
---|
571 | if $texindex $index_files 2>&5 1>&2; then :; else
|
---|
572 | echo "$0: $texindex exited with bad status, quitting." >&2
|
---|
573 | exit 1
|
---|
574 | fi
|
---|
575 | fi
|
---|
576 |
|
---|
577 | # Finally, run TeX.
|
---|
578 | # Prevent $ESCAPE from being interpreted by the shell if it happens
|
---|
579 | # to be `/'.
|
---|
580 | $batch tex_args="\\${escape}nonstopmode\ \\${escape}input"
|
---|
581 | cmd="$tex $tex_args $filename_input"
|
---|
582 | $verbose "Running $cmd ..."
|
---|
583 | if $cmd >&5; then :; else
|
---|
584 | echo "$0: $tex exited with bad status, quitting." >&2
|
---|
585 | echo "$0: see $filename_noext.log for errors." >&2
|
---|
586 | test "$clean" = t \
|
---|
587 | && cp "$filename_noext.log" "$orig_pwd"
|
---|
588 | exit 1
|
---|
589 | fi
|
---|
590 |
|
---|
591 |
|
---|
592 | # Decide if looping again is needed.
|
---|
593 | finished=t
|
---|
594 |
|
---|
595 | # LaTeX (and the package changebar) report in the LOG file if it
|
---|
596 | # should be rerun. This is needed for files included from
|
---|
597 | # subdirs, since texi2dvi does not try to compare xref files in
|
---|
598 | # subdirs. Performing xref files test is still good since LaTeX
|
---|
599 | # does not report changes in xref files.
|
---|
600 | if grep "Rerun to get" "$filename_noext.log" >/dev/null 2>&1; then
|
---|
601 | finished=
|
---|
602 | fi
|
---|
603 |
|
---|
604 | # Check if xref files changed.
|
---|
605 | new_xref_files=`$get_xref_files "$filename_noext"`
|
---|
606 | $verbose "Original xref files = `echo $orig_xref_files | sed 's|\./||g'`"
|
---|
607 | $verbose "New xref files = `echo $new_xref_files | sed 's|\./||g'`"
|
---|
608 |
|
---|
609 | # If old and new lists don't at least have the same file list,
|
---|
610 | # then one file or another has definitely changed.
|
---|
611 | test "x$orig_xref_files" != "x$new_xref_files" && finished=
|
---|
612 |
|
---|
613 | # File list is the same. We must compare each file until we find
|
---|
614 | # a difference.
|
---|
615 | if test -n "$finished"; then
|
---|
616 | for this_file in $new_xref_files; do
|
---|
617 | $verbose "Comparing xref file `echo $this_file | sed 's|\./||g'` ..."
|
---|
618 | # cmp -s returns nonzero exit status if files differ.
|
---|
619 | if cmp -s "$this_file" "$tmpdir_bak/$this_file"; then :; else
|
---|
620 | # We only need to keep comparing until we find one that
|
---|
621 | # differs, because we'll have to run texindex & tex again no
|
---|
622 | # matter how many more there might be.
|
---|
623 | finished=
|
---|
624 | $verbose "xref file `echo $this_file | sed 's|\./||g'` differed ..."
|
---|
625 | test "$debug" = t && diff -c "$tmpdir_bak/$this_file" "$this_file"
|
---|
626 | break
|
---|
627 | fi
|
---|
628 | done
|
---|
629 | fi
|
---|
630 |
|
---|
631 | # If finished, exit the loop, else rerun the loop.
|
---|
632 | test -n "$finished" && break
|
---|
633 | done
|
---|
634 |
|
---|
635 | # If we were in clean mode, compilation was in a tmp directory.
|
---|
636 | # Copy the DVI (or PDF) file into the directory where the compilation
|
---|
637 | # has been done. (The temp dir is about to get removed anyway.)
|
---|
638 | # We also return to the original directory so that
|
---|
639 | # - the next file is processed in correct conditions
|
---|
640 | # - the temporary file can be removed
|
---|
641 | if test -n "$clean"; then
|
---|
642 | if test -n "$oname"; then
|
---|
643 | dest=$oname
|
---|
644 | else
|
---|
645 | dest=$orig_pwd
|
---|
646 | fi
|
---|
647 | $verbose "Copying $oformat file from `pwd` to $dest"
|
---|
648 | cp -p "./$filename_noext.$oformat" "$dest"
|
---|
649 | cd / # in case $orig_pwd is on a different drive (for DOS)
|
---|
650 | cd $orig_pwd || exit 1
|
---|
651 | fi
|
---|
652 |
|
---|
653 | # Remove temporary files.
|
---|
654 | if test "x$debug" = "x"; then
|
---|
655 | $verbose "Removing $tmpdir_src $tmpdir_xtr $tmpdir_bak ..."
|
---|
656 | cd /
|
---|
657 | rm -rf $tmpdir_src $tmpdir_xtr $tmpdir_bak
|
---|
658 | fi
|
---|
659 | done
|
---|
660 |
|
---|
661 | $verbose "$0 done."
|
---|
662 | exit 0 # exit successfully, not however we ended the loop.
|
---|