2
2
# texi2dvi --- produce DVI (or PDF) files from Texinfo (or LaTeX) sources.
3
# $Id: texi2dvi,v 0.47 2002/03/04 16:50:32 karl Exp $
3
# $Id: texi2dvi,v 1.34 2004/12/01 18:35:36 karl Exp $
5
# Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 99, 2001, 02
6
# Free Software Foundation, Inc.
5
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001,
6
# 2002, 2003, 2004 Free Software Foundation, Inc.
8
8
# This program is free software; you can redistribute it and/or modify
9
9
# it under the terms of the GNU General Public License as published by
20
20
# program's maintainer or write to: The Free Software Foundation,
21
21
# Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
23
# Original author: Noah Friedman <friedman@gnu.org>.
23
# Original author: Noah Friedman.
25
25
# Please send bug reports, etc. to bug-texinfo@gnu.org.
26
26
# If possible, please send a copy of the output of the script called with
27
27
# the `--debug' option when making a bug report.
29
29
# This string is expanded by rcs automatically when this file is checked out.
30
rcs_revision='$Revision: 0.47 $'
30
rcs_revision='$Revision: 1.34 $'
31
31
rcs_version=`set - $rcs_revision; echo $2`
32
32
program=`echo $0 | sed -e 's!.*/!!'`
33
version="texi2dvi (GNU Texinfo 4.1) $rcs_version
33
version="texi2dvi (GNU Texinfo 4.8) $rcs_version
35
Copyright (C) 2002 Free Software Foundation, Inc.
35
Copyright (C) 2004 Free Software Foundation, Inc.
36
36
There is NO warranty. You may redistribute this software
37
37
under the terms of the GNU General Public License.
38
38
For more information about these matters, see the files named COPYING."
63
63
-@ use @input instead of \input; for preloaded Texinfo
64
-e, --expand force macro expansion using makeinfo
64
-e, -E, --expand force macro expansion using makeinfo
65
65
-I DIR search DIR for Texinfo files
66
66
-l, --language=LANG specify the LANG of FILE (LaTeX or Texinfo)
67
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
68
-r, --recode call recode before TeX to translate input characters
69
-t, --command=CMD insert CMD in copy of input file
70
or --texinfo=CMD multiple values accumulate
71
72
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.
73
TEX (or PDFTEX), TEXINDEX, and THUMBPDF environment variables are used
74
to run those commands, if they are set. Any CMD strings are added
75
after @setfilename for Texinfo input, in the first line for LaTeX input.
75
77
Email bug reports to <bug-texinfo@gnu.org>,
76
general questions and discussion to <help-texinfo@gnu.org>."
78
general questions and discussion to <help-texinfo@gnu.org>.
79
Texinfo home page: http://www.gnu.org/software/texinfo/"
78
81
# Initialize variables for option overriding and otherwise.
79
82
# Don't use `unset' since old bourne shells don't have this command.
85
88
expand= # t for expansion via makeinfo
86
89
miincludes= # makeinfo include path
89
92
quiet= # by default let the tools' message be displayed
95
textra= # Extra TeX commands to insert in the input file.
96
textra_cmd= # sed command to insert TEXTRA where appropriate
92
97
tmpdir=${TMPDIR:-/tmp}/t2d$$ # avoid collisions on 8.3 filesystems.
93
txincludes= # TEXINPUTS extensions
94
txiprereq=19990129 # minimum texinfo.tex version to have macro expansion
98
txincludes= # TEXINPUTS extensions, with trailing colon
99
txiprereq=19990129 # minimum texinfo.tex version with macro expansion
95
100
verbose=false # echo for verbose mode
107
# Save this so we can construct a new TEXINPUTS path for each file.
108
TEXINPUTS_orig="$TEXINPUTS"
109
# Unfortunately makeindex does not read TEXINPUTS.
110
INDEXSTYLE_orig="$INDEXSTYLE"
111
export TEXINPUTS INDEXSTYLE
112
# Pacify verbose cds.
113
CDPATH=${ZSH_VERSION+.}$path_sep
115
# In case someone crazy insists on using grep -E.
118
# return true if program $1 is somewhere in PATH, else false.
122
for dir in `echo $PATH | tr "$path_sep" " "`; do
123
if test -x "$dir/$1"; then # does anyone still need test -f?
131
# Report an error and exit with failure.
137
# Save TEXINPUTS so we can construct a new TEXINPUTS path for each file.
138
# Likewise for bibtex and makeindex.
139
tex_envvars="BIBINPUTS BSTINPUTS INDEXSTYLE TEXINPUTS"
140
for var in $tex_envvars; do
141
eval ${var}_orig=\$$var
113
146
# Push a token among the arguments that will be used to notice when we
114
147
# ended options/arguments parsing.
140
173
# Silently and without documentation accept -b and --b[atch] as synonyms.
141
-b | --b*) batch=eval;;
142
-q | -s | --q* | --s*) quiet=t; batch=eval;;
174
-b | --b*) batch=true;;
143
175
-c | --c*) clean=t;;
144
176
-D | --d*) debug=t;;
145
-e | --e*) expand=t;;
177
-e | -E | --e*) expand=t;;
146
178
-h | --h*) echo "$usage"; exit 0;;
149
181
miincludes="$miincludes -I $1"
150
txincludes="$txincludes$path_sep$1"
182
txincludes="$txincludes$1$path_sep"
152
184
-l | --l*) shift; set_language=$1;;
158
190
*) oname="$orig_pwd/$1";;
160
192
-p | --p*) oformat=pdf;;
161
-t | --t*) shift; textra="$textra\\
193
-q | -s | --q* | --s*) quiet=t; batch=true;;
194
-r | --r*) recode=true;;
195
-t | --tex* | --com* ) shift; textra="$textra\\
196
"`echo "$1" | sed 's/\\\\/\\\\\\\\/g'`;;
163
197
-v | --vers*) echo "$version"; exit 0;;
164
198
-V | --verb*) verbose=echo;;
165
199
--) # What remains are not options.
234
# We can't do much without tex.
236
if findprog ${TEX:-tex}; then :; else cat <<EOM
237
You don't have a working TeX binary (${TEX:-tex}) installed anywhere in
238
your PATH, and texi2dvi cannot proceed without one. If you want to use
239
this script, you'll need to install TeX (if you don't have it) or change
240
your PATH or TEX environment variable (if you do). See the --help
241
output for more details.
243
For information about obtaining TeX, please see http://www.tug.org. If
244
you happen to be using Debian, you can get it with this command:
245
apt-get install tetex-bin
251
# We want to use etex (or pdftex) if they are available, and the user
252
# didn't explicitly specify. We don't check for elatex and pdfelatex
253
# because (as of 2003), the LaTeX team has asked that new distributions
254
# use etex by default anyway.
256
# End up with the TEX and PDFTEX variables set to what we are going to use.
257
if test -z "$TEX"; then
258
if findprog etex; then TEX=etex; else TEX=tex; fi
261
if test -z "$PDFTEX"; then
262
if findprog pdfetex; then PDFTEX=pdfetex; else PDFTEX=pdftex; fi
199
266
# Prepare the temporary directory. Remove it at exit, unless debugging.
200
267
if test -z "$debug"; then
201
268
trap "cd / && rm -rf $tmpdir" 0 1 2 15
205
272
(umask 077 && mkdir $tmpdir) || exit 1
207
274
# Prepare the tools we might need. This may be extra work in some
208
# cases, but improves the readibility of the script.
275
# cases, but improves the readability of the script.
209
276
utildir=$tmpdir/utils
210
277
mkdir $utildir || exit 1
212
279
# A sed script that preprocesses Texinfo sources in order to keep the
213
# iftex sections only. We want to remove non TeX sections, and
214
# comment (with `@c texi2dvi') TeX sections so that makeinfo does not
215
# try to parse them. Nevertheless, while commenting TeX sections,
216
# don't comment @macro/@end macro so that makeinfo does propagate
217
# them. Unfortunately makeinfo --iftex --no-ifhtml --no-ifinfo
218
# doesn't work well enough (yet) to use that, so work around with sed.
280
# iftex sections only. We want to remove non TeX sections, and comment
281
# (with `@c texi2dvi') TeX sections so that makeinfo does not try to
282
# parse them. Nevertheless, while commenting TeX sections, don't
283
# comment @macro/@end macro so that makeinfo does propagate them.
284
# Unfortunately makeinfo --iftex --no-ifinfo doesn't work well enough
285
# (yet), makeinfo can't parse the TeX commands, so work around with sed.
219
287
comment_iftex_sed=$utildir/comment.sed
220
288
cat <<EOF >$comment_iftex_sed
221
289
/^@tex/,/^@end tex/{
254
# A shell script that computes the list of xref files.
316
# Compute the list of xref files.
255
317
# Takes the filename (without extension) of which we look for xref
256
318
# files as argument. The index files must be reported last.
257
get_xref_files=$utildir/get_xref.sh
258
cat <<\EOF >$get_xref_files
261
# Get list of xref files (indexes, tables and lists).
262
# Find all files having root filename with a two-letter extension,
263
# saves the ones that are really Texinfo-related files. .?o? catches
264
# LaTeX tables and lists.
265
for this_file in "$1".?o? "$1".aux "$1".?? "$1".idx; do
266
# If file is empty, skip it.
267
test -s "$this_file" || continue
268
# If the file is not suitable to be an index or xref file, don't
269
# process it. The file can't be if its first character is not a
270
# backslash or single quote.
271
first_character=`sed -n '1s/^\(.\).*$/\1/p;q' $this_file`
272
if test "x$first_character" = "x\\" \
273
|| test "x$first_character" = "x'"; then
274
xref_files="$xref_files ./$this_file"
279
chmod 500 $get_xref_files
321
# Get list of xref files (indexes, tables and lists).
322
# Find all files having root filename with a two-letter extension,
323
# saves the ones that are really Texinfo-related files. .?o? catches
324
# many files: .toc, .log, LaTeX tables and lists, FiXme's .lox, maybe more.
325
for this_file in "$1".?o? "$1".aux "$1".?? "$1".idx; do
326
# If file is empty, skip it.
327
test -s "$this_file" || continue
328
# If the file is not suitable to be an index or xref file, don't
329
# process it. It's suitable if the first character is a
330
# backslash or right quote or at, as long as the first line isn't
332
first_character=`sed -n '1s/^\(.\).*$/\1/p;q' $this_file`
333
if (test "x$first_character" = "x\\" \
334
&& sed 1q $this_file | grep -v '^\\input *texinfo' >/dev/null) \
335
|| test "x$first_character" = "x'" \
336
|| test "x$first_character" = "x@"; then
337
xref_files="$xref_files ./$this_file"
281
343
# File descriptor usage:
282
344
# 0 standard input
305
372
# If the COMMAND_LINE_FILENAME is not absolute (e.g., --debug.tex),
306
373
# prepend `./' in order to avoid that the tools take it as an option.
307
echo "$command_line_filename" | egrep '^(/|[A-z]:/)' >/dev/null \
374
echo "$command_line_filename" | $EGREP '^(/|[A-z]:/)' >&6 \
308
375
|| command_line_filename="./$command_line_filename"
310
377
# See if the file exists. If it doesn't we're in trouble since, even
338
405
tmpdir_xtr=$tmpdir/xtr
339
406
filename_xtr=$tmpdir_xtr/$filename_noext.$ext
408
# _rcd. The Texinfo file recoded in 7bit.
409
tmpdir_rcd=$tmpdir/rcd
410
filename_rcd=$tmpdir_rcd/$filename_noext.$ext
341
412
# _bak. Copies of the previous xref files (another round is run if
342
413
# they differ from the new one).
343
414
tmpdir_bak=$tmpdir/bak
345
416
# Make all those directories and give up if we can't succeed.
346
mkdir $tmpdir_src $tmpdir_xtr $tmpdir_bak || exit 1
417
mkdir $tmpdir_src $tmpdir_xtr $tmpdir_rcd $tmpdir_bak || exit 1
348
# Source file might include additional sources. Put `.' and
349
# directory where source file(s) reside in TEXINPUTS before anything
350
# else. `.' goes first to ensure that any old .aux, .cps,
419
# Source file might include additional sources.
420
# We want `.:$orig_pwd' before anything else. (We'll add `.:' later
421
# after all other directories have been turned into absolute paths.)
422
# `.' goes first to ensure that any old .aux, .cps,
351
423
# etc. files in ${directory} don't get used in preference to fresher
352
424
# files in `.'. Include orig_pwd in case we are in clean mode, where
353
425
# we've cd'd to a temp directory.
354
common=".$path_sep$orig_pwd$path_sep$filename_dir$path_sep$txincludes$path_sep"
355
TEXINPUTS="$common$TEXINPUTS_orig"
356
INDEXSTYLE="$common$INDEXSTYLE_orig"
426
common="$orig_pwd$path_sep$filename_dir$path_sep$txincludes"
427
for var in $tex_envvars; do
428
eval ${var}="\$common\$${var}_orig"
432
# Convert relative paths to absolute paths, so we can run in another
433
# directory (e.g., in --clean mode, or during the macro-support detection.)
435
# Empty path components are meaningful to tex. We rewrite them
436
# as `EMPTY' so they don't get lost when we split on $path_sep.
437
# Hopefully no one will have an actual directory named EMPTY.
438
replace_empty="-e 's/^$path_sep/EMPTY$path_sep/g' \
439
-e 's/$path_sep\$/${path_sep}EMPTY/g' \
440
-e 's/$path_sep$path_sep/${path_sep}EMPTY:/g'"
441
TEXINPUTS=`echo $TEXINPUTS | eval sed $replace_empty`
442
INDEXSTYLE=`echo $INDEXSTYLE | eval sed $replace_empty`
445
set x $TEXINPUTS; shift
451
TEXINPUTS=$TEXINPUTS$path_sep
453
[\\/]* | ?:[\\/]*) # Absolute paths don't need to be expanded.
454
TEXINPUTS=$TEXINPUTS$path_sep$dir
457
abs=`cd "$dir" && pwd` && TEXINPUTS=$TEXINPUTS$path_sep$abs
461
set x $INDEXSTYLE; shift
467
INDEXSTYLE=$INDEXSTYLE$path_sep
469
[\\/]* | ?:[\\/]*) # Absolute paths don't need to be expansed.
470
INDEXSTYLE=$INDEXSTYLE$path_sep$dir
473
abs=`cd "$dir" && pwd` && INDEXSTYLE=$INDEXSTYLE$path_sep$abs
358
479
# If the user explicitly specified the language, use that.
359
480
# Otherwise, if the first line is \input texinfo, assume it's texinfo.
360
481
# Otherwise, guess from the file extension.
361
482
if test -n "$set_language"; then
362
483
language=$set_language
363
elif sed 1q "$command_line_filename" | fgrep 'input texinfo' >/dev/null; then
484
elif sed 1q "$command_line_filename" | grep 'input texinfo' >&6; then
372
493
[lL]a[tT]e[xX] | *.ltx | *.tex)
373
494
# Assume a LaTeX file. LaTeX needs bibtex and uses latex for
374
495
# compilation. No makeinfo.
375
497
bibtex=${BIBTEX:-bibtex}
376
498
makeinfo= # no point in running makeinfo on latex source.
377
499
texindex=${MAKEINDEX:-makeindex}
378
501
if test $oformat = dvi; then
379
502
tex=${LATEX:-latex}
381
504
tex=${PDFLATEX:-pdflatex}
506
thumbpdf=${THUMBPDF:-thumbpdf}
386
510
# Assume a Texinfo file. Texinfo files need makeinfo, texindex and tex.
388
513
texindex=${TEXINDEX:-texindex}
514
textra_cmd='/^@setfilename/a'
389
515
if test $oformat = dvi; then
516
# MetaPost also uses the TEX environment variable. If the user
517
# has set TEX=latex for that reason, don't bomb out.
518
if echo $TEX | grep 'latex$' >/dev/null; then
519
tex=tex # don't bother trying to find etex
392
tex=${PDFTEX:-pdftex}
394
526
# Unless required by the user, makeinfo expansion is wanted only
395
527
# if texinfo.tex is too old.
401
533
# We don't need to use [0-9] to match the digits since anyway
402
534
# the comparison with $txiprereq, a number, will fail with non
404
txiversion_tex=txiversion.tex
405
echo '\input texinfo.tex @bye' >$tmpdir/$txiversion_tex
406
536
# Run in the tmpdir to avoid leaving files.
407
eval `cd $tmpdir >/dev/null &&
408
$tex $txiversion_tex 2>/dev/null |
409
sed -n 's/^.*\[\(.*\)version \(....\)-\(..\)-\(..\).*$/txiformat=\1 txiversion="\2\3\4"/p'`
539
echo '\input texinfo.tex @bye' >txiversion.tex
540
# Be sure that if tex wants to fail, it is not interactive:
542
$tex txiversion.tex </dev/null
543
) >$tmpdir/txiversion.out 2>$tmpdir/txiversion.err
544
if test $? != 0; then
545
cat $tmpdir/txiversion.out
546
cat $tmpdir/txiversion.err >&2
547
fatal "texinfo.tex appears to be broken, quitting."
549
eval `sed -n 's/^.*\[\(.*\)version \(....\)-\(..\)-\(..\).*$/txiformat=\1 txiversion="\2\3\4"/p' $tmpdir/txiversion.out`
410
550
$verbose "texinfo.tex preloaded as \`$txiformat', version is \`$txiversion' ..."
411
551
if test "$txiprereq" -le "$txiversion" >/dev/null 2>&1; then
414
554
makeinfo=${MAKEINFO:-makeinfo}
416
# As long as we had to run TeX, offer the user this convenience
417
if test "$txiformat" = Texinfo; then
556
# As long as we had to run TeX, offer the user this convenience:
557
test "$txiformat" = Texinfo && escape=@
559
thumbpdf=${THUMBPDF:-thumbpdf}
563
# Go to $tmpdir to try --help, since old versions that don't accept
564
# --help will generate a texput.log.
565
tex_help=`cd $tmpdir >/dev/null && $tex --help </dev/null 2>&1`
567
# If possible, make TeX report error locations in GNU format.
570
*file-line-error*) tex_args="$tex_args --file-line-error";;
573
# Tell TeX to be batch if requested. (\batchmode does not show
574
# terminal output at all, so we don't want that.)
575
$batch && tex_args="$tex_args ${escape}nonstopmode ${escape}input"
424
577
# Expand macro commands in the original source file using Makeinfo.
425
578
# Always use `end' footnote style, since the `separate' style
426
579
# generates different output (arguably this is a bug in -E).
444
597
# Used most commonly for @finalout, @smallbook, etc.
445
598
if test -n "$textra"; then
446
599
$verbose "Inserting extra commands: $textra"
447
sed '/^@setfilename/a\
448
'"$textra" "$filename_input" >$filename_xtr
601
$textra" "$filename_input" >"$filename_xtr"
449
602
filename_input=$filename_xtr
605
# If this is a Texinfo file with a specified input encoding, and
606
# recode is available, then recode to plain 7 bit Texinfo.
607
if test $language = texinfo; then
608
pgm='s/\(^\|.* \)@documentencoding *\([^ ][^ ]*\)\( .*\|$\)/\2/
613
encoding=`sed -e "$pgm" "$filename_input"`
614
if $recode && test -n "$encoding" && findprog recode; then
615
$verbose "Recoding from $encoding to Texinfo."
616
if recode "$encoding"..texinfo <"$filename_input" >"$filename_rcd" \
617
&& test -s "$filename_rcd"; then
618
filename_input=$filename_rcd
620
$verbose "Recoding failed, using original input."
452
625
# If clean mode was specified, then move to the temporary directory.
453
626
if test "$clean" = t; then
454
627
$verbose "cd $tmpdir_src"
487
660
&& grep '^\\bibstyle[{]' "$filename_noext.aux" \
488
661
&& (grep 'Warning:.*Citation.*undefined' "$filename_noext.log" \
489
662
|| grep 'No file .*\.bbl\.' "$filename_noext.log")) \
492
665
$verbose "Running $bibtex $filename_noext ..."
493
if $bibtex "$filename_noext" >&5; then :; else
494
echo "$0: $bibtex exited with bad status, quitting." >&2
666
$bibtex "$filename_noext" >&5 ||
667
fatal "$bibtex exited with bad status, quitting."
499
670
# What we'll run texindex on -- exclude non-index files.
500
671
# Since we know index files are last, it is correct to remove everything
501
# before .aux and .?o?.
672
# before .aux and .?o?. But don't really do <anything>o<anything>
673
# -- don't match whitespace as <anything>.
674
# Otherwise, if orig_xref_files contains something like
675
# foo.xo foo.whatever
676
# the space after the o will get matched.
502
677
index_files=`echo "$orig_xref_files" \
503
678
| sed "s!.*\.aux!!g;
504
s!./$filename_noext\..o.!!g;
679
s!./$filename_noext\.[^ ]o[^ ]!!g;
505
680
s/^[ ]*//;s/[ ]*$//"`
506
681
# Run texindex (or makeindex) on current index files. If they
507
682
# already exist, and after running TeX a first time the index
511
686
if test -n "$texindex" && test -n "$index_files"; then
512
687
$verbose "Running $texindex $index_files ..."
513
if $texindex $index_files 2>&5 1>&2; then :; else
514
echo "$0: $texindex exited with bad status, quitting." >&2
688
$texindex $index_files 2>&5 1>&2 ||
689
fatal "$texindex exited with bad status, quitting."
519
692
# Finally, run TeX.
520
# Prevent $ESCAPE from being interpreted by the shell if it happens
522
$batch tex_args="\\${escape}nonstopmode\ \\${escape}input"
523
$verbose "Running $cmd ..."
524
cmd="$tex $tex_args $filename_input"
525
if $cmd >&5; then :; else
694
$verbose "Running $cmd $filename_input ..."
695
if $cmd "$filename_input" >&5; then :; else
526
696
echo "$0: $tex exited with bad status, quitting." >&2
527
697
echo "$0: see $filename_noext.log for errors." >&2
528
698
test "$clean" = t \
539
709
# subdirs, since texi2dvi does not try to compare xref files in
540
710
# subdirs. Performing xref files test is still good since LaTeX
541
711
# does not report changes in xref files.
542
if fgrep "Rerun to get" "$filename_noext.log" >/dev/null 2>&1; then
712
if grep "Rerun to get" "$filename_noext.log" >&6 2>&1; then
546
716
# Check if xref files changed.
547
new_xref_files=`$get_xref_files "$filename_noext"`
717
new_xref_files=`get_xref_files "$filename_noext"`
548
718
$verbose "Original xref files = `echo $orig_xref_files | sed 's|\./||g'`"
549
719
$verbose "New xref files = `echo $new_xref_files | sed 's|\./||g'`"
573
743
# If finished, exit the loop, else rerun the loop.
574
744
test -n "$finished" && break
747
# If we were using thumbpdf and producing PDF, then run thumbpdf
748
# and TeX one last time.
749
if test $oformat = pdf \
750
&& test -r "$filename_noext.log" \
751
&& grep 'thumbpdf\.sty' "$filename_noext.log" >&6 2>&1; \
753
$verbose "Running $thumbpdf $filename_noext ..."
754
$thumbpdf "$filename_noext" >&5 ||
755
fatal "$thumbpdf exited with bad status, quitting."
757
$verbose "Running $cmd $filename_input..."
758
if $cmd "$filename_input" >&5; then :; else
759
echo "$0: $tex exited with bad status, quitting." >&2
760
echo "$0: see $filename_noext.log for errors." >&2
762
&& cp "$filename_noext.log" "$orig_pwd"
577
768
# If we were in clean mode, compilation was in a tmp directory.
578
769
# Copy the DVI (or PDF) file into the directory where the compilation