The R Project SVN R

Rev

Rev 22639 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 22639 Rev 25403
Line 1... Line 1...
1
#! /bin/sh
1
#! /bin/sh
2
# texi2dvi --- produce DVI (or PDF) files from Texinfo (or LaTeX) sources.
2
# texi2dvi --- produce DVI (or PDF) files from Texinfo (or LaTeX) sources.
3
# $Id: texi2dvi,v 1.2 2003/01/08 14:37:06 hornik Exp $
3
# $Id: texi2dvi,v 1.3 2003/07/28 16:51:25 hornik Exp $
4
#
4
#
5
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001,
5
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001,
6
# 2002, 2003 Free Software Foundation, Inc.
6
# 2002, 2003 Free Software Foundation, Inc.
7
#
7
#
8
# This program is free software; you can redistribute it and/or modify
8
# This program is free software; you can redistribute it and/or modify
Line 24... Line 24...
24
#
24
#
25
# Please send bug reports, etc. to bug-texinfo@gnu.org.
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
26
# If possible, please send a copy of the output of the script called with
27
# the `--debug' option when making a bug report.
27
# the `--debug' option when making a bug report.
28
 
28
 
-
 
29
if ! command -v tex >/dev/null 2>&1; then
-
 
30
 cat <<%EOM%
-
 
31
You don't have a working TeX binary installed, but the texi2dvi script
-
 
32
can't proceed without it. If you want to use this script, you have to
-
 
33
install some kind of TeX, for example teTeX Debian packages. You can do
-
 
34
that with this command:
-
 
35
	apt-get install tetex-bin
-
 
36
%EOM%
-
 
37
 exit 1
-
 
38
fi
-
 
39
 
29
# This string is expanded by rcs automatically when this file is checked out.
40
# This string is expanded by rcs automatically when this file is checked out.
30
rcs_revision='$Revision: 1.2 $'
41
rcs_revision='$Revision: 1.3 $'
31
rcs_version=`set - $rcs_revision; echo $2`
42
rcs_version=`set - $rcs_revision; echo $2`
32
program=`echo $0 | sed -e 's!.*/!!'`
43
program=`echo $0 | sed -e 's!.*/!!'`
33
version="texi2dvi (GNU Texinfo 4.3) $rcs_version
44
version="texi2dvi (GNU Texinfo 4.6) $rcs_version
34
 
45
 
35
Copyright (C) 2002 Free Software Foundation, Inc.
46
Copyright (C) 2003 Free Software Foundation, Inc.
36
There is NO warranty.  You may redistribute this software
47
There is NO warranty.  You may redistribute this software
37
under the terms of the GNU General Public License.
48
under the terms of the GNU General Public License.
38
For more information about these matters, see the files named COPYING."
49
For more information about these matters, see the files named COPYING."
39
 
50
 
40
usage="Usage: $program [OPTION]... FILE...
51
usage="Usage: $program [OPTION]... FILE...
Line 63... Line 74...
63
  -@                   use @input instead of \input; for preloaded Texinfo
74
  -@                   use @input instead of \input; for preloaded Texinfo
64
  -e, -E, --expand     force macro expansion using makeinfo
75
  -e, -E, --expand     force macro expansion using makeinfo
65
  -I DIR               search DIR for Texinfo files
76
  -I DIR               search DIR for Texinfo files
66
  -l, --language=LANG  specify the LANG of FILE (LaTeX or Texinfo)
77
  -l, --language=LANG  specify the LANG of FILE (LaTeX or Texinfo)
67
  -p, --pdf            use pdftex or pdflatex for processing
78
  -p, --pdf            use pdftex or pdflatex for processing
68
  -t, --texinfo=CMD    insert CMD after @setfilename in copy of input file
79
  -t, --command=CMD    insert CMD in copy of input file;
69
                       multiple values accumulate
80
   or --texinfo=CMD    multiple values accumulate
70
 
81
 
71
The values of the BIBTEX, LATEX (or PDFLATEX), MAKEINDEX, MAKEINFO,
82
The values of the BIBTEX, LATEX (or PDFLATEX), MAKEINDEX, MAKEINFO, TEX
72
TEX (or PDFTEX), and TEXINDEX environment variables are used to run
83
(or PDFTEX), and TEXINDEX environment variables are used to run those
-
 
84
commands, if they are set.  Any CMD strings are added after @setfilename
73
those commands, if they are set.
85
for Texinfo input, in the first line for LaTeX input.
74
 
86
 
75
Email bug reports to <bug-texinfo@gnu.org>,
87
Email bug reports to <bug-texinfo@gnu.org>,
76
general questions and discussion to <help-texinfo@gnu.org>.
88
general questions and discussion to <help-texinfo@gnu.org>.
77
Texinfo home page: http://www.gnu.org/software/texinfo/"
89
Texinfo home page: http://www.gnu.org/software/texinfo/"
78
 
90
 
Line 87... Line 99...
87
miincludes=     # makeinfo include path
99
miincludes=     # makeinfo include path
88
oformat=dvi
100
oformat=dvi
89
oname=          # --output
101
oname=          # --output
90
quiet=          # by default let the tools' message be displayed
102
quiet=          # by default let the tools' message be displayed
91
set_language=
103
set_language=
-
 
104
textra=         # Extra TeX commands to insert in the input file.
92
textra=
105
textra_cmd=     # sed command to insert TEXTRA where appropriate
93
tmpdir=${TMPDIR:-/tmp}/t2d$$  # avoid collisions on 8.3 filesystems.
106
tmpdir=${TMPDIR:-/tmp}/t2d$$  # avoid collisions on 8.3 filesystems.
94
txincludes=     # TEXINPUTS extensions, with trailing colon
107
txincludes=     # TEXINPUTS extensions, with trailing colon
95
txiprereq=19990129 # minimum texinfo.tex version to have macro expansion
108
txiprereq=19990129 # minimum texinfo.tex version to have macro expansion
96
verbose=false   # echo for verbose mode
109
verbose=false   # echo for verbose mode
97
 
110
 
Line 109... Line 122...
109
CDPATH=${ZSH_VERSION+.}$path_sep
122
CDPATH=${ZSH_VERSION+.}$path_sep
110
 
123
 
111
# In case someone crazy insists on using grep -E.
124
# In case someone crazy insists on using grep -E.
112
: ${EGREP=egrep}
125
: ${EGREP=egrep}
113
 
126
 
114
# Save this so we can construct a new TEXINPUTS path for each file.
127
# Save TEXINPUTS so we can construct a new TEXINPUTS path for each file.
115
TEXINPUTS_orig="$TEXINPUTS"
-
 
116
# Unfortunately makeindex does not read TEXINPUTS.
128
# Unfortunately bibtex and makeindex do not read TEXINPUTS.
-
 
129
tex_envvars="BIBINPUTS BSTINPUTS INDEXSTYLE TEXINPUTS"
-
 
130
for var in $tex_envvars; do
117
INDEXSTYLE_orig="$INDEXSTYLE"
131
  eval ${var}_orig=\$$var
118
export TEXINPUTS INDEXSTYLE
132
  export $var
-
 
133
done
119
 
134
 
120
# Push a token among the arguments that will be used to notice when we
135
# Push a token among the arguments that will be used to notice when we
121
# ended options/arguments parsing.
136
# ended options/arguments parsing.
122
# Use "set dummy ...; shift" rather than 'set - ..." because on
137
# Use "set dummy ...; shift" rather than 'set - ..." because on
123
# Solaris set - turns off set -x (but keeps set -e).
138
# Solaris set - turns off set -x (but keeps set -e).
Line 143... Line 158...
143
 
158
 
144
  # This recognizes --quark as --quiet.  So what.
159
  # This recognizes --quark as --quiet.  So what.
145
  case "$1" in
160
  case "$1" in
146
    -@ ) escape=@;;
161
    -@ ) escape=@;;
147
    # Silently and without documentation accept -b and --b[atch] as synonyms.
162
    # Silently and without documentation accept -b and --b[atch] as synonyms.
148
    -b | --b*) batch=eval;;
163
    -b | --b*) batch=true;;
149
    -q | -s | --q* | --s*) quiet=t; batch=eval;;
164
    -q | -s | --q* | --s*) quiet=t; batch=true;;
150
    -c | --c*) clean=t;;
165
    -c | --c*) clean=t;;
151
    -D | --d*) debug=t;;
166
    -D | --d*) debug=t;;
152
    -e | -E | --e*) expand=t;;
167
    -e | -E | --e*) expand=t;;
153
    -h | --h*) echo "$usage"; exit 0;;
168
    -h | --h*) echo "$usage"; exit 0;;
154
    -I | --I*)
169
    -I | --I*)
Line 163... Line 178...
163
      case "$1" in
178
      case "$1" in
164
        /* | ?:/*) oname=$1;;
179
        /* | ?:/*) oname=$1;;
165
                *) oname="$orig_pwd/$1";;
180
                *) oname="$orig_pwd/$1";;
166
      esac;;
181
      esac;;
167
    -p | --p*) oformat=pdf;;
182
    -p | --p*) oformat=pdf;;
168
    -t | --t*) shift; textra="$textra\\
183
    -t | --tex* | --com* ) shift; textra="$textra\\
169
$1";;
184
"`echo "$1" | sed 's/\\\\/\\\\\\\\/g'`;;
170
    -v | --vers*) echo "$version"; exit 0;;
185
    -v | --vers*) echo "$version"; exit 0;;
171
    -V | --verb*) verbose=echo;;
186
    -V | --verb*) verbose=echo;;
172
    --) # What remains are not options.
187
    --) # What remains are not options.
173
      shift
188
      shift
174
      while test x"$1" != x"$arg_sep"; do
189
      while test x"$1" != x"$arg_sep"; do
Line 271... Line 286...
271
# many files: .toc, .log, LaTeX tables and lists, FiXme's .lox, maybe more.
286
# many files: .toc, .log, LaTeX tables and lists, FiXme's .lox, maybe more.
272
for this_file in "$1".?o? "$1".aux "$1".?? "$1".idx; do
287
for this_file in "$1".?o? "$1".aux "$1".?? "$1".idx; do
273
  # If file is empty, skip it.
288
  # If file is empty, skip it.
274
  test -s "$this_file" || continue
289
  test -s "$this_file" || continue
275
  # If the file is not suitable to be an index or xref file, don't
290
  # If the file is not suitable to be an index or xref file, don't
276
  # process it.  The file can't be if its first character is not a
291
  # process it.  It's suitable if the first character is a
277
  # backslash or single quote.
292
  # backslash or right quote, as long as the first line isn't
-
 
293
  # \input texinfo.
278
  first_character=`sed -n '1s/^\(.\).*$/\1/p;q' $this_file`
294
  first_character=`sed -n '1s/^\(.\).*$/\1/p;q' $this_file`
279
  if test "x$first_character" = "x\\" \
295
  if (test "x$first_character" = "x\\" \
-
 
296
      && sed 1q $this_file | grep -v '^\\input *texinfo' >/dev/null) \
280
     || test "x$first_character" = "x'"; then
297
     || test "x$first_character" = "x'"; then
281
    xref_files="$xref_files ./$this_file"
298
    xref_files="$xref_files ./$this_file"
282
  fi
299
  fi
283
done
300
done
284
echo "$xref_files"
301
echo "$xref_files"
Line 358... Line 375...
358
  # `.' goes first to ensure that any old .aux, .cps,
375
  # `.' goes first to ensure that any old .aux, .cps,
359
  # etc. files in ${directory} don't get used in preference to fresher
376
  # etc. files in ${directory} don't get used in preference to fresher
360
  # files in `.'.  Include orig_pwd in case we are in clean mode, where
377
  # files in `.'.  Include orig_pwd in case we are in clean mode, where
361
  # we've cd'd to a temp directory.
378
  # we've cd'd to a temp directory.
362
  common="$orig_pwd$path_sep$filename_dir$path_sep$txincludes"
379
  common="$orig_pwd$path_sep$filename_dir$path_sep$txincludes"
363
   TEXINPUTS="$common$TEXINPUTS_orig"
380
  for var in $tex_envvars; do
364
  INDEXSTYLE="$common$INDEXSTYLE_orig"
381
    eval ${var}="\$common\$${var}_orig"
-
 
382
    export $var
-
 
383
  done
365
 
384
 
366
  # Convert relative paths to absolute paths, so we can run in another
385
  # Convert relative paths to absolute paths, so we can run in another
367
  # directory (e.g., in --clean mode, or during the macro-support
386
  # directory (e.g., in --clean mode, or during the macro-support detection.)
368
  # detection.)
-
 
369
  #
387
  #
370
  # Empty path components are meaningful to tex.  We rewrite them
388
  # Empty path components are meaningful to tex.  We rewrite them
371
  # as `EMPTY' so they don't get lost when we split on $path_sep.
389
  # as `EMPTY' so they don't get lost when we split on $path_sep.
-
 
390
  # Hopefully no one will have an actual directory named EMPTY.
-
 
391
  replace_empty="-e 's/^$path_sep/EMPTY$path_sep/g' \
-
 
392
                 -e 's/$path_sep\$/${path_sep}EMPTY/g' \
-
 
393
                 -e 's/$path_sep$path_sep/${path_sep}EMPTY:/g'"
372
   TEXINPUTS=`echo $TEXINPUTS  |sed 's/^:/EMPTY:/;s/:$/:EMPTY/;s/::/:EMPTY:/g'`
394
   TEXINPUTS=`echo $TEXINPUTS  | eval sed $replace_empty`
373
  INDEXSTYLE=`echo $INDEXSTYLE |sed 's/^:/EMPTY:/;s/:$/:EMPTY/;s/::/:EMPTY:/g'`
395
  INDEXSTYLE=`echo $INDEXSTYLE | eval sed $replace_empty`
374
  save_IFS=$IFS
396
  save_IFS=$IFS
375
  IFS=$path_sep
397
  IFS=$path_sep
376
  set x $TEXINPUTS; shift
398
  set x $TEXINPUTS; shift
377
  TEXINPUTS=.
399
  TEXINPUTS=.
378
  for dir
400
  for dir
379
  do
401
  do
380
    case $dir in
402
    case $dir in
381
      EMPTY)
403
      EMPTY)
382
        TEXINPUTS=$TEXINPUTS$path_sep
404
        TEXINPUTS=$TEXINPUTS$path_sep
383
        ;;
405
        ;;
384
      [\\/]* | ?:[\\/]*)        # Absolute paths don't need to be expansed.
406
      [\\/]* | ?:[\\/]*)        # Absolute paths don't need to be expanded.
385
        TEXINPUTS=$TEXINPUTS$path_sep$dir
407
        TEXINPUTS=$TEXINPUTS$path_sep$dir
386
        ;;
408
        ;;
387
      *)
409
      *)
388
        abs=`cd "$dir" && pwd` && TEXINPUTS=$TEXINPUTS$path_sep$abs
410
        abs=`cd "$dir" && pwd` && TEXINPUTS=$TEXINPUTS$path_sep$abs
389
        ;;
411
        ;;
Line 425... Line 447...
425
      # Assume a LaTeX file.  LaTeX needs bibtex and uses latex for
447
      # Assume a LaTeX file.  LaTeX needs bibtex and uses latex for
426
      # compilation.  No makeinfo.
448
      # compilation.  No makeinfo.
427
      bibtex=${BIBTEX:-bibtex}
449
      bibtex=${BIBTEX:-bibtex}
428
      makeinfo= # no point in running makeinfo on latex source.
450
      makeinfo= # no point in running makeinfo on latex source.
429
      texindex=${MAKEINDEX:-makeindex}
451
      texindex=${MAKEINDEX:-makeindex}
-
 
452
      textra_cmd=1i
430
      if test $oformat = dvi; then
453
      if test $oformat = dvi; then
431
        tex=${LATEX:-latex}
454
        tex=${LATEX:-latex}
432
      else
455
      else
433
        tex=${PDFLATEX:-pdflatex}
456
        tex=${PDFLATEX:-pdflatex}
434
      fi
457
      fi
Line 436... Line 459...
436
 
459
 
437
    *)
460
    *)
438
      # Assume a Texinfo file.  Texinfo files need makeinfo, texindex and tex.
461
      # Assume a Texinfo file.  Texinfo files need makeinfo, texindex and tex.
439
      bibtex=
462
      bibtex=
440
      texindex=${TEXINDEX:-texindex}
463
      texindex=${TEXINDEX:-texindex}
-
 
464
      textra_cmd='/^@setfilename/a'
441
      if test $oformat = dvi; then
465
      if test $oformat = dvi; then
442
        tex=${TEX:-tex}
466
        tex=${TEX:-tex}
443
      else
467
      else
444
        tex=${PDFTEX:-pdftex}
468
        tex=${PDFTEX:-pdftex}
445
      fi
469
      fi
Line 463... Line 487...
463
        if test "$txiprereq" -le "$txiversion" >/dev/null 2>&1; then
487
        if test "$txiprereq" -le "$txiversion" >/dev/null 2>&1; then
464
          makeinfo=
488
          makeinfo=
465
        else
489
        else
466
          makeinfo=${MAKEINFO:-makeinfo}
490
          makeinfo=${MAKEINFO:-makeinfo}
467
        fi
491
        fi
468
        # As long as we had to run TeX, offer the user this convenience
492
        # As long as we had to run TeX, offer the user this convenience:
469
        if test "$txiformat" = Texinfo; then
493
        test "$txiformat" = Texinfo && escape=@
470
          escape=@
-
 
471
        fi
-
 
472
      fi
494
      fi
473
      ;;
495
      ;;
474
  esac
496
  esac
475
 
497
 
-
 
498
  # If possible, make TeX report error locations in GNU format.
-
 
499
  tex_args=
-
 
500
  case `$tex --help </dev/null 2>&1` in
-
 
501
   *file-line-error-style*) tex_args='--file-line-error-style';;
-
 
502
  esac
-
 
503
 
-
 
504
  # Tell TeX to be batch if requested.  (\batchmode does not show
-
 
505
  # terminal output at all, so we don't want that.)
-
 
506
  $batch && tex_args="$tex_args ${escape}nonstopmode ${escape}input"
-
 
507
 
476
  # Expand macro commands in the original source file using Makeinfo.
508
  # Expand macro commands in the original source file using Makeinfo.
477
  # Always use `end' footnote style, since the `separate' style
509
  # Always use `end' footnote style, since the `separate' style
478
  #   generates different output (arguably this is a bug in -E).
510
  #   generates different output (arguably this is a bug in -E).
479
  # Discard main info output, the user asked to run TeX, not makeinfo.
511
  # Discard main info output, the user asked to run TeX, not makeinfo.
480
  if test -n "$makeinfo"; then
512
  if test -n "$makeinfo"; then
Line 494... Line 526...
494
  fi
526
  fi
495
 
527
 
496
  # Used most commonly for @finalout, @smallbook, etc.
528
  # Used most commonly for @finalout, @smallbook, etc.
497
  if test -n "$textra"; then
529
  if test -n "$textra"; then
498
    $verbose "Inserting extra commands: $textra"
530
    $verbose "Inserting extra commands: $textra"
499
    sed '/^@setfilename/a\
531
    sed "$textra_cmd\\
500
'"$textra" "$filename_input" >$filename_xtr
532
$textra" "$filename_input" >$filename_xtr
501
    filename_input=$filename_xtr
533
    filename_input=$filename_xtr
502
  fi
534
  fi
503
 
535
 
504
  # If clean mode was specified, then move to the temporary directory.
536
  # If clean mode was specified, then move to the temporary directory.
505
  if test "$clean" = t; then
537
  if test "$clean" = t; then
Line 571... Line 603...
571
         exit 1
603
         exit 1
572
      fi
604
      fi
573
    fi
605
    fi
574
 
606
 
575
    # Finally, run TeX.
607
    # Finally, run TeX.
576
    # Prevent $ESCAPE from being interpreted by the shell if it happens
-
 
577
    # to be `/'.
-
 
578
    $batch tex_args="\\${escape}nonstopmode\ \\${escape}input"
-
 
579
    cmd="$tex $tex_args $filename_input"
608
    cmd="$tex $tex_args $filename_input"
580
    $verbose "Running $cmd ..."
609
    $verbose "Running $cmd ..."
581
    if $cmd >&5; then :; else
610
    if $cmd >&5; then :; else
582
      echo "$0: $tex exited with bad status, quitting." >&2
611
      echo "$0: $tex exited with bad status, quitting." >&2
583
      echo "$0: see $filename_noext.log for errors." >&2
612
      echo "$0: see $filename_noext.log for errors." >&2