2 # texi2dvi --- produce DVI (or PDF) files from Texinfo (or (La)TeX) sources.
4 # Copyright 1992-2019 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License,
9 # or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Originally written by Noah Friedman.
21 # Please send bug reports, etc. to bug-texinfo@gnu.org.
22 # If possible, please send a copy of the output of the script called with
23 # the `--debug' option when making a bug report.
25 test -f /bin
/ksh
&& test -z "$RUNNING_KSH" \
26 && { UNAMES
=`uname -s`; test "x$UNAMES" = xULTRIX
; } 2>/dev
/null \
27 && { RUNNING_KSH
=true
; export RUNNING_KSH
; exec /bin
/ksh
$0 ${1+"$@"}; }
30 # No failure shall remain unpunished.
33 # In case the default sed doesn't suffice.
36 program
=`echo $0 | $SED -e 's!.*/!!'`
38 build_mode
=${TEXI2DVI_BUILD_MODE:-local}
39 build_dir
=${TEXI2DVI_BUILD_DIRECTORY:-.}
43 # Initialize variables for option overriding and otherwise.
44 # Don't use `unset' since old bourne shells don't have this command.
45 # Instead, assign them an empty value.
49 expand=false
# true for expansion via makeinfo
51 line_error
=true
# pass --file-line-error to TeX
52 max_iters
=7 # when to quit
55 quiet
=false
# let the tools' message be displayed
59 latex2html
=hevea
# or set to tex4ht
60 textra
= # Extra TeX commands to insert in the input file.
61 txiprereq
=19990129 # minimum texinfo.tex version with macro expansion
62 verb
=false
# true for verbose mode
63 translate_file
= # name of charset translation file
65 # We have to initialize IFS to space tab newline since we save and
66 # restore IFS and apparently POSIX allows stupid/broken behavior with
68 # http://lists.gnu.org/archive/html/automake-patches/2006-05/msg00008.html
69 # We need space, tab and newline, in precisely that order. And don't leave
75 IFS
="$space$tab$newline"
79 # Systems which define $COMSPEC or $ComSpec use semicolons to separate
80 # directories in TEXINPUTS -- except for Cygwin and Msys, where COMSPEC
81 # might be inherited, but : is used.
83 # In the case of Msys, uname returns a value derived from MSYSTEM, as
84 # MSYSTEM is user configurable, it is not so safe to use it to detect
85 # Msys. It is safer to use OSTYPE, this is why we set MSYSTEM to
86 # $OSTYPE before calling uname
87 if test -n "$COMSPEC$ComSpec" \
88 && MSYSTEM
=$OSTYPE uname |
$EGREP -iv 'cygwin|msys' >/dev
/null
; then
96 CDPATH
=${ZSH_VERSION+.}$path_sep
99 # Now we define numerous functions, with no other executable code.
100 # The main program is at the end of the file.
103 # \f Standard help and version functions.
105 # usage - display usage and exit successfully.
109 Usage: $program [OPTION]... FILE...
110 or: texi2pdf [OPTION]... FILE...
111 or: pdftexi2dvi [OPTION]... FILE...
113 Run each Texinfo or (La)TeX FILE through TeX in turn until all
114 cross-references are resolved, building all indices. The directory
115 containing each FILE is searched for included files. The suffix of FILE
116 is used to determine its language ((La)TeX or Texinfo). To process
117 (e)plain TeX files, set the environment variable LATEX=tex.
119 When invoked as \`texi2pdf' or given the option --pdf generate PDF output.
120 Otherwise, generate DVI.
123 -D, --debug turn on shell debugging (set -x)
124 -h, --help display this help and exit successfully
125 -o, --output=OFILE leave output in OFILE; only one input FILE is allowed
126 -q, --quiet no output unless errors
127 -v, --version display version information and exit successfully
128 -V, --verbose report on what is done
129 --max-iterations=N don't process files more than N times [$max_iters]
130 --mostly-clean remove auxiliary files or directories from
131 previous runs (but not the output)
134 --dvi output a DVI file [default]
135 --dvipdf output a PDF file via DVI (using a dvi-to-pdf program)
136 --html output an HTML file from LaTeX, using HeVeA
137 --info output an Info file from LaTeX, using HeVeA
138 -p, --pdf use pdftex or pdflatex for processing
139 --ps output a PostScript file via DVI (using dvips)
140 --text output a plain text file from LaTeX, using HeVeA
143 -E, --expand macro expansion using makeinfo
144 -I DIR search DIR for Texinfo files
145 -l, --language=LANG specify LANG for FILE, either latex or texinfo
146 --no-line-error do not pass --file-line-error to TeX
147 --shell-escape pass --shell-escape to TeX
148 --src-specials pass --src-specials to TeX
149 --translate-file=FILE use given charset translation file for TeX
150 -t, --command=CMD insert CMD in copy of input file
153 --build=MODE specify the treatment of auxiliary files [$build_mode]
154 --tidy same as --build=tidy
155 -c, --clean same as --build=clean
156 --build-dir=DIR specify where the tidy compilation is performed;
158 defaults to TEXI2DVI_BUILD_DIRECTORY [$build_dir]
160 The MODE specifies where the TeX compilation takes place, and, as a
161 consequence, how auxiliary files are treated. The build mode can also
162 be set using the environment variable TEXI2DVI_BUILD_MODE.
164 Valid values of MODE are:
165 \`local' compile in the current directory, leaving all the auxiliary
166 files around. This is the traditional TeX use.
167 \`tidy' compile in a local *.t2d directory, where the auxiliary files
168 are left. Output files are copied back to the original file.
169 \`clean' same as \`tidy', but remove the auxiliary directory afterwards.
170 Every compilation therefore requires the full cycle.
172 The values of these environment variables are used to run the
173 corresponding commands, if they are set:
175 BIBER BIBTEX DVIPDF DVIPS EGREP HEVEA LATEX MAKEINDEX MAKEINFO
176 PDFLATEX PDFTEX SED T4HT TEX TEX4HT TEXINDEX TEXINDY THUMBPDF_CMD
178 Regarding --dvipdf, if DVIPDF is not set in the environment, the
179 following programs are looked for (in this order): dvipdfmx dvipdfm
180 dvipdf dvi2pdf dvitopdf.
182 If Texinfo is installed on your site, then the command
186 should give you access to more documentation.
188 Report bugs to bug-texinfo@gnu.org,
189 general questions and discussion to help-texinfo@gnu.org.
190 GNU Texinfo home page: <http://www.gnu.org/software/texinfo/>
191 General help using GNU software: <http://www.gnu.org/gethelp/>
197 # version - Display version info and exit successfully.
201 texi2dvi (GNU Texinfo 6.7)
203 Copyright (C) 2019 Free Software Foundation, Inc.
204 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
205 This is free software: you are free to change and redistribute it.
206 There is NO WARRANTY, to the extent permitted by law.
212 # \f Generic auxiliary functions.
214 # Used to access files and directories after we have changed directory
218 # Change directory, updating some relative paths.
223 # Check if argument or input file is absolute, and if so, make all the path
224 # variables absolute.
227 [\\/]* | ?
:[\\/]*) # absolute path
235 if $use_absolute ; then
236 for cdd_dir
in work_build workdir t2ddir work_bak in_input in_dir
; do
237 eval "$cdd_dir=\`absolute \$$cdd_dir\`"
242 # Replace each path component with ".." and add a single trailing slash.
243 rel
=`echo "$1" | \$SED -e 's/[^/\\][^/\\]*/../g' -e 's/[/\\]*$/\//'`
246 # cd_orig - Return to the original directory.
249 # In case $orig_pwd is on a different drive (for DOS).
252 # Return to the original directory so that
253 # - the next file is processed in correct conditions
254 # - the temporary file can be removed
255 cd "$orig_pwd" ||
exit 1
261 # func_dirname FILE - Return the directory part of FILE.
264 dirname "$1" 2>/dev
/null \
265 ||
{ echo "$1" |
$SED 's!/[^/]*$!!;s!^$!.!'; }
269 # noext FILE - Return FILE with one extension removed:
270 # foo.bar.baz -> foo.bar
273 echo "$1" |
$SED -e 's/\.[^/.][^/.]*$//'
277 # absolute NAME - Return an absolute path to NAME.
282 # Absolute paths don't need to be expanded.
285 *) absolute_slashes
=`echo "$1" | $SED -n 's,.*[^/]\(/*\)$,\1,p'`
286 absolute_rel
=$orig_pwd/`func_dirname "$1"`
287 if test -d "$absolute_rel"; then
288 (cd "$absolute_rel" 2>/dev
/null \
289 && absolute_name
=`pwd`/`basename "$1"`"$absolute_slashes"
290 echo "$absolute_name")
292 error
1 "not a directory: $absolute_rel"
299 # ensure_dir DIR1 DIR2... - Make sure given directories exist.
304 # Beware that in parallel builds we may have several concurrent
305 # attempts to create the directory. So fail only if "mkdir"
306 # failed *and* the directory still does not exist.
310 || error
1 "cannot create directory: $dir"
315 # error EXIT_STATUS LINE1 LINE2... - Report an error and exit with
316 # failure if EXIT_STATUS is non-null.
322 if test "$error_status" != 0; then
328 # findprog PROG - Return true if PROG is somewhere in PATH, else false.
332 IFS
=$path_sep # break path components at the path separator
335 # The basic test for an executable is `test -f $f && test -x $f'.
336 # (`test -x' is not enough, because it can also be true for directories.)
337 # We have to try this both for $1 and $1.exe.
339 # Note: On Cygwin and DJGPP, `test -x' also looks for .exe. On Cygwin,
340 # also `test -f' has this enhancement, but not on DJGPP. (Both are
341 # design decisions, so there is little chance to make them consistent.)
342 # Thusly, it seems to be difficult to make use of these enhancements.
344 if { test -f "$dir/$1" && test -x "$dir/$1"; } \
345 ||
{ test -f "$dir/$1.exe" && test -x "$dir/$1.exe"; }; then
352 # report LINE1 LINE2... - Echo each argument to stderr.
362 # run COMMAND-LINE - Run COMMAND-LINE verbosely, catching errors as failures.
367 || error
1 "$1 failed"
371 # verbose WORD1 WORD2... - Echo concatenated WORDs to stderr, if $verb.
382 # list_append LIST-NAME ELEM - Append ELEM to (the contents of) LIST-NAME.
387 eval set X \$
$list_name "$@"
389 eval $list_name=\""$@"\"
393 # list_concat_dirs LIST-NAME DIR-LIST - Append to LIST-NAME all the
394 # components (including empty ones) from the $path_sep-separated list
395 # DIR-LIST. Make the paths absolute.
399 # Empty path components are meaningful to tex. We rewrite them as
400 # `EMPTY' so they don't get lost when we split on $path_sep.
401 # Hopefully no one will have an actual directory named EMPTY.
402 lcd_replace_EMPTY
="-e 's/^$path_sep/EMPTY$path_sep/g' \
403 -e 's/$path_sep\$/${path_sep}EMPTY/g' \
404 -e 's/$path_sep$path_sep/${path_sep}EMPTY${path_sep}/g'"
407 set x
`echo "$2" | eval $SED $lcd_replace_EMPTY`; shift
413 list_append
$lcd_list ""
416 if test -d $lcd_dir; then
417 dir
=`absolute "$lcd_dir"`
418 list_append
$lcd_list "$lcd_dir"
426 # list_prefix LIST-NAME SEP -> STRING - Return string with each element
427 # of LIST-NAME preceded by SEP.
436 lp_result
="$lp_result \"$lp_separator\" \"$i\""
441 # list_infix LIST-NAME SEP -> STRING - Same as list_prefix, but a separator.
452 # list_dir_to_abs LIST-NAME - Convert list to using only absolute dir names.
453 # Currently unused, but should replace absolute_filenames some day.
457 eval set X \$
$ldta_list
462 dir
=`absolute "$dir"`
463 test -d "$dir" ||
continue
464 ldta_result
="$ldata_result \"$dir\""
466 set X
$ldta_result; shift
467 eval $ldta_list=\"$@
\"
471 # \f Language auxiliary functions.
473 # out_lang_set LANG - set $out_lang to LANG (dvi, pdf, etc.), or error.
477 dvi|dvipdf|html|info|pdf|ps|text
) out_lang
=$1;;
478 *) error
1 "invalid output format: $1";;
482 # out_lang_tex - Return the tex output language (DVI or PDF) for $out_lang.
486 dvi | ps | dvipdf
) echo dvi
;;
487 pdf
) echo $out_lang;;
488 html | info | text
) echo $out_lang;;
489 *) error
1 "invalid out_lang: $1";;
493 # out_lang_ext - Return the extension for $out_lang (pdf, dvi, etc.).
498 dvi | html | info | pdf | ps | text
) echo $out_lang;;
499 *) error
1 "invalid out_lang: $1";;
504 # \f TeX file auxiliary functions.
506 # absolute_filenames TEX-PATH -> TEX-PATH - Convert relative paths to
507 # absolute, so we can run in another directory (e.g., in tidy build
508 # mode, or during the macro-support detection).
509 absolute_filenames
()
511 # Empty path components are meaningful to tex. We rewrite them as
512 # `EMPTY' so they don't get lost when we split on $path_sep.
513 # Hopefully no one will have an actual directory named EMPTY.
514 af_replace_empty
="-e 's/^$path_sep/EMPTY$path_sep/g' \
515 -e 's/$path_sep\$/${path_sep}EMPTY/g' \
516 -e 's/$path_sep$path_sep/${path_sep}EMPTY${path_sep}/g'"
517 af_result
=`echo "$1" | eval $SED $af_replace_empty`
520 set x
$af_result; shift
527 af_result
=$af_result$af_path_sep
530 if test -d "$dir"; then
531 af_result
=$af_result$af_path_sep`absolute "$dir"`
533 # Even if $dir is not a directory, preserve it in the path.
534 # It might contain metacharacters that TeX will expand in
535 # turn, e.g., /some/path/{a,b,c}. This will not get the
536 # implicit absolutification of the path, but we can't help that.
537 af_result
=$af_result$af_path_sep$dir
541 af_path_sep
=$path_sep
547 # output_base_name FILE - Return the name of FILE, possibly renamed to
548 # satisfy --output. FILE is local, i.e., without any directory part.
553 *) obn_out_noext
=`noext "$oname"`
554 obn_file_ext
=`echo "$1" | $SED 's/^.*\.//'`
555 echo "$obn_out_noext.$obn_file_ext"
561 # destdir - Return the directory where the output is expected.
565 '') echo "$orig_pwd";;
566 *) dirname "$oname";;
571 # move_to_dest FILE... - Move FILE(s) to the place where the user expects.
572 # Truly move it, that is, it must not remain in its build location
573 # unless that is also the output location. (Otherwise it might appear
574 # as an extra file in make distcheck.)
576 # FILE can be the principal output (in which case -o directly applies),
577 # or an auxiliary file with the same base name.
580 # echo "move_to_dest $*, tidy=$tidy, oname=$oname"
582 # If we built in place and have no output name, there is nothing to
583 # do, so just return.
591 || error
1 "no such file or directory: $file"
593 true
:) mtd_destdir
=$orig_pwd
594 mtd_destfile
=$mtd_destdir/$file;;
595 true
:*) mtd_destfile
=`output_base_name "$file"`
596 mtd_destdir
=`dirname "$mtd_destfile"`;;
597 false
:*) mtd_destfile
=$oname
598 mtd_destdir
=`dirname "$mtd_destfile"`;;
601 # We want to compare the source location and the output location,
602 # and if they are different, do the move. But if they are the
603 # same, we must preserve the source. Since we can't assume
604 # stat(1) or test -ef is available, resort to comparing the
605 # directory names, canonicalized with pwd. We can't use cmp -s
606 # since the output file might not actually change from run to run;
607 # e.g., TeX DVI output is timestamped to only the nearest minute.
608 mtd_destdir
=`cd "$mtd_destdir" && pwd`
609 mtd_destbase
=`basename "$mtd_destfile"`
611 mtd_sourcedir
=`dirname "$file"`
612 mtd_sourcedir
=`cd "$mtd_sourcedir" && pwd`
613 mtd_sourcebase
=`basename "$file"`
615 if test "$mtd_sourcedir/$mtd_sourcebase" != "$mtd_destdir/$mtd_destbase"
617 verbose
"Moving $file to $mtd_destfile"
618 rm -f "$mtd_destfile"
619 mv "$file" "$mtd_destfile"
625 # \f Managing xref files.
627 # aux_file_p FILE - Echo FILE if FILE is an aux file.
630 test -f "$1" ||
return 0
637 # bibaux_file_p FILE - Echo FILE if FILE contains citation requests.
640 test -s "$1" ||
return 0
641 if (grep '^\\bibstyle[{]' "$1" \
642 && grep '^\\bibdata[{]' "$1" \
643 ## The following line is suspicious: fails when there
644 ## are citations in sub aux files. We need to be
645 ## smarter in this case.
646 ## && grep '^\\citation[{]' "$f"
654 # index_file_p FILE - Echo FILE if FILE is an index file.
657 test -f "$1" ||
return 0
658 case $in_lang:$latex2html:`out_lang_tex`:`$SED '1q' "$1"` in
659 # When working with TeX4HT, *.idx are created by LaTeX. They must
660 # be processed to produce *.4ix, *.4dx files. The *.4dx file is
661 # passed to makeindex to produce the *.ind file. This sequence is
662 # handled by run_index, so we are only interested in the *.idx
663 # files, which have each "\indexentry" preceded by a
665 latex
:tex4ht
:html
:"\\beforeentry {"*) echo $1;;
667 # When index.sty is used, there is a space before the brace.
668 latex
:*:*:"\\indexentry{"*|latex
:*:*:"\\indexentry {"*) echo $1;;
670 texinfo
:*:*:"\\entry{"*) echo $1;;
671 texinfo
:*:*:"@entry{"*) echo $1;;
672 # @entry is output from newer versions of texinfo.tex
677 ########### not used currently
678 # xref_file_p FILE - Return success if FILE is an xref file (indexes,
682 test -f "$1" ||
return 1
683 # If the file is not suitable to be an index or xref file, don't
684 # process it. It's suitable if the first character is a
685 # backslash or right quote or at, as long as the first line isn't
687 case `$SED '1q' "$1"` in
688 "\\input texinfo"*) return 1;;
695 # Used in generated_files_get
696 generated_files_get_from_log
()
698 if test -f "$1.log"; then
699 # Usually the output is like: \openout1 = `foobar.tex'.
700 # (including the final period)
701 # but luatex outputs: \openout1 = foobar.tex
702 # (no quotes, no period).
703 # So we have to make the punctuation optional.
704 grep '^\\openout[0-9]' "$1.log" \
705 |
$SED -e "s/\\\\openout[^=]*= *[\`']*//" \
710 # Used in generated_files_get
711 generated_files_get_from_fls
()
713 if test -f "$1.fls"; then
714 grep '^OUTPUT ' "$1.fls" | cut
-b 8- \
715 |
grep -v '\.dvi$' |
grep -v '\.log$' |
grep -v '\.pdf$' || true
719 # generated_files_get - Output the list of files generated by the TeX
721 generated_files_get
()
723 $generated_files_get_method "$in_noext"
724 if test $generated_files_get_method = generated_files_get_from_fls
; then
725 if test -r "$in_noext.fl"; then
726 report
'WARNING!! The fl index may typeset as garbage!' # goes to stderr
727 report
'Try upgrading your version of texinfo.tex, or else try setting'
728 report
'the environment variable TEXI2DVI_USE_RECORDER to '\''no'\''.'
729 report
'Once you'\''ve done that, delete the file with an '\''fl'\'' extension.'
735 # xref_files_save - set xref_files_orig from xref_files_new, and save xref
736 # files in $work_bak.
739 # Save copies of auxiliary files for later comparison.
740 xref_files_orig
=$xref_files_new
741 if test -n "$xref_files_orig"; then
742 verbose
"Backing up xref files: $xref_files_orig"
743 # The following line improves `cp $xref_files_orig "$work_bak"'
744 # by preserving the directory parts. Think of
745 # cp chap1/main.aux chap2/main.aux $work_bak.
747 # Users may have, e.g., --keep-old-files. Don't let this interfere.
748 # (Don't use unset for the sake of ancient shells.)
749 TAR_OPTIONS
=; export TAR_OPTIONS
750 tar cf
- $xref_files_orig |
(cd "$rel$work_bak" && tar xf
-)
753 # Remove auxiliary files in same directory as main input file. Otherwise,
754 # these will likely be read instead of those in the build dir.
756 secondary_xref_files
=`sorted_index_files`
757 for f
in $xref_files_new $secondary_xref_files ; do
758 if test -f "$rel$in_dir/$f" ; then
759 remove
$rel$in_dir/$f
766 # xref_files_changed - Return success if the xref files have changed
767 # since the previous run.
768 xref_files_changed
()
770 # LaTeX (and the package changebar) report in the LOG file if it
771 # should be rerun. This is needed for files included from
772 # subdirs, since texi2dvi does not try to compare xref files in
773 # subdirs. Performing xref files test is still good since LaTeX
774 # does not report changes in xref files.
775 if grep "Rerun to get" "$in_noext.log" >&6 2>&1; then
778 # Similarly, check for biblatex report of whether rerunning is needed.
779 if grep "biblatex.*(re)run" "$in_noext.log" >&6 2>&1; then
783 # If old and new lists don't have the same file list,
784 # then something has definitely changed.
785 xref_files_new
=`generated_files_get`
786 verbose
"Original xref files = $xref_files_orig"
787 verbose
"New xref files = $xref_files_new"
788 if test "x$xref_files_orig" != "x$xref_files_new"; then
792 # Compare each file until we find a difference.
793 for this_file
in $xref_files_new; do
794 verbose
"Comparing xref file `echo $this_file | $SED 's|\./||g'` ..."
795 # cmp -s returns nonzero exit status if files differ.
796 if cmp -s "$this_file" "$rel$work_bak/$this_file"; then :; else
797 verbose
"xref file `echo $this_file | $SED 's|\./||g'` differed ..."
799 diff -u "$rel$work_bak/$this_file" "$this_file"
805 secondary_xref_files
=`sorted_index_files`
806 verbose
"Secondary xref files = $secondary_xref_files"
807 for this_file
in $secondary_xref_files; do
808 if test -f $this_file; then :; else
809 verbose
"$this_file missing ..."
818 # \f Running the TeX suite.
820 # Set tex_cmd variable, for running TeX.
823 case $in_lang:$latex2html:`out_lang_tex` in
824 latex
:*:dvi|latex
:tex4ht
:html
)
825 tex
=${LATEX:-latex};;
827 tex
=${PDFLATEX:-pdflatex};;
829 # MetaPost also uses the TEX environment variable. If the user
830 # has set TEX=latex for that reason, don't bomb out.
832 *latex
) tex
=tex
;; # don't bother trying to find etex
835 texinfo
:*:pdf
) tex
=$PDFTEX;;
836 *) error
1 "$out_lang not supported for $in_lang";;
839 # Beware of aux files in subdirectories that require the
840 # subdirectory to exist.
841 case $in_lang:$tidy in
843 $SED -n 's|^[ ]*\\include{\(.*\)/.*}.*|\1|p' "$in_input" |
847 ensure_dir
"$work_build/$d"
852 # Note that this will be used via an eval: quote properly.
855 # If possible, make TeX report error locations in GNU format.
857 if test "${tex_help:+set}" != set; then
858 # Go to a temporary directory to try --help, since old versions that
859 # don't accept --help will generate a texput.log.
860 tex_help_dir
=$t2ddir/tex_help
861 ensure_dir
"$tex_help_dir"
862 tex_help
=`cd "$tex_help_dir" >&6 && $tex --help </dev/null 2>&1 || true`
864 # The mk program and perhaps others want to parse TeX's
865 # original error messages.
867 *file-line-error
*) tex_cmd
="$tex_cmd --file-line-error";;
871 # Tell TeX about -recorder option, if specified
872 # recorder_option_maybe is in { " -recorder", "" }
873 tex_cmd
="$tex_cmd$recorder_option_maybe"
876 # Tell TeX about TCX file, if specified.
877 test -n "$translate_file" \
878 && tex_cmd
="$tex_cmd --translate-file=$translate_file"
880 # Tell TeX to make source specials (for backtracking from output to
881 # source, given a sufficiently smart editor), if specified.
882 test -n "$src_specials" && tex_cmd
="$tex_cmd $src_specials"
884 # Tell TeX to allow running external executables
885 test -n "$shell_escape" && tex_cmd
="$tex_cmd $shell_escape"
887 # Run without interaction.
888 # \batchmode does not show terminal output at all, so we don't
889 # want that. And even in batch mode, TeX insists on having input
890 # from the user. Close its stdin to make it impossible.
891 tex_cmd
="$tex_cmd </dev/null '${escape}nonstopmode'"
895 # run_tex - Run TeX, taking care of errors and logs.
898 # Check for any unusual characters in the filename.
899 # However, >, \ and any whitespace characters are not supported
901 in_input_funnies
=`echo "$in_input" \
902 | $SED -e 's![^}#$%&^_{~]!!g' -e 's!\(.\)!\1\''
905 if test -n "$in_input_funnies" ; then
906 # Make > an end group character, as it's unlikely to appear in
908 tex_cmd
="$tex_cmd '${escape}bgroup${escape}catcode62=2${escape}relax'"
910 # If the filename has funny characters, change the TeX category codes of
911 # some characters within a group, and use \expandafter to input the file
912 # outside of the group.
913 for w
in $in_input_funnies ; do
914 tex_cmd
="$tex_cmd '${escape}catcode\`${escape}$w=12${escape}relax'"
917 # Set \toks0 to "\input FILENAME\relax"
918 tex_cmd
="$tex_cmd '${escape}toks0${escape}bgroup${escape}input' '$rel$in_input' '${escape}relax>"
920 # Expand \toks0 after the end of the group
921 tex_cmd
="$tex_cmd${escape}expandafter${escape}egroup"
922 tex_cmd
="$tex_cmd${escape}the${escape}toks0${escape}relax'"
924 # In the case of a simple filename, just pass the filename
925 # with no funny tricks.
926 tex_cmd
="$tex_cmd '${escape}input' '$rel$in_input'"
929 verbose
"$0: Running $tex_cmd ..."
930 if (eval "$tex_cmd" >&5); then
932 dvi | pdf
) move_to_dest
"$in_noext.$out_lang";;
940 # run_bibtex - Run bibtex (or biber) on current file
941 # - if its input (AUX) exists,
942 # - or if some citations are missing (LOG contains `Citation'),
943 # - or if the LOG complains of a missing .bbl.
945 # Don't try to be too smart:
946 # 1. Running bibtex only if the bbl file exists and is older than
947 # the LaTeX file is wrong, since the document might include files
950 # 2. Because there can be several AUX (if there are \include's),
951 # but a single LOG, looking for missing citations in LOG is
952 # easier, though we take the risk of matching false messages.
956 latex
) bibtex
=${BIBTEX:-bibtex};;
960 # "Citation undefined" is for LaTeX, "Undefined citation" for btxmac.tex.
961 # The no .aux && \bibdata test is also for btxmac, in case it was the
962 # first run of a bibtex-using document. Otherwise, it's possible that
963 # bibtex would never be run.
964 if test -r "$in_noext.aux" \
965 && test -r "$in_noext.log" \
966 && ( (grep 'Warning:.*Citation.*undefined' "$in_noext.log" \
967 ||
grep '.*Undefined citation' "$in_noext.log" \
968 ||
grep 'No file .*\.bbl\.' "$in_noext.log") \
969 ||
(grep 'No \.aux file' "$in_noext.log" \
970 && grep '^\\bibdata' "$in_noext.aux") ) \
973 bibtex_aux
=`filter_files bibaux_file_p`
974 for f
in $bibtex_aux; do
979 # biber(+biblatex) check.
980 if test -r "$in_noext.bcf" \
981 && grep '</bcf:controlfile>' "$in_noext.bcf" >/dev
/null
; then
982 run
${BIBER:-biber} "$in_noext"
987 # filter_file PREDICATE - Go through the list of files in xref_files_new
988 # and use PREDICATE on each one to optionally print it or print other files
989 # based on the filename.
992 test -n "$xref_files_new" ||
return 0
993 echo "$xref_files_new" |
994 # Filter existing files matching the criterion.
1000 # Some files are opened several times, e.g., listings.sty's *.vrb.
1004 # run_index - Run texindex (or makeindex or texindy) on current index
1005 # files. If they already exist, and after running TeX a first time the
1006 # index files don't change, then there's no reason to run TeX again.
1007 # But we won't know that if the index files are out of date or nonexistent.
1010 index_files
=`filter_files index_file_p`
1011 test -n "$index_files" \
1014 : ${MAKEINDEX:=makeindex}
1015 : ${TEXINDEX:=texindex}
1016 : ${TEXINDY:=texindy}
1018 case $in_lang:$latex2html:`out_lang_tex` in
1020 for index_file
in $index_files
1022 index_noext
=`noext "$index_file"`
1024 '\def\filename{{'"$index_noext"'}{idx}{4dx}{ind}}
1026 run
$MAKEINDEX -o $index_noext.ind
$index_noext.4dx
1031 if $TEXINDY --version >&6 2>&1; then
1032 run
$TEXINDY $index_files
1034 run
$MAKEINDEX $index_files
1039 run
$TEXINDEX $index_files
1045 # run_tex4ht - Run the last two phases of TeX4HT: tex4ht extracts the
1046 # HTML from the instrumented DVI file, and t4ht converts the figures and
1047 # installs the files when given -d.
1049 # Because knowing exactly which files are created is complex (in
1050 # addition the names are not simple to compute), which makes it
1051 # difficult to install the output files in a second step, we
1052 # tell t4ht to install the output files.
1055 case $in_lang:$latex2html:`out_lang_tex` in
1057 : ${TEX4HT:=tex4ht} ${T4HT:=t4ht}
1058 run
"$TEX4HT" "-f/$in_noext"
1059 # Do not remove the / after the destdir.
1060 run
"$T4HT" "-d`destdir`/" "-f/$in_noext"
1066 # run_thumbpdf - Run thumbpdf.
1069 if test `out_lang_tex` = pdf \
1070 && test -r "$in_noext.log" \
1071 && grep 'thumbpdf\.sty' "$in_noext.log" >&6 2>&1; \
1073 thumbpdf
=${THUMBPDF_CMD:-thumbpdf}
1074 thumbcmd
="$thumbpdf $in_dir/$in_noext"
1075 verbose
"Running $thumbcmd ..."
1076 if $thumbcmd >&5; then
1079 report
"$thumbpdf exited with bad status." \
1080 "Ignoring its output."
1086 # run_dvipdf FILE.dvi - Convert FILE.dvi to FILE.pdf.
1089 # Find which dvi->pdf program is available.
1090 if test -n "$DVIPDF"; then
1091 dvipdf
=$DVIPDF # user envvar, use it without checking
1093 elif test -z "$dvipdf"; then
1094 for i
in dvipdfmx dvipdfm dvipdf dvi2pdf dvitopdf
; do
1095 if findprog
$i; then
1100 # These tools have varying interfaces, some 'input output', others
1101 # 'input -o output'. They all seem to accept 'input' only,
1102 # outputting using the expected file name.
1104 if test ! -f `echo "$1" | $SED -e 's/\.dvi$/.pdf/'`; then
1105 error
1 "cannot find output file"
1109 # run_tex_suite - Run the TeX tools until a stable point is reached.
1114 # Move to the working directory.
1116 verbose
"cd $work_build"
1117 cd_dir
"$work_build" ||
exit 1
1120 # Count the number of cycles.
1123 # Start by checking the log files for what files were created last
1124 # time. This will mean that if they don't change, we finish in 1 cycle.
1125 xref_files_new
=`generated_files_get`
1129 # check for (probably) LaTeX loop (e.g. varioref)
1130 if test $suite_cycle -eq "$max_iters"; then
1131 error
0 "Maximum of $max_iters cycles exceeded"
1136 suite_cycle
=`expr $suite_cycle + 1`
1137 verbose
"Cycle $suite_cycle for $command_line_filename"
1141 xref_files_changed ||
break
1144 # We run bibtex first, because it's more likely for the indexes
1145 # to change after bibtex is run than the reverse, though either
1151 if $tex_failed ; then
1152 # TeX failed, and the xref files did not change.
1153 error
1 "$tex exited with bad status, quitting."
1156 # If we were using thumbpdf and producing PDF, then run thumbpdf
1157 # and TeX one last time.
1160 # If we are using tex4ht, call it.
1163 # Install the result if we didn't already (i.e., if the output is
1165 case $latex2html:$out_lang in
1167 run_dvipdf
"$in_noext.`out_lang_tex`"
1168 move_to_dest
"$in_noext.`out_lang_ext`"
1172 run
$DVIPS -o "$in_noext.`out_lang_ext`" "$in_noext.`out_lang_tex`"
1173 move_to_dest
"$in_noext.`out_lang_ext`"
1181 # \f TeX processing auxiliary tools.
1183 # run_makeinfo - Expand macro commands in the original source file using
1184 # Makeinfo. Always use `end' footnote style, since the `separate' style
1185 # generates different output (arguably this is a bug in -E). Discard
1186 # main info output, the user asked to run TeX, not makeinfo.
1189 test $in_lang = texinfo \
1192 # Unless required by the user, makeinfo expansion is wanted only
1193 # if texinfo.tex is too old.
1195 makeinfo
=${MAKEINFO:-makeinfo}
1197 # Check if texinfo.tex performs macro expansion by looking for
1198 # its version. The version is a date of the form YEAR-MO-DA.
1199 # We don't need to use [0-9] to match the digits since anyway
1200 # the comparison with $txiprereq, a number, will fail with non-digits.
1201 # Run in a temporary directory to avoid leaving files.
1202 version_test_dir
=$t2ddir/version_test
1203 ensure_dir
"$version_test_dir"
1205 cd "$version_test_dir"
1206 echo '\input texinfo.tex @bye' >txiversion.tex
1207 # Be sure that if tex wants to fail, it is not interactive:
1209 $TEX txiversion.tex
</dev
/null
>txiversion.out
2>txiversion.err
1211 report
"texinfo.tex appears to be broken.
1212 This may be due to the environment variable TEX set to something
1213 other than (plain) tex, a corrupt texinfo.tex file, or
1214 to tex itself simply not working."
1215 cat "$version_test_dir/txiversion.out"
1216 cat "$version_test_dir/txiversion.err" >&2
1219 eval `$SED -n 's/^.*\[\(.*\)version \(....\)-\(..\)-\(..\).*$/txiformat=\1 txiversion="\2\3\4"/p' "$version_test_dir/txiversion.out"`
1220 verbose
"texinfo.tex preloaded as \`$txiformat', version is \`$txiversion' ..."
1221 if test "$txiprereq" -le "$txiversion" >&6 2>&1; then
1224 makeinfo
=${MAKEINFO:-makeinfo}
1226 # If TeX is preloaded, offer the user this convenience:
1227 if test "$txiformat" = Texinfo
; then
1232 if test -n "$makeinfo"; then
1233 # in_src: the file with macros expanded.
1234 # Use the same basename to generate the same aux file names.
1235 work_src
=$workdir/src
1236 ensure_dir
"$work_src"
1237 in_src
=$work_src/$in_base
1238 run_mi_includes
=`list_prefix includes -I`
1239 verbose
"Macro-expanding $command_line_filename to $in_src ..."
1240 # eval $makeinfo because it might be defined as something complex
1241 # (running missing) and then we end up with things like '"-I"',
1242 # and "-I" (including the quotes) is not an option name. This
1243 # happens with gettext 0.14.5, at least.
1244 $SED "$comment_iftex" "$command_line_filename" \
1245 |
eval $makeinfo --footnote-style=end
-I "$in_dir" $run_mi_includes \
1246 -o /dev
/null
--macro-expand=- \
1247 |
$SED "$uncomment_iftex" >"$in_src"
1248 # Continue only if everything succeeded.
1250 ||
test ! -r "$in_src"; then
1251 verbose
"Expansion failed, ignored...";
1258 # Unfortunately, makeinfo --iftex --no-ifinfo doesn't work well enough
1259 # in versions before 5.0, as makeinfo can't parse the TeX commands
1260 # inside @tex blocks, so work around with sed.
1262 # This sed script preprocesses Texinfo sources in order to keep the
1263 # iftex sections only. We want to remove non-TeX sections, and comment
1264 # (with `@c _texi2dvi') TeX sections so that makeinfo does not try to
1265 # parse them. Nevertheless, while commenting TeX sections, don't
1266 # comment @macro/@end macro so that makeinfo does propagate them.
1267 # Similarly, preserve the @top node to avoid makeinfo complaining about
1268 # it being missed. Comment it out after preprocessing, so that it does
1269 # not appear in the generated document.
1271 # We assume that `@c _texi2dvi' or `@c (_texi2dvi)' starting a line is
1272 # not present in the document. Additionally, conditionally defined
1273 # macros inside the @top node may end up with the wrong value, although
1274 # this is unlikely in practice.
1277 '/^@tex/,/^@end tex/{
1280 /^@iftex/,/^@end iftex/{
1282 /^@c _texi2dvi@macro/,/^@c _texi2dvi@end macro/{
1286 /^@ifnottex/,/^@end ifnottex/{
1288 /^@c (_texi2dvi)@node Top/,/^@c (_texi2dvi)@end ifnottex/ {
1289 /^@c (_texi2dvi)@end ifnottex/b
1293 /^@ifinfo/,/^@end ifinfo/{
1295 /^@menu/,/^@end menu/p
1299 s/^@ifnotinfo/@c _texi2dvi@ifnotinfo/
1300 s/^@end ifnotinfo/@c _texi2dvi@end ifnotinfo/'
1302 # Uncomment @iftex blocks by removing any leading `@c texi2dvi' (repeated
1303 # copies can sneak in via macro invocations). Likewise, comment out
1304 # the @top node inside a @ifnottex block.
1306 's/^@c _texi2dvi\(@c _texi2dvi\)*//
1307 /^@c (_texi2dvi)@ifnottex/,/^@c (_texi2dvi)@end ifnottex/{
1312 # insert_commands - Insert $textra commands at the beginning of the file.
1313 # Recommended to be used for @finalout, @smallbook, etc.
1316 if test -n "$textra"; then
1317 # _xtr. The file with the user's extra commands.
1318 work_xtr
=$workdir/xtr
1319 in_xtr
=$work_xtr/$in_base
1320 ensure_dir
"$work_xtr"
1321 verbose
"Inserting extra commands: $textra"
1323 latex
) textra_cmd
=1i
;;
1325 textra_cmd
='/^\\input texinfo/a'
1326 # insert after @setfilename line if present
1327 if head -n 10 $in_input |
grep '^@setfilename' ; then
1328 textra_cmd
='/^@setfilename/a'
1331 *) error
1 "internal error, unknown language: $in_lang";;
1334 $textra" "$in_input" >"$in_xtr"
1338 case $in_lang:$latex2html:`out_lang_tex` in
1340 # _tex4ht. The file with the added \usepackage{tex4ht}.
1341 work_tex4ht
=$workdir/tex4ht
1342 in_tex4ht
=$work_tex4ht/$in_base
1343 ensure_dir
"$work_tex4ht"
1344 verbose
"Inserting \\usepackage{tex4ht}"
1345 perl
-pe 's<\\documentclass(?:\[.*\])?{.*}>
1346 <$&\\usepackage[xhtml]{tex4ht}>' \
1347 "$in_input" >"$in_tex4ht"
1354 # compute_language FILENAME - Return the short string for the language
1355 # in which FILENAME is written: `texinfo' or `latex'.
1358 # If the user explicitly specified the language, use that.
1359 # Otherwise, if the first line is \input texinfo, assume it's texinfo.
1360 # Otherwise, guess from the file extension.
1361 if test -n "$set_language"; then
1363 elif $SED 1q
"$1" |
grep 'input texinfo' >&6; then
1366 # Get the type of the file (latex or texinfo) from the given language
1367 # we just guessed, or from the file extension if not set yet.
1369 *.ltx |
*.tex |
*.drv |
*.dtx
) echo latex
;;
1376 # run_hevea (MODE) - Convert to HTML/INFO/TEXT.
1378 # Don't pass `-noiso' to hevea: it's useless in HTML since anyway the
1379 # charset is set to latin1, and troublesome in other modes since
1380 # accented characters loose their accents.
1382 # Don't pass `-o DEST' to hevea because in that case it leaves all its
1383 # auxiliary files there too... Too bad, because it means we will need
1384 # to handle images some day.
1387 run_hevea_name
="${HEVEA:-hevea}"
1388 run_hevea_cmd
="$run_hevea_name"
1392 text|info
) run_hevea_cmd
="$run_hevea_cmd -$1";;
1393 *) error
1 "run_hevea_cmd: invalid argument: $1";;
1396 # Compiling to the tmp directory enables to preserve a previous
1397 # successful compilation.
1398 run_hevea_cmd
="$run_hevea_cmd -fix -O -o '$out_base'"
1399 run_hevea_cmd
="$run_hevea_cmd `list_prefix includes -I` -I '$orig_pwd' "
1400 run_hevea_cmd
="$run_hevea_cmd '$rel$in_input'"
1403 run_hevea_cmd
="$run_hevea_cmd -v -v"
1406 verbose
"running $run_hevea_cmd"
1407 if eval "$run_hevea_cmd" >&5; then
1408 # hevea leaves trailing white spaces, this is annoying.
1409 case $1 in text|info
)
1410 perl
-pi -e 's/[ \t]+$//g' "$out_base"*;;
1413 html|text
) move_to_dest
"$out_base";;
1414 info
) # There can be foo.info-1, foo.info-2 etc.
1415 move_to_dest
"$out_base"*;;
1418 error
1 "$run_hevea_name exited with bad status, quitting."
1423 # run_core_conversion - Run TeX (or HeVeA).
1424 run_core_conversion
()
1426 case $in_lang:$latex2html:`out_lang_tex` in
1427 *:dvi|
*:pdf|latex
:tex4ht
:html
)
1429 latex
:*:html|latex
:*:text|latex
:*:info
)
1430 run_hevea
$out_lang;;
1432 error
1 "invalid input/output combination: $in_lang/$out_lang";;
1437 # compile - Run the full compilation chain, from pre-processing to
1438 # installation of the output at its expected location.
1441 # Set include path for tools:
1442 # . Include current directory in case there are files there already, so
1443 # we don't have more TeX runs than necessary. orig_pwd is used in case
1444 # we are in clean build mode, where we have cd'd to a temp directory.
1445 # . Include directory containing file, in case there are other
1447 # . Keep a final path_sep to get the default (system) TeX
1448 # directories included.
1449 # . If we have any includes, put those at the end.
1451 common
="$orig_pwd$path_sep$in_dir$path_sep"
1453 txincludes
=`list_infix includes $path_sep`
1454 test -n "$txincludes" && common
="$common$txincludes$path_sep"
1456 for var
in $tex_envvars; do
1457 eval val
="\$common\$${var}_orig"
1458 # Convert relative paths to absolute paths, so we can run in another
1459 # directory (e.g., in clean build mode, or during the macro-support
1461 val
=`absolute_filenames "$val"`
1462 eval $var="\"$val\""
1464 eval verbose
\"$var=\'\$
${var}\'\"
1470 # --command, --texinfo
1473 # Run until a fixed point is reached.
1477 # make_openout_test FLAGS EXTENSION
1478 # - Run TeX with an input file that performs an \openout. Pass FLAGS to TeX.
1480 make_openout_test
()
1482 recorder_option_maybe
="$1"
1485 ensure_dir
"$workdir"/check_recorder
1486 cd_dir
"$workdir"/check_recorder
1488 cat > openout.tex
<<EOF
1490 \immediate\openout\ourwrite dum.dum
1493 # \bye doesn't work for LaTeX, but it will cause latex
1494 # to exit with an input error.
1495 tex_cmd
="$tex_cmd '${escape}input' ./openout.tex"
1496 # ./ in case . isn't in path
1497 verbose
"$0: running $tex_cmd ..."
1499 (eval "$tex_cmd" >/dev
/null
2>&1)
1502 # Check tex supports -recorder option
1503 check_recorder_support
()
1505 verbose
"Checking TeX recorder support..."
1506 make_openout_test
" -recorder" fls
1507 if test -f openout.fls
&& grep '^OUTPUT dum.dum$' openout.fls
> /dev
/null
1510 verbose
"Checking TeX recorder support... yes"
1514 verbose
"Checking TeX recorder support... no"
1519 # Check tex supports \openout traces in log
1520 check_openout_in_log_support
()
1522 verbose
"Checking TeX \openout in log support..."
1523 make_openout_test
"" log
1524 if test -f openout.log \
1525 && grep '^\\openout..\? *= *`\?dum\.dum'\''\?' openout.log
>/dev
/null
1528 verbose
"Checking TeX \openout in log support... yes"
1532 verbose
"Checking TeX \openout in log support... no"
1537 # Set that output auxiliary files are detected with the -recorder option,
1538 # which creates a file JOBNAME.fls which is a machine-readable listing of
1539 # files read and written during the job.
1540 set_aux_files_from_fls
()
1542 recorder_option_maybe
=" -recorder"
1543 generated_files_get_method
=generated_files_get_from_fls
1546 # Set that output auxiliary files are detected with searching for \openout
1548 set_aux_files_from_log
()
1550 recorder_option_maybe
=''
1551 generated_files_get_method
=generated_files_get_from_log
1554 # Decide whether output auxiliary files are detected with the -recorder
1555 # option, or by searching for \openout in the log file.
1556 decide_aux_files_method
()
1558 # Select output file detection method
1559 # Valid values of TEXI2DVI_USE_RECORDER are:
1560 # yes use the -recorder option, no checks.
1561 # no scan for \openout in the log file, no checks.
1562 # yesmaybe check whether -recorder option is supported, and if yes
1563 # use it, otherwise check for tracing \openout in the
1564 # log file is supported, and if yes use it, else it is an
1566 # nomaybe same as `yesmaybe', except that the \openout trace in
1567 # log file is checked first.
1569 # The default behaviour is `nomaybe'.
1571 test -n "$TEXI2DVI_USE_RECORDER" || TEXI2DVI_USE_RECORDER
=nomaybe
1573 case $TEXI2DVI_USE_RECORDER in
1574 yes) set_aux_files_from_fls
;;
1576 no
) set_aux_files_from_log
;;
1579 if check_recorder_support
; then
1580 set_aux_files_from_fls
1581 elif check_openout_in_log_support
; then
1582 set_aux_files_from_log
1584 error
1 "TeX neither supports -recorder nor outputs \\openout lines in its log file"
1589 if check_openout_in_log_support
; then
1590 set_aux_files_from_log
1591 elif check_recorder_support
; then
1592 set_aux_files_from_fls
1594 error
1 "TeX neither supports -recorder nor outputs \\openout lines in its log file"
1598 *) error
1 "Invalid value of TEXI2DVI_USE_RECORDER environment variable : $TEXI2DVI_USE_RECORDER.";;
1606 verbose
"Removing" "$@"
1611 # all_files - Echo the names of all files generated, including those by
1612 # auxiliary tools like texindex.
1617 echo $xref_files_new
1618 echo `sorted_index_files`
1621 sorted_index_files
()
1623 filter_files sorted_index_filter
1626 # Print the name of a generated file based on FILE if there is one.
1627 sorted_index_filter
()
1631 # texindex: texinfo.cp -> texinfo.cps
1632 if test -n "`index_file_p $1`" ; then
1640 # Not currently used - use with filter_files to add secondary files created by
1642 bibtex_secondary_files
()
1646 if test -n "`aux_file_p $1`"; then
1647 # bibtex: *.aux -> *.bbl and *.blg.
1648 echo $1 |
$SED 's/^\(.*\)\.aux$/\1.bbl/'
1649 echo $1 |
$SED 's/^\(.*\)\.aux$/\1.blg/'
1655 # mostly_clean - Remove auxiliary files and directories. Changes back to
1656 # the original directory.
1663 set X
${1+"$@"} `all_files`
1670 # cleanup - Remove what should be removed according to options.
1671 # Called at the end of each compilation cycle, and at the end of
1672 # the script. Changes the current directory.
1675 case $clean:$tidy in
1676 true
:true
) mostly_clean
;; # build mode is "clean"
1677 false
:false
) cd_orig
; remove
"$t2ddir";; # build mode is "local"
1682 # \f input_file_name_decode - Decode COMMAND_LINE_FILENAME, and set the
1683 # following shell variables:
1685 # - COMMAND_LINE_FILENAME
1686 # The filename given on the commmand line, but cleaned of TeX commands.
1688 # The directory containing the input file.
1690 # The input file base name (no directory part).
1692 # The input file name with neither file extensions nor directory part.
1694 # The path to the input file for passing as a command-line argument
1695 # to TeX. Defaults to COMMAND_LINE_FILENAME, but might change if the
1696 # input is preprocessed.
1697 input_file_name_decode
()
1699 case $command_line_filename in
1701 # Let AUC-TeX error parser deal with line numbers.
1703 command_line_filename
=`\
1704 expr X"$command_line_filename" : X'.*input{\([^}]*\)}'`
1708 # If the COMMAND_LINE_FILENAME is not absolute (e.g., --debug.tex),
1709 # prepend `./' in order to avoid that the tools take it as an option.
1710 echo "$command_line_filename" | LC_ALL
=C
$EGREP '^(/|[A-Za-z]:/)' >&6 \
1711 || command_line_filename
="./$command_line_filename"
1713 # See if the file exists. If it doesn't we're in trouble since, even
1714 # though the user may be able to reenter a valid filename at the tex
1715 # prompt (assuming they're attending the terminal), this script won't
1716 # be able to find the right xref files and so forth.
1717 test -r "$command_line_filename" \
1718 || error
1 "cannot read $command_line_filename, skipping."
1720 # Get the name of the current directory.
1721 in_dir
=`func_dirname "$command_line_filename"`
1723 # Strip directory part but leave extension.
1724 in_base
=`basename "$command_line_filename"`
1726 in_noext
=`noext "$in_base"`
1728 # The normalized file name to compile. Must always point to the
1729 # file to actually compile (in case of recoding, macro-expansion etc.).
1730 in_input
=$in_dir/$in_base
1733 # Compute the output file name.
1734 if test x
"$oname" != x
; then
1737 out_name
=$in_noext.
`out_lang_ext`
1739 out_dir
=`func_dirname "$out_name"`
1740 out_dir_abs
=`absolute "$out_dir"`
1741 out_base
=`basename "$out_name"`
1742 out_noext
=`noext "$out_base"`
1747 #################### Main program starts ##########################
1749 # Initialize more variables.
1751 # Save TEXINPUTS so we can construct a new TEXINPUTS path for each file.
1752 # Likewise for bibtex and makeindex.
1753 tex_envvars
="BIBINPUTS BSTINPUTS DVIPSHEADERS INDEXSTYLE MFINPUTS MPINPUTS \
1755 for var
in $tex_envvars; do
1756 eval ${var}_orig
=\$
$var
1760 # Push a token among the arguments that will be used to notice when we
1761 # ended options/arguments parsing.
1762 # Use "set dummy ...; shift" rather than 'set - ..." because on
1763 # Solaris set - turns off set -x (but keeps set -e).
1764 # Use ${1+"$@"} rather than "$@" because Digital Unix and Ultrix 4.3
1765 # still expand "$@" to a single argument (the empty string) rather
1766 # than nothing at all.
1768 set dummy
${1+"$@"} "$arg_sep"; shift
1770 while test x
"$1" != x
"$arg_sep"; do
1771 # Handle --option=value by splitting apart and putting back on argv.
1774 opt
=`echo "$1" | $SED -e 's/=.*//'`
1775 val
=`echo "$1" | $SED -e 's/[^=]*=//'`
1777 set dummy
"$opt" "$val" ${1+"$@"}; shift
1783 -~
) verbose
"Option -~ is obsolete: texi2dvi ignores it.";;
1784 -b |
--batch) ;; # Obsolete
1785 --build) shift; build_mode
=$1;;
1786 --build-dir) shift; build_dir
=$1; build_mode
=tidy
;;
1787 -c |
--clean) build_mode
=clean
;;
1788 -D |
--debug) debug
=true
;;
1789 -e |
-E |
--expand) expand=true
;;
1790 -h |
--help) usage
;;
1791 -I) shift; list_concat_dirs includes
"$1";;
1792 -l |
--lang |
--language) shift; set_language
=$1;;
1793 --mostly-clean) action
=mostly-clean
;;
1794 --no-line-error) line_error
=false
;;
1795 --max-iterations) shift; max_iters
=$1;;
1796 -o |
--out |
--output)
1798 # Make it absolute, just in case we also have --clean, or whatever.
1799 oname
=`absolute "$1"`;;
1802 -O|
--output-format) shift; out_lang_set
"$1";;
1803 --dvi|
--dvipdf|
--html|
--info|
--pdf|
--ps|
--text)
1804 out_lang_set
`echo "x$1" | $SED 's/^x--//'`;;
1806 -p) out_lang_set pdf
;;
1807 -q |
-s |
--quiet |
--silent) quiet
=true
;;
1808 --src-specials) src_specials
=--src-specials;;
1809 --shell-escape) shell_escape
=--shell-escape;;
1810 --tex4ht) latex2html
=tex4ht
;;
1811 -t |
--texinfo |
--command ) shift; textra
="$textra\\
1812 "`echo "$1" | $SED 's/\\\\/\\\\\\\\/g'`;;
1813 --translate-file ) shift; translate_file
="$1";;
1814 --tidy) build_mode
=tidy
;;
1815 -v |
--vers*) version
;;
1816 -V |
--verb*) verb
=true
;;
1817 --) # What remains are not options.
1819 while test x
"$1" != x
"$arg_sep"; do
1820 set dummy
${1+"$@"} "$1"; shift
1825 error
1 "Unknown or ambiguous option \`$1'." \
1826 "Try \`--help' for more information."
1828 *) set dummy
${1+"$@"} "$1"; shift;;
1835 # $tidy: compile in a t2d directory.
1836 # $clean: remove all the aux files.
1838 local) clean
=false
; tidy
=false
;;
1839 tidy
) clean
=false
; tidy
=true
;;
1840 clean
) clean
=true
; tidy
=true
;;
1841 *) error
1 "invalid build mode: $build_mode";;
1844 # Interpret remaining command line args as filenames.
1847 error
2 "Missing file arguments." "Try \`--help' for more information."
1851 if test -n "$oname"; then
1852 error
2 "Can't use option \`--output' with more than one argument."
1858 # We can't do much without tex.
1859 # End up with the TEX and PDFTEX variables set to what we are going to use.
1861 # If $TEX is set to a directory, don't use it.
1862 test -n "$TEX" && test -d "$TEX" && unset TEX
1864 # But otherwise, use $TEX if it is set.
1865 if test -z "$TEX"; then
1866 if findprog tex
; then :; else cat <<EOM >&2
1867 You don't have a working TeX binary (tex) installed anywhere in
1868 your PATH, and texi2dvi cannot proceed without one. If you want to use
1869 this script, you'll need to install TeX (if you don't have it) or change
1870 your PATH or TEX environment variable (if you do). See the --help
1871 output for more details.
1873 For information about obtaining TeX, please see http://tug.org/texlive,
1874 or do a web search for TeX and your operating system or distro.
1879 # We want to use etex (or pdftex) if they are available, and the user
1880 # didn't explicitly specify. We don't check for elatex and pdfelatex
1881 # because (as of 2003), the LaTeX team has asked that new distributions
1882 # use etex by default anyway.
1884 if findprog etex
; then TEX
=etex
; else TEX
=tex
; fi
1887 # For many years, the pdftex binary has included the e-tex extensions,
1888 # but for those people with ancient TeX distributions ...
1889 if test -z "$PDFTEX"; then
1890 if findprog pdfetex
; then PDFTEX
=pdfetex
; else PDFTEX
=pdftex
; fi
1894 # File descriptor usage:
1896 # 1 standard output (--verbose messages)
1898 # 5 tools output (turned off by --quiet)
1899 # 6 tracing/debugging (set -x output, etc.)
1901 # Main tools' output (TeX, etc.) that TeX users are used to seeing.
1903 # If quiet, discard, else redirect to the message flow.
1911 # Enable tracing, and auxiliary tools output.
1913 # This fd should be used where you'd typically use /dev/null to throw
1914 # output away. But sometimes it is convenient to see that output (e.g.,
1915 # from a grep) to aid debugging. Especially debugging at distance, via
1926 # \f Main program main loop - TeXify each file in turn.
1927 for command_line_filename
1929 verbose
"Processing $command_line_filename ..."
1931 input_file_name_decode
1933 # `texinfo' or `latex'?
1934 in_lang
=`compute_language "$command_line_filename"`
1936 # An auxiliary directory used for all the auxiliary tasks involved
1937 # in compiling this document.
1939 '' | .
) t2ddir
=$out_noext.t2d
;;
1940 *) # Avoid collisions between multiple occurrences of the same
1941 # file, so depend on the output path. Remove leading `./',
1942 # at least to avoid creating a file starting with `.!', i.e.,
1943 # an invisible file. The sed expression is fragile if the cwd
1944 # has active characters. Transform / into ! so that we don't
1945 # need `mkdir -p'. It might be something to reconsider.
1946 t2ddir
=$build_dir/`echo "$out_dir_abs/$out_noext.t2d" |
1947 $SED "s,^$orig_pwd/,,;s,^\./,,;s,/,!,g"`
1949 # Remove it at exit if clean mode.
1950 trap "cleanup" 0 1 2 15
1952 ensure_dir
"$build_dir" "$t2ddir"
1954 # Sometimes there are incompatibilities between auxiliary files for
1955 # DVI and PDF. The contents can also change whether we work on PDF
1956 # and/or DVI. So keep separate spaces for each.
1957 workdir
=$t2ddir/`out_lang_tex`
1958 ensure_dir
"$workdir"
1960 # _build. In a tidy build, where the auxiliary files are output.
1962 work_build
=$workdir/build
1967 # _bak. Copies of the previous auxiliary files (another round is
1968 # run if they differ from the new ones).
1969 work_bak
=$workdir/bak
1971 # Make those directories.
1972 ensure_dir
"$work_build" "$work_bak"
1974 # Decide how to find auxiliary files created by TeX.
1975 decide_aux_files_method
1979 # Compile the document.
1985 xref_files_new
=`generated_files_get`
1992 exit 0 # exit successfully, not however we ended the loop.
1994 # sh-basic-offset: 2