diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-09-26 23:06:02 +0000 |
---|---|---|
committer | <> | 2015-02-03 11:56:22 +0000 |
commit | e0b511b834f3529395df67126a7314097c2cf97e (patch) | |
tree | 89945ae53183ab2acdc61659c8b0b3e57e4a1f3a /util/texi2dvi | |
parent | 2d8ae7b161658c4a589172db0072fc99f76fa979 (diff) | |
download | texinfo-tarball-master.tar.gz |
Imported from /home/lorry/working-area/delta_texinfo-tarball/texinfo-5.2.tar.xz.HEADtexinfo-5.2master
Diffstat (limited to 'util/texi2dvi')
-rwxr-xr-x | util/texi2dvi | 747 |
1 files changed, 472 insertions, 275 deletions
diff --git a/util/texi2dvi b/util/texi2dvi index 18b2214..1d2bb8b 100755 --- a/util/texi2dvi +++ b/util/texi2dvi @@ -1,9 +1,10 @@ #! /bin/sh # texi2dvi --- produce DVI (or PDF) files from Texinfo (or (La)TeX) sources. -# $Id: texi2dvi,v 1.135 2008/09/18 18:46:01 karl Exp $ +# $Id: texi2dvi 5381 2013-09-26 23:03:58Z karl $ # -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, -# 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +# Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 +# 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 @@ -18,7 +19,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # -# Original author: Noah Friedman. +# Originally written by Noah Friedman. # # Please send bug reports, etc. to bug-texinfo@gnu.org. # If possible, please send a copy of the output of the script called with @@ -32,8 +33,8 @@ unset RUNNING_KSH # No failure shall remain unpunished. set -e -# This string is expanded by rcs automatically when this file is checked out. -rcs_revision='$Revision: 1.135 $' +# This string is expanded automatically when this file is checked out. +rcs_revision='$Revision: 5381 $' rcs_version=`set - $rcs_revision; echo $2` program=`echo $0 | sed -e 's!.*/!!'` @@ -44,19 +45,22 @@ build_dir=${TEXI2DVI_BUILD_DIRECTORY:-.} # Don't use `unset' since old bourne shells don't have this command. # Instead, assign them an empty value. action=compile -batch=false # true for batch mode +batch=false # interact normally +catcode_special=maybe debug=false escape="\\" -expand= # t for expansion via makeinfo +expand=false # true for expansion via makeinfo includes= -line_error=true # Pass --file-line-error to TeX. -no_line_error=false # absolutely do not pass --file-line-error to TeX +line_error=true # pass --file-line-error to TeX +max_iters=-1 # keep going forever oname= # --output out_lang=dvi -quiet=false # by default let the tools' message be displayed +quiet=false # let the tools' message be displayed recode=false set_language= src_specials= +shell_escape= +latex2html=hevea # or set to tex4ht textra= # Extra TeX commands to insert in the input file. txiprereq=19990129 # minimum texinfo.tex version with macro expansion verb=false # true for verbose mode @@ -127,13 +131,15 @@ test -n "$TEX" && test -d "$TEX" && unset TEX test_local () { local foo=foo } - test_local + test_local >/dev/null 2>&1 test $foo = bar -) || local () { +) || eval ' +local () { case $1 in *=*) eval "$1";; esac } +' # cd_orig @@ -160,6 +166,15 @@ func_dirname () } +# noexit FILE +# ----------- +# Return FILE with one extension remove. foo.bar.baz -> foo.bar. +noext () +{ + echo "$1" | sed -e 's/\.[^/.][^/.]*$//' +} + + # absolute NAME -> ABS-NAME # ------------------------- # Return an absolute path to NAME. @@ -175,12 +190,12 @@ absolute () 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") + (cd "$rel" 2>/dev/null \ + && local n + n=`pwd`/`basename "$1"`"$slashes" + echo "$n") else - error 1 "not a directory: $rel" + error 1 "not a directory: $rel" fi ;; esac @@ -194,8 +209,12 @@ ensure_dir () { for dir do + # Beware that in parallel builds we may have several concurrent + # attempts to create the directory. So fail only if "mkdir" + # failed *and* the directory still does not exist. test -d "$dir" \ || mkdir "$dir" \ + || test -d "$dir" \ || error 1 "cannot create directory: $dir" done } @@ -203,7 +222,7 @@ ensure_dir () # error EXIT_STATUS LINE1 LINE2... # -------------------------------- -# Report an error and exit with failure if EXIT_STATUS is non null. +# Report an error and exit with failure if EXIT_STATUS is non-null. error () { local s="$1" @@ -229,12 +248,12 @@ findprog () # We have to try this both for $1 and $1.exe. # # Note: On Cygwin and DJGPP, `test -x' also looks for .exe. On Cygwin, - # also `test -f' has this enhancement, bot not on DJGPP. (Both are + # also `test -f' has this enhancement, but not on DJGPP. (Both are # design decisions, so there is little chance to make them consistent.) # Thusly, it seems to be difficult to make use of these enhancements. # - if { test -f "$dir/$1" && test -x "$dir/$1"; } || - { test -f "$dir/$1.exe" && test -x "$dir/$1.exe"; }; then + if { test -f "$dir/$1" && test -x "$dir/$1"; } \ + || { test -f "$dir/$1.exe" && test -x "$dir/$1.exe"; }; then return 0 fi done @@ -259,8 +278,8 @@ report () run () { verbose "Running $@" - "$@" 2>&5 1>&2 || - error 1 "$1 failed" + "$@" 2>&5 1>&2 \ + || error 1 "$1 failed" } @@ -280,6 +299,8 @@ usage () # 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 @@ -292,31 +313,37 @@ the FILE may also be composed of the following simple TeX commands. \`\\input{FILE}' the actual file to compile \`\\nonstopmode' same as --batch -Makeinfo is used to perform Texinfo macro expansion before running TeX -when needed. +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 (implies --clean); - only one input FILE may be specified in this case + -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 - --dvi output a DVI file [default] - --dvipdf output a PDF file via DVI (using dvipdf) -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 - -p, --pdf use pdftex or pdflatex for processing -r, --recode call recode before TeX to translate input --recode-from=ENC recode from ENC to the @documentencoding + --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 @@ -327,10 +354,11 @@ Build modes: --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] + implies --tidy; + defaults to TEXI2DVI_BUILD_DIRECTORY [$build_dir] --mostly-clean remove the auxiliary files and directories - but not the output + but not the output + --max-iterations=N don't process files more than N times The MODE specifies where the TeX compilation takes place, and, as a consequence, how auxiliary files are treated. The build mode @@ -338,39 +366,46 @@ 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. + 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. + 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. + 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 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 succesful 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. + - 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 +using \\graphicspath): in that case, use -I to specify the additional directories to consider. -The values of the BIBTEX, LATEX (or PDFLATEX), MAKEINDEX, MAKEINFO, -TEX (or PDFTEX), TEXINDEX, and THUMBPDF environment variables are used -to run those commands, if they are set. Any CMD strings are added -after @setfilename for Texinfo input, in the first line for LaTeX input. +The values of the BIBER, BIBTEX, DVIPDF, DVIPS, HEVEA, LATEX, MAKEINDEX, +MAKEINFO, PDFLATEX, PDFTEX, T4HT, TEX, TEX4HT, TEXINDEX, and THUMBPDF +environment variables are used to run those commands, if they are set. -Email bug reports to <bug-texinfo@gnu.org>, -general questions and discussion to <help-texinfo@gnu.org>. -Texinfo home page: http://www.gnu.org/software/texinfo/ +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 } @@ -389,13 +424,13 @@ verbose () # version # ------- -# Display version info and exit succesfully. +# Display version info and exit successfully. version () { cat <<EOF -texi2dvi (GNU Texinfo 4.13) $rcs_version +texi2dvi (GNU Texinfo 5.2) $rcs_version -Copyright (C) 2008 Free Software Foundation, Inc. +Copyright (C) 2013 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. @@ -512,6 +547,18 @@ list_dir_to_abs () ## Language auxiliary functions. ## ## ------------------------------ ## + +# out_lang_set LANG +# ----------------- +out_lang_set () +{ + case $1 in + dvi|dvipdf|html|info|pdf|ps|text) out_lang=$1;; + *) error 1 "invalid output format: $1";; + esac +} + + # out_lang_tex # ------------ # Return the tex output language (DVI or PDF) for $OUT_LANG. @@ -521,7 +568,7 @@ out_lang_tex () dvi | ps | dvipdf ) echo dvi;; pdf ) echo $out_lang;; html | info | text ) echo $out_lang;; - *) error 1 "$0: invalid out_lang: $1";; + *) error 1 "invalid out_lang: $1";; esac } @@ -534,7 +581,7 @@ out_lang_ext () case $out_lang in dvipdf ) echo pdf;; dvi | html | info | pdf | ps | text ) echo $out_lang;; - *) error 1 "$0: invalid out_lang: $1";; + *) error 1 "invalid out_lang: $1";; esac } @@ -576,19 +623,19 @@ absolute_filenames () do case $dir in EMPTY) - res=$res$path_sep - ;; + res=$res$path_sep + ;; *) - if test -d "$dir"; then - res=$res$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 - fi - ;; + if test -d "$dir"; then + res=$res$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 + fi + ;; esac done echo "$res" @@ -598,20 +645,33 @@ absolute_filenames () # output_base_name FILE # --------------------- # The name of FILE, possibly renamed to satisfy --output. +# FILE is local, there is no directory part. output_base_name () { case $oname in '') echo "$1";; *) local out_noext - out_noext=`echo "$oname" | sed 's/\.[^.]*$//'` - local file_ext - file_ext=`echo "$1" | sed 's/^.*\.//'` - echo "$out_noext.$file_ext" + out_noext=`noext "$oname"` + local file_ext + file_ext=`echo "$1" | sed 's/^.*\.//'` + echo "$out_noext.$file_ext" ;; esac } +# destdir +# ------- +# Return the name of the directory where the output is expected. +destdir () +{ + case $oname in + '') echo "$orig_pwd";; + *) dirname "$oname";; + esac +} + + # move_to_dest FILE... # -------------------- # Move FILE to the place where the user expects it. Truly move it, that @@ -623,7 +683,14 @@ output_base_name () # an auxiliary file with the same base name. move_to_dest () { - local dest +# echo "move_to_dest $*, tidy=$tidy, oname=$oname" + + # If we built in place and have no output name, there is nothing to + # do, so just return. + case $tidy:$oname in + false:) return;; + esac + local destfile local destdir local destbase @@ -632,42 +699,35 @@ move_to_dest () for file do + test -f "$file" \ + || error 1 "no such file or directory: $file" case $tidy:$oname in - true:) dest=$orig_pwd;; - false:) dest=;; - *:*) dest=`output_base_name "$file"`;; + true:) destdir=$orig_pwd + destfile=$destdir/$file;; + true:*) destfile=`output_base_name "$file"` + destdir=`dirname "$destfile"`;; + false:*) destfile=$oname + destdir=`dirname "$destfile"`;; esac - if test ! -f "$file"; then - error 1 "no such file or directory: $file" - fi - if test -n "$dest"; then - # We need to know whether $dest is a directory. - if test -d "$dest"; then - destdir=$dest - destfile=$dest/$file - else - destdir="`dirname $dest`" - destfile=$dest - fi - # We want to compare the source location and the output location, - # and if they are different, do the move. But if they are the - # same, we must preserve the source. Since we can't assume - # stat(1) or test -ef is available, resort to comparing the - # 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" - fi + + # We want to compare the source location and the output location, + # and if they are different, do the move. But if they are the + # same, we must preserve the source. Since we can't assume + # stat(1) or test -ef is available, resort to comparing the + # 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" fi done } @@ -679,7 +739,7 @@ move_to_dest () # aux_file_p FILE # --------------- -# Return with success with FILE is an aux file. +# Return with success if FILE is an aux file. aux_file_p () { test -f "$1" || return 1 @@ -691,7 +751,7 @@ aux_file_p () # bibaux_file_p FILE # ------------------ -# Return with success with FILE is an aux file containing citation +# Return with success if FILE is an aux file containing citation # requests. bibaux_file_p () { @@ -711,13 +771,24 @@ bibaux_file_p () # index_file_p FILE # ----------------- -# Return with success with FILE is an index file. -# When index.sty is used, there is a space before the brace. +# Return with success if FILE is an index file. index_file_p () { test -f "$1" || return 1 - case `sed '1q' "$1"` in - "\\entry{"*|"\\indexentry{"*|"\\indexentry {"*) 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 + # passed to makeindex to produce the *.ind file. This sequence is + # 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;; + + # When index.sty is used, there is a space before the brace. + latex:*:*:"\\indexentry{"*|latex:*:*:"\\indexentry {"*) return 0;; + + texinfo:*:*:"\\entry{"*) return 0;; + *) return 1;; esac } @@ -735,7 +806,7 @@ xref_file_p () case `sed '1q' "$1"` in "\\input texinfo"*) return 1;; [\\''@]*) return 0;; - *) return 1;; + *) return 1;; esac } @@ -762,15 +833,15 @@ generated_files_get () echo $file case $in_lang in texinfo) - # texindex: texinfo.cp -> texinfo.cps + # texindex: texinfo.cp -> texinfo.cps if index_file_p $file; then - echo ${file}s + echo ${file}s fi ;; latex) - if aux_file_p $file; then + if aux_file_p $file; then # bibtex: *.aux -> *.bbl and *.blg. - echo $file | sed 's/^\(.*\)\.aux$/\1.bbl/' + echo $file | sed 's/^\(.*\)\.aux$/\1.bbl/' echo $file | sed 's/^\(.*\)\.aux$/\1.blg/' # -recorder: .fls echo $file | sed 's/^\(.*\)\.aux$/\1.fls/' @@ -828,9 +899,13 @@ 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. + if grep "biblatex.*(re)run" "$in_noext.log" >&6 2>&1; then + return 0 + fi - # If old and new lists don't at least have the same file list, - # then one file or another has definitely changed. + # 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` verbose "Original xref files = $xref_files_orig" verbose "New xref files = $xref_files_new" @@ -845,7 +920,7 @@ xref_files_changed () if cmp -s "$this_file" "$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 "$work_bak/$this_file" "$this_file" fi return 0 fi @@ -868,21 +943,31 @@ xref_files_changed () # Run TeX as "$tex $in_input", taking care of errors and logs. run_tex () { - case $in_lang:`out_lang_tex` in - latex:dvi) tex=${LATEX:-latex};; - latex:pdf) tex=${PDFLATEX:-pdflatex};; - texinfo:dvi) - # MetaPost also uses the TEX environment variable. If the user - # has set TEX=latex for that reason, don't bomb out. - case $TEX in - *latex) tex=tex;; # don't bother trying to find etex - *) tex=$TEX - esac;; - texinfo:pdf) tex=$PDFTEX;; - - *) error 1 "$0: $out_lang not supported for $in_lang";; + case $in_lang:$latex2html:`out_lang_tex` in + latex:*:dvi|latex:tex4ht:html) + tex=${LATEX:-latex};; + latex:*:pdf) + tex=${PDFLATEX:-pdflatex};; + texinfo:*:dvi) + # MetaPost also uses the TEX environment variable. If the user + # has set TEX=latex for that reason, don't bomb out. + case $TEX in + *latex) tex=tex;; # don't bother trying to find etex + *) 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 @@ -891,7 +976,7 @@ run_tex () sort -u | while read d do - ensure_dir "$work_build/$d" + ensure_dir "$work_build/$d" done ;; esac @@ -900,18 +985,18 @@ run_tex () local cmd="$tex" # If possible, make TeX report error locations in GNU format. - if test "${tex_help:+set}" != set; then - # Go to a temporary directory to try --help, since old versions that - # don't accept --help will generate a texput.log. - tex_help_dir=$t2ddir/tex_help - ensure_dir "$tex_help_dir" - tex_help=`cd "$tex_help_dir" >&6 && $tex --help </dev/null 2>&1` - fi - if $no_line_error; then :; else + if $line_error; then + if test "${tex_help:+set}" != set; then + # Go to a temporary directory to try --help, since old versions that + # don't accept --help will generate a texput.log. + tex_help_dir=$t2ddir/tex_help + ensure_dir "$tex_help_dir" + tex_help=`cd "$tex_help_dir" >&6 && $tex --help </dev/null 2>&1 || true` + fi # The mk program and perhaps others want to parse TeX's # original error messages. - case $line_error:$tex_help in - true:*file-line-error*) cmd="$cmd --file-line-error";; + case $tex_help in + *file-line-error*) cmd="$cmd --file-line-error";; esac fi @@ -919,20 +1004,38 @@ run_tex () test -n "$translate_file" && cmd="$cmd --translate-file=$translate_file" # Tell TeX to make source specials (for backtracking from output to - # source, given a sufficiently smart editor), if specifed. + # source, given a sufficiently smart editor), if specified. test -n "$src_specials" && cmd="$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' '${escape}input'" + cmd="$cmd </dev/null '${escape}nonstopmode'" fi - # we'd like to handle arbitrary input file names, such as a~b.tex. - # This isn't a general way to do it :), though it does work, kind of. - # cmd="$cmd '${escape}catcode126=12 \input '" + # 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 @@ -947,12 +1050,12 @@ run_tex () # harm in making the link. # case $tidy:`func_dirname "$in_input"` in - true:*["$space$tab$newline\"#\$%\\^_{}"]*) + 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" + # 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'" ;; @@ -974,20 +1077,19 @@ run_tex () # run_bibtex () # ------------- -# Run bibtex on current file. +# 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 # # 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), # but a single LOG, looking for missing citations in LOG is -# easier, though we take the risk to match false messages. +# easier, though we take the risk of matching false messages. run_bibtex () { case $in_lang in @@ -1001,36 +1103,91 @@ run_bibtex () # bibtex would never be run. if test -r "$in_noext.aux" \ && test -r "$in_noext.log" \ - && (grep 'Warning:.*Citation.*undefined' "$in_noext.log" \ - || grep '.*Undefined citation' "$in_noext.log" \ - || grep 'No file .*\.bbl\.' "$in_noext.log") \ - || (grep 'No \.aux file' "$in_noext.log" \ - && grep '^\\bibdata' "$in_noext.aux") \ - >&6 2>&1; \ + && ((grep 'Warning:.*Citation.*undefined' "$in_noext.log" \ + || grep '.*Undefined citation' "$in_noext.log" \ + || grep 'No file .*\.bbl\.' "$in_noext.log") \ + || (grep 'No \.aux file' "$in_noext.log" \ + && grep '^\\bibdata' "$in_noext.aux")) \ + >&6 2>&1; \ then - for f in `generated_files_get "$in_noext" bibaux_file_p` - do + for f in `generated_files_get "$in_noext" bibaux_file_p`; do run $bibtex "$f" done fi + + # biber(+biblatex) check. + if test -r "$in_noext.bcf" \ + && grep '</bcf:controlfile>' "$in_noext.bcf" >/dev/null; then + run ${BIBER:-biber} "$in_noext" + fi } # run_index () # ------------ -# Run texindex (or makeindex) 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 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 () { - case $in_lang in - latex) texindex=${MAKEINDEX:-makeindex};; - texinfo) texindex=${TEXINDEX:-texindex};; - esac + local index_files index_files=`generated_files_get $in_noext index_file_p` - if test -n "$texindex" && test -n "$index_files"; then - run $texindex $index_files - fi + test -n "$index_files" \ + || return 0 + + : ${MAKEINDEX:=makeindex} + : ${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 + do + index_noext=`noext "$index_file"` + run tex \ + '\def\filename{{'"$index_noext"'}{idx}{4dx}{ind}} + \input idxmake.4ht' + run $MAKEINDEX -o $index_noext.ind $index_noext.4dx + done + ;; + + latex:*) + if $TEXINDY --version >&6 2>&1; then + run $TEXINDY $index_files + else + run $MAKEINDEX $index_files + fi + ;; + + texinfo:*) + run $TEXINDEX $index_files + ;; + esac +} + + +# 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. +run_tex4ht () +{ + case $in_lang:$latex2html:`out_lang_tex` in + latex:tex4ht:html) + : ${TEX4HT:=tex4ht} ${T4HT:=t4ht} + run "$TEX4HT" "-f/$in_noext" + # Do not remove the / after the destdir. + run "$T4HT" "-d`destdir`/" "-f/$in_noext" + ;; + esac } @@ -1049,7 +1206,7 @@ run_thumbpdf () run_tex else report "$thumbpdf exited with bad status." \ - "Ignoring its output." + "Ignoring its output." fi fi } @@ -1062,10 +1219,9 @@ run_dvipdf () { # Find which dvi->pdf program is available. if test -z "$dvipdf"; then - for i in "$DVIPDF" dvipdfmx dvipdfm dvipdf dvi2pdf dvitopdf; - do + for i in "$DVIPDF" dvipdfmx dvipdfm dvipdf dvi2pdf dvitopdf; do if findprog $i; then - dvipdf=$i + dvipdf=$i fi done fi @@ -1074,7 +1230,7 @@ run_dvipdf () # outputting using the expected file name. run $dvipdf "$1" if test ! -f `echo "$1" | sed -e 's/\.dvi$/.pdf/'`; then - error 1 "$0: cannot find output file" + error 1 "cannot find output file" fi } @@ -1093,6 +1249,13 @@ run_tex_suite () local cycle=0 while :; do + # check for probably LaTeX loop (e.g. varioref) + if test $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" @@ -1112,15 +1275,19 @@ run_tex_suite () # and TeX one last time. run_thumbpdf + # If we are using tex4ht, call it. + run_tex4ht + # Install the result if we didn't already (i.e., if the output is # dvipdf or ps). - case $out_lang in - dvipdf) + case $latex2html:$out_lang in + *:dvipdf) run_dvipdf "$in_noext.`out_lang_tex`" move_to_dest "$in_noext.`out_lang_ext`" ;; - ps) - dvips -o "$in_noext.`out_lang_ext`" "$in_noext.`out_lang_tex`" + *:ps) + : ${DVIPS:=dvips} + run $DVIPS -o "$in_noext.`out_lang_ext`" "$in_noext.`out_lang_tex`" move_to_dest "$in_noext.`out_lang_ext`" ;; esac @@ -1134,37 +1301,41 @@ run_tex_suite () # 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 +# 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. +# comment_iftex=\ '/^@tex/,/^@end tex/{ - s/^/@c texi2dvi/ + s/^/@c _texi2dvi/ } /^@iftex/,/^@end iftex/{ - s/^/@c texi2dvi/ - /^@c texi2dvi@macro/,/^@c texi2dvi@end macro/{ - s/^@c texi2dvi// + s/^/@c _texi2dvi/ + /^@c _texi2dvi@macro/,/^@c _texi2dvi@end macro/{ + s/^@c _texi2dvi// } } /^@ifnottex/,/^@end ifnottex/{ - s/^/@c (texi2dvi)/ + s/^/@c (_texi2dvi)/ } /^@ifinfo/,/^@end ifinfo/{ /^@node/p /^@menu/,/^@end menu/p t - s/^/@c (texi2dvi)/ + s/^/@c (_texi2dvi)/ } -s/^@ifnotinfo/@c texi2dvi@ifnotinfo/ -s/^@end ifnotinfo/@c texi2dvi@end ifnotinfo/' +s/^@ifnotinfo/@c _texi2dvi@ifnotinfo/ +s/^@end ifnotinfo/@c _texi2dvi@end ifnotinfo/' -# Uncommenting is simple: Remove any leading `@c texi2dvi'. -uncomment_iftex='s/^@c texi2dvi//' +# 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 () @@ -1180,28 +1351,30 @@ run_makeinfo () # Unless required by the user, makeinfo expansion is wanted only # if texinfo.tex is too old. - if test "$expand" = t; then + if $expand; then makeinfo=${MAKEINFO:-makeinfo} else # Check if texinfo.tex performs macro expansion by looking for # its version. The version is a date of the form YEAR-MO-DA. # We don't need to use [0-9] to match the digits since anyway - # the comparison with $txiprereq, a number, will fail with non - # digits. + # the comparison with $txiprereq, a number, will fail with non-digits. # Run in a temporary directory to avoid leaving files. version_test_dir=$t2ddir/version_test ensure_dir "$version_test_dir" - ( + if ( cd "$version_test_dir" echo '\input texinfo.tex @bye' >txiversion.tex # Be sure that if tex wants to fail, it is not interactive: # close stdin. $TEX txiversion.tex </dev/null >txiversion.out 2>txiversion.err - ) - if test $? != 0; then + ); then :; else + report "texinfo.tex appears to be broken. +This may be due to the environment variable TEX set to something +other than (plain) tex, a corrupt texinfo.tex file, or +to tex itself simply not working." cat "$version_test_dir/txiversion.out" cat "$version_test_dir/txiversion.err" >&2 - error 1 "texinfo.tex appears to be broken, quitting." + error 1 "quitting." fi eval `sed -n 's/^.*\[\(.*\)version \(....\)-\(..\)-\(..\).*$/txiformat=\1 txiversion="\2\3\4"/p' "$version_test_dir/txiversion.out"` verbose "texinfo.tex preloaded as \`$txiformat', version is \`$txiversion' ..." @@ -1210,9 +1383,9 @@ run_makeinfo () else makeinfo=${MAKEINFO:-makeinfo} fi - # As long as we had to run TeX, offer the user this convenience: + # If TeX is preloaded, offer the user this convenience: if test "$txiformat" = Texinfo; then - escape=@ + escape=@ fi fi @@ -1231,7 +1404,7 @@ run_makeinfo () # happens with gettext 0.14.5, at least. sed "$comment_iftex" "$command_line_filename" \ | eval $makeinfo --footnote-style=end -I "$in_dir" $miincludes \ - -o /dev/null --macro-expand=- \ + -o /dev/null --macro-expand=- \ | sed "$uncomment_iftex" >"$in_src" # Continue only if everything succeeded. if test $? -ne 0 \ @@ -1248,23 +1421,36 @@ run_makeinfo () # Used most commonly for @finalout, @smallbook, etc. insert_commands () { - local textra_cmd - case $in_lang in - latex) textra_cmd=1i;; - texinfo) textra_cmd='/^@setfilename/a';; - *) error 1 "internal error, unknown language: $in_lang";; - esac - if test -n "$textra"; then # _xtr. The file with the user's extra commands. work_xtr=$workdir/xtr 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';; + *) error 1 "internal error, unknown language: $in_lang";; + esac sed "$textra_cmd\\ $textra" "$in_input" >"$in_xtr" in_input=$in_xtr fi + + case $in_lang:$latex2html:`out_lang_tex` in + latex:tex4ht:html) + # _tex4ht. The file with the added \usepackage{tex4ht}. + work_tex4ht=$workdir/tex4ht + in_tex4ht=$work_tex4ht/$in_base + ensure_dir "$work_tex4ht" + verbose "Inserting \\usepackage{tex4ht}" + perl -pe 's<\\documentclass(?:\[.*\])?{.*}> + <$&\\usepackage[xhtml]{tex4ht}>' \ + "$in_input" >"$in_tex4ht" + in_input=$in_tex4ht + ;; + esac } # run_recode () @@ -1278,18 +1464,18 @@ run_recode () if test $in_lang = texinfo; then pgm='s/^ *@documentencoding *\([^ ][^ ]*\) *$/\1/ - t found - d - :found - q' + t found + d + :found + q' encoding=`sed -e "$pgm" "$in_input"` if $recode && test -n "$encoding" && findprog recode; then if test -n "$recode_from"; then - from=$recode_from - to=$encoding + from=$recode_from + to=$encoding else - from=$encoding - to=$texinfo + from=$encoding + to=$texinfo fi verbose "Recoding from $from to $to." # _rcd. The Texinfo file recoded in 7bit. @@ -1297,10 +1483,10 @@ run_recode () in_rcd=$work_rcd/$in_base ensure_dir "$work_rcd" if recode "$encoding..$to" <"$in_input" >"$in_rcd" \ - && test -s "$in_rcd"; then - in_input=$in_rcd + && test -s "$in_rcd"; then + in_input=$in_rcd else - verbose "Recoding failed, using original input." + verbose "Recoding failed, using original input." fi fi fi @@ -1371,7 +1557,7 @@ run_hevea () case $1 in html|text) move_to_dest "$out_base";; info) # There can be foo.info-1, foo.info-2 etc. - move_to_dest "$out_base"*;; + move_to_dest "$out_base"*;; esac else error 1 "$hevea exited with bad status, quitting." @@ -1384,13 +1570,13 @@ run_hevea () # Run the TeX (or HeVeA). run_core_conversion () { - case $in_lang:`out_lang_tex` in - *:dvi|*:pdf) - run_tex;; - latex:html|latex:text|latex:info) - run_hevea $out_lang;; + case $in_lang:$latex2html:`out_lang_tex` in + *:dvi|*:pdf|latex:tex4ht:html) + run_tex;; + latex:*:html|latex:*:text|latex:*:info) + run_hevea $out_lang;; *) - error 1 "invalid input/output combination: $in_lang/$out_lang";; + error 1 "invalid input/output combination: $in_lang/$out_lang";; esac } @@ -1407,9 +1593,14 @@ compile () # `.' 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've cd'd to a temp directory. + # we have cd'd to a temp directory. + 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` - common="$orig_pwd$path_sep$in_dir$path_sep$txincludes$path_sep" + test -n "$txincludes" && common="$common$txincludes$path_sep" + # for var in $tex_envvars; do eval val="\$common\$${var}_orig" # Convert relative paths to absolute paths, so we can run in another @@ -1505,38 +1696,42 @@ while test x"$1" != x"$arg_sep"; do ;; esac - # This recognizes --quark as --quiet. So what. + # This recognizes --quark as --quiet. Oh well. case "$1" in -@ ) escape=@;; + -~ ) catcode_special=false;; # Silently and without documentation accept -b and --b[atch] as synonyms. -b | --batch) batch=true;; - --build) shift; build_mode=$1;; - --build-dir) shift; build_dir=$1; build_mode=tidy;; + --build) shift; build_mode=$1;; + --build-dir) shift; build_dir=$1; build_mode=tidy;; -c | --clean) build_mode=clean;; -D | --debug) debug=true;; - --dvi) out_lang=dvi;; - --dvipdf) out_lang=dvipdf;; - -e | -E | --expand) expand=t;; + -e | -E | --expand) expand=true;; -h | --help) usage;; - --html) out_lang=html;; -I) shift; list_concat_dirs includes "$1";; - --info) out_lang=info;; -l | --lang | --language) shift; set_language=$1;; --mostly-clean) action=mostly-clean;; - --no-line-error) no_line_error=true;; + --no-line-error) line_error=false;; + --max-iterations) shift; max_iters=$1;; -o | --out | --output) shift # Make it absolute, just in case we also have --clean, or whatever. oname=`absolute "$1"`;; - -p | --pdf) out_lang=pdf;; - --ps) out_lang=ps;; + + # Output formats. + -O|--output-format) shift; out_lang_set "$1";; + --dvi|--dvipdf|--html|--info|--pdf|--ps|--text) + out_lang_set `echo "x$1" | sed 's/^x--//'`;; + + -p) out_lang_set pdf;; -q | -s | --quiet | --silent) quiet=true; batch=true;; -r | --recode) recode=true;; --recode-from) shift; recode=true; recode_from="$1";; --src-specials) src_specials=--src-specials;; + --shell-escape) shell_escape=--shell-escape;; + --tex4ht) latex2html=tex4ht;; -t | --texinfo | --command ) shift; textra="$textra\\ "`echo "$1" | sed 's/\\\\/\\\\\\\\/g'`;; - --text) out_lang=text;; --translate-file ) shift; translate_file="$1";; --tidy) build_mode=tidy;; -v | --vers*) version;; @@ -1544,13 +1739,13 @@ while test x"$1" != x"$arg_sep"; do --) # What remains are not options. shift while test x"$1" != x"$arg_sep"; do - set dummy ${1+"$@"} "$1"; shift - shift + set dummy ${1+"$@"} "$1"; shift + shift done break;; -*) error 1 "Unknown or ambiguous option \`$1'." \ - "Try \`--help' for more information." + "Try \`--help' for more information." ;; *) set dummy ${1+"$@"} "$1"; shift;; esac @@ -1591,9 +1786,8 @@ 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 output for more details. -For information about obtaining TeX, please see http://www.tug.org. If -you happen to be using Debian, you can get it with this command: - apt-get install tetex-bin +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 @@ -1635,14 +1829,15 @@ fi # Enable tracing, and auxiliary tools output. -# -# Should be used where you'd typically use /dev/null to throw output -# away. But sometimes it is convenient to see that output (e.g., from -# a grep) to aid debugging. Especially debugging at distance, via the -# user. +# +# This fd should be used where you'd typically use /dev/null to throw +# output away. But sometimes it is convenient to see that output (e.g., +# from a grep) to aid debugging. Especially debugging at distance, via +# the user. +# if $debug; then exec 6>&1 - set -x + set -vx else exec 6>/dev/null fi @@ -1677,21 +1872,21 @@ input_file_name_decode () # Let AUC-TeX error parser deal with line numbers. line_error=false command_line_filename=`\ - expr X"$command_line_filename" : X'.*input{\([^}]*\)}'` + 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" | $EGREP '^(/|[A-z]:/)' >&6 \ + 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." + 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"` @@ -1704,7 +1899,7 @@ input_file_name_decode () # Strip directory part but leave extension. in_base=`basename "$command_line_filename"` # Strip extension. - in_noext=`echo "$in_base" | sed 's/\.[^.]*$//'` + 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.). @@ -1720,7 +1915,7 @@ input_file_name_decode () out_dir=`func_dirname "$out_name"` out_dir_abs=`absolute "$out_dir"` out_base=`basename "$out_name"` - out_noext=`echo "$out_base" | sed 's/\.[^.]*$//'` + out_noext=`noext "$out_base"` } @@ -1742,11 +1937,13 @@ do case $build_dir in '' | . ) t2ddir=$out_noext.t2d ;; *) # Avoid collisions between multiple occurrences of the same - # file. The sed expression is fragile if the cwd has - # active characters. - t2ddir=$build_dir/`echo "$out_dir_abs/$out_noext.t2d" | - sed "s,^$orig_pwd/,," | - sed 's,/,!,g'` + # file, so depend on the output path. Remove leading `./', + # at least to avoid creating a file starting with `.!', i.e., + # an invisible file. The sed expression is fragile if the cwd + # has active characters. Transform / into ! so that we don't + # need `mkdir -p'. It might be something to reconsider. + t2ddir=$build_dir/`echo "$out_dir_abs/$out_noext.t2d" | + sed "s,^$orig_pwd/,,;s,^\./,,;s,/,!,g"` esac # Remove it at exit if clean mode. trap "cleanup" 0 1 2 15 |