summaryrefslogtreecommitdiff
path: root/doc/texi2dvi
diff options
context:
space:
mode:
Diffstat (limited to 'doc/texi2dvi')
-rwxr-xr-xdoc/texi2dvi1656
1 files changed, 854 insertions, 802 deletions
diff --git a/doc/texi2dvi b/doc/texi2dvi
index 173e8ab..17f4355 100755
--- a/doc/texi2dvi
+++ b/doc/texi2dvi
@@ -1,10 +1,7 @@
#! /bin/sh
# texi2dvi --- produce DVI (or PDF) files from Texinfo (or (La)TeX) sources.
-# $Id: texi2dvi 5704 2014-07-07 17:45:16Z karl $
#
-# Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
-# Free Software Foundation, Inc.
+# Copyright 1992-2019 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -36,20 +33,17 @@ set -e
# In case the default sed doesn't suffice.
: ${SED=sed}
-# This string is expanded automatically when this file is checked out.
-rcs_revision='$Revision: 5704 $'
-rcs_version=`set - $rcs_revision; echo $2`
program=`echo $0 | $SED -e 's!.*/!!'`
build_mode=${TEXI2DVI_BUILD_MODE:-local}
build_dir=${TEXI2DVI_BUILD_DIRECTORY:-.}
+orig_pwd=`pwd`
+
# Initialize variables for option overriding and otherwise.
# Don't use `unset' since old bourne shells don't have this command.
# Instead, assign them an empty value.
action=compile
-batch=false # interact normally
-catcode_special=maybe
debug=false
escape="\\"
expand=false # true for expansion via makeinfo
@@ -68,13 +62,11 @@ txiprereq=19990129 # minimum texinfo.tex version with macro expansion
verb=false # true for verbose mode
translate_file= # name of charset translation file
-orig_pwd=`pwd`
-
# We have to initialize IFS to space tab newline since we save and
# restore IFS and apparently POSIX allows stupid/broken behavior with
# empty-but-set IFS.
# http://lists.gnu.org/archive/html/automake-patches/2006-05/msg00008.html
-# We need space, tab and new line, in precisely that order. And don't leave
+# We need space, tab and newline, in precisely that order. And don't leave
# trailing blanks.
space=' '
tab=' '
@@ -82,70 +74,176 @@ newline='
'
IFS="$space$tab$newline"
-# In case someone pedantic insists on using grep -E.
: ${EGREP=egrep}
# Systems which define $COMSPEC or $ComSpec use semicolons to separate
-# directories in TEXINPUTS -- except for Cygwin et al., where COMSPEC
+# directories in TEXINPUTS -- except for Cygwin and Msys, where COMSPEC
# might be inherited, but : is used.
+
+# In the case of Msys, uname returns a value derived from MSYSTEM, as
+# MSYSTEM is user configurable, it is not so safe to use it to detect
+# Msys. It is safer to use OSTYPE, this is why we set MSYSTEM to
+# $OSTYPE before calling uname
if test -n "$COMSPEC$ComSpec" \
- && uname | $EGREP -iv 'cygwin|mingw|djgpp' >/dev/null; then
+ && MSYSTEM=$OSTYPE uname | $EGREP -iv 'cygwin|msys' >/dev/null; then
path_sep=";"
else
path_sep=":"
fi
+
# Pacify verbose cds.
CDPATH=${ZSH_VERSION+.}$path_sep
-# If $TEX is set to a directory, don't use it.
-test -n "$TEX" && test -d "$TEX" && unset TEX
-#
-## --------------------- ##
-## Auxiliary functions. ##
-## --------------------- ##
-
-# In case `local' is not supported by the shell, provide a function
-# that simulates it by simply performing the assignments. This means
-# that we must not expect `local' to work, i.e., we must not (i) rely
-# on it during recursion, and (ii) have two local declarations of the
-# same variable. (ii) is easy to check statically, and our test suite
-# does make sure there is never twice a static local declaration of a
-# variable. (i) cannot be checked easily, so just be careful.
-#
-# Note that since we might use a function simulating `local', we can
-# no longer rely on the fact that no IFS-splitting is performed. So,
-# while
-#
-# foo=$bar
-#
-# is fine (no IFS-splitting), never write
-#
-# local foo=$bar
-#
-# but rather
+# Now we define numerous functions, with no other executable code.
+# The main program is at the end of the file.
+
+
+# Standard help and version functions.
#
-# local foo="$bar"
-(
- foo=bar
- test_local () {
- local foo=foo
- }
- test_local >/dev/null 2>&1
- test $foo = bar
-) || eval '
-local () {
+# usage - display usage and exit successfully.
+usage ()
+{
+ cat <<EOF
+Usage: $program [OPTION]... FILE...
+ or: texi2pdf [OPTION]... FILE...
+ or: pdftexi2dvi [OPTION]... FILE...
+
+Run each Texinfo or (La)TeX FILE through TeX in turn until all
+cross-references are resolved, building all indices. The directory
+containing each FILE is searched for included files. The suffix of FILE
+is used to determine its language ((La)TeX or Texinfo). To process
+(e)plain TeX files, set the environment variable LATEX=tex.
+
+When invoked as \`texi2pdf' or given the option --pdf generate PDF output.
+Otherwise, generate DVI.
+
+General options:
+ -D, --debug turn on shell debugging (set -x)
+ -h, --help display this help and exit successfully
+ -o, --output=OFILE leave output in OFILE; only one input FILE is allowed
+ -q, --quiet no output unless errors
+ -v, --version display version information and exit successfully
+ -V, --verbose report on what is done
+ --max-iterations=N don't process files more than N times [$max_iters]
+ --mostly-clean remove auxiliary files or directories from
+ previous runs (but not the output)
+
+Output format:
+ --dvi output a DVI file [default]
+ --dvipdf output a PDF file via DVI (using a dvi-to-pdf program)
+ --html output an HTML file from LaTeX, using HeVeA
+ --info output an Info file from LaTeX, using HeVeA
+ -p, --pdf use pdftex or pdflatex for processing
+ --ps output a PostScript file via DVI (using dvips)
+ --text output a plain text file from LaTeX, using HeVeA
+
+TeX tuning:
+ -E, --expand macro expansion using makeinfo
+ -I DIR search DIR for Texinfo files
+ -l, --language=LANG specify LANG for FILE, either latex or texinfo
+ --no-line-error do not pass --file-line-error to TeX
+ --shell-escape pass --shell-escape to TeX
+ --src-specials pass --src-specials to TeX
+ --translate-file=FILE use given charset translation file for TeX
+ -t, --command=CMD insert CMD in copy of input file
+
+Build modes:
+ --build=MODE specify the treatment of auxiliary files [$build_mode]
+ --tidy same as --build=tidy
+ -c, --clean same as --build=clean
+ --build-dir=DIR specify where the tidy compilation is performed;
+ implies --tidy;
+ defaults to TEXI2DVI_BUILD_DIRECTORY [$build_dir]
+
+The MODE specifies where the TeX compilation takes place, and, as a
+consequence, how auxiliary files are treated. The build mode can also
+be set using the environment variable TEXI2DVI_BUILD_MODE.
+
+Valid values of MODE are:
+ \`local' compile in the current directory, leaving all the auxiliary
+ files around. This is the traditional TeX use.
+ \`tidy' compile in a local *.t2d directory, where the auxiliary files
+ are left. Output files are copied back to the original file.
+ \`clean' same as \`tidy', but remove the auxiliary directory afterwards.
+ Every compilation therefore requires the full cycle.
+
+The values of these environment variables are used to run the
+corresponding commands, if they are set:
+
+ BIBER BIBTEX DVIPDF DVIPS EGREP HEVEA LATEX MAKEINDEX MAKEINFO
+ PDFLATEX PDFTEX SED T4HT TEX TEX4HT TEXINDEX TEXINDY THUMBPDF_CMD
+
+Regarding --dvipdf, if DVIPDF is not set in the environment, the
+following programs are looked for (in this order): dvipdfmx dvipdfm
+dvipdf dvi2pdf dvitopdf.
+
+If Texinfo is installed on your site, then the command
+
+ info texi2dvi
+
+should give you access to more documentation.
+
+Report bugs to bug-texinfo@gnu.org,
+general questions and discussion to help-texinfo@gnu.org.
+GNU Texinfo home page: <http://www.gnu.org/software/texinfo/>
+General help using GNU software: <http://www.gnu.org/gethelp/>
+EOF
+ exit 0
+}
+
+
+# version - Display version info and exit successfully.
+version ()
+{
+ cat <<EOF
+texi2dvi (GNU Texinfo 6.7)
+
+Copyright (C) 2019 Free Software Foundation, Inc.
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.
+EOF
+ exit 0
+}
+
+
+# Generic auxiliary functions.
+
+# Used to access files and directories after we have changed directory
+# (for --tidy).
+rel=
+
+# Change directory, updating some relative paths.
+cd_dir ()
+{
+ cd "$1"
+
+ # Check if argument or input file is absolute, and if so, make all the path
+ # variables absolute.
+ use_absolute=false
case $1 in
- *=*) eval "$1";;
+ [\\/]* | ?:[\\/]*) # absolute path
+ use_absolute=true ;;
+ esac
+ case $in_input in
+ [\\/]* | ?:[\\/]*)
+ use_absolute=true ;;
esac
-}
-'
+ if $use_absolute ; then
+ for cdd_dir in work_build workdir t2ddir work_bak in_input in_dir; do
+ eval "$cdd_dir=\`absolute \$$cdd_dir\`"
+ done
+ return
+ fi
+
+ # Replace each path component with ".." and add a single trailing slash.
+ rel=`echo "$1" | \$SED -e 's/[^/\\][^/\\]*/../g' -e 's/[/\\]*$/\//'`
+}
-# cd_orig
-# -------
-# Return to the original directory.
+# cd_orig - Return to the original directory.
cd_orig ()
{
# In case $orig_pwd is on a different drive (for DOS).
@@ -155,11 +253,12 @@ cd_orig ()
# - the next file is processed in correct conditions
# - the temporary file can be removed
cd "$orig_pwd" || exit 1
+
+ rel=
}
-# func_dirname FILE
-# -----------------
-# Return the directory part of FILE.
+
+# func_dirname FILE - Return the directory part of FILE.
func_dirname ()
{
dirname "$1" 2>/dev/null \
@@ -167,18 +266,15 @@ func_dirname ()
}
-# noexit FILE
-# -----------
-# Return FILE with one extension remove. foo.bar.baz -> foo.bar.
+# noext FILE - Return FILE with one extension removed:
+# foo.bar.baz -> foo.bar
noext ()
{
echo "$1" | $SED -e 's/\.[^/.][^/.]*$//'
}
-# absolute NAME -> ABS-NAME
-# -------------------------
-# Return an absolute path to NAME.
+# absolute NAME - Return an absolute path to NAME.
absolute ()
{
case $1 in
@@ -186,26 +282,21 @@ absolute ()
# Absolute paths don't need to be expanded.
echo "$1"
;;
- *) local slashes
- slashes=`echo "$1" | $SED -n 's,.*[^/]\(/*\)$,\1,p'`
- local rel
- rel=$orig_pwd/`func_dirname "$1"`
- if test -d "$rel"; then
- (cd "$rel" 2>/dev/null \
- && local n
- n=`pwd`/`basename "$1"`"$slashes"
- echo "$n")
+ *) absolute_slashes=`echo "$1" | $SED -n 's,.*[^/]\(/*\)$,\1,p'`
+ absolute_rel=$orig_pwd/`func_dirname "$1"`
+ if test -d "$absolute_rel"; then
+ (cd "$absolute_rel" 2>/dev/null \
+ && absolute_name=`pwd`/`basename "$1"`"$absolute_slashes"
+ echo "$absolute_name")
else
- error 1 "not a directory: $rel"
+ error 1 "not a directory: $absolute_rel"
fi
;;
esac
}
-# ensure_dir DIR1 DIR2...
-# -----------------------
-# Make sure the directories exist.
+# ensure_dir DIR1 DIR2... - Make sure given directories exist.
ensure_dir ()
{
for dir
@@ -221,26 +312,23 @@ ensure_dir ()
}
-# error EXIT_STATUS LINE1 LINE2...
-# --------------------------------
-# Report an error and exit with failure if EXIT_STATUS is non-null.
+# error EXIT_STATUS LINE1 LINE2... - Report an error and exit with
+# failure if EXIT_STATUS is non-null.
error ()
{
- local s="$1"
+ error_status="$1"
shift
report "$@"
- if test "$s" != 0; then
- exit $s
+ if test "$error_status" != 0; then
+ exit $error_status
fi
}
-# findprog PROG
-# -------------
-# Return true if PROG is somewhere in PATH, else false.
+# findprog PROG - Return true if PROG is somewhere in PATH, else false.
findprog ()
{
- local saveIFS="$IFS"
+ saveIFS="$IFS"
IFS=$path_sep # break path components at the path separator
for dir in $PATH; do
IFS=$saveIFS
@@ -261,9 +349,7 @@ findprog ()
return 1
}
-# report LINE1 LINE2...
-# ---------------------
-# Report some information on stderr.
+# report LINE1 LINE2... - Echo each argument to stderr.
report ()
{
for i in "$@"
@@ -273,9 +359,7 @@ report ()
}
-# run COMMAND-LINE
-# ----------------
-# Run the COMMAND-LINE verbosely, and catching errors as failures.
+# run COMMAND-LINE - Run COMMAND-LINE verbosely, catching errors as failures.
run ()
{
verbose "Running $@"
@@ -284,135 +368,7 @@ run ()
}
-# usage
-# -----
-# Display usage and exit successfully.
-usage ()
-{
- # We used to simply have `echo "$usage"', but coping with the
- # changing behavior of `echo' is much harder than simply using a
- # here-doc.
- #
- # echo '\noto' echo '\\noto' echo -e '\\noto'
- # bash 3.1 \noto \\noto \noto
- # bash 3.2 %oto \noto -e \noto
- #
- # where % denotes the eol character.
- cat <<EOF
-Usage: $program [OPTION]... FILE...
- or: texi2pdf [OPTION]... FILE...
- or: pdftexi2dvi [OPTION]... FILE...
-
-Run each Texinfo or (La)TeX FILE through TeX in turn until all
-cross-references are resolved, building all indices. The directory
-containing each FILE is searched for included files. The suffix of FILE
-is used to determine its language ((La)TeX or Texinfo). To process
-(e)plain TeX files, set the environment variable LATEX=tex.
-
-In order to make texi2dvi a drop-in replacement of TeX/LaTeX in AUC-TeX,
-the FILE may also be composed of the following simple TeX commands.
- \`\\input{FILE}' the actual file to compile
- \`\\nonstopmode' same as --batch
-
-When invoked as \`texi2pdf' or \`pdftexi2dvi', or given the option --pdf
-or --dvipdf, generate PDF output. Otherwise, generate DVI.
-
-General options:
- -b, --batch no interaction
- -D, --debug turn on shell debugging (set -x)
- -h, --help display this help and exit successfully
- -o, --output=OFILE leave output in OFILE; only one input FILE is allowed
- -q, --quiet no output unless errors (implies --batch)
- -s, --silent same as --quiet
- -v, --version display version information and exit successfully
- -V, --verbose report on what is done
-
-Output format:
- --dvi output a DVI file [default]
- --dvipdf output a PDF file via DVI (using a dvi-to-pdf program)
- --html output an HTML file from LaTeX, using HeVeA
- --info output an Info file from LaTeX, using HeVeA
- -p, --pdf use pdftex or pdflatex for processing
- --ps output a PostScript file via DVI (using dvips)
- --text output a plain text file from LaTeX, using HeVeA
-
-TeX tuning:
- -@ use @input instead of \input for preloaded Texinfo
- -e, -E, --expand force macro expansion using makeinfo
- -I DIR search DIR for Texinfo files
- -l, --language=LANG specify LANG for FILE, either latex or texinfo
- --no-line-error do not pass --file-line-error to TeX
- --shell-escape pass --shell-escape to TeX
- --src-specials pass --src-specials to TeX
- -t, --command=CMD insert CMD in copy of input file
- or --texinfo=CMD multiple values accumulate
- --translate-file=FILE use given charset translation file for TeX
-
-Build modes:
- --build=MODE specify the treatment of auxiliary files [$build_mode]
- --tidy same as --build=tidy
- -c, --clean same as --build=clean
- --build-dir=DIR specify where the tidy compilation is performed;
- implies --tidy;
- defaults to TEXI2DVI_BUILD_DIRECTORY [$build_dir]
- --mostly-clean remove the auxiliary files and directories
- but not the output
- --max-iterations=N don't process files more than N times [$max_iters]
-
-The MODE specifies where the TeX compilation takes place, and, as a
-consequence, how auxiliary files are treated. The build mode
-can also be set using the environment variable TEXI2DVI_BUILD_MODE.
-
-Valid MODEs are:
- \`local' compile in the current directory, leaving all the auxiliary
- files around. This is the traditional TeX use.
- \`tidy' compile in a local *.t2d directory, where the auxiliary files
- are left. Output files are copied back to the original file.
- \`clean' same as \`tidy', but remove the auxiliary directory afterwards.
- Every compilation therefore requires the full cycle.
-
-Using the \`tidy' mode brings several advantages:
- - the current directory is not cluttered with plethora of temporary files.
- - clutter can be even further reduced using --build-dir=dir: all the *.t2d
- directories are stored there.
- - clutter can be reduced to zero using, e.g., --build-dir=/tmp/\$USER.t2d
- or --build-dir=\$HOME/.t2d.
- - the output file is updated after every successful TeX run, for
- sake of concurrent visualization of the output. In a \`local' build
- the viewer stops during the whole TeX run.
- - if the compilation fails, the previous state of the output file
- is preserved.
- - PDF and DVI compilation are kept in separate subdirectories
- preventing any possibility of auxiliary file incompatibility.
-
-On the other hand, because \`tidy' compilation takes place in another
-directory, occasionally TeX won't be able to find some files (e.g., when
-using \\graphicspath): in that case, use -I to specify the additional
-directories to consider.
-
-The values of the BIBER, BIBTEX, DVIPDF, DVIPS, HEVEA, LATEX, MAKEINDEX,
-MAKEINFO, PDFLATEX, PDFTEX, SED, T4HT, TEX, TEX4HT, TEXINDEX, and THUMBPDF_CMD
-environment variables are used to run those commands, if they are set.
-
-Regarding --dvipdf, if DVIPDF is not set in the environment, the
-following programs are looked for (in this order): dvipdfmx dvipdfm
-dvipdf dvi2pdf dvitopdf.
-
-Any CMD strings are added after @setfilename for Texinfo input, or in
-the first line for LaTeX input.
-
-Report bugs to bug-texinfo@gnu.org,
-general questions and discussion to help-texinfo@gnu.org.
-GNU Texinfo home page: <http://www.gnu.org/software/texinfo/>
-General help using GNU software: <http://www.gnu.org/gethelp/>
-EOF
- exit 0
-}
-
-
-# verbose WORD1 WORD2
-# -------------------
-# Report some verbose information.
+# verbose WORD1 WORD2... - Echo concatenated WORDs to stderr, if $verb.
verbose ()
{
if $verb; then
@@ -421,69 +377,45 @@ verbose ()
}
-# version
-# -------
-# Display version info and exit successfully.
-version ()
-{
- cat <<EOF
-texi2dvi (GNU Texinfo 5.2) $rcs_version
-
-Copyright (C) 2014 Free Software Foundation, Inc.
-License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
-This is free software: you are free to change and redistribute it.
-There is NO WARRANTY, to the extent permitted by law.
-EOF
- exit 0
-}
-
-
-## ---------------- ##
-## Handling lists. ##
-## ---------------- ##
-
-
-# list_append LIST-NAME ELEM
-# --------------------------
-# Set LIST-NAME to its former contents, with ELEM appended.
+# Handling lists.
+#
+# list_append LIST-NAME ELEM - Append ELEM to (the contents of) LIST-NAME.
list_append ()
{
- local la_l="$1"
+ list_name="$1"
shift
- eval set X \$$la_l "$@"
+ eval set X \$$list_name "$@"
shift
- eval $la_l=\""$@"\"
+ eval $list_name=\""$@"\"
}
-# list_concat_dirs LIST-NAME DIR-LIST
-# -----------------------------------
-# Append to LIST-NAME all the components (included empty) from
-# the $path_sep separated list DIR-LIST. Make the paths absolute.
+# list_concat_dirs LIST-NAME DIR-LIST - Append to LIST-NAME all the
+# components (including empty ones) from the $path_sep-separated list
+# DIR-LIST. Make the paths absolute.
list_concat_dirs ()
{
- local lcd_list="$1"
+ lcd_list="$1"
# Empty path components are meaningful to tex. We rewrite them as
# `EMPTY' so they don't get lost when we split on $path_sep.
# Hopefully no one will have an actual directory named EMPTY.
- local replace_EMPTY="-e 's/^$path_sep/EMPTY$path_sep/g' \
- -e 's/$path_sep\$/${path_sep}EMPTY/g' \
- -e 's/$path_sep$path_sep/${path_sep}EMPTY:/g'"
+ lcd_replace_EMPTY="-e 's/^$path_sep/EMPTY$path_sep/g' \
+ -e 's/$path_sep\$/${path_sep}EMPTY/g' \
+ -e 's/$path_sep$path_sep/${path_sep}EMPTY${path_sep}/g'"
save_IFS=$IFS
IFS=$path_sep
- set x `echo "$2" | eval $SED $replace_EMPTY`; shift
+ set x `echo "$2" | eval $SED $lcd_replace_EMPTY`; shift
IFS=$save_IFS
- local dir
- for dir
+ for lcd_dir
do
- case $dir in
+ case $lcd_dir in
EMPTY)
list_append $lcd_list ""
;;
*)
- if test -d $dir; then
- dir=`absolute "$dir"`
- list_append $lcd_list "$dir"
+ if test -d $lcd_dir; then
+ dir=`absolute "$lcd_dir"`
+ list_append $lcd_list "$lcd_dir"
fi
;;
esac
@@ -491,64 +423,54 @@ list_concat_dirs ()
}
-# list_prefix LIST-NAME SEP -> STRING
-# -----------------------------------
-# Return a string that is composed of the LIST-NAME with each item
-# preceded by SEP.
+# list_prefix LIST-NAME SEP -> STRING - Return string with each element
+# of LIST-NAME preceded by SEP.
list_prefix ()
{
- local lp_p="$2"
+ lp_separator="$2"
eval set X \$$1
shift
- local lp_res
+ lp_result=''
for i
do
- lp_res="$lp_res \"$lp_p\" \"$i\""
+ lp_result="$lp_result \"$lp_separator\" \"$i\""
done
- echo "$lp_res"
+ echo "$lp_result"
}
-# list_infix LIST-NAME SEP -> STRING
-# ----------------------------------
-# Same as list_prefix, but a separator.
+# list_infix LIST-NAME SEP -> STRING - Same as list_prefix, but a separator.
list_infix ()
{
eval set X \$$1
shift
- local la_IFS="$IFS"
+ save_IFS="$IFS"
IFS=$path_sep
echo "$*"
- IFS=$la_IFS
+ IFS=$save_IFS
}
-# list_dir_to_abs LIST-NAME
-# -------------------------
-# Convert the list to using only absolute dir names.
+# list_dir_to_abs LIST-NAME - Convert list to using only absolute dir names.
# Currently unused, but should replace absolute_filenames some day.
list_dir_to_abs ()
{
- local ld_l="$1"
- eval set X \$$ld_l
+ ldta_list="$1"
+ eval set X \$$ldta_list
shift
- local ld_res
+ ldta_result=''
for dir
do
dir=`absolute "$dir"`
test -d "$dir" || continue
- ld_res="$ld_res \"$dir\""
+ ldta_result="$ldata_result \"$dir\""
done
- set X $ld_res; shift
- eval $ld_l=\"$@\"
+ set X $ldta_result; shift
+ eval $ldta_list=\"$@\"
}
-## ------------------------------ ##
-## Language auxiliary functions. ##
-## ------------------------------ ##
-
-
-# out_lang_set LANG
-# -----------------
+# Language auxiliary functions.
+#
+# out_lang_set LANG - set $out_lang to LANG (dvi, pdf, etc.), or error.
out_lang_set ()
{
case $1 in
@@ -557,10 +479,7 @@ out_lang_set ()
esac
}
-
-# out_lang_tex
-# ------------
-# Return the tex output language (DVI or PDF) for $OUT_LANG.
+# out_lang_tex - Return the tex output language (DVI or PDF) for $out_lang.
out_lang_tex ()
{
case $out_lang in
@@ -571,10 +490,7 @@ out_lang_tex ()
esac
}
-
-# out_lang_ext
-# ------------
-# Return the extension for $OUT_LANG.
+# out_lang_ext - Return the extension for $out_lang (pdf, dvi, etc.).
out_lang_ext ()
{
case $out_lang in
@@ -585,83 +501,64 @@ out_lang_ext ()
}
-## ------------------------- ##
-## TeX auxiliary functions. ##
-## ------------------------- ##
-
-# Save TEXINPUTS so we can construct a new TEXINPUTS path for each file.
-# Likewise for bibtex and makeindex.
-tex_envvars="BIBINPUTS BSTINPUTS DVIPSHEADERS INDEXSTYLE MFINPUTS MPINPUTS \
-TEXINPUTS TFMFONTS"
-for var in $tex_envvars; do
- eval ${var}_orig=\$$var
- export $var
-done
-
-
-# absolute_filenames TEX-PATH -> TEX-PATH
-# ---------------------------------------
-# Convert relative paths to absolute paths, so we can run in another
-# directory (e.g., in tidy build mode, or during the macro-support
-# detection). Prepend ".".
+# TeX file auxiliary functions.
+#
+# absolute_filenames TEX-PATH -> TEX-PATH - Convert relative paths to
+# absolute, so we can run in another directory (e.g., in tidy build
+# mode, or during the macro-support detection).
absolute_filenames ()
{
# Empty path components are meaningful to tex. We rewrite them as
# `EMPTY' so they don't get lost when we split on $path_sep.
# Hopefully no one will have an actual directory named EMPTY.
- local replace_empty="-e 's/^$path_sep/EMPTY$path_sep/g' \
- -e 's/$path_sep\$/${path_sep}EMPTY/g' \
- -e 's/$path_sep$path_sep/${path_sep}EMPTY:/g'"
- local res
- res=`echo "$1" | eval $SED $replace_empty`
+ af_replace_empty="-e 's/^$path_sep/EMPTY$path_sep/g' \
+ -e 's/$path_sep\$/${path_sep}EMPTY/g' \
+ -e 's/$path_sep$path_sep/${path_sep}EMPTY${path_sep}/g'"
+ af_result=`echo "$1" | eval $SED $af_replace_empty`
save_IFS=$IFS
IFS=$path_sep
- set x $res; shift
- res=.
+ set x $af_result; shift
+ af_result=
+ af_path_sep=
for dir
do
case $dir in
EMPTY)
- res=$res$path_sep
+ af_result=$af_result$af_path_sep
;;
*)
if test -d "$dir"; then
- res=$res$path_sep`absolute "$dir"`
+ af_result=$af_result$af_path_sep`absolute "$dir"`
else
# Even if $dir is not a directory, preserve it in the path.
# It might contain metacharacters that TeX will expand in
# turn, e.g., /some/path/{a,b,c}. This will not get the
# implicit absolutification of the path, but we can't help that.
- res=$res$path_sep$dir
+ af_result=$af_result$af_path_sep$dir
fi
;;
esac
+ af_path_sep=$path_sep
done
- echo "$res"
+ echo "$af_result"
}
-# output_base_name FILE
-# ---------------------
-# The name of FILE, possibly renamed to satisfy --output.
-# FILE is local, there is no directory part.
+# output_base_name FILE - Return the name of FILE, possibly renamed to
+# satisfy --output. FILE is local, i.e., without any directory part.
output_base_name ()
{
case $oname in
'') echo "$1";;
- *) local out_noext
- out_noext=`noext "$oname"`
- local file_ext
- file_ext=`echo "$1" | $SED 's/^.*\.//'`
- echo "$out_noext.$file_ext"
+ *) obn_out_noext=`noext "$oname"`
+ obn_file_ext=`echo "$1" | $SED 's/^.*\.//'`
+ echo "$obn_out_noext.$obn_file_ext"
;;
esac
}
-# destdir
-# -------
-# Return the name of the directory where the output is expected.
+# destdir - Return the directory where the output is expected.
destdir ()
{
case $oname in
@@ -671,15 +568,13 @@ destdir ()
}
-# move_to_dest FILE...
-# --------------------
-# Move FILE to the place where the user expects it. Truly move it, that
-# is, it must not remain in its build location unless that is also the
-# output location. (Otherwise it might appear as an extra file in make
-# distcheck.)
+# move_to_dest FILE... - Move FILE(s) to the place where the user expects.
+# Truly move it, that is, it must not remain in its build location
+# unless that is also the output location. (Otherwise it might appear
+# as an extra file in make distcheck.)
#
-# FILE can be the principal output (in which case -o directly applies), or
-# an auxiliary file with the same base name.
+# FILE can be the principal output (in which case -o directly applies),
+# or an auxiliary file with the same base name.
move_to_dest ()
{
# echo "move_to_dest $*, tidy=$tidy, oname=$oname"
@@ -690,23 +585,17 @@ move_to_dest ()
false:) return;;
esac
- local destfile
- local destdir
- local destbase
- local sourcedir
- local sourcebase
-
for file
do
test -f "$file" \
|| error 1 "no such file or directory: $file"
case $tidy:$oname in
- true:) destdir=$orig_pwd
- destfile=$destdir/$file;;
- true:*) destfile=`output_base_name "$file"`
- destdir=`dirname "$destfile"`;;
- false:*) destfile=$oname
- destdir=`dirname "$destfile"`;;
+ true:) mtd_destdir=$orig_pwd
+ mtd_destfile=$mtd_destdir/$file;;
+ true:*) mtd_destfile=`output_base_name "$file"`
+ mtd_destdir=`dirname "$mtd_destfile"`;;
+ false:*) mtd_destfile=$oname
+ mtd_destdir=`dirname "$mtd_destfile"`;;
esac
# We want to compare the source location and the output location,
@@ -716,45 +605,39 @@ move_to_dest ()
# directory names, canonicalized with pwd. We can't use cmp -s
# since the output file might not actually change from run to run;
# e.g., TeX DVI output is timestamped to only the nearest minute.
- destdir=`cd "$destdir" && pwd`
- destbase=`basename "$destfile"`
-
- sourcedir=`dirname "$file"`
- sourcedir=`cd "$sourcedir" && pwd`
- sourcebase=`basename "$file"`
-
- if test "$sourcedir/$sourcebase" != "$destdir/$destbase"; then
- verbose "Moving $file to $destfile"
- rm -f "$destfile"
- mv "$file" "$destfile"
+ mtd_destdir=`cd "$mtd_destdir" && pwd`
+ mtd_destbase=`basename "$mtd_destfile"`
+
+ mtd_sourcedir=`dirname "$file"`
+ mtd_sourcedir=`cd "$mtd_sourcedir" && pwd`
+ mtd_sourcebase=`basename "$file"`
+
+ if test "$mtd_sourcedir/$mtd_sourcebase" != "$mtd_destdir/$mtd_destbase"
+ then
+ verbose "Moving $file to $mtd_destfile"
+ rm -f "$mtd_destfile"
+ mv "$file" "$mtd_destfile"
fi
done
}
-## --------------------- ##
-## Managing xref files. ##
-## --------------------- ##
-
-# aux_file_p FILE
-# ---------------
-# Return with success if FILE is an aux file.
+# Managing xref files.
+#
+# aux_file_p FILE - Echo FILE if FILE is an aux file.
aux_file_p ()
{
- test -f "$1" || return 1
+ test -f "$1" || return 0
case $1 in
- *.aux) return 0;;
- *) return 1;;
+ *.aux) echo "$1";;
+ *) return 0;;
esac
}
-# bibaux_file_p FILE
-# ------------------
-# Return with success if FILE is an aux file containing citation
-# requests.
+# bibaux_file_p FILE - Echo FILE if FILE contains citation requests.
bibaux_file_p ()
{
- test -s "$1" || return 1
+ test -s "$1" || return 0
if (grep '^\\bibstyle[{]' "$1" \
&& grep '^\\bibdata[{]' "$1" \
## The following line is suspicious: fails when there
@@ -763,17 +646,15 @@ bibaux_file_p ()
## && grep '^\\citation[{]' "$f"
) >&6 2>&1;
then
- return 0
+ echo "$1"
fi
- return 1
+ return 0
}
-# index_file_p FILE
-# -----------------
-# Return with success if FILE is an index file.
+# index_file_p FILE - Echo FILE if FILE is an index file.
index_file_p ()
{
- test -f "$1" || return 1
+ test -f "$1" || return 0
case $in_lang:$latex2html:`out_lang_tex`:`$SED '1q' "$1"` in
# When working with TeX4HT, *.idx are created by LaTeX. They must
# be processed to produce *.4ix, *.4dx files. The *.4dx file is
@@ -781,20 +662,21 @@ index_file_p ()
# handled by run_index, so we are only interested in the *.idx
# files, which have each "\indexentry" preceded by a
# "\beforeentry".
- latex:tex4ht:html:"\\beforeentry {"*) return 0;;
+ latex:tex4ht:html:"\\beforeentry {"*) echo $1;;
# When index.sty is used, there is a space before the brace.
- latex:*:*:"\\indexentry{"*|latex:*:*:"\\indexentry {"*) return 0;;
-
- texinfo:*:*:"\\entry{"*) return 0;;
+ latex:*:*:"\\indexentry{"*|latex:*:*:"\\indexentry {"*) echo $1;;
- *) return 1;;
+ texinfo:*:*:"\\entry{"*) echo $1;;
+ texinfo:*:*:"@entry{"*) echo $1;;
+ # @entry is output from newer versions of texinfo.tex
esac
+ return 0
}
-# xref_file_p FILE
-# ----------------
-# Return with success if FILE is an xref file (indexes, tables and lists).
+########### not used currently
+# xref_file_p FILE - Return success if FILE is an xref file (indexes,
+# tables and lists).
xref_file_p ()
{
test -f "$1" || return 1
@@ -810,67 +692,52 @@ xref_file_p ()
}
-# generated_files_get FILENAME-NOEXT [PREDICATE-FILTER]
-# -----------------------------------------------------
-# Return the list of files generated by the TeX compilation of FILENAME-NOEXT.
-generated_files_get ()
+# Used in generated_files_get
+generated_files_get_from_log ()
{
- local filter=true
- if test -n "$2"; then
- filter=$2
+ if test -f "$1.log"; then
+ # Usually the output is like: \openout1 = `foobar.tex'.
+ # (including the final period)
+ # but luatex outputs: \openout1 = foobar.tex
+ # (no quotes, no period).
+ # So we have to make the punctuation optional.
+ grep '^\\openout[0-9]' "$1.log" \
+ | $SED -e "s/\\\\openout[^=]*= *[\`']*//" \
+ -e "s/'\.$//"
fi
+}
- # Gather the files created by TeX.
- (
- if test -f "$1.log"; then
- $SED -n -e "s,^\\\\openout.* = \`\\(.*\\)'\\.,\\1,p" "$1.log"
- fi
- echo "$1.log"
- ) |
- # Depending on these files, infer outputs from other tools.
- while read file; do
- echo $file
- case $in_lang in
- texinfo)
- # texindex: texinfo.cp -> texinfo.cps
- if index_file_p $file; then
- echo ${file}s
- fi
- ;;
- latex)
- if aux_file_p $file; then
- # bibtex: *.aux -> *.bbl and *.blg.
- echo $file | $SED 's/^\(.*\)\.aux$/\1.bbl/'
- echo $file | $SED 's/^\(.*\)\.aux$/\1.blg/'
- # -recorder: .fls
- echo $file | $SED 's/^\(.*\)\.aux$/\1.fls/'
- fi
- ;;
- esac
- done |
- # Filter existing files matching the criterion.
- #
- # With an input file name containing a space, this produces a
- # "command not found" message (and filtering is ineffective).
- # The situation with a newline is presumably even worse.
- while read file; do
- if $filter "$file"; then
- echo $file
+# Used in generated_files_get
+generated_files_get_from_fls ()
+{
+ if test -f "$1.fls"; then
+ grep '^OUTPUT ' "$1.fls" | cut -b 8- \
+ | grep -v '\.dvi$' | grep -v '\.log$' | grep -v '\.pdf$' || true
+ fi
+}
+
+# generated_files_get - Output the list of files generated by the TeX
+# compilation.
+generated_files_get ()
+{
+ $generated_files_get_method "$in_noext"
+ if test $generated_files_get_method = generated_files_get_from_fls; then
+ if test -r "$in_noext.fl"; then
+ report 'WARNING!! The fl index may typeset as garbage!' # goes to stderr
+ report 'Try upgrading your version of texinfo.tex, or else try setting'
+ report 'the environment variable TEXI2DVI_USE_RECORDER to '\''no'\''.'
+report 'Once you'\''ve done that, delete the file with an '\''fl'\'' extension.'
fi
- done |
- sort |
- # Some files are opened several times, e.g., listings.sty's *.vrb.
- uniq
+ fi
}
-# xref_files_save
-# ---------------
-# Save the xref files.
+# xref_files_save - set xref_files_orig from xref_files_new, and save xref
+# files in $work_bak.
xref_files_save ()
{
# Save copies of auxiliary files for later comparison.
- xref_files_orig=`generated_files_get "$in_noext" xref_file_p`
+ xref_files_orig=$xref_files_new
if test -n "$xref_files_orig"; then
verbose "Backing up xref files: $xref_files_orig"
# The following line improves `cp $xref_files_orig "$work_bak"'
@@ -880,14 +747,24 @@ xref_files_save ()
# Users may have, e.g., --keep-old-files. Don't let this interfere.
# (Don't use unset for the sake of ancient shells.)
TAR_OPTIONS=; export TAR_OPTIONS
- tar cf - $xref_files_orig | (cd "$work_bak" && tar xf -)
+ tar cf - $xref_files_orig | (cd "$rel$work_bak" && tar xf -)
+ fi
+
+ # Remove auxiliary files in same directory as main input file. Otherwise,
+ # these will likely be read instead of those in the build dir.
+ if $tidy ; then
+ secondary_xref_files=`sorted_index_files`
+ for f in $xref_files_new $secondary_xref_files ; do
+ if test -f "$rel$in_dir/$f" ; then
+ remove $rel$in_dir/$f
+ fi
+ done
fi
}
-# xref_files_changed
-# ------------------
-# Whether the xref files were changed since the previous run.
+# xref_files_changed - Return success if the xref files have changed
+# since the previous run.
xref_files_changed ()
{
# LaTeX (and the package changebar) report in the LOG file if it
@@ -898,14 +775,14 @@ xref_files_changed ()
if grep "Rerun to get" "$in_noext.log" >&6 2>&1; then
return 0
fi
- # biblatex report of whether rerunning is needed.
+ # Similarly, check for biblatex report of whether rerunning is needed.
if grep "biblatex.*(re)run" "$in_noext.log" >&6 2>&1; then
return 0
fi
# If old and new lists don't have the same file list,
# then something has definitely changed.
- xref_files_new=`generated_files_get "$in_noext" xref_file_p`
+ xref_files_new=`generated_files_get`
verbose "Original xref files = $xref_files_orig"
verbose "New xref files = $xref_files_new"
if test "x$xref_files_orig" != "x$xref_files_new"; then
@@ -916,31 +793,32 @@ xref_files_changed ()
for this_file in $xref_files_new; do
verbose "Comparing xref file `echo $this_file | $SED 's|\./||g'` ..."
# cmp -s returns nonzero exit status if files differ.
- if cmp -s "$this_file" "$work_bak/$this_file"; then :; else
+ if cmp -s "$this_file" "$rel$work_bak/$this_file"; then :; else
verbose "xref file `echo $this_file | $SED 's|\./||g'` differed ..."
if $debug; then
- diff -u "$work_bak/$this_file" "$this_file"
+ diff -u "$rel$work_bak/$this_file" "$this_file"
fi
return 0
fi
done
+ secondary_xref_files=`sorted_index_files`
+ verbose "Secondary xref files = $secondary_xref_files"
+ for this_file in $secondary_xref_files; do
+ if test -f $this_file; then :; else
+ verbose "$this_file missing ..."
+ return 0
+ fi
+ done
+
# No change.
return 1
}
-
-
-## ----------------------- ##
-## Running the TeX suite. ##
-## ----------------------- ##
-
-
-
-# run_tex ()
-# ----------
-# Run TeX as "$tex $in_input", taking care of errors and logs.
-run_tex ()
+# Running the TeX suite.
+#
+# Set tex_cmd variable, for running TeX.
+make_tex_cmd ()
{
case $in_lang:$latex2html:`out_lang_tex` in
latex:*:dvi|latex:tex4ht:html)
@@ -955,18 +833,9 @@ run_tex ()
*) tex=$TEX
esac;;
texinfo:*:pdf) tex=$PDFTEX;;
-
*) error 1 "$out_lang not supported for $in_lang";;
esac
- # do the special catcode trick for ~ in filenames only for Texinfo,
- # not LaTeX.
- if test x"$in_lang" = xtexinfo && test $catcode_special = maybe; then
- catcode_special=true
- else
- catcode_special=false
- fi
-
# Beware of aux files in subdirectories that require the
# subdirectory to exist.
case $in_lang:$tidy in
@@ -981,7 +850,7 @@ run_tex ()
esac
# Note that this will be used via an eval: quote properly.
- local cmd="$tex"
+ tex_cmd="$tex"
# If possible, make TeX report error locations in GNU format.
if $line_error; then
@@ -995,98 +864,90 @@ run_tex ()
# The mk program and perhaps others want to parse TeX's
# original error messages.
case $tex_help in
- *file-line-error*) cmd="$cmd --file-line-error";;
+ *file-line-error*) tex_cmd="$tex_cmd --file-line-error";;
esac
fi
+ # Tell TeX about -recorder option, if specified
+ # recorder_option_maybe is in { " -recorder", "" }
+ tex_cmd="$tex_cmd$recorder_option_maybe"
+
+
# Tell TeX about TCX file, if specified.
- test -n "$translate_file" && cmd="$cmd --translate-file=$translate_file"
+ test -n "$translate_file" \
+ && tex_cmd="$tex_cmd --translate-file=$translate_file"
# Tell TeX to make source specials (for backtracking from output to
# source, given a sufficiently smart editor), if specified.
- test -n "$src_specials" && cmd="$cmd $src_specials"
+ test -n "$src_specials" && tex_cmd="$tex_cmd $src_specials"
# Tell TeX to allow running external executables
- test -n "$shell_escape" && cmd="$cmd $shell_escape"
-
- # Tell TeX to be batch if requested.
- if $batch; then
- # \batchmode does not show terminal output at all, so we don't
- # want that. And even in batch mode, TeX insists on having input
- # from the user. Close its stdin to make it impossible.
- cmd="$cmd </dev/null '${escape}nonstopmode'"
- fi
+ test -n "$shell_escape" && tex_cmd="$tex_cmd $shell_escape"
- # we'd like to handle arbitrary input file names, especially
- # foo~bar/a~b.tex, since Debian likes ~ characters.
- if $catcode_special; then
- # $normaltilde is just to reduce line length in this source file.
- # The idea is to define \normaltilde as a catcode other ~ character,
- # then make the active ~ be equivalent to that, instead of the plain
- # TeX tie. Then when the active ~ appears in the filename, it will
- # be expanded to itself, as far as \input will see. (This is the
- # same thing that texinfo.tex does in general, BTW.)
- normaltilde="${escape}catcode126=12 ${escape}def${escape}normaltilde{~}"
- cmd="$cmd '$normaltilde${escape}catcode126=13 ${escape}let~\normaltilde '"
- fi
- # Other special (non-active) characters could be supported by
- # resetting their catcodes to other on the command line and changing
- # texinfo.tex to initialize everything to plain catcodes. Maybe someday.
-
- # append the \input command.
- cmd="$cmd '${escape}input'"
-
- # TeX's \input does not (easily or reliably) support whitespace
- # characters or other special characters in file names. Our intensive
- # use of absolute file names makes this worse: the enclosing directory
- # names may include white spaces. Improve the situation using a
- # symbolic link to the filename in the current directory, in tidy mode
- # only. Do not alter in_input.
- #
- # The filename is almost always tokenized using plain TeX conventions
- # (the exception would be if the user made a texinfo.fmt file). Not
- # all the plain TeX special characters cause trouble, but there's no
- # harm in making the link.
- #
- case $tidy:`func_dirname "$in_input"` in
- true:*["$space$tab$newline\"#\$%\\^_{}~"]*)
- _run_tex_file_name=`basename "$in_input"`
- if test ! -f "$_run_tex_file_name"; then
- # It might not be a file, clear it.
- run rm -f "$_run_tex_file_name"
- run ln -s "$in_input"
- fi
- cmd="$cmd '$_run_tex_file_name'"
- ;;
+ # Run without interaction.
+ # \batchmode does not show terminal output at all, so we don't
+ # want that. And even in batch mode, TeX insists on having input
+ # from the user. Close its stdin to make it impossible.
+ tex_cmd="$tex_cmd </dev/null '${escape}nonstopmode'"
+}
- *)
- cmd="$cmd '$in_input'"
- ;;
- esac
- verbose "$0: Running $cmd ..."
- if eval "$cmd" >&5; then
+# run_tex - Run TeX, taking care of errors and logs.
+run_tex ()
+{
+ # Check for any unusual characters in the filename.
+ # However, >, \ and any whitespace characters are not supported
+ # filenames.
+ in_input_funnies=`echo "$in_input" \
+ | $SED -e 's![^}#$%&^_{~]!!g' -e 's!\(.\)!\1\''
+!g' | uniq`
+
+ if test -n "$in_input_funnies" ; then
+ # Make > an end group character, as it's unlikely to appear in
+ # a filename.
+ tex_cmd="$tex_cmd '${escape}bgroup${escape}catcode62=2${escape}relax'"
+
+ # If the filename has funny characters, change the TeX category codes of
+ # some characters within a group, and use \expandafter to input the file
+ # outside of the group.
+ for w in $in_input_funnies ; do
+ tex_cmd="$tex_cmd '${escape}catcode\`${escape}$w=12${escape}relax'"
+ done
+
+ # Set \toks0 to "\input FILENAME\relax"
+ tex_cmd="$tex_cmd '${escape}toks0${escape}bgroup${escape}input' '$rel$in_input' '${escape}relax>"
+
+ # Expand \toks0 after the end of the group
+ tex_cmd="$tex_cmd${escape}expandafter${escape}egroup"
+ tex_cmd="$tex_cmd${escape}the${escape}toks0${escape}relax'"
+ else
+ # In the case of a simple filename, just pass the filename
+ # with no funny tricks.
+ tex_cmd="$tex_cmd '${escape}input' '$rel$in_input'"
+ fi
+
+ verbose "$0: Running $tex_cmd ..."
+ if (eval "$tex_cmd" >&5); then
case $out_lang in
dvi | pdf ) move_to_dest "$in_noext.$out_lang";;
esac
else
- error 1 "$tex exited with bad status, quitting."
+ tex_failed=true
fi
}
-# run_bibtex ()
-# -------------
-# Run bibtex on (or biber) current file.
-# - If its input (AUX) exists.
-# - If some citations are missing (LOG contains `Citation').
-# or the LOG complains of a missing .bbl
+
+# run_bibtex - Run bibtex (or biber) on current file
+# - if its input (AUX) exists,
+# - or if some citations are missing (LOG contains `Citation'),
+# - or if the LOG complains of a missing .bbl.
#
# Don't try to be too smart:
# 1. Running bibtex only if the bbl file exists and is older than
# the LaTeX file is wrong, since the document might include files
# that have changed.
#
-# 3. Because there can be several AUX (if there are \include's),
+# 2. Because there can be several AUX (if there are \include's),
# but a single LOG, looking for missing citations in LOG is
# easier, though we take the risk of matching false messages.
run_bibtex ()
@@ -1109,7 +970,7 @@ run_bibtex ()
&& grep '^\\bibdata' "$in_noext.aux") ) \
>&6 2>&1; \
then
- bibtex_aux=`generated_files_get "$in_noext" bibaux_file_p`
+ bibtex_aux=`filter_files bibaux_file_p`
for f in $bibtex_aux; do
run $bibtex "$f"
done
@@ -1122,16 +983,31 @@ run_bibtex ()
fi
}
-# run_index ()
-# ------------
-# Run texindex (or makeindex or texindy) on current index files. If
-# they already exist, and after running TeX a first time the index
-# files don't change, then there's no reason to run TeX again. But we
-# won't know that if the index files are out of date or nonexistent.
+
+# filter_file PREDICATE - Go through the list of files in xref_files_new
+# and use PREDICATE on each one to optionally print it or print other files
+# based on the filename.
+filter_files ()
+{
+ test -n "$xref_files_new" || return 0
+ echo "$xref_files_new" |
+ # Filter existing files matching the criterion.
+ #
+ while read file; do
+ $1 "$file"
+ done |
+ sort |
+ # Some files are opened several times, e.g., listings.sty's *.vrb.
+ uniq
+}
+
+# run_index - Run texindex (or makeindex or texindy) on current index
+# files. If they already exist, and after running TeX a first time the
+# index files don't change, then there's no reason to run TeX again.
+# But we won't know that if the index files are out of date or nonexistent.
run_index ()
{
- local index_files
- index_files=`generated_files_get $in_noext index_file_p`
+ index_files=`filter_files index_file_p`
test -n "$index_files" \
|| return 0
@@ -1139,8 +1015,6 @@ run_index ()
: ${TEXINDEX:=texindex}
: ${TEXINDY:=texindy}
- local index_file
- local index_noext
case $in_lang:$latex2html:`out_lang_tex` in
latex:tex4ht:html)
for index_file in $index_files
@@ -1168,16 +1042,14 @@ run_index ()
}
-# run_tex4ht ()
-# -------------
-# Run the last two phases of TeX4HT: tex4ht extracts the HTML from the
-# instrumented DVI file, and t4ht converts the figures and installs
-# the files when given -d.
+# run_tex4ht - Run the last two phases of TeX4HT: tex4ht extracts the
+# HTML from the instrumented DVI file, and t4ht converts the figures and
+# installs the files when given -d.
#
# Because knowing exactly which files are created is complex (in
# addition the names are not simple to compute), which makes it
-# difficult to install the output files in a second step, it is much
-# simpler to install directly the output files.
+# difficult to install the output files in a second step, we
+# tell t4ht to install the output files.
run_tex4ht ()
{
case $in_lang:$latex2html:`out_lang_tex` in
@@ -1191,8 +1063,7 @@ run_tex4ht ()
}
-# run_thumbpdf ()
-# ---------------
+# run_thumbpdf - Run thumbpdf.
run_thumbpdf ()
{
if test `out_lang_tex` = pdf \
@@ -1212,14 +1083,15 @@ run_thumbpdf ()
}
-# run_dvipdf FILE.dvi
-# -------------------
-# Convert FILE.dvi to FILE.pdf.
+# run_dvipdf FILE.dvi - Convert FILE.dvi to FILE.pdf.
run_dvipdf ()
{
# Find which dvi->pdf program is available.
- if test -z "$dvipdf"; then
- for i in "$DVIPDF" dvipdfmx dvipdfm dvipdf dvi2pdf dvitopdf; do
+ if test -n "$DVIPDF"; then
+ dvipdf=$DVIPDF # user envvar, use it without checking
+
+ elif test -z "$dvipdf"; then
+ for i in dvipdfmx dvipdfm dvipdf dvi2pdf dvitopdf; do
if findprog $i; then
dvipdf=$i
fi
@@ -1234,31 +1106,39 @@ run_dvipdf ()
fi
}
-# run_tex_suite ()
-# ----------------
-# Run the TeX tools until a fix point is reached.
+# run_tex_suite - Run the TeX tools until a stable point is reached.
run_tex_suite ()
{
+ make_tex_cmd
+
# Move to the working directory.
if $tidy; then
verbose "cd $work_build"
- cd "$work_build" || exit 1
+ cd_dir "$work_build" || exit 1
fi
# Count the number of cycles.
- local cycle=0
+ suite_cycle=0
+
+ # Start by checking the log files for what files were created last
+ # time. This will mean that if they don't change, we finish in 1 cycle.
+ xref_files_new=`generated_files_get`
+ xref_files_save
while :; do
- # check for probably LaTeX loop (e.g. varioref)
- if test $cycle -eq "$max_iters"; then
+ # check for (probably) LaTeX loop (e.g. varioref)
+ if test $suite_cycle -eq "$max_iters"; then
error 0 "Maximum of $max_iters cycles exceeded"
break
fi
# report progress
- cycle=`expr $cycle + 1`
- verbose "Cycle $cycle for $command_line_filename"
+ suite_cycle=`expr $suite_cycle + 1`
+ verbose "Cycle $suite_cycle for $command_line_filename"
+ tex_failed=false
+ run_core_conversion
+ xref_files_changed || break
xref_files_save
# We run bibtex first, because it's more likely for the indexes
@@ -1266,11 +1146,13 @@ run_tex_suite ()
# would be rare.
run_bibtex
run_index
- run_core_conversion
-
- xref_files_changed || break
done
+ if $tex_failed ; then
+ # TeX failed, and the xref files did not change.
+ error 1 "$tex exited with bad status, quitting."
+ fi
+
# If we were using thumbpdf and producing PDF, then run thumbpdf
# and TeX one last time.
run_thumbpdf
@@ -1295,53 +1177,11 @@ run_tex_suite ()
cd_orig
}
-## -------------------------------- ##
-## TeX processing auxiliary tools. ##
-## -------------------------------- ##
-
-# A sed script that preprocesses Texinfo sources in order to keep the
-# iftex sections only. We want to remove non-TeX sections, and comment
-# (with `@c _texi2dvi') TeX sections so that makeinfo does not try to
-# parse them. Nevertheless, while commenting TeX sections, don't
-# comment @macro/@end macro so that makeinfo does propagate them.
-# Unfortunately makeinfo --iftex --no-ifinfo doesn't work well enough
-# (yet), makeinfo can't parse the TeX commands, so work around with sed.
-#
-# We assume that `@c _texi2dvi' starting a line is not present in the
-# document.
+# TeX processing auxiliary tools.
#
-comment_iftex=\
-'/^@tex/,/^@end tex/{
- s/^/@c _texi2dvi/
-}
-/^@iftex/,/^@end iftex/{
- s/^/@c _texi2dvi/
- /^@c _texi2dvi@macro/,/^@c _texi2dvi@end macro/{
- s/^@c _texi2dvi//
- }
-}
-/^@ifnottex/,/^@end ifnottex/{
- s/^/@c (_texi2dvi)/
-}
-/^@ifinfo/,/^@end ifinfo/{
- /^@node/p
- /^@menu/,/^@end menu/p
- t
- s/^/@c (_texi2dvi)/
-}
-s/^@ifnotinfo/@c _texi2dvi@ifnotinfo/
-s/^@end ifnotinfo/@c _texi2dvi@end ifnotinfo/'
-
-# Uncommenting is simpler: remove any leading `@c texi2dvi'; repeated
-# copies can sneak in via macro invocations.
-uncomment_iftex='s/^@c _texi2dvi\(@c _texi2dvi\)*//'
-
-
-# run_makeinfo ()
-# ---------------
-# Expand macro commands in the original source file using Makeinfo.
-# Always use `end' footnote style, since the `separate' style
+# run_makeinfo - Expand macro commands in the original source file using
+# Makeinfo. Always use `end' footnote style, since the `separate' style
# generates different output (arguably this is a bug in -E). Discard
# main info output, the user asked to run TeX, not makeinfo.
run_makeinfo ()
@@ -1395,15 +1235,14 @@ to tex itself simply not working."
work_src=$workdir/src
ensure_dir "$work_src"
in_src=$work_src/$in_base
- local miincludes
- miincludes=`list_prefix includes -I`
+ run_mi_includes=`list_prefix includes -I`
verbose "Macro-expanding $command_line_filename to $in_src ..."
# eval $makeinfo because it might be defined as something complex
# (running missing) and then we end up with things like '"-I"',
# and "-I" (including the quotes) is not an option name. This
# happens with gettext 0.14.5, at least.
$SED "$comment_iftex" "$command_line_filename" \
- | eval $makeinfo --footnote-style=end -I "$in_dir" $miincludes \
+ | eval $makeinfo --footnote-style=end -I "$in_dir" $run_mi_includes \
-o /dev/null --macro-expand=- \
| $SED "$uncomment_iftex" >"$in_src"
# Continue only if everything succeeded.
@@ -1416,9 +1255,62 @@ to tex itself simply not working."
fi
}
-# insert_commands ()
-# ------------------
-# Used most commonly for @finalout, @smallbook, etc.
+# Unfortunately, makeinfo --iftex --no-ifinfo doesn't work well enough
+# in versions before 5.0, as makeinfo can't parse the TeX commands
+# inside @tex blocks, so work around with sed.
+#
+# This sed script preprocesses Texinfo sources in order to keep the
+# iftex sections only. We want to remove non-TeX sections, and comment
+# (with `@c _texi2dvi') TeX sections so that makeinfo does not try to
+# parse them. Nevertheless, while commenting TeX sections, don't
+# comment @macro/@end macro so that makeinfo does propagate them.
+# Similarly, preserve the @top node to avoid makeinfo complaining about
+# it being missed. Comment it out after preprocessing, so that it does
+# not appear in the generated document.
+#
+# We assume that `@c _texi2dvi' or `@c (_texi2dvi)' starting a line is
+# not present in the document. Additionally, conditionally defined
+# macros inside the @top node may end up with the wrong value, although
+# this is unlikely in practice.
+#
+comment_iftex=\
+'/^@tex/,/^@end tex/{
+ s/^/@c _texi2dvi/
+}
+/^@iftex/,/^@end iftex/{
+ s/^/@c _texi2dvi/
+ /^@c _texi2dvi@macro/,/^@c _texi2dvi@end macro/{
+ s/^@c _texi2dvi//
+ }
+}
+/^@ifnottex/,/^@end ifnottex/{
+ s/^/@c (_texi2dvi)/
+ /^@c (_texi2dvi)@node Top/,/^@c (_texi2dvi)@end ifnottex/ {
+ /^@c (_texi2dvi)@end ifnottex/b
+ s/^@c (_texi2dvi)//
+ }
+}
+/^@ifinfo/,/^@end ifinfo/{
+ /^@node/p
+ /^@menu/,/^@end menu/p
+ t
+ s/^/@c (_texi2dvi)/
+}
+s/^@ifnotinfo/@c _texi2dvi@ifnotinfo/
+s/^@end ifnotinfo/@c _texi2dvi@end ifnotinfo/'
+
+# Uncomment @iftex blocks by removing any leading `@c texi2dvi' (repeated
+# copies can sneak in via macro invocations). Likewise, comment out
+# the @top node inside a @ifnottex block.
+uncomment_iftex=\
+'s/^@c _texi2dvi\(@c _texi2dvi\)*//
+/^@c (_texi2dvi)@ifnottex/,/^@c (_texi2dvi)@end ifnottex/{
+ s/^/@c (_texi2dvi)/
+}'
+
+
+# insert_commands - Insert $textra commands at the beginning of the file.
+# Recommended to be used for @finalout, @smallbook, etc.
insert_commands ()
{
if test -n "$textra"; then
@@ -1427,10 +1319,15 @@ insert_commands ()
in_xtr=$work_xtr/$in_base
ensure_dir "$work_xtr"
verbose "Inserting extra commands: $textra"
- local textra_cmd
case $in_lang in
latex) textra_cmd=1i;;
- texinfo) textra_cmd='/^@setfilename/a';;
+ texinfo)
+ textra_cmd='/^\\input texinfo/a'
+ # insert after @setfilename line if present
+ if head -n 10 $in_input | grep '^@setfilename' ; then
+ textra_cmd='/^@setfilename/a'
+ fi
+ ;;
*) error 1 "internal error, unknown language: $in_lang";;
esac
$SED "$textra_cmd\\
@@ -1453,10 +1350,9 @@ $textra" "$in_input" >"$in_xtr"
esac
}
-# compute_language FILENAME
-# -------------------------
-# Return the short string describing the language in which FILENAME
-# is written: `texinfo' or `latex'.
+
+# compute_language FILENAME - Return the short string for the language
+# in which FILENAME is written: `texinfo' or `latex'.
compute_language ()
{
# If the user explicitly specified the language, use that.
@@ -1477,9 +1373,7 @@ compute_language ()
}
-# run_hevea (MODE)
-# ----------------
-# Convert to HTML/INFO/TEXT.
+# run_hevea (MODE) - Convert to HTML/INFO/TEXT.
#
# Don't pass `-noiso' to hevea: it's useless in HTML since anyway the
# charset is set to latin1, and troublesome in other modes since
@@ -1490,27 +1384,27 @@ compute_language ()
# to handle images some day.
run_hevea ()
{
- local hevea="${HEVEA:-hevea}"
- local run_hevea="$hevea"
+ run_hevea_name="${HEVEA:-hevea}"
+ run_hevea_cmd="$run_hevea_name"
case $1 in
html) ;;
- text|info) run_hevea="$run_hevea -$1";;
- *) error 1 "run_hevea: invalid argument: $1";;
+ text|info) run_hevea_cmd="$run_hevea_cmd -$1";;
+ *) error 1 "run_hevea_cmd: invalid argument: $1";;
esac
# Compiling to the tmp directory enables to preserve a previous
# successful compilation.
- run_hevea="$run_hevea -fix -O -o '$out_base'"
- run_hevea="$run_hevea `list_prefix includes -I` -I '$orig_pwd' "
- run_hevea="$run_hevea '$in_input'"
+ run_hevea_cmd="$run_hevea_cmd -fix -O -o '$out_base'"
+ run_hevea_cmd="$run_hevea_cmd `list_prefix includes -I` -I '$orig_pwd' "
+ run_hevea_cmd="$run_hevea_cmd '$rel$in_input'"
if $debug; then
- run_hevea="$run_hevea -v -v"
+ run_hevea_cmd="$run_hevea_cmd -v -v"
fi
- verbose "running $run_hevea"
- if eval "$run_hevea" >&5; then
+ verbose "running $run_hevea_cmd"
+ if eval "$run_hevea_cmd" >&5; then
# hevea leaves trailing white spaces, this is annoying.
case $1 in text|info)
perl -pi -e 's/[ \t]+$//g' "$out_base"*;;
@@ -1521,14 +1415,12 @@ run_hevea ()
move_to_dest "$out_base"*;;
esac
else
- error 1 "$hevea exited with bad status, quitting."
+ error 1 "$run_hevea_name exited with bad status, quitting."
fi
}
-# run_core_conversion ()
-# ----------------------
-# Run the TeX (or HeVeA).
+# run_core_conversion - Run TeX (or HeVeA).
run_core_conversion ()
{
case $in_lang:$latex2html:`out_lang_tex` in
@@ -1542,23 +1434,22 @@ run_core_conversion ()
}
-# compile ()
-# ----------
-# Run the full compilation chain, from pre-processing to installation
-# of the output at its expected location.
+# compile - Run the full compilation chain, from pre-processing to
+# installation of the output at its expected location.
compile ()
{
- # Source file might include additional sources.
- # We want `.:$orig_pwd' before anything else. (We'll add `.:' later
- # after all other directories have been turned into absolute paths.)
- # `.' goes first to ensure that any old .aux, .cps,
- # etc. files in ${directory} don't get used in preference to fresher
- # files in `.'. Include orig_pwd in case we are in clean build mode, where
- # we have cd'd to a temp directory.
+ # Set include path for tools:
+ # . Include current directory in case there are files there already, so
+ # we don't have more TeX runs than necessary. orig_pwd is used in case
+ # we are in clean build mode, where we have cd'd to a temp directory.
+ # . Include directory containing file, in case there are other
+ # files @include'd.
+ # . Keep a final path_sep to get the default (system) TeX
+ # directories included.
+ # . If we have any includes, put those at the end.
+
common="$orig_pwd$path_sep$in_dir$path_sep"
#
- # If we have any includes, put those at the end.
- # Keep a final path_sep to get the default (system) TeX directories included.
txincludes=`list_infix includes $path_sep`
test -n "$txincludes" && common="$common$txincludes$path_sep"
#
@@ -1566,7 +1457,7 @@ compile ()
eval val="\$common\$${var}_orig"
# Convert relative paths to absolute paths, so we can run in another
# directory (e.g., in clean build mode, or during the macro-support
- # detection). ".:" is added here.
+ # detection).
val=`absolute_filenames "$val"`
eval $var="\"$val\""
export $var
@@ -1579,13 +1470,137 @@ compile ()
# --command, --texinfo
insert_commands
- # Run until a fix point is reached.
+ # Run until a fixed point is reached.
run_tex_suite
}
+# make_openout_test FLAGS EXTENSION
+# - Run TeX with an input file that performs an \openout. Pass FLAGS to TeX.
+#
+make_openout_test ()
+{
+ recorder_option_maybe="$1"
+ make_tex_cmd
+
+ ensure_dir "$workdir"/check_recorder
+ cd_dir "$workdir"/check_recorder
+
+ cat > openout.tex <<EOF
+\newwrite\ourwrite
+\immediate\openout\ourwrite dum.dum
+\bye
+EOF
+ # \bye doesn't work for LaTeX, but it will cause latex
+ # to exit with an input error.
+ tex_cmd="$tex_cmd '${escape}input' ./openout.tex"
+ # ./ in case . isn't in path
+ verbose "$0: running $tex_cmd ..."
+ rm -fr "openout.$2"
+ (eval "$tex_cmd" >/dev/null 2>&1)
+}
+
+# Check tex supports -recorder option
+check_recorder_support ()
+{
+ verbose "Checking TeX recorder support..."
+ make_openout_test " -recorder" fls
+ if test -f openout.fls && grep '^OUTPUT dum.dum$' openout.fls > /dev/null
+ then
+ cd_orig
+ verbose "Checking TeX recorder support... yes"
+ return 0
+ else
+ cd_orig
+ verbose "Checking TeX recorder support... no"
+ return 1
+ fi
+}
+
+# Check tex supports \openout traces in log
+check_openout_in_log_support ()
+{
+ verbose "Checking TeX \openout in log support..."
+ make_openout_test "" log
+ if test -f openout.log \
+ && grep '^\\openout..\? *= *`\?dum\.dum'\''\?' openout.log >/dev/null
+ then
+ cd_orig
+ verbose "Checking TeX \openout in log support... yes"
+ return 0
+ else
+ cd_orig
+ verbose "Checking TeX \openout in log support... no"
+ return 1
+ fi
+}
+
+# Set that output auxiliary files are detected with the -recorder option,
+# which creates a file JOBNAME.fls which is a machine-readable listing of
+# files read and written during the job.
+set_aux_files_from_fls ()
+{
+ recorder_option_maybe=" -recorder"
+ generated_files_get_method=generated_files_get_from_fls
+}
+
+# Set that output auxiliary files are detected with searching for \openout
+# in the log file.
+set_aux_files_from_log ()
+{
+ recorder_option_maybe=''
+ generated_files_get_method=generated_files_get_from_log
+}
+
+# Decide whether output auxiliary files are detected with the -recorder
+# option, or by searching for \openout in the log file.
+decide_aux_files_method ()
+{
+ # Select output file detection method
+ # Valid values of TEXI2DVI_USE_RECORDER are:
+ # yes use the -recorder option, no checks.
+ # no scan for \openout in the log file, no checks.
+ # yesmaybe check whether -recorder option is supported, and if yes
+ # use it, otherwise check for tracing \openout in the
+ # log file is supported, and if yes use it, else it is an
+ # error.
+ # nomaybe same as `yesmaybe', except that the \openout trace in
+ # log file is checked first.
+ #
+ # The default behaviour is `nomaybe'.
+
+ test -n "$TEXI2DVI_USE_RECORDER" || TEXI2DVI_USE_RECORDER=nomaybe
+
+ case $TEXI2DVI_USE_RECORDER in
+ yes) set_aux_files_from_fls;;
+
+ no) set_aux_files_from_log;;
+
+ yesmaybe)
+ if check_recorder_support; then
+ set_aux_files_from_fls
+ elif check_openout_in_log_support; then
+ set_aux_files_from_log
+ else
+ error 1 "TeX neither supports -recorder nor outputs \\openout lines in its log file"
+ fi
+ ;;
+
+ nomaybe)
+ if check_openout_in_log_support; then
+ set_aux_files_from_log
+ elif check_recorder_support; then
+ set_aux_files_from_fls
+ else
+ error 1 "TeX neither supports -recorder nor outputs \\openout lines in its log file"
+ fi
+ ;;
+
+ *) error 1 "Invalid value of TEXI2DVI_USE_RECORDER environment variable : $TEXI2DVI_USE_RECORDER.";;
-# remove FILES
-# ------------
+ esac
+}
+
+# remove FILE...
remove ()
{
verbose "Removing" "$@"
@@ -1593,42 +1608,154 @@ remove ()
}
-# mostly_clean
-# ------------
-# Remove auxiliary files and directories. Changes the current directory.
+# all_files - Echo the names of all files generated, including those by
+# auxiliary tools like texindex.
+all_files ()
+{
+ echo $in_noext.log
+ echo $in_noext.fls
+ echo $xref_files_new
+ echo `sorted_index_files`
+}
+
+sorted_index_files ()
+{
+ filter_files sorted_index_filter
+}
+
+# Print the name of a generated file based on FILE if there is one.
+sorted_index_filter ()
+{
+ case $in_lang in
+ texinfo)
+ # texindex: texinfo.cp -> texinfo.cps
+ if test -n "`index_file_p $1`" ; then
+ echo $1s
+ fi
+ ;;
+ esac
+}
+
+
+# Not currently used - use with filter_files to add secondary files created by
+# bibtex
+bibtex_secondary_files ()
+{
+ case $in_lang in
+ latex)
+ if test -n "`aux_file_p $1`"; then
+ # bibtex: *.aux -> *.bbl and *.blg.
+ echo $1 | $SED 's/^\(.*\)\.aux$/\1.bbl/'
+ echo $1 | $SED 's/^\(.*\)\.aux$/\1.blg/'
+ fi
+ ;;
+ esac
+}
+
+# mostly_clean - Remove auxiliary files and directories. Changes back to
+# the original directory.
mostly_clean ()
{
cd_orig
set X "$t2ddir"
shift
$tidy || {
- local log="$work_build/$in_noext.log"
- set X ${1+"$@"} "$log" `generated_files_get "$work_build/$in_noext"`
+ set X ${1+"$@"} `all_files`
shift
}
remove ${1+"$@"}
}
-# cleanup ()
-# ----------
-# Remove what should be removed according to options.
+# cleanup - Remove what should be removed according to options.
# Called at the end of each compilation cycle, and at the end of
# the script. Changes the current directory.
cleanup ()
{
- case $build_mode in
- local) cd_orig; remove "$t2ddir";;
- clean) mostly_clean;;
- tidy) ;;
+ case $clean:$tidy in
+ true:true) mostly_clean ;; # build mode is "clean"
+ false:false) cd_orig; remove "$t2ddir";; # build mode is "local"
esac
}
+# input_file_name_decode - Decode COMMAND_LINE_FILENAME, and set the
+# following shell variables:
+#
+# - COMMAND_LINE_FILENAME
+# The filename given on the commmand line, but cleaned of TeX commands.
+# - IN_DIR
+# The directory containing the input file.
+# - IN_BASE
+# The input file base name (no directory part).
+# - IN_NOEXT
+# The input file name with neither file extensions nor directory part.
+# - IN_INPUT
+# The path to the input file for passing as a command-line argument
+# to TeX. Defaults to COMMAND_LINE_FILENAME, but might change if the
+# input is preprocessed.
+input_file_name_decode ()
+{
+ case $command_line_filename in
+ *\\input{*}*)
+ # Let AUC-TeX error parser deal with line numbers.
+ line_error=false
+ command_line_filename=`\
+ expr X"$command_line_filename" : X'.*input{\([^}]*\)}'`
+ ;;
+ esac
+
+ # If the COMMAND_LINE_FILENAME is not absolute (e.g., --debug.tex),
+ # prepend `./' in order to avoid that the tools take it as an option.
+ echo "$command_line_filename" | LC_ALL=C $EGREP '^(/|[A-Za-z]:/)' >&6 \
+ || command_line_filename="./$command_line_filename"
+
+ # See if the file exists. If it doesn't we're in trouble since, even
+ # though the user may be able to reenter a valid filename at the tex
+ # prompt (assuming they're attending the terminal), this script won't
+ # be able to find the right xref files and so forth.
+ test -r "$command_line_filename" \
+ || error 1 "cannot read $command_line_filename, skipping."
+
+ # Get the name of the current directory.
+ in_dir=`func_dirname "$command_line_filename"`
+
+ # Strip directory part but leave extension.
+ in_base=`basename "$command_line_filename"`
+ # Strip extension.
+ in_noext=`noext "$in_base"`
+
+ # The normalized file name to compile. Must always point to the
+ # file to actually compile (in case of recoding, macro-expansion etc.).
+ in_input=$in_dir/$in_base
+
+
+ # Compute the output file name.
+ if test x"$oname" != x; then
+ out_name=$oname
+ else
+ out_name=$in_noext.`out_lang_ext`
+ fi
+ out_dir=`func_dirname "$out_name"`
+ out_dir_abs=`absolute "$out_dir"`
+ out_base=`basename "$out_name"`
+ out_noext=`noext "$out_base"`
+}
+
+
+#
+#################### Main program starts ##########################
-## ---------------------- ##
-## Command line parsing. ##
-## ---------------------- ##
+# Initialize more variables.
+#
+# Save TEXINPUTS so we can construct a new TEXINPUTS path for each file.
+# Likewise for bibtex and makeindex.
+tex_envvars="BIBINPUTS BSTINPUTS DVIPSHEADERS INDEXSTYLE MFINPUTS MPINPUTS \
+TEXINPUTS TFMFONTS"
+for var in $tex_envvars; do
+ eval ${var}_orig=\$$var
+ export $var
+done
# Push a token among the arguments that will be used to notice when we
# ended options/arguments parsing.
@@ -1640,10 +1767,7 @@ cleanup ()
arg_sep="$$--$$"
set dummy ${1+"$@"} "$arg_sep"; shift
-#
-# Parse command line arguments.
while test x"$1" != x"$arg_sep"; do
-
# Handle --option=value by splitting apart and putting back on argv.
case "$1" in
--*=*)
@@ -1656,9 +1780,8 @@ while test x"$1" != x"$arg_sep"; do
case "$1" in
-@ ) escape=@;;
- -~ ) catcode_special=false;;
- # Silently and without documentation accept -b and --b[atch] as synonyms.
- -b | --batch) batch=true;;
+ -~ ) verbose "Option -~ is obsolete: texi2dvi ignores it.";;
+ -b | --batch) ;; # Obsolete
--build) shift; build_mode=$1;;
--build-dir) shift; build_dir=$1; build_mode=tidy;;
-c | --clean) build_mode=clean;;
@@ -1681,7 +1804,7 @@ while test x"$1" != x"$arg_sep"; do
out_lang_set `echo "x$1" | $SED 's/^x--//'`;;
-p) out_lang_set pdf;;
- -q | -s | --quiet | --silent) quiet=true; batch=true;;
+ -q | -s | --quiet | --silent) quiet=true;;
--src-specials) src_specials=--src-specials;;
--shell-escape) shell_escape=--shell-escape;;
--tex4ht) latex2html=tex4ht;;
@@ -1733,9 +1856,15 @@ esac
# We can't do much without tex.
+# End up with the TEX and PDFTEX variables set to what we are going to use.
#
-if findprog ${TEX:-tex}; then :; else cat <<EOM
-You don't have a working TeX binary (${TEX:-tex}) installed anywhere in
+# If $TEX is set to a directory, don't use it.
+test -n "$TEX" && test -d "$TEX" && unset TEX
+
+# But otherwise, use $TEX if it is set.
+if test -z "$TEX"; then
+ if findprog tex; then :; else cat <<EOM >&2
+You don't have a working TeX binary (tex) installed anywhere in
your PATH, and texi2dvi cannot proceed without one. If you want to use
this script, you'll need to install TeX (if you don't have it) or change
your PATH or TEX environment variable (if you do). See the --help
@@ -1744,20 +1873,19 @@ output for more details.
For information about obtaining TeX, please see http://tug.org/texlive,
or do a web search for TeX and your operating system or distro.
EOM
- exit 1
-fi
-
+ exit 1
+ fi
-# We want to use etex (or pdftex) if they are available, and the user
-# didn't explicitly specify. We don't check for elatex and pdfelatex
-# because (as of 2003), the LaTeX team has asked that new distributions
-# use etex by default anyway.
-#
-# End up with the TEX and PDFTEX variables set to what we are going to use.
-if test -z "$TEX"; then
+ # We want to use etex (or pdftex) if they are available, and the user
+ # didn't explicitly specify. We don't check for elatex and pdfelatex
+ # because (as of 2003), the LaTeX team has asked that new distributions
+ # use etex by default anyway.
+ #
if findprog etex; then TEX=etex; else TEX=tex; fi
fi
-#
+
+# For many years, the pdftex binary has included the e-tex extensions,
+# but for those people with ancient TeX distributions ...
if test -z "$PDFTEX"; then
if findprog pdfetex; then PDFTEX=pdfetex; else PDFTEX=pdftex; fi
fi
@@ -1767,12 +1895,9 @@ fi
# 0 standard input
# 1 standard output (--verbose messages)
# 2 standard error
-# 3 some systems may open it to /dev/tty
-# 4 used on the Kubota Titan
# 5 tools output (turned off by --quiet)
# 6 tracing/debugging (set -x output, etc.)
-
# Main tools' output (TeX, etc.) that TeX users are used to seeing.
#
# If quiet, discard, else redirect to the message flow.
@@ -1797,87 +1922,8 @@ else
exec 6>/dev/null
fi
-#
-
-# input_file_name_decode
-# ----------------------
-# Decode COMMAND_LINE_FILENAME, and compute:
-# - COMMAND_LINE_FILENAME clean of TeX commands
-# - IN_DIR
-# The directory to the input file, possibly absolute if needed.
-# - IN_DIR_ABS
-# The absolute directory of the input file.
-# - IN_BASE
-# The input file base name (no directory part).
-# - IN_NOEXT
-# The input file name without extensions (nor directory part).
-# - IN_INPUT
-# Defaults to COMMAND_LINE_FILENAME, but might change if the
-# input is preprocessed. With directory, possibly absolute.
-input_file_name_decode ()
-{
- # See if we are run from within AUC-Tex, in which case we are
- # passed `\input{FOO.tex}' or even `\nonstopmode\input{FOO.tex}'.
- case $command_line_filename in
- *\\nonstopmode*)
- batch=true;;
- esac
- case $command_line_filename in
- *\\input{*}*)
- # Let AUC-TeX error parser deal with line numbers.
- line_error=false
- command_line_filename=`\
- expr X"$command_line_filename" : X'.*input{\([^}]*\)}'`
- ;;
- esac
-
- # If the COMMAND_LINE_FILENAME is not absolute (e.g., --debug.tex),
- # prepend `./' in order to avoid that the tools take it as an option.
- echo "$command_line_filename" | LC_ALL=C $EGREP '^(/|[A-Za-z]:/)' >&6 \
- || command_line_filename="./$command_line_filename"
-
- # See if the file exists. If it doesn't we're in trouble since, even
- # though the user may be able to reenter a valid filename at the tex
- # prompt (assuming they're attending the terminal), this script won't
- # be able to find the right xref files and so forth.
- test -r "$command_line_filename" \
- || error 1 "cannot read $command_line_filename, skipping."
-
- # Get the name of the current directory.
- in_dir=`func_dirname "$command_line_filename"`
- in_dir_abs=`absolute "$in_dir"`
- # In a clean build, we `cd', so get an absolute file name.
- if $tidy; then
- in_dir=$in_dir_abs
- fi
-
- # Strip directory part but leave extension.
- in_base=`basename "$command_line_filename"`
- # Strip extension.
- in_noext=`noext "$in_base"`
-
- # The normalized file name to compile. Must always point to the
- # file to actually compile (in case of recoding, macro-expansion etc.).
- in_input=$in_dir/$in_base
-
-
- # Compute the output file name.
- if test x"$oname" != x; then
- out_name=$oname
- else
- out_name=$in_noext.`out_lang_ext`
- fi
- out_dir=`func_dirname "$out_name"`
- out_dir_abs=`absolute "$out_dir"`
- out_base=`basename "$out_name"`
- out_noext=`noext "$out_base"`
-}
-
-
-## -------------- ##
-## TeXify files. ##
-## -------------- ##
+# Main program main loop - TeXify each file in turn.
for command_line_filename
do
verbose "Processing $command_line_filename ..."
@@ -1905,8 +1951,6 @@ do
ensure_dir "$build_dir" "$t2ddir"
- # We will change directory, better work with an absolute path...
- t2ddir=`absolute "$t2ddir"`
# Sometimes there are incompatibilities between auxiliary files for
# DVI and PDF. The contents can also change whether we work on PDF
# and/or DVI. So keep separate spaces for each.
@@ -1927,6 +1971,9 @@ do
# Make those directories.
ensure_dir "$work_build" "$work_bak"
+ # Decide how to find auxiliary files created by TeX.
+ decide_aux_files_method
+
case $action in
compile)
# Compile the document.
@@ -1935,6 +1982,7 @@ do
;;
mostly-clean)
+ xref_files_new=`generated_files_get`
mostly_clean
;;
esac
@@ -1942,3 +1990,7 @@ done
verbose "done."
exit 0 # exit successfully, not however we ended the loop.
+# Local Variables:
+# sh-basic-offset: 2
+# sh-indentation: 2
+# End: