~ubuntu-branches/ubuntu/maverick/texinfo/maverick

« back to all changes in this revision

Viewing changes to util/texi2dvi

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2005-10-28 15:10:30 UTC
  • mto: (2.1.1 dapper) (3.1.4 hardy)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20051028151030-9nsf2s2k2z3fktjt
Tags: upstream-4.8
ImportĀ upstreamĀ versionĀ 4.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#! /bin/sh
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 $
4
4
#
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.
7
7
#
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.
22
22
#
23
 
# Original author: Noah Friedman <friedman@gnu.org>.
 
23
# Original author: Noah Friedman.
24
24
#
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.
28
28
 
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
34
34
 
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."
61
61
 
62
62
TeX tuning:
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
70
71
 
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.
74
76
 
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/"
77
80
 
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
87
90
oformat=dvi
88
 
oname=          # --output
 
91
oname=          # --output
89
92
quiet=          # by default let the tools' message be displayed
 
93
recode=false
90
94
set_language=
91
 
textra=
 
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
96
101
 
97
102
orig_pwd=`pwd`
104
109
  path_sep=":"
105
110
fi
106
111
 
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
 
114
 
 
115
# In case someone crazy insists on using grep -E.
 
116
: ${EGREP=egrep}
 
117
 
 
118
# return true if program $1 is somewhere in PATH, else false.
 
119
#
 
120
findprog () {
 
121
  foundprog=false
 
122
  for dir in `echo $PATH | tr "$path_sep" " "`; do
 
123
    if test -x "$dir/$1"; then  # does anyone still need test -f?
 
124
      foundprog=true
 
125
      break
 
126
    fi
 
127
  done
 
128
  $foundprog
 
129
}
 
130
 
 
131
# Report an error and exit with failure.
 
132
fatal () {
 
133
  echo "$0: $*" >&2
 
134
  exit 1
 
135
}
 
136
 
 
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
 
142
  export $var
 
143
done
 
144
 
112
145
 
113
146
# Push a token among the arguments that will be used to notice when we
114
147
# ended options/arguments parsing.
138
171
  case "$1" in
139
172
    -@ ) escape=@;;
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;;
147
179
    -I | --I*)
148
180
      shift
149
181
      miincludes="$miincludes -I $1"
150
 
      txincludes="$txincludes$path_sep$1"
 
182
      txincludes="$txincludes$1$path_sep"
151
183
      ;;
152
184
    -l | --l*) shift; set_language=$1;;
153
185
    -o | --o*)
158
190
                *) oname="$orig_pwd/$1";;
159
191
      esac;;
160
192
    -p | --p*) oformat=pdf;;
161
 
    -t | --t*) shift; textra="$textra\\
162
 
$1";;
 
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.
196
230
  ;;
197
231
esac
198
232
 
 
233
 
 
234
# We can't do much without tex.
 
235
#
 
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.
 
242
 
 
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
 
246
EOM
 
247
  exit 1
 
248
fi
 
249
 
 
250
 
 
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.
 
255
#
 
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
 
259
fi
 
260
#
 
261
if test -z "$PDFTEX"; then
 
262
  if findprog pdfetex; then PDFTEX=pdfetex; else PDFTEX=pdftex; fi
 
263
fi
 
264
 
 
265
 
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
206
273
 
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
211
278
 
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.
 
286
#
219
287
comment_iftex_sed=$utildir/comment.sed
220
288
cat <<EOF >$comment_iftex_sed
221
289
/^@tex/,/^@end tex/{
227
295
    s/^@c texi2dvi//
228
296
  }
229
297
}
230
 
/^@html/,/^@end html/{
231
 
  s/^/@c (texi2dvi)/
232
 
}
233
 
/^@ifhtml/,/^@end ifhtml/{
234
 
  s/^/@c (texi2dvi)/
235
 
}
236
298
/^@ifnottex/,/^@end ifnottex/{
237
299
  s/^/@c (texi2dvi)/
238
300
}
251
313
s/^@c texi2dvi//
252
314
EOF
253
315
 
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
259
 
#! /bin/sh
260
 
 
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"
275
 
  fi
276
 
done
277
 
echo "$xref_files"
278
 
EOF
279
 
chmod 500 $get_xref_files
 
319
get_xref_files ()
 
320
{
 
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
 
331
    # \input texinfo.
 
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"
 
338
    fi
 
339
  done
 
340
  echo "$xref_files"
 
341
}
280
342
 
281
343
# File descriptor usage:
282
344
# 0 standard input
294
356
fi
295
357
 
296
358
# Enable tracing
297
 
test "$debug" = t && set -x
 
359
if test "$debug" = t; then
 
360
  exec 6>&1
 
361
  set -x
 
362
else
 
363
  exec 6>/dev/null
 
364
fi
298
365
 
299
366
300
367
# TeXify files.
304
371
 
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"
309
376
 
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
340
407
 
 
408
  # _rcd.  The Texinfo file recoded in 7bit.
 
409
  tmpdir_rcd=$tmpdir/rcd
 
410
  filename_rcd=$tmpdir_rcd/$filename_noext.$ext
 
411
 
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
344
415
 
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
347
418
 
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"
 
429
    export $var
 
430
  done
 
431
 
 
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.)
 
434
  #
 
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`
 
443
  save_IFS=$IFS
 
444
  IFS=$path_sep
 
445
  set x $TEXINPUTS; shift
 
446
  TEXINPUTS=.
 
447
  for dir
 
448
  do
 
449
    case $dir in
 
450
      EMPTY)
 
451
        TEXINPUTS=$TEXINPUTS$path_sep
 
452
        ;;
 
453
      [\\/]* | ?:[\\/]*)        # Absolute paths don't need to be expanded.
 
454
        TEXINPUTS=$TEXINPUTS$path_sep$dir
 
455
        ;;
 
456
      *)
 
457
        abs=`cd "$dir" && pwd` && TEXINPUTS=$TEXINPUTS$path_sep$abs
 
458
        ;;
 
459
    esac
 
460
  done
 
461
  set x $INDEXSTYLE; shift
 
462
  INDEXSTYLE=.
 
463
  for dir
 
464
  do
 
465
    case $dir in
 
466
      EMPTY)
 
467
        INDEXSTYLE=$INDEXSTYLE$path_sep
 
468
        ;;
 
469
      [\\/]* | ?:[\\/]*)        # Absolute paths don't need to be expansed.
 
470
        INDEXSTYLE=$INDEXSTYLE$path_sep$dir
 
471
        ;;
 
472
      *)
 
473
        abs=`cd "$dir" && pwd` && INDEXSTYLE=$INDEXSTYLE$path_sep$abs
 
474
        ;;
 
475
    esac
 
476
  done
 
477
  IFS=$save_IFS
357
478
 
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
364
485
    language=texinfo
365
486
  else
366
487
    language=
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.
 
496
      language=latex
375
497
      bibtex=${BIBTEX:-bibtex}
376
498
      makeinfo= # no point in running makeinfo on latex source.
377
499
      texindex=${MAKEINDEX:-makeindex}
 
500
      textra_cmd=1i
378
501
      if test $oformat = dvi; then
379
502
        tex=${LATEX:-latex}
380
503
      else
381
504
        tex=${PDFLATEX:-pdflatex}
382
505
      fi
 
506
      thumbpdf=${THUMBPDF:-thumbpdf}
383
507
      ;;
384
508
 
385
509
    *)
386
510
      # Assume a Texinfo file.  Texinfo files need makeinfo, texindex and tex.
 
511
      language=texinfo
387
512
      bibtex=
388
513
      texindex=${TEXINDEX:-texindex}
 
514
      textra_cmd='/^@setfilename/a'
389
515
      if test $oformat = dvi; then
390
 
        tex=${TEX:-tex}
 
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
 
520
        else
 
521
          tex=$TEX
 
522
        fi
391
523
      else
392
 
        tex=${PDFTEX:-pdftex}
 
524
        tex=$PDFTEX
393
525
      fi
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
403
535
        # digits.
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'`
 
537
        (
 
538
           cd $tmpdir
 
539
           echo '\input texinfo.tex @bye' >txiversion.tex
 
540
           # Be sure that if tex wants to fail, it is not interactive:
 
541
           # close stdin.
 
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."
 
548
        fi
 
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
412
552
          makeinfo=
413
553
        else
414
554
          makeinfo=${MAKEINFO:-makeinfo}
415
555
        fi
416
 
        # As long as we had to run TeX, offer the user this convenience
417
 
        if test "$txiformat" = Texinfo; then
418
 
          escape=@
419
 
        fi
 
556
        # As long as we had to run TeX, offer the user this convenience:
 
557
        test "$txiformat" = Texinfo && escape=@
420
558
      fi
 
559
      thumbpdf=${THUMBPDF:-thumbpdf}
421
560
      ;;
422
561
  esac
423
562
 
 
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`
 
566
 
 
567
  # If possible, make TeX report error locations in GNU format.
 
568
  tex_args=
 
569
  case $tex_help in
 
570
    *file-line-error*) tex_args="$tex_args --file-line-error";;
 
571
  esac
 
572
 
 
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"
 
576
 
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
 
600
    sed "$textra_cmd\\
 
601
$textra" "$filename_input" >"$filename_xtr"
449
602
    filename_input=$filename_xtr
450
603
  fi
451
604
 
 
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/  
 
609
        t found                                                
 
610
        d                                                     
 
611
        :found                                               
 
612
        q'
 
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
 
619
      else
 
620
        $verbose "Recoding failed, using original input."
 
621
      fi
 
622
    fi
 
623
  fi
 
624
 
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"
456
629
  fi
457
630
 
458
631
  while :; do # will break out of loop below
459
 
    orig_xref_files=`$get_xref_files "$filename_noext"`
 
632
    orig_xref_files=`get_xref_files "$filename_noext"`
460
633
 
461
634
    # Save copies of originals for later comparison.
462
635
    if test -n "$orig_xref_files"; then
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")) \
490
 
          >/dev/null 2>&1; \
 
663
          >&6 2>&1; \
491
664
    then
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
495
 
        exit 1
496
 
      fi
 
666
      $bibtex "$filename_noext" >&5 ||
 
667
        fatal "$bibtex exited with bad status, quitting."
497
668
    fi
498
669
 
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
510
685
    # nonexistent.
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
515
 
         exit 1
516
 
      fi
 
688
      $texindex $index_files 2>&5 1>&2 ||
 
689
         fatal "$texindex exited with bad status, quitting."
517
690
    fi
518
691
 
519
692
    # Finally, run TeX.
520
 
    # Prevent $ESCAPE from being interpreted by the shell if it happens
521
 
    # to be `/'.
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
 
693
    cmd="$tex $tex_args"
 
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
543
713
      finished=
544
714
    fi
545
715
 
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'`"
550
720
 
572
742
 
573
743
    # If finished, exit the loop, else rerun the loop.
574
744
    test -n "$finished" && break
575
 
  done
 
745
  done # while :;
 
746
 
 
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; \
 
752
  then
 
753
    $verbose "Running $thumbpdf $filename_noext ..."
 
754
    $thumbpdf "$filename_noext" >&5 ||
 
755
      fatal "$thumbpdf exited with bad status, quitting."
 
756
 
 
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
 
761
      test "$clean" = t \
 
762
        && cp "$filename_noext.log" "$orig_pwd"
 
763
      exit 1
 
764
    fi
 
765
  fi
 
766
 
576
767
 
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
600
791
  fi
601
792
done
602
793
 
603
 
$verbose "$0 done."
 
794
$verbose "$0: done."
604
795
exit 0 # exit successfully, not however we ended the loop.