2
# texi2dvi --- produce DVI (or PDF) files from Texinfo (or LaTeX) sources.
3
# $Id: texi2dvi,v 0.43 1999/09/28 19:36:53 karl Exp $
5
# Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2, or (at your option)
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, you can either send email to this
19
# program's maintainer or write to: The Free Software Foundation,
20
# Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
22
# Original author: Noah Friedman <friedman@gnu.org>.
24
# Please send bug reports, etc. to bug-texinfo@gnu.org.
25
# If possible, please send a copy of the output of the script called with
26
# the `--debug' option when making a bug report.
28
# This string is expanded by rcs automatically when this file is checked out.
29
rcs_revision='$Revision: 0.43 $'
30
rcs_version=`set - $rcs_revision; echo $2`
31
program=`echo $0 | sed -e 's!.*/!!'`
32
version="texi2dvi (GNU Texinfo 4.0) $rcs_version
34
Copyright (C) 1999 Free Software Foundation, Inc.
35
There is NO warranty. You may redistribute this software
36
under the terms of the GNU General Public License.
37
For more information about these matters, see the files named COPYING."
40
Usage: $program [OPTION]... FILE...
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).
47
Makeinfo is used to perform Texinfo macro expansion before running TeX
51
-h, --help display this help and exit successfully
52
-v, --version display version information and exit successfully
53
-V, --verbose report on what is done
54
-q, --quiet no output unless errors (implies --batch)
55
-s, --silent same as --quiet
56
-D, --debug turn on shell debugging (set -x)
57
-b, --batch no interaction
58
-c, --clean remove all auxiliary files
59
-o, --output=FILE leave output in FILE (implies --clean)
61
Only one FILE may be specified if \`--output' is used.
65
-@ use @input instead of \input; for preloaded Texinfo
66
-e, --expand force macro expansion using makeinfo
67
-I DIR search DIR for Texinfo files
68
-l, --language=LANG specify the LANG of FILE (LaTeX or Texinfo)
69
-p, --pdf use pdftex or pdflatex for processing
70
-t, --texinfo=CMD insert CMD after @setfilename in copy of input file
71
multiple values accumulate
73
The values of the BIBTEX, LATEX (or PDFLATEX), MAKEINDEX, MAKEINFO,
74
TEX (or PDFTEX), and TEXINDEX environment variables are used to run
75
those commands, if they are set.
77
Email bug reports to <bug-texinfo@gnu.org>,
78
general questions and discussion to <help-texinfo@gnu.org>."
80
# Initialize variables for option overriding and otherwise.
81
# Don't use `unset' since old bourne shells don't have this command.
82
# Instead, assign them an empty value.
83
batch=false # eval for batch mode
87
expand= # t for expansion via makeinfo
88
miincludes= # makeinfo include path
91
quiet= # by default let the tools' message be displayed
94
tmpdir=${TMPDIR:-/tmp}/t2d$$ # avoid collisions on 8.3 filesystems.
95
txincludes= # TEXINPUTS extensions
96
txiprereq=19990129 # minimum texinfo.tex version to have macro expansion
97
verbose=false # echo for verbose mode
101
# Systems which define $COMSPEC or $ComSpec use semicolons to separate
102
# directories in TEXINPUTS.
103
if test -n "$COMSPEC$ComSpec"; then
109
# Save this so we can construct a new TEXINPUTS path for each file.
110
TEXINPUTS_orig="$TEXINPUTS"
111
# Unfortunately makeindex does not read TEXINPUTS.
112
INDEXSTYLE_orig="$INDEXSTYLE"
113
export TEXINPUTS INDEXSTYLE
115
# Push a token among the arguments that will be used to notice when we
116
# ended options/arguments parsing.
117
# Use "set dummy ...; shift" rather than 'set - ..." because on
118
# Solaris set - turns off set -x (but keeps set -e).
119
# Use ${1+"$@"} rather than "$@" because Digital Unix and Ultrix 4.3
120
# still expand "$@" to a single argument (the empty string) rather
121
# than nothing at all.
123
set dummy ${1+"$@"} "$arg_sep"; shift
126
# Parse command line arguments.
127
while test x"$1" != x"$arg_sep"; do
129
# Handle --option=value by splitting apart and putting back on argv.
132
opt=`echo "$1" | sed -e 's/=.*//'`
133
val=`echo "$1" | sed -e 's/[^=]*=//'`
135
set dummy "$opt" "$val" ${1+"$@"}; shift
139
# This recognizes --quark as --quiet. So what.
142
# Silently and without documentation accept -b and --b[atch] as synonyms.
143
-b | --b*) batch=eval;;
144
-q | -s | --q* | --s*) quiet=t; batch=eval;;
147
-e | --e*) expand=t;;
148
-h | --h*) echo "$usage"; exit 0;;
151
miincludes="$miincludes -I $1"
152
txincludes="$txincludes$path_sep$1"
154
-l | --l*) shift; set_language=$1;;
159
/* | ?:/*) oname=$1;;
160
*) oname="$orig_pwd/$1";;
162
-p | --p*) oformat=pdf;;
163
-t | --t*) shift; textra="$textra\\
165
-v | --vers*) echo "$version"; exit 0;;
166
-V | --verb*) verbose=echo;;
167
--) # What remains are not options.
169
while test x"$1" != x"$arg_sep"; do
170
set dummy ${1+"$@"} "$1"; shift
175
echo "$0: Unknown or ambiguous option \`$1'." >&2
176
echo "$0: Try \`--help' for more information." >&2
178
*) set dummy ${1+"$@"} "$1"; shift;;
185
# Interpret remaining command line args as filenames.
188
echo "$0: Missing file arguments." >&2
189
echo "$0: Try \`--help' for more information." >&2
194
if test -n "$oname"; then
195
echo "$0: Can't use option \`--output' with more than one argument." >&2
201
# Prepare the temporary directory. Remove it at exit, unless debugging.
202
if test -z "$debug"; then
203
trap "cd / && rm -rf $tmpdir" 0 1 2 15
206
# Create the temporary directory with strict rights
207
(umask 077 && mkdir $tmpdir) || exit 1
209
# Prepare the tools we might need. This may be extra work in some
210
# cases, but improves the readibility of the script.
211
utildir=$tmpdir/utils
212
mkdir $utildir || exit 1
214
# A sed script that preprocesses Texinfo sources in order to keep the
215
# iftex sections only. We want to remove non TeX sections, and
216
# comment (with `@c texi2dvi') TeX sections so that makeinfo does not
217
# try to parse them. Nevertheless, while commenting TeX sections,
218
# don't comment @macro/@end macro so that makeinfo does propagate
219
# them. Unfortunately makeinfo --iftex --no-ifhtml --no-ifinfo
220
# doesn't work well enough (yet) to use that, so work around with sed.
221
comment_iftex_sed=$utildir/comment.sed
222
cat <<EOF >$comment_iftex_sed
226
/^@iftex/,/^@end iftex/{
228
/^@c texi2dvi@macro/,/^@c texi2dvi@end macro/{
232
/^@html/,/^@end html/d
233
/^@ifhtml/,/^@end ifhtml/d
234
/^@ifnottex/,/^@end ifnottex/d
235
/^@ifinfo/,/^@end ifinfo/{
237
/^@menu/,/^@end menu/p
241
# Uncommenting is simple: Remove any leading `@c texi2dvi'.
242
uncomment_iftex_sed=$utildir/uncomment.sed
243
cat <<EOF >$uncomment_iftex_sed
247
# A shell script that computes the list of xref files.
248
# Takes the filename (without extension) of which we look for xref
249
# files as argument. The index files must be reported last.
250
get_xref_files=$utildir/get_xref.sh
251
cat <<\EOF >$get_xref_files
254
# Get list of xref files (indexes, tables and lists).
255
# Find all files having root filename with a two-letter extension,
256
# saves the ones that are really Texinfo-related files. .?o? catches
257
# LaTeX tables and lists.
258
for this_file in "$1".?o? "$1".aux "$1".?? "$1".idx; do
259
# If file is empty, skip it.
260
test -s "$this_file" || continue
261
# If the file is not suitable to be an index or xref file, don't
262
# process it. The file can't be if its first character is not a
263
# backslash or single quote.
264
first_character=`sed -n '1s/^\(.\).*$/\1/p;q' $this_file`
265
if test "x$first_character" = "x\\" \
266
|| test "x$first_character" = "x'"; then
267
xref_files="$xref_files ./$this_file"
272
chmod 500 $get_xref_files
274
# File descriptor usage:
276
# 1 standard output (--verbose messages)
278
# 3 some systems may open it to /dev/tty
279
# 4 used on the Kubota Titan
280
# 5 tools output (turned off by --quiet)
282
# Tools' output. If quiet, discard, else redirect to the message flow.
283
if test "$quiet" = t; then
290
test "$debug" = t && set -x
295
for command_line_filename in ${1+"$@"}; do
296
$verbose "Processing $command_line_filename ..."
298
# If the COMMAND_LINE_FILENAME is not absolute (e.g., --debug.tex),
299
# prepend `./' in order to avoid that the tools take it as an option.
300
echo "$command_line_filename" | egrep '^(/|[A-z]:/)' >/dev/null \
301
|| command_line_filename="./$command_line_filename"
303
# See if the file exists. If it doesn't we're in trouble since, even
304
# though the user may be able to reenter a valid filename at the tex
305
# prompt (assuming they're attending the terminal), this script won't
306
# be able to find the right xref files and so forth.
307
if test ! -r "$command_line_filename"; then
308
echo "$0: Could not read $command_line_filename, skipping." >&2
312
# Get the name of the current directory. We want the full path
313
# because in clean mode we are in tmp, in which case a relative
314
# path has no meaning.
315
filename_dir=`echo $command_line_filename | sed 's!/[^/]*$!!;s!^$!.!'`
316
filename_dir=`cd "$filename_dir" >/dev/null && pwd`
318
# Strip directory part but leave extension.
319
filename_ext=`basename "$command_line_filename"`
321
filename_noext=`echo "$filename_ext" | sed 's/\.[^.]*$//'`
322
ext=`echo "$filename_ext" | sed 's/^.*\.//'`
324
# _src. Use same basename since we want to generate aux files with
325
# the same basename as the manual. If --expand, then output the
326
# macro-expanded file to here, else copy the original file.
327
tmpdir_src=$tmpdir/src
328
filename_src=$tmpdir_src/$filename_noext.$ext
330
# _xtr. The file with the user's extra commands.
331
tmpdir_xtr=$tmpdir/xtr
332
filename_xtr=$tmpdir_xtr/$filename_noext.$ext
334
# _bak. Copies of the previous xref files (another round is run if
335
# they differ from the new one).
336
tmpdir_bak=$tmpdir/bak
338
# Make all those directories and give up if we can't succeed.
339
mkdir $tmpdir_src $tmpdir_xtr $tmpdir_bak || exit 1
341
# Source file might include additional sources. Put `.' and
342
# directory where source file(s) reside in TEXINPUTS before anything
343
# else. `.' goes first to ensure that any old .aux, .cps,
344
# etc. files in ${directory} don't get used in preference to fresher
345
# files in `.'. Include orig_pwd in case we are in clean mode, where
346
# we've cd'd to a temp directory.
347
common=".$path_sep$orig_pwd$path_sep$filename_dir$path_sep$txincludes$path_sep"
348
TEXINPUTS="$common$TEXINPUTS_orig"
349
INDEXSTYLE="$common$INDEXSTYLE_orig"
351
# If the user explicitly specified the language, use that.
352
# Otherwise, if the first line is \input texinfo, assume it's texinfo.
353
# Otherwise, guess from the file extension.
354
if test -n "$set_language"; then
355
language=$set_language
356
elif sed 1q "$command_line_filename" | fgrep 'input texinfo' >/dev/null; then
362
# Get the type of the file (latex or texinfo) from the given language
363
# we just guessed, or from the file extension if not set yet.
364
case ${language:-$filename_ext} in
365
[lL]a[tT]e[xX] | *.ltx | *.tex)
366
# Assume a LaTeX file. LaTeX needs bibtex and uses latex for
367
# compilation. No makeinfo.
368
bibtex=${BIBTEX:-bibtex}
369
makeinfo= # no point in running makeinfo on latex source.
370
texindex=${MAKEINDEX:-makeindex}
371
if test $oformat = dvi; then
374
tex=${PDFLATEX:-pdflatex}
379
# Assume a Texinfo file. Texinfo files need makeinfo, texindex and tex.
381
texindex=${TEXINDEX:-texindex}
382
if test $oformat = dvi; then
385
tex=${PDFTEX:-pdftex}
387
# Unless required by the user, makeinfo expansion is wanted only
388
# if texinfo.tex is too old.
389
if test "$expand" = t; then
390
makeinfo=${MAKEINFO:-makeinfo}
392
# Check if texinfo.tex performs macro expansion by looking for
393
# its version. The version is a date of the form YEAR-MO-DA.
394
# We don't need to use [0-9] to match the digits since anyway
395
# the comparison with $txiprereq, a number, will fail with non
397
txiversion_tex=txiversion.tex
398
echo '\input texinfo.tex @bye' >$tmpdir/$txiversion_tex
399
# Run in the tmpdir to avoid leaving files.
400
eval `cd $tmpdir >/dev/null &&
401
$tex $txiversion_tex 2>/dev/null |
402
sed -n 's/^.*\[\(.*\)version \(....\)-\(..\)-\(..\).*$/txiformat=\1 txiversion="\2\3\4"/p'`
403
$verbose "texinfo.tex preloaded as \`$txiformat', version is \`$txiversion' ..."
404
if test "$txiprereq" -le "$txiversion" >/dev/null 2>&1; then
407
makeinfo=${MAKEINFO:-makeinfo}
409
# As long as we had to run TeX, offer the user this convenience
410
if test "$txiformat" = Texinfo; then
417
# Expand macro commands in the original source file using Makeinfo.
418
# Always use `end' footnote style, since the `separate' style
419
# generates different output (arguably this is a bug in -E).
420
# Discard main info output, the user asked to run TeX, not makeinfo.
421
if test -n "$makeinfo"; then
422
$verbose "Macro-expanding $command_line_filename to $filename_src ..."
423
sed -f $comment_iftex_sed "$command_line_filename" \
424
| $makeinfo --footnote-style=end -I "$filename_dir" $miincludes \
425
-o /dev/null --macro-expand=- \
426
| sed -f $uncomment_iftex_sed >"$filename_src"
427
filename_input=$filename_src
430
# If makeinfo failed (or was not even run), use the original file as input.
432
|| test ! -r "$filename_src"; then
433
$verbose "Reverting to $command_line_filename ..."
434
filename_input=$filename_dir/$filename_ext
437
# Used most commonly for @finalout, @smallbook, etc.
438
if test -n "$textra"; then
439
$verbose "Inserting extra commands: $textra"
440
sed '/^@setfilename/a\
441
'"$textra" "$filename_input" >$filename_xtr
442
filename_input=$filename_xtr
445
# If clean mode was specified, then move to the temporary directory.
446
if test "$clean" = t; then
447
$verbose "cd $tmpdir_src"
448
cd "$tmpdir_src" || exit 1
451
while :; do # will break out of loop below
452
orig_xref_files=`$get_xref_files "$filename_noext"`
454
# Save copies of originals for later comparison.
455
if test -n "$orig_xref_files"; then
456
$verbose "Backing up xref files: `echo $orig_xref_files | sed 's|\./||g'`"
457
cp $orig_xref_files $tmpdir_bak
460
# Run bibtex on current file.
461
# - If its input (AUX) exists.
462
# - If AUX contains both `\bibdata' and `\bibstyle'.
463
# - If some citations are missing (LOG contains `Citation').
464
# or the LOG complains of a missing .bbl
466
# We run bibtex first, because I can see reasons for the indexes
467
# to change after bibtex is run, but I see no reason for the
470
# Don't try to be too smart. Running bibtex only if the bbl file
471
# exists and is older than the LaTeX file is wrong, since the
472
# document might include files that have changed. Because there
473
# can be several AUX (if there are \include's), but a single LOG,
474
# looking for missing citations in LOG is easier, though we take
475
# the risk to match false messages.
476
if test -n "$bibtex" \
477
&& test -r "$filename_noext.aux" \
478
&& test -r "$filename_noext.log" \
479
&& (grep '^\\bibdata[{]' "$filename_noext.aux" \
480
&& grep '^\\bibstyle[{]' "$filename_noext.aux" \
481
&& (grep 'Warning:.*Citation.*undefined' "$filename_noext.log" \
482
|| grep 'No file .*\.bbl\.' "$filename_noext.log")) \
485
$verbose "Running $bibtex $filename_noext ..."
486
if $bibtex "$filename_noext" >&5; then :; else
487
echo "$0: $bibtex exited with bad status, quitting." >&2
492
# What we'll run texindex on -- exclude non-index files.
493
# Since we know index files are last, it is correct to remove everything
494
# before .aux and .?o?.
495
index_files=`echo "$orig_xref_files" \
497
s!./$filename_noext\..o.!!g;
498
s/^[ ]*//;s/[ ]*$//"`
499
# Run texindex (or makeindex) on current index files. If they
500
# already exist, and after running TeX a first time the index
501
# files don't change, then there's no reason to run TeX again.
502
# But we won't know that if the index files are out of date or
504
if test -n "$texindex" && test -n "$index_files"; then
505
$verbose "Running $texindex $index_files ..."
506
if $texindex $index_files 2>&5 1>&2; then :; else
507
echo "$0: $texindex exited with bad status, quitting." >&2
513
# Prevent $ESCAPE from being interpreted by the shell if it happens
515
$batch tex_args="\\${escape}nonstopmode\ \\${escape}input"
516
$verbose "Running $cmd ..."
517
cmd="$tex $tex_args $filename_input"
518
if $cmd >&5; then :; else
519
echo "$0: $tex exited with bad status, quitting." >&2
520
echo "$0: see $filename_noext.log for errors." >&2
522
&& cp "$filename_noext.log" "$orig_pwd"
527
# Decide if looping again is needed.
530
# LaTeX (and the package changebar) report in the LOG file if it
531
# should be rerun. This is needed for files included from
532
# subdirs, since texi2dvi does not try to compare xref files in
533
# subdirs. Performing xref files test is still good since LaTeX
534
# does not report changes in xref files.
535
if fgrep "Rerun to get" "$filename_noext.log" >/dev/null 2>&1; then
539
# Check if xref files changed.
540
new_xref_files=`$get_xref_files "$filename_noext"`
541
$verbose "Original xref files = `echo $orig_xref_files | sed 's|\./||g'`"
542
$verbose "New xref files = `echo $new_xref_files | sed 's|\./||g'`"
544
# If old and new lists don't at least have the same file list,
545
# then one file or another has definitely changed.
546
test "x$orig_xref_files" != "x$new_xref_files" && finished=
548
# File list is the same. We must compare each file until we find
550
if test -n "$finished"; then
551
for this_file in $new_xref_files; do
552
$verbose "Comparing xref file `echo $this_file | sed 's|\./||g'` ..."
553
# cmp -s returns nonzero exit status if files differ.
554
if cmp -s "$this_file" "$tmpdir_bak/$this_file"; then :; else
555
# We only need to keep comparing until we find one that
556
# differs, because we'll have to run texindex & tex again no
557
# matter how many more there might be.
559
$verbose "xref file `echo $this_file | sed 's|\./||g'` differed ..."
560
test "$debug" = t && diff -c "$tmpdir_bak/$this_file" "$this_file"
566
# If finished, exit the loop, else rerun the loop.
567
test -n "$finished" && break
570
# If we were in clean mode, compilation was in a tmp directory.
571
# Copy the DVI (or PDF) file into the directory where the compilation
572
# has been done. (The temp dir is about to get removed anyway.)
573
# We also return to the original directory so that
574
# - the next file is processed in correct conditions
575
# - the temporary file can be removed
576
if test -n "$clean"; then
577
if test -n "$oname"; then
582
$verbose "Copying $oformat file from `pwd` to $dest"
583
cp -p "./$filename_noext.$oformat" "$dest"
584
cd / # in case $orig_pwd is on a different drive (for DOS)
585
cd $orig_pwd || exit 1
588
# Remove temporary files.
589
if test "x$debug" = "x"; then
590
$verbose "Removing $tmpdir_src $tmpdir_xtr $tmpdir_bak ..."
592
rm -rf $tmpdir_src $tmpdir_xtr $tmpdir_bak
597
exit 0 # exit successfully, not however we ended the loop.