| 1 |
#! /bin/sh |
| 2 |
# texi2dvi --- produce DVI (or PDF) files from Texinfo (or (La)TeX) sources. |
| 3 |
# |
| 4 |
# Copyright 1992-2019 Free Software Foundation, Inc. |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation; either version 3 of the License, |
| 9 |
# or (at your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
# |
| 19 |
# Originally written by Noah Friedman. |
| 20 |
# |
| 21 |
# Please send bug reports, etc. to [email protected]. |
| 22 |
# If possible, please send a copy of the output of the script called with |
| 23 |
# the `--debug' option when making a bug report. |
| 24 |
|
| 25 |
test -f /bin/ksh && test -z "$RUNNING_KSH" \ |
| 26 |
&& { UNAMES=`uname -s`; test "x$UNAMES" = xULTRIX; } 2>/dev/null \ |
| 27 |
&& { RUNNING_KSH=true; export RUNNING_KSH; exec /bin/ksh $0 ${1+"$@"}; } |
| 28 |
unset RUNNING_KSH |
| 29 |
|
| 30 |
# No failure shall remain unpunished. |
| 31 |
set -e |
| 32 |
|
| 33 |
# In case the default sed doesn't suffice. |
| 34 |
: ${SED=sed} |
| 35 |
|
| 36 |
program=`echo $0 | $SED -e 's!.*/!!'` |
| 37 |
|
| 38 |
build_mode=${TEXI2DVI_BUILD_MODE:-local} |
| 39 |
build_dir=${TEXI2DVI_BUILD_DIRECTORY:-.} |
| 40 |
|
| 41 |
orig_pwd=`pwd` |
| 42 |
|
| 43 |
# Initialize variables for option overriding and otherwise. |
| 44 |
# Don't use `unset' since old bourne shells don't have this command. |
| 45 |
# Instead, assign them an empty value. |
| 46 |
action=compile |
| 47 |
debug=false |
| 48 |
escape="\\" |
| 49 |
expand=false # true for expansion via makeinfo |
| 50 |
includes= |
| 51 |
line_error=true # pass --file-line-error to TeX |
| 52 |
max_iters=7 # when to quit |
| 53 |
oname= # --output |
| 54 |
out_lang=dvi |
| 55 |
quiet=false # let the tools' message be displayed |
| 56 |
set_language= |
| 57 |
src_specials= |
| 58 |
shell_escape= |
| 59 |
latex2html=hevea # or set to tex4ht |
| 60 |
textra= # Extra TeX commands to insert in the input file. |
| 61 |
txiprereq=19990129 # minimum texinfo.tex version with macro expansion |
| 62 |
verb=false # true for verbose mode |
| 63 |
translate_file= # name of charset translation file |
| 64 |
|
| 65 |
# We have to initialize IFS to space tab newline since we save and |
| 66 |
# restore IFS and apparently POSIX allows stupid/broken behavior with |
| 67 |
# empty-but-set IFS. |
| 68 |
# http://lists.gnu.org/archive/html/automake-patches/2006-05/msg00008.html |
| 69 |
# We need space, tab and newline, in precisely that order. And don't leave |
| 70 |
# trailing blanks. |
| 71 |
space=' ' |
| 72 |
tab=' ' |
| 73 |
newline=' |
| 74 |
' |
| 75 |
IFS="$space$tab$newline" |
| 76 |
|
| 77 |
: ${EGREP=egrep} |
| 78 |
|
| 79 |
# Systems which define $COMSPEC or $ComSpec use semicolons to separate |
| 80 |
# directories in TEXINPUTS -- except for Cygwin and Msys, where COMSPEC |
| 81 |
# might be inherited, but : is used. |
| 82 |
|
| 83 |
# In the case of Msys, uname returns a value derived from MSYSTEM, as |
| 84 |
# MSYSTEM is user configurable, it is not so safe to use it to detect |
| 85 |
# Msys. It is safer to use OSTYPE, this is why we set MSYSTEM to |
| 86 |
# $OSTYPE before calling uname |
| 87 |
if test -n "$COMSPEC$ComSpec" \ |
| 88 |
&& MSYSTEM=$OSTYPE uname | $EGREP -iv 'cygwin|msys' >/dev/null; then |
| 89 |
path_sep=";" |
| 90 |
else |
| 91 |
path_sep=":" |
| 92 |
fi |
| 93 |
|
| 94 |
|
| 95 |
# Pacify verbose cds. |
| 96 |
CDPATH=${ZSH_VERSION+.}$path_sep |
| 97 |
|
| 98 |
|
| 99 |
# Now we define numerous functions, with no other executable code. |
| 100 |
# The main program is at the end of the file. |
| 101 |
|
| 102 |
|
| 103 |
# Standard help and version functions. |
| 104 |
# |
| 105 |
# usage - display usage and exit successfully. |
| 106 |
usage () |
| 107 |
{ |
| 108 |
cat <<EOF |
| 109 |
Usage: $program [OPTION]... FILE... |
| 110 |
or: texi2pdf [OPTION]... FILE... |
| 111 |
or: pdftexi2dvi [OPTION]... FILE... |
| 112 |
|
| 113 |
Run each Texinfo or (La)TeX FILE through TeX in turn until all |
| 114 |
cross-references are resolved, building all indices. The directory |
| 115 |
containing each FILE is searched for included files. The suffix of FILE |
| 116 |
is used to determine its language ((La)TeX or Texinfo). To process |
| 117 |
(e)plain TeX files, set the environment variable LATEX=tex. |
| 118 |
|
| 119 |
When invoked as \`texi2pdf' or given the option --pdf generate PDF output. |
| 120 |
Otherwise, generate DVI. |
| 121 |
|
| 122 |
General options: |
| 123 |
-D, --debug turn on shell debugging (set -x) |
| 124 |
-h, --help display this help and exit successfully |
| 125 |
-o, --output=OFILE leave output in OFILE; only one input FILE is allowed |
| 126 |
-q, --quiet no output unless errors |
| 127 |
-v, --version display version information and exit successfully |
| 128 |
-V, --verbose report on what is done |
| 129 |
--max-iterations=N don't process files more than N times [$max_iters] |
| 130 |
--mostly-clean remove auxiliary files or directories from |
| 131 |
previous runs (but not the output) |
| 132 |
|
| 133 |
Output format: |
| 134 |
--dvi output a DVI file [default] |
| 135 |
--dvipdf output a PDF file via DVI (using a dvi-to-pdf program) |
| 136 |
--html output an HTML file from LaTeX, using HeVeA |
| 137 |
--info output an Info file from LaTeX, using HeVeA |
| 138 |
-p, --pdf use pdftex or pdflatex for processing |
| 139 |
--ps output a PostScript file via DVI (using dvips) |
| 140 |
--text output a plain text file from LaTeX, using HeVeA |
| 141 |
|
| 142 |
TeX tuning: |
| 143 |
-E, --expand macro expansion using makeinfo |
| 144 |
-I DIR search DIR for Texinfo files |
| 145 |
-l, --language=LANG specify LANG for FILE, either latex or texinfo |
| 146 |
--no-line-error do not pass --file-line-error to TeX |
| 147 |
--shell-escape pass --shell-escape to TeX |
| 148 |
--src-specials pass --src-specials to TeX |
| 149 |
--translate-file=FILE use given charset translation file for TeX |
| 150 |
-t, --command=CMD insert CMD in copy of input file |
| 151 |
|
| 152 |
Build modes: |
| 153 |
--build=MODE specify the treatment of auxiliary files [$build_mode] |
| 154 |
--tidy same as --build=tidy |
| 155 |
-c, --clean same as --build=clean |
| 156 |
--build-dir=DIR specify where the tidy compilation is performed; |
| 157 |
implies --tidy; |
| 158 |
defaults to TEXI2DVI_BUILD_DIRECTORY [$build_dir] |
| 159 |
|
| 160 |
The MODE specifies where the TeX compilation takes place, and, as a |
| 161 |
consequence, how auxiliary files are treated. The build mode can also |
| 162 |
be set using the environment variable TEXI2DVI_BUILD_MODE. |
| 163 |
|
| 164 |
Valid values of MODE are: |
| 165 |
\`local' compile in the current directory, leaving all the auxiliary |
| 166 |
files around. This is the traditional TeX use. |
| 167 |
\`tidy' compile in a local *.t2d directory, where the auxiliary files |
| 168 |
are left. Output files are copied back to the original file. |
| 169 |
\`clean' same as \`tidy', but remove the auxiliary directory afterwards. |
| 170 |
Every compilation therefore requires the full cycle. |
| 171 |
|
| 172 |
The values of these environment variables are used to run the |
| 173 |
corresponding commands, if they are set: |
| 174 |
|
| 175 |
BIBER BIBTEX DVIPDF DVIPS EGREP HEVEA LATEX MAKEINDEX MAKEINFO |
| 176 |
PDFLATEX PDFTEX SED T4HT TEX TEX4HT TEXINDEX TEXINDY THUMBPDF_CMD |
| 177 |
|
| 178 |
Regarding --dvipdf, if DVIPDF is not set in the environment, the |
| 179 |
following programs are looked for (in this order): dvipdfmx dvipdfm |
| 180 |
dvipdf dvi2pdf dvitopdf. |
| 181 |
|
| 182 |
If Texinfo is installed on your site, then the command |
| 183 |
|
| 184 |
info texi2dvi |
| 185 |
|
| 186 |
should give you access to more documentation. |
| 187 |
|
| 188 |
Report bugs to [email protected], |
| 189 |
general questions and discussion to [email protected]. |
| 190 |
GNU Texinfo home page: <http://www.gnu.org/software/texinfo/> |
| 191 |
General help using GNU software: <http://www.gnu.org/gethelp/> |
| 192 |
EOF |
| 193 |
exit 0 |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
# version - Display version info and exit successfully. |
| 198 |
version () |
| 199 |
{ |
| 200 |
cat <<EOF |
| 201 |
texi2dvi (GNU Texinfo 6.7) |
| 202 |
|
| 203 |
Copyright (C) 2019 Free Software Foundation, Inc. |
| 204 |
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> |
| 205 |
This is free software: you are free to change and redistribute it. |
| 206 |
There is NO WARRANTY, to the extent permitted by law. |
| 207 |
EOF |
| 208 |
exit 0 |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
# Generic auxiliary functions. |
| 213 |
|
| 214 |
# Used to access files and directories after we have changed directory |
| 215 |
# (for --tidy). |
| 216 |
rel= |
| 217 |
|
| 218 |
# Change directory, updating some relative paths. |
| 219 |
cd_dir () |
| 220 |
{ |
| 221 |
cd "$1" |
| 222 |
|
| 223 |
# Check if argument or input file is absolute, and if so, make all the path |
| 224 |
# variables absolute. |
| 225 |
use_absolute=false |
| 226 |
case $1 in |
| 227 |
[\\/]* | ?:[\\/]*) # absolute path |
| 228 |
use_absolute=true ;; |
| 229 |
esac |
| 230 |
case $in_input in |
| 231 |
[\\/]* | ?:[\\/]*) |
| 232 |
use_absolute=true ;; |
| 233 |
esac |
| 234 |
|
| 235 |
if $use_absolute ; then |
| 236 |
for cdd_dir in work_build workdir t2ddir work_bak in_input in_dir; do |
| 237 |
eval "$cdd_dir=\`absolute \$$cdd_dir\`" |
| 238 |
done |
| 239 |
return |
| 240 |
fi |
| 241 |
|
| 242 |
# Replace each path component with ".." and add a single trailing slash. |
| 243 |
rel=`echo "$1" | \$SED -e 's/[^/\\][^/\\]*/../g' -e 's/[/\\]*$/\//'` |
| 244 |
} |
| 245 |
|
| 246 |
# cd_orig - Return to the original directory. |
| 247 |
cd_orig () |
| 248 |
{ |
| 249 |
# In case $orig_pwd is on a different drive (for DOS). |
| 250 |
cd / |
| 251 |
|
| 252 |
# Return to the original directory so that |
| 253 |
# - the next file is processed in correct conditions |
| 254 |
# - the temporary file can be removed |
| 255 |
cd "$orig_pwd" || exit 1 |
| 256 |
|
| 257 |
rel= |
| 258 |
} |
| 259 |
|
| 260 |
|
| 261 |
# func_dirname FILE - Return the directory part of FILE. |
| 262 |
func_dirname () |
| 263 |
{ |
| 264 |
dirname "$1" 2>/dev/null \ |
| 265 |
|| { echo "$1" | $SED 's!/[^/]*$!!;s!^$!.!'; } |
| 266 |
} |
| 267 |
|
| 268 |
|
| 269 |
# noext FILE - Return FILE with one extension removed: |
| 270 |
# foo.bar.baz -> foo.bar |
| 271 |
noext () |
| 272 |
{ |
| 273 |
echo "$1" | $SED -e 's/\.[^/.][^/.]*$//' |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
# absolute NAME - Return an absolute path to NAME. |
| 278 |
absolute () |
| 279 |
{ |
| 280 |
case $1 in |
| 281 |
[\\/]* | ?:[\\/]*) |
| 282 |
# Absolute paths don't need to be expanded. |
| 283 |
echo "$1" |
| 284 |
;; |
| 285 |
*) absolute_slashes=`echo "$1" | $SED -n 's,.*[^/]\(/*\)$,\1,p'` |
| 286 |
absolute_rel=$orig_pwd/`func_dirname "$1"` |
| 287 |
if test -d "$absolute_rel"; then |
| 288 |
(cd "$absolute_rel" 2>/dev/null \ |
| 289 |
&& absolute_name=`pwd`/`basename "$1"`"$absolute_slashes" |
| 290 |
echo "$absolute_name") |
| 291 |
else |
| 292 |
error 1 "not a directory: $absolute_rel" |
| 293 |
fi |
| 294 |
;; |
| 295 |
esac |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
# ensure_dir DIR1 DIR2... - Make sure given directories exist. |
| 300 |
ensure_dir () |
| 301 |
{ |
| 302 |
for dir |
| 303 |
do |
| 304 |
# Beware that in parallel builds we may have several concurrent |
| 305 |
# attempts to create the directory. So fail only if "mkdir" |
| 306 |
# failed *and* the directory still does not exist. |
| 307 |
test -d "$dir" \ |
| 308 |
|| mkdir "$dir" \ |
| 309 |
|| test -d "$dir" \ |
| 310 |
|| error 1 "cannot create directory: $dir" |
| 311 |
done |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
# error EXIT_STATUS LINE1 LINE2... - Report an error and exit with |
| 316 |
# failure if EXIT_STATUS is non-null. |
| 317 |
error () |
| 318 |
{ |
| 319 |
error_status="$1" |
| 320 |
shift |
| 321 |
report "$@" |
| 322 |
if test "$error_status" != 0; then |
| 323 |
exit $error_status |
| 324 |
fi |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
# findprog PROG - Return true if PROG is somewhere in PATH, else false. |
| 329 |
findprog () |
| 330 |
{ |
| 331 |
saveIFS="$IFS" |
| 332 |
IFS=$path_sep # break path components at the path separator |
| 333 |
for dir in $PATH; do |
| 334 |
IFS=$saveIFS |
| 335 |
# The basic test for an executable is `test -f $f && test -x $f'. |
| 336 |
# (`test -x' is not enough, because it can also be true for directories.) |
| 337 |
# We have to try this both for $1 and $1.exe. |
| 338 |
# |
| 339 |
# Note: On Cygwin and DJGPP, `test -x' also looks for .exe. On Cygwin, |
| 340 |
# also `test -f' has this enhancement, but not on DJGPP. (Both are |
| 341 |
# design decisions, so there is little chance to make them consistent.) |
| 342 |
# Thusly, it seems to be difficult to make use of these enhancements. |
| 343 |
# |
| 344 |
if { test -f "$dir/$1" && test -x "$dir/$1"; } \ |
| 345 |
|| { test -f "$dir/$1.exe" && test -x "$dir/$1.exe"; }; then |
| 346 |
return 0 |
| 347 |
fi |
| 348 |
done |
| 349 |
return 1 |
| 350 |
} |
| 351 |
|
| 352 |
# report LINE1 LINE2... - Echo each argument to stderr. |
| 353 |
report () |
| 354 |
{ |
| 355 |
for i in "$@" |
| 356 |
do |
| 357 |
echo >&2 "$0: $i" |
| 358 |
done |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
# run COMMAND-LINE - Run COMMAND-LINE verbosely, catching errors as failures. |
| 363 |
run () |
| 364 |
{ |
| 365 |
verbose "Running $@" |
| 366 |
"$@" 2>&5 1>&2 \ |
| 367 |
|| error 1 "$1 failed" |
| 368 |
} |
| 369 |
|
| 370 |
|
| 371 |
# verbose WORD1 WORD2... - Echo concatenated WORDs to stderr, if $verb. |
| 372 |
verbose () |
| 373 |
{ |
| 374 |
if $verb; then |
| 375 |
echo >&2 "$0: $@" |
| 376 |
fi |
| 377 |
} |
| 378 |
|
| 379 |
|
| 380 |
# Handling lists. |
| 381 |
# |
| 382 |
# list_append LIST-NAME ELEM - Append ELEM to (the contents of) LIST-NAME. |
| 383 |
list_append () |
| 384 |
{ |
| 385 |
list_name="$1" |
| 386 |
shift |
| 387 |
eval set X \$$list_name "$@" |
| 388 |
shift |
| 389 |
eval $list_name=\""$@"\" |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
# list_concat_dirs LIST-NAME DIR-LIST - Append to LIST-NAME all the |
| 394 |
# components (including empty ones) from the $path_sep-separated list |
| 395 |
# DIR-LIST. Make the paths absolute. |
| 396 |
list_concat_dirs () |
| 397 |
{ |
| 398 |
lcd_list="$1" |
| 399 |
# Empty path components are meaningful to tex. We rewrite them as |
| 400 |
# `EMPTY' so they don't get lost when we split on $path_sep. |
| 401 |
# Hopefully no one will have an actual directory named EMPTY. |
| 402 |
lcd_replace_EMPTY="-e 's/^$path_sep/EMPTY$path_sep/g' \ |
| 403 |
-e 's/$path_sep\$/${path_sep}EMPTY/g' \ |
| 404 |
-e 's/$path_sep$path_sep/${path_sep}EMPTY${path_sep}/g'" |
| 405 |
save_IFS=$IFS |
| 406 |
IFS=$path_sep |
| 407 |
set x `echo "$2" | eval $SED $lcd_replace_EMPTY`; shift |
| 408 |
IFS=$save_IFS |
| 409 |
for lcd_dir |
| 410 |
do |
| 411 |
case $lcd_dir in |
| 412 |
EMPTY) |
| 413 |
list_append $lcd_list "" |
| 414 |
;; |
| 415 |
*) |
| 416 |
if test -d $lcd_dir; then |
| 417 |
dir=`absolute "$lcd_dir"` |
| 418 |
list_append $lcd_list "$lcd_dir" |
| 419 |
fi |
| 420 |
;; |
| 421 |
esac |
| 422 |
done |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
# list_prefix LIST-NAME SEP -> STRING - Return string with each element |
| 427 |
# of LIST-NAME preceded by SEP. |
| 428 |
list_prefix () |
| 429 |
{ |
| 430 |
lp_separator="$2" |
| 431 |
eval set X \$$1 |
| 432 |
shift |
| 433 |
lp_result='' |
| 434 |
for i |
| 435 |
do |
| 436 |
lp_result="$lp_result \"$lp_separator\" \"$i\"" |
| 437 |
done |
| 438 |
echo "$lp_result" |
| 439 |
} |
| 440 |
|
| 441 |
# list_infix LIST-NAME SEP -> STRING - Same as list_prefix, but a separator. |
| 442 |
list_infix () |
| 443 |
{ |
| 444 |
eval set X \$$1 |
| 445 |
shift |
| 446 |
save_IFS="$IFS" |
| 447 |
IFS=$path_sep |
| 448 |
echo "$*" |
| 449 |
IFS=$save_IFS |
| 450 |
} |
| 451 |
|
| 452 |
# list_dir_to_abs LIST-NAME - Convert list to using only absolute dir names. |
| 453 |
# Currently unused, but should replace absolute_filenames some day. |
| 454 |
list_dir_to_abs () |
| 455 |
{ |
| 456 |
ldta_list="$1" |
| 457 |
eval set X \$$ldta_list |
| 458 |
shift |
| 459 |
ldta_result='' |
| 460 |
for dir |
| 461 |
do |
| 462 |
dir=`absolute "$dir"` |
| 463 |
test -d "$dir" || continue |
| 464 |
ldta_result="$ldata_result \"$dir\"" |
| 465 |
done |
| 466 |
set X $ldta_result; shift |
| 467 |
eval $ldta_list=\"$@\" |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
# Language auxiliary functions. |
| 472 |
# |
| 473 |
# out_lang_set LANG - set $out_lang to LANG (dvi, pdf, etc.), or error. |
| 474 |
out_lang_set () |
| 475 |
{ |
| 476 |
case $1 in |
| 477 |
dvi|dvipdf|html|info|pdf|ps|text) out_lang=$1;; |
| 478 |
*) error 1 "invalid output format: $1";; |
| 479 |
esac |
| 480 |
} |
| 481 |
|
| 482 |
# out_lang_tex - Return the tex output language (DVI or PDF) for $out_lang. |
| 483 |
out_lang_tex () |
| 484 |
{ |
| 485 |
case $out_lang in |
| 486 |
dvi | ps | dvipdf ) echo dvi;; |
| 487 |
pdf ) echo $out_lang;; |
| 488 |
html | info | text ) echo $out_lang;; |
| 489 |
*) error 1 "invalid out_lang: $1";; |
| 490 |
esac |
| 491 |
} |
| 492 |
|
| 493 |
# out_lang_ext - Return the extension for $out_lang (pdf, dvi, etc.). |
| 494 |
out_lang_ext () |
| 495 |
{ |
| 496 |
case $out_lang in |
| 497 |
dvipdf ) echo pdf;; |
| 498 |
dvi | html | info | pdf | ps | text ) echo $out_lang;; |
| 499 |
*) error 1 "invalid out_lang: $1";; |
| 500 |
esac |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
# TeX file auxiliary functions. |
| 505 |
# |
| 506 |
# absolute_filenames TEX-PATH -> TEX-PATH - Convert relative paths to |
| 507 |
# absolute, so we can run in another directory (e.g., in tidy build |
| 508 |
# mode, or during the macro-support detection). |
| 509 |
absolute_filenames () |
| 510 |
{ |
| 511 |
# Empty path components are meaningful to tex. We rewrite them as |
| 512 |
# `EMPTY' so they don't get lost when we split on $path_sep. |
| 513 |
# Hopefully no one will have an actual directory named EMPTY. |
| 514 |
af_replace_empty="-e 's/^$path_sep/EMPTY$path_sep/g' \ |
| 515 |
-e 's/$path_sep\$/${path_sep}EMPTY/g' \ |
| 516 |
-e 's/$path_sep$path_sep/${path_sep}EMPTY${path_sep}/g'" |
| 517 |
af_result=`echo "$1" | eval $SED $af_replace_empty` |
| 518 |
save_IFS=$IFS |
| 519 |
IFS=$path_sep |
| 520 |
set x $af_result; shift |
| 521 |
af_result= |
| 522 |
af_path_sep= |
| 523 |
for dir |
| 524 |
do |
| 525 |
case $dir in |
| 526 |
EMPTY) |
| 527 |
af_result=$af_result$af_path_sep |
| 528 |
;; |
| 529 |
*) |
| 530 |
if test -d "$dir"; then |
| 531 |
af_result=$af_result$af_path_sep`absolute "$dir"` |
| 532 |
else |
| 533 |
# Even if $dir is not a directory, preserve it in the path. |
| 534 |
# It might contain metacharacters that TeX will expand in |
| 535 |
# turn, e.g., /some/path/{a,b,c}. This will not get the |
| 536 |
# implicit absolutification of the path, but we can't help that. |
| 537 |
af_result=$af_result$af_path_sep$dir |
| 538 |
fi |
| 539 |
;; |
| 540 |
esac |
| 541 |
af_path_sep=$path_sep |
| 542 |
done |
| 543 |
echo "$af_result" |
| 544 |
} |
| 545 |
|
| 546 |
|
| 547 |
# output_base_name FILE - Return the name of FILE, possibly renamed to |
| 548 |
# satisfy --output. FILE is local, i.e., without any directory part. |
| 549 |
output_base_name () |
| 550 |
{ |
| 551 |
case $oname in |
| 552 |
'') echo "$1";; |
| 553 |
*) obn_out_noext=`noext "$oname"` |
| 554 |
obn_file_ext=`echo "$1" | $SED 's/^.*\.//'` |
| 555 |
echo "$obn_out_noext.$obn_file_ext" |
| 556 |
;; |
| 557 |
esac |
| 558 |
} |
| 559 |
|
| 560 |
|
| 561 |
# destdir - Return the directory where the output is expected. |
| 562 |
destdir () |
| 563 |
{ |
| 564 |
case $oname in |
| 565 |
'') echo "$orig_pwd";; |
| 566 |
*) dirname "$oname";; |
| 567 |
esac |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
# move_to_dest FILE... - Move FILE(s) to the place where the user expects. |
| 572 |
# Truly move it, that is, it must not remain in its build location |
| 573 |
# unless that is also the output location. (Otherwise it might appear |
| 574 |
# as an extra file in make distcheck.) |
| 575 |
# |
| 576 |
# FILE can be the principal output (in which case -o directly applies), |
| 577 |
# or an auxiliary file with the same base name. |
| 578 |
move_to_dest () |
| 579 |
{ |
| 580 |
# echo "move_to_dest $*, tidy=$tidy, oname=$oname" |
| 581 |
|
| 582 |
# If we built in place and have no output name, there is nothing to |
| 583 |
# do, so just return. |
| 584 |
case $tidy:$oname in |
| 585 |
false:) return;; |
| 586 |
esac |
| 587 |
|
| 588 |
for file |
| 589 |
do |
| 590 |
test -f "$file" \ |
| 591 |
|| error 1 "no such file or directory: $file" |
| 592 |
case $tidy:$oname in |
| 593 |
true:) mtd_destdir=$orig_pwd |
| 594 |
mtd_destfile=$mtd_destdir/$file;; |
| 595 |
true:*) mtd_destfile=`output_base_name "$file"` |
| 596 |
mtd_destdir=`dirname "$mtd_destfile"`;; |
| 597 |
false:*) mtd_destfile=$oname |
| 598 |
mtd_destdir=`dirname "$mtd_destfile"`;; |
| 599 |
esac |
| 600 |
|
| 601 |
# We want to compare the source location and the output location, |
| 602 |
# and if they are different, do the move. But if they are the |
| 603 |
# same, we must preserve the source. Since we can't assume |
| 604 |
# stat(1) or test -ef is available, resort to comparing the |
| 605 |
# directory names, canonicalized with pwd. We can't use cmp -s |
| 606 |
# since the output file might not actually change from run to run; |
| 607 |
# e.g., TeX DVI output is timestamped to only the nearest minute. |
| 608 |
mtd_destdir=`cd "$mtd_destdir" && pwd` |
| 609 |
mtd_destbase=`basename "$mtd_destfile"` |
| 610 |
|
| 611 |
mtd_sourcedir=`dirname "$file"` |
| 612 |
mtd_sourcedir=`cd "$mtd_sourcedir" && pwd` |
| 613 |
mtd_sourcebase=`basename "$file"` |
| 614 |
|
| 615 |
if test "$mtd_sourcedir/$mtd_sourcebase" != "$mtd_destdir/$mtd_destbase" |
| 616 |
then |
| 617 |
verbose "Moving $file to $mtd_destfile" |
| 618 |
rm -f "$mtd_destfile" |
| 619 |
mv "$file" "$mtd_destfile" |
| 620 |
fi |
| 621 |
done |
| 622 |
} |
| 623 |
|
| 624 |
|
| 625 |
# Managing xref files. |
| 626 |
# |
| 627 |
# aux_file_p FILE - Echo FILE if FILE is an aux file. |
| 628 |
aux_file_p () |
| 629 |
{ |
| 630 |
test -f "$1" || return 0 |
| 631 |
case $1 in |
| 632 |
*.aux) echo "$1";; |
| 633 |
*) return 0;; |
| 634 |
esac |
| 635 |
} |
| 636 |
|
| 637 |
# bibaux_file_p FILE - Echo FILE if FILE contains citation requests. |
| 638 |
bibaux_file_p () |
| 639 |
{ |
| 640 |
test -s "$1" || return 0 |
| 641 |
if (grep '^\\bibstyle[{]' "$1" \ |
| 642 |
&& grep '^\\bibdata[{]' "$1" \ |
| 643 |
## The following line is suspicious: fails when there |
| 644 |
## are citations in sub aux files. We need to be |
| 645 |
## smarter in this case. |
| 646 |
## && grep '^\\citation[{]' "$f" |
| 647 |
) >&6 2>&1; |
| 648 |
then |
| 649 |
echo "$1" |
| 650 |
fi |
| 651 |
return 0 |
| 652 |
} |
| 653 |
|
| 654 |
# index_file_p FILE - Echo FILE if FILE is an index file. |
| 655 |
index_file_p () |
| 656 |
{ |
| 657 |
test -f "$1" || return 0 |
| 658 |
case $in_lang:$latex2html:`out_lang_tex`:`$SED '1q' "$1"` in |
| 659 |
# When working with TeX4HT, *.idx are created by LaTeX. They must |
| 660 |
# be processed to produce *.4ix, *.4dx files. The *.4dx file is |
| 661 |
# passed to makeindex to produce the *.ind file. This sequence is |
| 662 |
# handled by run_index, so we are only interested in the *.idx |
| 663 |
# files, which have each "\indexentry" preceded by a |
| 664 |
# "\beforeentry". |
| 665 |
latex:tex4ht:html:"\\beforeentry {"*) echo $1;; |
| 666 |
|
| 667 |
# When index.sty is used, there is a space before the brace. |
| 668 |
latex:*:*:"\\indexentry{"*|latex:*:*:"\\indexentry {"*) echo $1;; |
| 669 |
|
| 670 |
texinfo:*:*:"\\entry{"*) echo $1;; |
| 671 |
texinfo:*:*:"@entry{"*) echo $1;; |
| 672 |
# @entry is output from newer versions of texinfo.tex |
| 673 |
esac |
| 674 |
return 0 |
| 675 |
} |
| 676 |
|
| 677 |
########### not used currently |
| 678 |
# xref_file_p FILE - Return success if FILE is an xref file (indexes, |
| 679 |
# tables and lists). |
| 680 |
xref_file_p () |
| 681 |
{ |
| 682 |
test -f "$1" || return 1 |
| 683 |
# If the file is not suitable to be an index or xref file, don't |
| 684 |
# process it. It's suitable if the first character is a |
| 685 |
# backslash or right quote or at, as long as the first line isn't |
| 686 |
# \input texinfo. |
| 687 |
case `$SED '1q' "$1"` in |
| 688 |
"\\input texinfo"*) return 1;; |
| 689 |
[\\''@]*) return 0;; |
| 690 |
*) return 1;; |
| 691 |
esac |
| 692 |
} |
| 693 |
|
| 694 |
|
| 695 |
# Used in generated_files_get |
| 696 |
generated_files_get_from_log () |
| 697 |
{ |
| 698 |
if test -f "$1.log"; then |
| 699 |
# Usually the output is like: \openout1 = `foobar.tex'. |
| 700 |
# (including the final period) |
| 701 |
# but luatex outputs: \openout1 = foobar.tex |
| 702 |
# (no quotes, no period). |
| 703 |
# So we have to make the punctuation optional. |
| 704 |
grep '^\\openout[0-9]' "$1.log" \ |
| 705 |
| $SED -e "s/\\\\openout[^=]*= *[\`']*//" \ |
| 706 |
-e "s/'\.$//" |
| 707 |
fi |
| 708 |
} |
| 709 |
|
| 710 |
# Used in generated_files_get |
| 711 |
generated_files_get_from_fls () |
| 712 |
{ |
| 713 |
if test -f "$1.fls"; then |
| 714 |
grep '^OUTPUT ' "$1.fls" | cut -b 8- \ |
| 715 |
| grep -v '\.dvi$' | grep -v '\.log$' | grep -v '\.pdf$' || true |
| 716 |
fi |
| 717 |
} |
| 718 |
|
| 719 |
# generated_files_get - Output the list of files generated by the TeX |
| 720 |
# compilation. |
| 721 |
generated_files_get () |
| 722 |
{ |
| 723 |
$generated_files_get_method "$in_noext" |
| 724 |
if test $generated_files_get_method = generated_files_get_from_fls; then |
| 725 |
if test -r "$in_noext.fl"; then |
| 726 |
report 'WARNING!! The fl index may typeset as garbage!' # goes to stderr |
| 727 |
report 'Try upgrading your version of texinfo.tex, or else try setting' |
| 728 |
report 'the environment variable TEXI2DVI_USE_RECORDER to '\''no'\''.' |
| 729 |
report 'Once you'\''ve done that, delete the file with an '\''fl'\'' extension.' |
| 730 |
fi |
| 731 |
fi |
| 732 |
} |
| 733 |
|
| 734 |
|
| 735 |
# xref_files_save - set xref_files_orig from xref_files_new, and save xref |
| 736 |
# files in $work_bak. |
| 737 |
xref_files_save () |
| 738 |
{ |
| 739 |
# Save copies of auxiliary files for later comparison. |
| 740 |
xref_files_orig=$xref_files_new |
| 741 |
if test -n "$xref_files_orig"; then |
| 742 |
verbose "Backing up xref files: $xref_files_orig" |
| 743 |
# The following line improves `cp $xref_files_orig "$work_bak"' |
| 744 |
# by preserving the directory parts. Think of |
| 745 |
# cp chap1/main.aux chap2/main.aux $work_bak. |
| 746 |
# |
| 747 |
# Users may have, e.g., --keep-old-files. Don't let this interfere. |
| 748 |
# (Don't use unset for the sake of ancient shells.) |
| 749 |
TAR_OPTIONS=; export TAR_OPTIONS |
| 750 |
tar cf - $xref_files_orig | (cd "$rel$work_bak" && tar xf -) |
| 751 |
fi |
| 752 |
|
| 753 |
# Remove auxiliary files in same directory as main input file. Otherwise, |
| 754 |
# these will likely be read instead of those in the build dir. |
| 755 |
if $tidy ; then |
| 756 |
secondary_xref_files=`sorted_index_files` |
| 757 |
for f in $xref_files_new $secondary_xref_files ; do |
| 758 |
if test -f "$rel$in_dir/$f" ; then |
| 759 |
remove $rel$in_dir/$f |
| 760 |
fi |
| 761 |
done |
| 762 |
fi |
| 763 |
} |
| 764 |
|
| 765 |
|
| 766 |
# xref_files_changed - Return success if the xref files have changed |
| 767 |
# since the previous run. |
| 768 |
xref_files_changed () |
| 769 |
{ |
| 770 |
# LaTeX (and the package changebar) report in the LOG file if it |
| 771 |
# should be rerun. This is needed for files included from |
| 772 |
# subdirs, since texi2dvi does not try to compare xref files in |
| 773 |
# subdirs. Performing xref files test is still good since LaTeX |
| 774 |
# does not report changes in xref files. |
| 775 |
if grep "Rerun to get" "$in_noext.log" >&6 2>&1; then |
| 776 |
return 0 |
| 777 |
fi |
| 778 |
# Similarly, check for biblatex report of whether rerunning is needed. |
| 779 |
if grep "biblatex.*(re)run" "$in_noext.log" >&6 2>&1; then |
| 780 |
return 0 |
| 781 |
fi |
| 782 |
|
| 783 |
# If old and new lists don't have the same file list, |
| 784 |
# then something has definitely changed. |
| 785 |
xref_files_new=`generated_files_get` |
| 786 |
verbose "Original xref files = $xref_files_orig" |
| 787 |
verbose "New xref files = $xref_files_new" |
| 788 |
if test "x$xref_files_orig" != "x$xref_files_new"; then |
| 789 |
return 0 |
| 790 |
fi |
| 791 |
|
| 792 |
# Compare each file until we find a difference. |
| 793 |
for this_file in $xref_files_new; do |
| 794 |
verbose "Comparing xref file `echo $this_file | $SED 's|\./||g'` ..." |
| 795 |
# cmp -s returns nonzero exit status if files differ. |
| 796 |
if cmp -s "$this_file" "$rel$work_bak/$this_file"; then :; else |
| 797 |
verbose "xref file `echo $this_file | $SED 's|\./||g'` differed ..." |
| 798 |
if $debug; then |
| 799 |
diff -u "$rel$work_bak/$this_file" "$this_file" |
| 800 |
fi |
| 801 |
return 0 |
| 802 |
fi |
| 803 |
done |
| 804 |
|
| 805 |
secondary_xref_files=`sorted_index_files` |
| 806 |
verbose "Secondary xref files = $secondary_xref_files" |
| 807 |
for this_file in $secondary_xref_files; do |
| 808 |
if test -f $this_file; then :; else |
| 809 |
verbose "$this_file missing ..." |
| 810 |
return 0 |
| 811 |
fi |
| 812 |
done |
| 813 |
|
| 814 |
# No change. |
| 815 |
return 1 |
| 816 |
} |
| 817 |
|
| 818 |
# Running the TeX suite. |
| 819 |
# |
| 820 |
# Set tex_cmd variable, for running TeX. |
| 821 |
make_tex_cmd () |
| 822 |
{ |
| 823 |
case $in_lang:$latex2html:`out_lang_tex` in |
| 824 |
latex:*:dvi|latex:tex4ht:html) |
| 825 |
tex=${LATEX:-latex};; |
| 826 |
latex:*:pdf) |
| 827 |
tex=${PDFLATEX:-pdflatex};; |
| 828 |
texinfo:*:dvi) |
| 829 |
# MetaPost also uses the TEX environment variable. If the user |
| 830 |
# has set TEX=latex for that reason, don't bomb out. |
| 831 |
case $TEX in |
| 832 |
*latex) tex=tex;; # don't bother trying to find etex |
| 833 |
*) tex=$TEX |
| 834 |
esac;; |
| 835 |
texinfo:*:pdf) tex=$PDFTEX;; |
| 836 |
*) error 1 "$out_lang not supported for $in_lang";; |
| 837 |
esac |
| 838 |
|
| 839 |
# Beware of aux files in subdirectories that require the |
| 840 |
# subdirectory to exist. |
| 841 |
case $in_lang:$tidy in |
| 842 |
latex:true) |
| 843 |
$SED -n 's|^[ ]*\\include{\(.*\)/.*}.*|\1|p' "$in_input" | |
| 844 |
sort -u | |
| 845 |
while read d |
| 846 |
do |
| 847 |
ensure_dir "$work_build/$d" |
| 848 |
done |
| 849 |
;; |
| 850 |
esac |
| 851 |
|
| 852 |
# Note that this will be used via an eval: quote properly. |
| 853 |
tex_cmd="$tex" |
| 854 |
|
| 855 |
# If possible, make TeX report error locations in GNU format. |
| 856 |
if $line_error; then |
| 857 |
if test "${tex_help:+set}" != set; then |
| 858 |
# Go to a temporary directory to try --help, since old versions that |
| 859 |
# don't accept --help will generate a texput.log. |
| 860 |
tex_help_dir=$t2ddir/tex_help |
| 861 |
ensure_dir "$tex_help_dir" |
| 862 |
tex_help=`cd "$tex_help_dir" >&6 && $tex --help </dev/null 2>&1 || true` |
| 863 |
fi |
| 864 |
# The mk program and perhaps others want to parse TeX's |
| 865 |
# original error messages. |
| 866 |
case $tex_help in |
| 867 |
*file-line-error*) tex_cmd="$tex_cmd --file-line-error";; |
| 868 |
esac |
| 869 |
fi |
| 870 |
|
| 871 |
# Tell TeX about -recorder option, if specified |
| 872 |
# recorder_option_maybe is in { " -recorder", "" } |
| 873 |
tex_cmd="$tex_cmd$recorder_option_maybe" |
| 874 |
|
| 875 |
|
| 876 |
# Tell TeX about TCX file, if specified. |
| 877 |
test -n "$translate_file" \ |
| 878 |
&& tex_cmd="$tex_cmd --translate-file=$translate_file" |
| 879 |
|
| 880 |
# Tell TeX to make source specials (for backtracking from output to |
| 881 |
# source, given a sufficiently smart editor), if specified. |
| 882 |
test -n "$src_specials" && tex_cmd="$tex_cmd $src_specials" |
| 883 |
|
| 884 |
# Tell TeX to allow running external executables |
| 885 |
test -n "$shell_escape" && tex_cmd="$tex_cmd $shell_escape" |
| 886 |
|
| 887 |
# Run without interaction. |
| 888 |
# \batchmode does not show terminal output at all, so we don't |
| 889 |
# want that. And even in batch mode, TeX insists on having input |
| 890 |
# from the user. Close its stdin to make it impossible. |
| 891 |
tex_cmd="$tex_cmd </dev/null '${escape}nonstopmode'" |
| 892 |
} |
| 893 |
|
| 894 |
|
| 895 |
# run_tex - Run TeX, taking care of errors and logs. |
| 896 |
run_tex () |
| 897 |
{ |
| 898 |
# Check for any unusual characters in the filename. |
| 899 |
# However, >, \ and any whitespace characters are not supported |
| 900 |
# filenames. |
| 901 |
in_input_funnies=`echo "$in_input" \ |
| 902 |
| $SED -e 's![^}#$%&^_{~]!!g' -e 's!\(.\)!\1\'' |
| 903 |
!g' | uniq` |
| 904 |
|
| 905 |
if test -n "$in_input_funnies" ; then |
| 906 |
# Make > an end group character, as it's unlikely to appear in |
| 907 |
# a filename. |
| 908 |
tex_cmd="$tex_cmd '${escape}bgroup${escape}catcode62=2${escape}relax'" |
| 909 |
|
| 910 |
# If the filename has funny characters, change the TeX category codes of |
| 911 |
# some characters within a group, and use \expandafter to input the file |
| 912 |
# outside of the group. |
| 913 |
for w in $in_input_funnies ; do |
| 914 |
tex_cmd="$tex_cmd '${escape}catcode\`${escape}$w=12${escape}relax'" |
| 915 |
done |
| 916 |
|
| 917 |
# Set \toks0 to "\input FILENAME\relax" |
| 918 |
tex_cmd="$tex_cmd '${escape}toks0${escape}bgroup${escape}input' '$rel$in_input' '${escape}relax>" |
| 919 |
|
| 920 |
# Expand \toks0 after the end of the group |
| 921 |
tex_cmd="$tex_cmd${escape}expandafter${escape}egroup" |
| 922 |
tex_cmd="$tex_cmd${escape}the${escape}toks0${escape}relax'" |
| 923 |
else |
| 924 |
# In the case of a simple filename, just pass the filename |
| 925 |
# with no funny tricks. |
| 926 |
tex_cmd="$tex_cmd '${escape}input' '$rel$in_input'" |
| 927 |
fi |
| 928 |
|
| 929 |
verbose "$0: Running $tex_cmd ..." |
| 930 |
if (eval "$tex_cmd" >&5); then |
| 931 |
case $out_lang in |
| 932 |
dvi | pdf ) move_to_dest "$in_noext.$out_lang";; |
| 933 |
esac |
| 934 |
else |
| 935 |
tex_failed=true |
| 936 |
fi |
| 937 |
} |
| 938 |
|
| 939 |
|
| 940 |
# run_bibtex - Run bibtex (or biber) on current file |
| 941 |
# - if its input (AUX) exists, |
| 942 |
# - or if some citations are missing (LOG contains `Citation'), |
| 943 |
# - or if the LOG complains of a missing .bbl. |
| 944 |
# |
| 945 |
# Don't try to be too smart: |
| 946 |
# 1. Running bibtex only if the bbl file exists and is older than |
| 947 |
# the LaTeX file is wrong, since the document might include files |
| 948 |
# that have changed. |
| 949 |
# |
| 950 |
# 2. Because there can be several AUX (if there are \include's), |
| 951 |
# but a single LOG, looking for missing citations in LOG is |
| 952 |
# easier, though we take the risk of matching false messages. |
| 953 |
run_bibtex () |
| 954 |
{ |
| 955 |
case $in_lang in |
| 956 |
latex) bibtex=${BIBTEX:-bibtex};; |
| 957 |
texinfo) return;; |
| 958 |
esac |
| 959 |
|
| 960 |
# "Citation undefined" is for LaTeX, "Undefined citation" for btxmac.tex. |
| 961 |
# The no .aux && \bibdata test is also for btxmac, in case it was the |
| 962 |
# first run of a bibtex-using document. Otherwise, it's possible that |
| 963 |
# bibtex would never be run. |
| 964 |
if test -r "$in_noext.aux" \ |
| 965 |
&& test -r "$in_noext.log" \ |
| 966 |
&& ( (grep 'Warning:.*Citation.*undefined' "$in_noext.log" \ |
| 967 |
|| grep '.*Undefined citation' "$in_noext.log" \ |
| 968 |
|| grep 'No file .*\.bbl\.' "$in_noext.log") \ |
| 969 |
|| (grep 'No \.aux file' "$in_noext.log" \ |
| 970 |
&& grep '^\\bibdata' "$in_noext.aux") ) \ |
| 971 |
>&6 2>&1; \ |
| 972 |
then |
| 973 |
bibtex_aux=`filter_files bibaux_file_p` |
| 974 |
for f in $bibtex_aux; do |
| 975 |
run $bibtex "$f" |
| 976 |
done |
| 977 |
fi |
| 978 |
|
| 979 |
# biber(+biblatex) check. |
| 980 |
if test -r "$in_noext.bcf" \ |
| 981 |
&& grep '</bcf:controlfile>' "$in_noext.bcf" >/dev/null; then |
| 982 |
run ${BIBER:-biber} "$in_noext" |
| 983 |
fi |
| 984 |
} |
| 985 |
|
| 986 |
|
| 987 |
# filter_file PREDICATE - Go through the list of files in xref_files_new |
| 988 |
# and use PREDICATE on each one to optionally print it or print other files |
| 989 |
# based on the filename. |
| 990 |
filter_files () |
| 991 |
{ |
| 992 |
test -n "$xref_files_new" || return 0 |
| 993 |
echo "$xref_files_new" | |
| 994 |
# Filter existing files matching the criterion. |
| 995 |
# |
| 996 |
while read file; do |
| 997 |
$1 "$file" |
| 998 |
done | |
| 999 |
sort | |
| 1000 |
# Some files are opened several times, e.g., listings.sty's *.vrb. |
| 1001 |
uniq |
| 1002 |
} |
| 1003 |
|
| 1004 |
# run_index - Run texindex (or makeindex or texindy) on current index |
| 1005 |
# files. If they already exist, and after running TeX a first time the |
| 1006 |
# index files don't change, then there's no reason to run TeX again. |
| 1007 |
# But we won't know that if the index files are out of date or nonexistent. |
| 1008 |
run_index () |
| 1009 |
{ |
| 1010 |
index_files=`filter_files index_file_p` |
| 1011 |
test -n "$index_files" \ |
| 1012 |
|| return 0 |
| 1013 |
|
| 1014 |
: ${MAKEINDEX:=makeindex} |
| 1015 |
: ${TEXINDEX:=texindex} |
| 1016 |
: ${TEXINDY:=texindy} |
| 1017 |
|
| 1018 |
case $in_lang:$latex2html:`out_lang_tex` in |
| 1019 |
latex:tex4ht:html) |
| 1020 |
for index_file in $index_files |
| 1021 |
do |
| 1022 |
index_noext=`noext "$index_file"` |
| 1023 |
run tex \ |
| 1024 |
'\def\filename{{'"$index_noext"'}{idx}{4dx}{ind}} |
| 1025 |
\input idxmake.4ht' |
| 1026 |
run $MAKEINDEX -o $index_noext.ind $index_noext.4dx |
| 1027 |
done |
| 1028 |
;; |
| 1029 |
|
| 1030 |
latex:*) |
| 1031 |
if $TEXINDY --version >&6 2>&1; then |
| 1032 |
run $TEXINDY $index_files |
| 1033 |
else |
| 1034 |
run $MAKEINDEX $index_files |
| 1035 |
fi |
| 1036 |
;; |
| 1037 |
|
| 1038 |
texinfo:*) |
| 1039 |
run $TEXINDEX $index_files |
| 1040 |
;; |
| 1041 |
esac |
| 1042 |
} |
| 1043 |
|
| 1044 |
|
| 1045 |
# run_tex4ht - Run the last two phases of TeX4HT: tex4ht extracts the |
| 1046 |
# HTML from the instrumented DVI file, and t4ht converts the figures and |
| 1047 |
# installs the files when given -d. |
| 1048 |
# |
| 1049 |
# Because knowing exactly which files are created is complex (in |
| 1050 |
# addition the names are not simple to compute), which makes it |
| 1051 |
# difficult to install the output files in a second step, we |
| 1052 |
# tell t4ht to install the output files. |
| 1053 |
run_tex4ht () |
| 1054 |
{ |
| 1055 |
case $in_lang:$latex2html:`out_lang_tex` in |
| 1056 |
latex:tex4ht:html) |
| 1057 |
: ${TEX4HT:=tex4ht} ${T4HT:=t4ht} |
| 1058 |
run "$TEX4HT" "-f/$in_noext" |
| 1059 |
# Do not remove the / after the destdir. |
| 1060 |
run "$T4HT" "-d`destdir`/" "-f/$in_noext" |
| 1061 |
;; |
| 1062 |
esac |
| 1063 |
} |
| 1064 |
|
| 1065 |
|
| 1066 |
# run_thumbpdf - Run thumbpdf. |
| 1067 |
run_thumbpdf () |
| 1068 |
{ |
| 1069 |
if test `out_lang_tex` = pdf \ |
| 1070 |
&& test -r "$in_noext.log" \ |
| 1071 |
&& grep 'thumbpdf\.sty' "$in_noext.log" >&6 2>&1; \ |
| 1072 |
then |
| 1073 |
thumbpdf=${THUMBPDF_CMD:-thumbpdf} |
| 1074 |
thumbcmd="$thumbpdf $in_dir/$in_noext" |
| 1075 |
verbose "Running $thumbcmd ..." |
| 1076 |
if $thumbcmd >&5; then |
| 1077 |
run_tex |
| 1078 |
else |
| 1079 |
report "$thumbpdf exited with bad status." \ |
| 1080 |
"Ignoring its output." |
| 1081 |
fi |
| 1082 |
fi |
| 1083 |
} |
| 1084 |
|
| 1085 |
|
| 1086 |
# run_dvipdf FILE.dvi - Convert FILE.dvi to FILE.pdf. |
| 1087 |
run_dvipdf () |
| 1088 |
{ |
| 1089 |
# Find which dvi->pdf program is available. |
| 1090 |
if test -n "$DVIPDF"; then |
| 1091 |
dvipdf=$DVIPDF # user envvar, use it without checking |
| 1092 |
|
| 1093 |
elif test -z "$dvipdf"; then |
| 1094 |
for i in dvipdfmx dvipdfm dvipdf dvi2pdf dvitopdf; do |
| 1095 |
if findprog $i; then |
| 1096 |
dvipdf=$i |
| 1097 |
fi |
| 1098 |
done |
| 1099 |
fi |
| 1100 |
# These tools have varying interfaces, some 'input output', others |
| 1101 |
# 'input -o output'. They all seem to accept 'input' only, |
| 1102 |
# outputting using the expected file name. |
| 1103 |
run $dvipdf "$1" |
| 1104 |
if test ! -f `echo "$1" | $SED -e 's/\.dvi$/.pdf/'`; then |
| 1105 |
error 1 "cannot find output file" |
| 1106 |
fi |
| 1107 |
} |
| 1108 |
|
| 1109 |
# run_tex_suite - Run the TeX tools until a stable point is reached. |
| 1110 |
run_tex_suite () |
| 1111 |
{ |
| 1112 |
make_tex_cmd |
| 1113 |
|
| 1114 |
# Move to the working directory. |
| 1115 |
if $tidy; then |
| 1116 |
verbose "cd $work_build" |
| 1117 |
cd_dir "$work_build" || exit 1 |
| 1118 |
fi |
| 1119 |
|
| 1120 |
# Count the number of cycles. |
| 1121 |
suite_cycle=0 |
| 1122 |
|
| 1123 |
# Start by checking the log files for what files were created last |
| 1124 |
# time. This will mean that if they don't change, we finish in 1 cycle. |
| 1125 |
xref_files_new=`generated_files_get` |
| 1126 |
xref_files_save |
| 1127 |
|
| 1128 |
while :; do |
| 1129 |
# check for (probably) LaTeX loop (e.g. varioref) |
| 1130 |
if test $suite_cycle -eq "$max_iters"; then |
| 1131 |
error 0 "Maximum of $max_iters cycles exceeded" |
| 1132 |
break |
| 1133 |
fi |
| 1134 |
|
| 1135 |
# report progress |
| 1136 |
suite_cycle=`expr $suite_cycle + 1` |
| 1137 |
verbose "Cycle $suite_cycle for $command_line_filename" |
| 1138 |
|
| 1139 |
tex_failed=false |
| 1140 |
run_core_conversion |
| 1141 |
xref_files_changed || break |
| 1142 |
xref_files_save |
| 1143 |
|
| 1144 |
# We run bibtex first, because it's more likely for the indexes |
| 1145 |
# to change after bibtex is run than the reverse, though either |
| 1146 |
# would be rare. |
| 1147 |
run_bibtex |
| 1148 |
run_index |
| 1149 |
done |
| 1150 |
|
| 1151 |
if $tex_failed ; then |
| 1152 |
# TeX failed, and the xref files did not change. |
| 1153 |
error 1 "$tex exited with bad status, quitting." |
| 1154 |
fi |
| 1155 |
|
| 1156 |
# If we were using thumbpdf and producing PDF, then run thumbpdf |
| 1157 |
# and TeX one last time. |
| 1158 |
run_thumbpdf |
| 1159 |
|
| 1160 |
# If we are using tex4ht, call it. |
| 1161 |
run_tex4ht |
| 1162 |
|
| 1163 |
# Install the result if we didn't already (i.e., if the output is |
| 1164 |
# dvipdf or ps). |
| 1165 |
case $latex2html:$out_lang in |
| 1166 |
*:dvipdf) |
| 1167 |
run_dvipdf "$in_noext.`out_lang_tex`" |
| 1168 |
move_to_dest "$in_noext.`out_lang_ext`" |
| 1169 |
;; |
| 1170 |
*:ps) |
| 1171 |
: ${DVIPS:=dvips} |
| 1172 |
run $DVIPS -o "$in_noext.`out_lang_ext`" "$in_noext.`out_lang_tex`" |
| 1173 |
move_to_dest "$in_noext.`out_lang_ext`" |
| 1174 |
;; |
| 1175 |
esac |
| 1176 |
|
| 1177 |
cd_orig |
| 1178 |
} |
| 1179 |
|
| 1180 |
|
| 1181 |
# TeX processing auxiliary tools. |
| 1182 |
# |
| 1183 |
# run_makeinfo - Expand macro commands in the original source file using |
| 1184 |
# Makeinfo. Always use `end' footnote style, since the `separate' style |
| 1185 |
# generates different output (arguably this is a bug in -E). Discard |
| 1186 |
# main info output, the user asked to run TeX, not makeinfo. |
| 1187 |
run_makeinfo () |
| 1188 |
{ |
| 1189 |
test $in_lang = texinfo \ |
| 1190 |
|| return 0 |
| 1191 |
|
| 1192 |
# Unless required by the user, makeinfo expansion is wanted only |
| 1193 |
# if texinfo.tex is too old. |
| 1194 |
if $expand; then |
| 1195 |
makeinfo=${MAKEINFO:-makeinfo} |
| 1196 |
else |
| 1197 |
# Check if texinfo.tex performs macro expansion by looking for |
| 1198 |
# its version. The version is a date of the form YEAR-MO-DA. |
| 1199 |
# We don't need to use [0-9] to match the digits since anyway |
| 1200 |
# the comparison with $txiprereq, a number, will fail with non-digits. |
| 1201 |
# Run in a temporary directory to avoid leaving files. |
| 1202 |
version_test_dir=$t2ddir/version_test |
| 1203 |
ensure_dir "$version_test_dir" |
| 1204 |
if ( |
| 1205 |
cd "$version_test_dir" |
| 1206 |
echo '\input texinfo.tex @bye' >txiversion.tex |
| 1207 |
# Be sure that if tex wants to fail, it is not interactive: |
| 1208 |
# close stdin. |
| 1209 |
$TEX txiversion.tex </dev/null >txiversion.out 2>txiversion.err |
| 1210 |
); then :; else |
| 1211 |
report "texinfo.tex appears to be broken. |
| 1212 |
This may be due to the environment variable TEX set to something |
| 1213 |
other than (plain) tex, a corrupt texinfo.tex file, or |
| 1214 |
to tex itself simply not working." |
| 1215 |
cat "$version_test_dir/txiversion.out" |
| 1216 |
cat "$version_test_dir/txiversion.err" >&2 |
| 1217 |
error 1 "quitting." |
| 1218 |
fi |
| 1219 |
eval `$SED -n 's/^.*\[\(.*\)version \(....\)-\(..\)-\(..\).*$/txiformat=\1 txiversion="\2\3\4"/p' "$version_test_dir/txiversion.out"` |
| 1220 |
verbose "texinfo.tex preloaded as \`$txiformat', version is \`$txiversion' ..." |
| 1221 |
if test "$txiprereq" -le "$txiversion" >&6 2>&1; then |
| 1222 |
makeinfo= |
| 1223 |
else |
| 1224 |
makeinfo=${MAKEINFO:-makeinfo} |
| 1225 |
fi |
| 1226 |
# If TeX is preloaded, offer the user this convenience: |
| 1227 |
if test "$txiformat" = Texinfo; then |
| 1228 |
escape=@ |
| 1229 |
fi |
| 1230 |
fi |
| 1231 |
|
| 1232 |
if test -n "$makeinfo"; then |
| 1233 |
# in_src: the file with macros expanded. |
| 1234 |
# Use the same basename to generate the same aux file names. |
| 1235 |
work_src=$workdir/src |
| 1236 |
ensure_dir "$work_src" |
| 1237 |
in_src=$work_src/$in_base |
| 1238 |
run_mi_includes=`list_prefix includes -I` |
| 1239 |
verbose "Macro-expanding $command_line_filename to $in_src ..." |
| 1240 |
# eval $makeinfo because it might be defined as something complex |
| 1241 |
# (running missing) and then we end up with things like '"-I"', |
| 1242 |
# and "-I" (including the quotes) is not an option name. This |
| 1243 |
# happens with gettext 0.14.5, at least. |
| 1244 |
$SED "$comment_iftex" "$command_line_filename" \ |
| 1245 |
| eval $makeinfo --footnote-style=end -I "$in_dir" $run_mi_includes \ |
| 1246 |
-o /dev/null --macro-expand=- \ |
| 1247 |
| $SED "$uncomment_iftex" >"$in_src" |
| 1248 |
# Continue only if everything succeeded. |
| 1249 |
if test $? -ne 0 \ |
| 1250 |
|| test ! -r "$in_src"; then |
| 1251 |
verbose "Expansion failed, ignored..."; |
| 1252 |
else |
| 1253 |
in_input=$in_src |
| 1254 |
fi |
| 1255 |
fi |
| 1256 |
} |
| 1257 |
|
| 1258 |
# Unfortunately, makeinfo --iftex --no-ifinfo doesn't work well enough |
| 1259 |
# in versions before 5.0, as makeinfo can't parse the TeX commands |
| 1260 |
# inside @tex blocks, so work around with sed. |
| 1261 |
# |
| 1262 |
# This sed script preprocesses Texinfo sources in order to keep the |
| 1263 |
# iftex sections only. We want to remove non-TeX sections, and comment |
| 1264 |
# (with `@c _texi2dvi') TeX sections so that makeinfo does not try to |
| 1265 |
# parse them. Nevertheless, while commenting TeX sections, don't |
| 1266 |
# comment @macro/@end macro so that makeinfo does propagate them. |
| 1267 |
# Similarly, preserve the @top node to avoid makeinfo complaining about |
| 1268 |
# it being missed. Comment it out after preprocessing, so that it does |
| 1269 |
# not appear in the generated document. |
| 1270 |
# |
| 1271 |
# We assume that `@c _texi2dvi' or `@c (_texi2dvi)' starting a line is |
| 1272 |
# not present in the document. Additionally, conditionally defined |
| 1273 |
# macros inside the @top node may end up with the wrong value, although |
| 1274 |
# this is unlikely in practice. |
| 1275 |
# |
| 1276 |
comment_iftex=\ |
| 1277 |
'/^@tex/,/^@end tex/{ |
| 1278 |
s/^/@c _texi2dvi/ |
| 1279 |
} |
| 1280 |
/^@iftex/,/^@end iftex/{ |
| 1281 |
s/^/@c _texi2dvi/ |
| 1282 |
/^@c _texi2dvi@macro/,/^@c _texi2dvi@end macro/{ |
| 1283 |
s/^@c _texi2dvi// |
| 1284 |
} |
| 1285 |
} |
| 1286 |
/^@ifnottex/,/^@end ifnottex/{ |
| 1287 |
s/^/@c (_texi2dvi)/ |
| 1288 |
/^@c (_texi2dvi)@node Top/,/^@c (_texi2dvi)@end ifnottex/ { |
| 1289 |
/^@c (_texi2dvi)@end ifnottex/b |
| 1290 |
s/^@c (_texi2dvi)// |
| 1291 |
} |
| 1292 |
} |
| 1293 |
/^@ifinfo/,/^@end ifinfo/{ |
| 1294 |
/^@node/p |
| 1295 |
/^@menu/,/^@end menu/p |
| 1296 |
t |
| 1297 |
s/^/@c (_texi2dvi)/ |
| 1298 |
} |
| 1299 |
s/^@ifnotinfo/@c _texi2dvi@ifnotinfo/ |
| 1300 |
s/^@end ifnotinfo/@c _texi2dvi@end ifnotinfo/' |
| 1301 |
|
| 1302 |
# Uncomment @iftex blocks by removing any leading `@c texi2dvi' (repeated |
| 1303 |
# copies can sneak in via macro invocations). Likewise, comment out |
| 1304 |
# the @top node inside a @ifnottex block. |
| 1305 |
uncomment_iftex=\ |
| 1306 |
's/^@c _texi2dvi\(@c _texi2dvi\)*// |
| 1307 |
/^@c (_texi2dvi)@ifnottex/,/^@c (_texi2dvi)@end ifnottex/{ |
| 1308 |
s/^/@c (_texi2dvi)/ |
| 1309 |
}' |
| 1310 |
|
| 1311 |
|
| 1312 |
# insert_commands - Insert $textra commands at the beginning of the file. |
| 1313 |
# Recommended to be used for @finalout, @smallbook, etc. |
| 1314 |
insert_commands () |
| 1315 |
{ |
| 1316 |
if test -n "$textra"; then |
| 1317 |
# _xtr. The file with the user's extra commands. |
| 1318 |
work_xtr=$workdir/xtr |
| 1319 |
in_xtr=$work_xtr/$in_base |
| 1320 |
ensure_dir "$work_xtr" |
| 1321 |
verbose "Inserting extra commands: $textra" |
| 1322 |
case $in_lang in |
| 1323 |
latex) textra_cmd=1i;; |
| 1324 |
texinfo) |
| 1325 |
textra_cmd='/^\\input texinfo/a' |
| 1326 |
# insert after @setfilename line if present |
| 1327 |
if head -n 10 $in_input | grep '^@setfilename' ; then |
| 1328 |
textra_cmd='/^@setfilename/a' |
| 1329 |
fi |
| 1330 |
;; |
| 1331 |
*) error 1 "internal error, unknown language: $in_lang";; |
| 1332 |
esac |
| 1333 |
$SED "$textra_cmd\\ |
| 1334 |
$textra" "$in_input" >"$in_xtr" |
| 1335 |
in_input=$in_xtr |
| 1336 |
fi |
| 1337 |
|
| 1338 |
case $in_lang:$latex2html:`out_lang_tex` in |
| 1339 |
latex:tex4ht:html) |
| 1340 |
# _tex4ht. The file with the added \usepackage{tex4ht}. |
| 1341 |
work_tex4ht=$workdir/tex4ht |
| 1342 |
in_tex4ht=$work_tex4ht/$in_base |
| 1343 |
ensure_dir "$work_tex4ht" |
| 1344 |
verbose "Inserting \\usepackage{tex4ht}" |
| 1345 |
perl -pe 's<\\documentclass(?:\[.*\])?{.*}> |
| 1346 |
<$&\\usepackage[xhtml]{tex4ht}>' \ |
| 1347 |
"$in_input" >"$in_tex4ht" |
| 1348 |
in_input=$in_tex4ht |
| 1349 |
;; |
| 1350 |
esac |
| 1351 |
} |
| 1352 |
|
| 1353 |
|
| 1354 |
# compute_language FILENAME - Return the short string for the language |
| 1355 |
# in which FILENAME is written: `texinfo' or `latex'. |
| 1356 |
compute_language () |
| 1357 |
{ |
| 1358 |
# If the user explicitly specified the language, use that. |
| 1359 |
# Otherwise, if the first line is \input texinfo, assume it's texinfo. |
| 1360 |
# Otherwise, guess from the file extension. |
| 1361 |
if test -n "$set_language"; then |
| 1362 |
echo $set_language |
| 1363 |
elif $SED 1q "$1" | grep 'input texinfo' >&6; then |
| 1364 |
echo texinfo |
| 1365 |
else |
| 1366 |
# Get the type of the file (latex or texinfo) from the given language |
| 1367 |
# we just guessed, or from the file extension if not set yet. |
| 1368 |
case $1 in |
| 1369 |
*.ltx | *.tex | *.drv | *.dtx) echo latex;; |
| 1370 |
*) echo texinfo;; |
| 1371 |
esac |
| 1372 |
fi |
| 1373 |
} |
| 1374 |
|
| 1375 |
|
| 1376 |
# run_hevea (MODE) - Convert to HTML/INFO/TEXT. |
| 1377 |
# |
| 1378 |
# Don't pass `-noiso' to hevea: it's useless in HTML since anyway the |
| 1379 |
# charset is set to latin1, and troublesome in other modes since |
| 1380 |
# accented characters loose their accents. |
| 1381 |
# |
| 1382 |
# Don't pass `-o DEST' to hevea because in that case it leaves all its |
| 1383 |
# auxiliary files there too... Too bad, because it means we will need |
| 1384 |
# to handle images some day. |
| 1385 |
run_hevea () |
| 1386 |
{ |
| 1387 |
run_hevea_name="${HEVEA:-hevea}" |
| 1388 |
run_hevea_cmd="$run_hevea_name" |
| 1389 |
|
| 1390 |
case $1 in |
| 1391 |
html) ;; |
| 1392 |
text|info) run_hevea_cmd="$run_hevea_cmd -$1";; |
| 1393 |
*) error 1 "run_hevea_cmd: invalid argument: $1";; |
| 1394 |
esac |
| 1395 |
|
| 1396 |
# Compiling to the tmp directory enables to preserve a previous |
| 1397 |
# successful compilation. |
| 1398 |
run_hevea_cmd="$run_hevea_cmd -fix -O -o '$out_base'" |
| 1399 |
run_hevea_cmd="$run_hevea_cmd `list_prefix includes -I` -I '$orig_pwd' " |
| 1400 |
run_hevea_cmd="$run_hevea_cmd '$rel$in_input'" |
| 1401 |
|
| 1402 |
if $debug; then |
| 1403 |
run_hevea_cmd="$run_hevea_cmd -v -v" |
| 1404 |
fi |
| 1405 |
|
| 1406 |
verbose "running $run_hevea_cmd" |
| 1407 |
if eval "$run_hevea_cmd" >&5; then |
| 1408 |
# hevea leaves trailing white spaces, this is annoying. |
| 1409 |
case $1 in text|info) |
| 1410 |
perl -pi -e 's/[ \t]+$//g' "$out_base"*;; |
| 1411 |
esac |
| 1412 |
case $1 in |
| 1413 |
html|text) move_to_dest "$out_base";; |
| 1414 |
info) # There can be foo.info-1, foo.info-2 etc. |
| 1415 |
move_to_dest "$out_base"*;; |
| 1416 |
esac |
| 1417 |
else |
| 1418 |
error 1 "$run_hevea_name exited with bad status, quitting." |
| 1419 |
fi |
| 1420 |
} |
| 1421 |
|
| 1422 |
|
| 1423 |
# run_core_conversion - Run TeX (or HeVeA). |
| 1424 |
run_core_conversion () |
| 1425 |
{ |
| 1426 |
case $in_lang:$latex2html:`out_lang_tex` in |
| 1427 |
*:dvi|*:pdf|latex:tex4ht:html) |
| 1428 |
run_tex;; |
| 1429 |
latex:*:html|latex:*:text|latex:*:info) |
| 1430 |
run_hevea $out_lang;; |
| 1431 |
*) |
| 1432 |
error 1 "invalid input/output combination: $in_lang/$out_lang";; |
| 1433 |
esac |
| 1434 |
} |
| 1435 |
|
| 1436 |
|
| 1437 |
# compile - Run the full compilation chain, from pre-processing to |
| 1438 |
# installation of the output at its expected location. |
| 1439 |
compile () |
| 1440 |
{ |
| 1441 |
# Set include path for tools: |
| 1442 |
# . Include current directory in case there are files there already, so |
| 1443 |
# we don't have more TeX runs than necessary. orig_pwd is used in case |
| 1444 |
# we are in clean build mode, where we have cd'd to a temp directory. |
| 1445 |
# . Include directory containing file, in case there are other |
| 1446 |
# files @include'd. |
| 1447 |
# . Keep a final path_sep to get the default (system) TeX |
| 1448 |
# directories included. |
| 1449 |
# . If we have any includes, put those at the end. |
| 1450 |
|
| 1451 |
common="$orig_pwd$path_sep$in_dir$path_sep" |
| 1452 |
# |
| 1453 |
txincludes=`list_infix includes $path_sep` |
| 1454 |
test -n "$txincludes" && common="$common$txincludes$path_sep" |
| 1455 |
# |
| 1456 |
for var in $tex_envvars; do |
| 1457 |
eval val="\$common\$${var}_orig" |
| 1458 |
# Convert relative paths to absolute paths, so we can run in another |
| 1459 |
# directory (e.g., in clean build mode, or during the macro-support |
| 1460 |
# detection). |
| 1461 |
val=`absolute_filenames "$val"` |
| 1462 |
eval $var="\"$val\"" |
| 1463 |
export $var |
| 1464 |
eval verbose \"$var=\'\$${var}\'\" |
| 1465 |
done |
| 1466 |
|
| 1467 |
# --expand |
| 1468 |
run_makeinfo |
| 1469 |
|
| 1470 |
# --command, --texinfo |
| 1471 |
insert_commands |
| 1472 |
|
| 1473 |
# Run until a fixed point is reached. |
| 1474 |
run_tex_suite |
| 1475 |
} |
| 1476 |
|
| 1477 |
# make_openout_test FLAGS EXTENSION |
| 1478 |
# - Run TeX with an input file that performs an \openout. Pass FLAGS to TeX. |
| 1479 |
# |
| 1480 |
make_openout_test () |
| 1481 |
{ |
| 1482 |
recorder_option_maybe="$1" |
| 1483 |
make_tex_cmd |
| 1484 |
|
| 1485 |
ensure_dir "$workdir"/check_recorder |
| 1486 |
cd_dir "$workdir"/check_recorder |
| 1487 |
|
| 1488 |
cat > openout.tex <<EOF |
| 1489 |
\newwrite\ourwrite |
| 1490 |
\immediate\openout\ourwrite dum.dum |
| 1491 |
\bye |
| 1492 |
EOF |
| 1493 |
# \bye doesn't work for LaTeX, but it will cause latex |
| 1494 |
# to exit with an input error. |
| 1495 |
tex_cmd="$tex_cmd '${escape}input' ./openout.tex" |
| 1496 |
# ./ in case . isn't in path |
| 1497 |
verbose "$0: running $tex_cmd ..." |
| 1498 |
rm -fr "openout.$2" |
| 1499 |
(eval "$tex_cmd" >/dev/null 2>&1) |
| 1500 |
} |
| 1501 |
|
| 1502 |
# Check tex supports -recorder option |
| 1503 |
check_recorder_support () |
| 1504 |
{ |
| 1505 |
verbose "Checking TeX recorder support..." |
| 1506 |
make_openout_test " -recorder" fls |
| 1507 |
if test -f openout.fls && grep '^OUTPUT dum.dum$' openout.fls > /dev/null |
| 1508 |
then |
| 1509 |
cd_orig |
| 1510 |
verbose "Checking TeX recorder support... yes" |
| 1511 |
return 0 |
| 1512 |
else |
| 1513 |
cd_orig |
| 1514 |
verbose "Checking TeX recorder support... no" |
| 1515 |
return 1 |
| 1516 |
fi |
| 1517 |
} |
| 1518 |
|
| 1519 |
# Check tex supports \openout traces in log |
| 1520 |
check_openout_in_log_support () |
| 1521 |
{ |
| 1522 |
verbose "Checking TeX \openout in log support..." |
| 1523 |
make_openout_test "" log |
| 1524 |
if test -f openout.log \ |
| 1525 |
&& grep '^\\openout..\? *= *`\?dum\.dum'\''\?' openout.log >/dev/null |
| 1526 |
then |
| 1527 |
cd_orig |
| 1528 |
verbose "Checking TeX \openout in log support... yes" |
| 1529 |
return 0 |
| 1530 |
else |
| 1531 |
cd_orig |
| 1532 |
verbose "Checking TeX \openout in log support... no" |
| 1533 |
return 1 |
| 1534 |
fi |
| 1535 |
} |
| 1536 |
|
| 1537 |
# Set that output auxiliary files are detected with the -recorder option, |
| 1538 |
# which creates a file JOBNAME.fls which is a machine-readable listing of |
| 1539 |
# files read and written during the job. |
| 1540 |
set_aux_files_from_fls () |
| 1541 |
{ |
| 1542 |
recorder_option_maybe=" -recorder" |
| 1543 |
generated_files_get_method=generated_files_get_from_fls |
| 1544 |
} |
| 1545 |
|
| 1546 |
# Set that output auxiliary files are detected with searching for \openout |
| 1547 |
# in the log file. |
| 1548 |
set_aux_files_from_log () |
| 1549 |
{ |
| 1550 |
recorder_option_maybe='' |
| 1551 |
generated_files_get_method=generated_files_get_from_log |
| 1552 |
} |
| 1553 |
|
| 1554 |
# Decide whether output auxiliary files are detected with the -recorder |
| 1555 |
# option, or by searching for \openout in the log file. |
| 1556 |
decide_aux_files_method () |
| 1557 |
{ |
| 1558 |
# Select output file detection method |
| 1559 |
# Valid values of TEXI2DVI_USE_RECORDER are: |
| 1560 |
# yes use the -recorder option, no checks. |
| 1561 |
# no scan for \openout in the log file, no checks. |
| 1562 |
# yesmaybe check whether -recorder option is supported, and if yes |
| 1563 |
# use it, otherwise check for tracing \openout in the |
| 1564 |
# log file is supported, and if yes use it, else it is an |
| 1565 |
# error. |
| 1566 |
# nomaybe same as `yesmaybe', except that the \openout trace in |
| 1567 |
# log file is checked first. |
| 1568 |
# |
| 1569 |
# The default behaviour is `nomaybe'. |
| 1570 |
|
| 1571 |
test -n "$TEXI2DVI_USE_RECORDER" || TEXI2DVI_USE_RECORDER=nomaybe |
| 1572 |
|
| 1573 |
case $TEXI2DVI_USE_RECORDER in |
| 1574 |
yes) set_aux_files_from_fls;; |
| 1575 |
|
| 1576 |
no) set_aux_files_from_log;; |
| 1577 |
|
| 1578 |
yesmaybe) |
| 1579 |
if check_recorder_support; then |
| 1580 |
set_aux_files_from_fls |
| 1581 |
elif check_openout_in_log_support; then |
| 1582 |
set_aux_files_from_log |
| 1583 |
else |
| 1584 |
error 1 "TeX neither supports -recorder nor outputs \\openout lines in its log file" |
| 1585 |
fi |
| 1586 |
;; |
| 1587 |
|
| 1588 |
nomaybe) |
| 1589 |
if check_openout_in_log_support; then |
| 1590 |
set_aux_files_from_log |
| 1591 |
elif check_recorder_support; then |
| 1592 |
set_aux_files_from_fls |
| 1593 |
else |
| 1594 |
error 1 "TeX neither supports -recorder nor outputs \\openout lines in its log file" |
| 1595 |
fi |
| 1596 |
;; |
| 1597 |
|
| 1598 |
*) error 1 "Invalid value of TEXI2DVI_USE_RECORDER environment variable : $TEXI2DVI_USE_RECORDER.";; |
| 1599 |
|
| 1600 |
esac |
| 1601 |
} |
| 1602 |
|
| 1603 |
# remove FILE... |
| 1604 |
remove () |
| 1605 |
{ |
| 1606 |
verbose "Removing" "$@" |
| 1607 |
rm -rf "$@" |
| 1608 |
} |
| 1609 |
|
| 1610 |
|
| 1611 |
# all_files - Echo the names of all files generated, including those by |
| 1612 |
# auxiliary tools like texindex. |
| 1613 |
all_files () |
| 1614 |
{ |
| 1615 |
echo $in_noext.log |
| 1616 |
echo $in_noext.fls |
| 1617 |
echo $xref_files_new |
| 1618 |
echo `sorted_index_files` |
| 1619 |
} |
| 1620 |
|
| 1621 |
sorted_index_files () |
| 1622 |
{ |
| 1623 |
filter_files sorted_index_filter |
| 1624 |
} |
| 1625 |
|
| 1626 |
# Print the name of a generated file based on FILE if there is one. |
| 1627 |
sorted_index_filter () |
| 1628 |
{ |
| 1629 |
case $in_lang in |
| 1630 |
texinfo) |
| 1631 |
# texindex: texinfo.cp -> texinfo.cps |
| 1632 |
if test -n "`index_file_p $1`" ; then |
| 1633 |
echo $1s |
| 1634 |
fi |
| 1635 |
;; |
| 1636 |
esac |
| 1637 |
} |
| 1638 |
|
| 1639 |
|
| 1640 |
# Not currently used - use with filter_files to add secondary files created by |
| 1641 |
# bibtex |
| 1642 |
bibtex_secondary_files () |
| 1643 |
{ |
| 1644 |
case $in_lang in |
| 1645 |
latex) |
| 1646 |
if test -n "`aux_file_p $1`"; then |
| 1647 |
# bibtex: *.aux -> *.bbl and *.blg. |
| 1648 |
echo $1 | $SED 's/^\(.*\)\.aux$/\1.bbl/' |
| 1649 |
echo $1 | $SED 's/^\(.*\)\.aux$/\1.blg/' |
| 1650 |
fi |
| 1651 |
;; |
| 1652 |
esac |
| 1653 |
} |
| 1654 |
|
| 1655 |
# mostly_clean - Remove auxiliary files and directories. Changes back to |
| 1656 |
# the original directory. |
| 1657 |
mostly_clean () |
| 1658 |
{ |
| 1659 |
cd_orig |
| 1660 |
set X "$t2ddir" |
| 1661 |
shift |
| 1662 |
$tidy || { |
| 1663 |
set X ${1+"$@"} `all_files` |
| 1664 |
shift |
| 1665 |
} |
| 1666 |
remove ${1+"$@"} |
| 1667 |
} |
| 1668 |
|
| 1669 |
|
| 1670 |
# cleanup - Remove what should be removed according to options. |
| 1671 |
# Called at the end of each compilation cycle, and at the end of |
| 1672 |
# the script. Changes the current directory. |
| 1673 |
cleanup () |
| 1674 |
{ |
| 1675 |
case $clean:$tidy in |
| 1676 |
true:true) mostly_clean ;; # build mode is "clean" |
| 1677 |
false:false) cd_orig; remove "$t2ddir";; # build mode is "local" |
| 1678 |
esac |
| 1679 |
} |
| 1680 |
|
| 1681 |
|
| 1682 |
# input_file_name_decode - Decode COMMAND_LINE_FILENAME, and set the |
| 1683 |
# following shell variables: |
| 1684 |
# |
| 1685 |
# - COMMAND_LINE_FILENAME |
| 1686 |
# The filename given on the commmand line, but cleaned of TeX commands. |
| 1687 |
# - IN_DIR |
| 1688 |
# The directory containing the input file. |
| 1689 |
# - IN_BASE |
| 1690 |
# The input file base name (no directory part). |
| 1691 |
# - IN_NOEXT |
| 1692 |
# The input file name with neither file extensions nor directory part. |
| 1693 |
# - IN_INPUT |
| 1694 |
# The path to the input file for passing as a command-line argument |
| 1695 |
# to TeX. Defaults to COMMAND_LINE_FILENAME, but might change if the |
| 1696 |
# input is preprocessed. |
| 1697 |
input_file_name_decode () |
| 1698 |
{ |
| 1699 |
case $command_line_filename in |
| 1700 |
*\\input{*}*) |
| 1701 |
# Let AUC-TeX error parser deal with line numbers. |
| 1702 |
line_error=false |
| 1703 |
command_line_filename=`\ |
| 1704 |
expr X"$command_line_filename" : X'.*input{\([^}]*\)}'` |
| 1705 |
;; |
| 1706 |
esac |
| 1707 |
|
| 1708 |
# If the COMMAND_LINE_FILENAME is not absolute (e.g., --debug.tex), |
| 1709 |
# prepend `./' in order to avoid that the tools take it as an option. |
| 1710 |
echo "$command_line_filename" | LC_ALL=C $EGREP '^(/|[A-Za-z]:/)' >&6 \ |
| 1711 |
|| command_line_filename="./$command_line_filename" |
| 1712 |
|
| 1713 |
# See if the file exists. If it doesn't we're in trouble since, even |
| 1714 |
# though the user may be able to reenter a valid filename at the tex |
| 1715 |
# prompt (assuming they're attending the terminal), this script won't |
| 1716 |
# be able to find the right xref files and so forth. |
| 1717 |
test -r "$command_line_filename" \ |
| 1718 |
|| error 1 "cannot read $command_line_filename, skipping." |
| 1719 |
|
| 1720 |
# Get the name of the current directory. |
| 1721 |
in_dir=`func_dirname "$command_line_filename"` |
| 1722 |
|
| 1723 |
# Strip directory part but leave extension. |
| 1724 |
in_base=`basename "$command_line_filename"` |
| 1725 |
# Strip extension. |
| 1726 |
in_noext=`noext "$in_base"` |
| 1727 |
|
| 1728 |
# The normalized file name to compile. Must always point to the |
| 1729 |
# file to actually compile (in case of recoding, macro-expansion etc.). |
| 1730 |
in_input=$in_dir/$in_base |
| 1731 |
|
| 1732 |
|
| 1733 |
# Compute the output file name. |
| 1734 |
if test x"$oname" != x; then |
| 1735 |
out_name=$oname |
| 1736 |
else |
| 1737 |
out_name=$in_noext.`out_lang_ext` |
| 1738 |
fi |
| 1739 |
out_dir=`func_dirname "$out_name"` |
| 1740 |
out_dir_abs=`absolute "$out_dir"` |
| 1741 |
out_base=`basename "$out_name"` |
| 1742 |
out_noext=`noext "$out_base"` |
| 1743 |
} |
| 1744 |
|
| 1745 |
|
| 1746 |
# |
| 1747 |
#################### Main program starts ########################## |
| 1748 |
|
| 1749 |
# Initialize more variables. |
| 1750 |
# |
| 1751 |
# Save TEXINPUTS so we can construct a new TEXINPUTS path for each file. |
| 1752 |
# Likewise for bibtex and makeindex. |
| 1753 |
tex_envvars="BIBINPUTS BSTINPUTS DVIPSHEADERS INDEXSTYLE MFINPUTS MPINPUTS \ |
| 1754 |
TEXINPUTS TFMFONTS" |
| 1755 |
for var in $tex_envvars; do |
| 1756 |
eval ${var}_orig=\$$var |
| 1757 |
export $var |
| 1758 |
done |
| 1759 |
|
| 1760 |
# Push a token among the arguments that will be used to notice when we |
| 1761 |
# ended options/arguments parsing. |
| 1762 |
# Use "set dummy ...; shift" rather than 'set - ..." because on |
| 1763 |
# Solaris set - turns off set -x (but keeps set -e). |
| 1764 |
# Use ${1+"$@"} rather than "$@" because Digital Unix and Ultrix 4.3 |
| 1765 |
# still expand "$@" to a single argument (the empty string) rather |
| 1766 |
# than nothing at all. |
| 1767 |
arg_sep="$$--$$" |
| 1768 |
set dummy ${1+"$@"} "$arg_sep"; shift |
| 1769 |
|
| 1770 |
while test x"$1" != x"$arg_sep"; do |
| 1771 |
# Handle --option=value by splitting apart and putting back on argv. |
| 1772 |
case "$1" in |
| 1773 |
--*=*) |
| 1774 |
opt=`echo "$1" | $SED -e 's/=.*//'` |
| 1775 |
val=`echo "$1" | $SED -e 's/[^=]*=//'` |
| 1776 |
shift |
| 1777 |
set dummy "$opt" "$val" ${1+"$@"}; shift |
| 1778 |
;; |
| 1779 |
esac |
| 1780 |
|
| 1781 |
case "$1" in |
| 1782 |
-@ ) escape=@;; |
| 1783 |
-~ ) verbose "Option -~ is obsolete: texi2dvi ignores it.";; |
| 1784 |
-b | --batch) ;; # Obsolete |
| 1785 |
--build) shift; build_mode=$1;; |
| 1786 |
--build-dir) shift; build_dir=$1; build_mode=tidy;; |
| 1787 |
-c | --clean) build_mode=clean;; |
| 1788 |
-D | --debug) debug=true;; |
| 1789 |
-e | -E | --expand) expand=true;; |
| 1790 |
-h | --help) usage;; |
| 1791 |
-I) shift; list_concat_dirs includes "$1";; |
| 1792 |
-l | --lang | --language) shift; set_language=$1;; |
| 1793 |
--mostly-clean) action=mostly-clean;; |
| 1794 |
--no-line-error) line_error=false;; |
| 1795 |
--max-iterations) shift; max_iters=$1;; |
| 1796 |
-o | --out | --output) |
| 1797 |
shift |
| 1798 |
# Make it absolute, just in case we also have --clean, or whatever. |
| 1799 |
oname=`absolute "$1"`;; |
| 1800 |
|
| 1801 |
# Output formats. |
| 1802 |
-O|--output-format) shift; out_lang_set "$1";; |
| 1803 |
--dvi|--dvipdf|--html|--info|--pdf|--ps|--text) |
| 1804 |
out_lang_set `echo "x$1" | $SED 's/^x--//'`;; |
| 1805 |
|
| 1806 |
-p) out_lang_set pdf;; |
| 1807 |
-q | -s | --quiet | --silent) quiet=true;; |
| 1808 |
--src-specials) src_specials=--src-specials;; |
| 1809 |
--shell-escape) shell_escape=--shell-escape;; |
| 1810 |
--tex4ht) latex2html=tex4ht;; |
| 1811 |
-t | --texinfo | --command ) shift; textra="$textra\\ |
| 1812 |
"`echo "$1" | $SED 's/\\\\/\\\\\\\\/g'`;; |
| 1813 |
--translate-file ) shift; translate_file="$1";; |
| 1814 |
--tidy) build_mode=tidy;; |
| 1815 |
-v | --vers*) version;; |
| 1816 |
-V | --verb*) verb=true;; |
| 1817 |
--) # What remains are not options. |
| 1818 |
shift |
| 1819 |
while test x"$1" != x"$arg_sep"; do |
| 1820 |
set dummy ${1+"$@"} "$1"; shift |
| 1821 |
shift |
| 1822 |
done |
| 1823 |
break;; |
| 1824 |
-*) |
| 1825 |
error 1 "Unknown or ambiguous option \`$1'." \ |
| 1826 |
"Try \`--help' for more information." |
| 1827 |
;; |
| 1828 |
*) set dummy ${1+"$@"} "$1"; shift;; |
| 1829 |
esac |
| 1830 |
shift |
| 1831 |
done |
| 1832 |
# Pop the token |
| 1833 |
shift |
| 1834 |
|
| 1835 |
# $tidy: compile in a t2d directory. |
| 1836 |
# $clean: remove all the aux files. |
| 1837 |
case $build_mode in |
| 1838 |
local) clean=false; tidy=false;; |
| 1839 |
tidy) clean=false; tidy=true;; |
| 1840 |
clean) clean=true; tidy=true;; |
| 1841 |
*) error 1 "invalid build mode: $build_mode";; |
| 1842 |
esac |
| 1843 |
|
| 1844 |
# Interpret remaining command line args as filenames. |
| 1845 |
case $# in |
| 1846 |
0) |
| 1847 |
error 2 "Missing file arguments." "Try \`--help' for more information." |
| 1848 |
;; |
| 1849 |
1) ;; |
| 1850 |
*) |
| 1851 |
if test -n "$oname"; then |
| 1852 |
error 2 "Can't use option \`--output' with more than one argument." |
| 1853 |
fi |
| 1854 |
;; |
| 1855 |
esac |
| 1856 |
|
| 1857 |
|
| 1858 |
# We can't do much without tex. |
| 1859 |
# End up with the TEX and PDFTEX variables set to what we are going to use. |
| 1860 |
# |
| 1861 |
# If $TEX is set to a directory, don't use it. |
| 1862 |
test -n "$TEX" && test -d "$TEX" && unset TEX |
| 1863 |
|
| 1864 |
# But otherwise, use $TEX if it is set. |
| 1865 |
if test -z "$TEX"; then |
| 1866 |
if findprog tex; then :; else cat <<EOM >&2 |
| 1867 |
You don't have a working TeX binary (tex) installed anywhere in |
| 1868 |
your PATH, and texi2dvi cannot proceed without one. If you want to use |
| 1869 |
this script, you'll need to install TeX (if you don't have it) or change |
| 1870 |
your PATH or TEX environment variable (if you do). See the --help |
| 1871 |
output for more details. |
| 1872 |
|
| 1873 |
For information about obtaining TeX, please see http://tug.org/texlive, |
| 1874 |
or do a web search for TeX and your operating system or distro. |
| 1875 |
EOM |
| 1876 |
exit 1 |
| 1877 |
fi |
| 1878 |
|
| 1879 |
# We want to use etex (or pdftex) if they are available, and the user |
| 1880 |
# didn't explicitly specify. We don't check for elatex and pdfelatex |
| 1881 |
# because (as of 2003), the LaTeX team has asked that new distributions |
| 1882 |
# use etex by default anyway. |
| 1883 |
# |
| 1884 |
if findprog etex; then TEX=etex; else TEX=tex; fi |
| 1885 |
fi |
| 1886 |
|
| 1887 |
# For many years, the pdftex binary has included the e-tex extensions, |
| 1888 |
# but for those people with ancient TeX distributions ... |
| 1889 |
if test -z "$PDFTEX"; then |
| 1890 |
if findprog pdfetex; then PDFTEX=pdfetex; else PDFTEX=pdftex; fi |
| 1891 |
fi |
| 1892 |
|
| 1893 |
|
| 1894 |
# File descriptor usage: |
| 1895 |
# 0 standard input |
| 1896 |
# 1 standard output (--verbose messages) |
| 1897 |
# 2 standard error |
| 1898 |
# 5 tools output (turned off by --quiet) |
| 1899 |
# 6 tracing/debugging (set -x output, etc.) |
| 1900 |
|
| 1901 |
# Main tools' output (TeX, etc.) that TeX users are used to seeing. |
| 1902 |
# |
| 1903 |
# If quiet, discard, else redirect to the message flow. |
| 1904 |
if $quiet; then |
| 1905 |
exec 5>/dev/null |
| 1906 |
else |
| 1907 |
exec 5>&1 |
| 1908 |
fi |
| 1909 |
|
| 1910 |
|
| 1911 |
# Enable tracing, and auxiliary tools output. |
| 1912 |
# |
| 1913 |
# This fd should be used where you'd typically use /dev/null to throw |
| 1914 |
# output away. But sometimes it is convenient to see that output (e.g., |
| 1915 |
# from a grep) to aid debugging. Especially debugging at distance, via |
| 1916 |
# the user. |
| 1917 |
# |
| 1918 |
if $debug; then |
| 1919 |
exec 6>&1 |
| 1920 |
set -vx |
| 1921 |
else |
| 1922 |
exec 6>/dev/null |
| 1923 |
fi |
| 1924 |
|
| 1925 |
|
| 1926 |
# Main program main loop - TeXify each file in turn. |
| 1927 |
for command_line_filename |
| 1928 |
do |
| 1929 |
verbose "Processing $command_line_filename ..." |
| 1930 |
|
| 1931 |
input_file_name_decode |
| 1932 |
|
| 1933 |
# `texinfo' or `latex'? |
| 1934 |
in_lang=`compute_language "$command_line_filename"` |
| 1935 |
|
| 1936 |
# An auxiliary directory used for all the auxiliary tasks involved |
| 1937 |
# in compiling this document. |
| 1938 |
case $build_dir in |
| 1939 |
'' | . ) t2ddir=$out_noext.t2d ;; |
| 1940 |
*) # Avoid collisions between multiple occurrences of the same |
| 1941 |
# file, so depend on the output path. Remove leading `./', |
| 1942 |
# at least to avoid creating a file starting with `.!', i.e., |
| 1943 |
# an invisible file. The sed expression is fragile if the cwd |
| 1944 |
# has active characters. Transform / into ! so that we don't |
| 1945 |
# need `mkdir -p'. It might be something to reconsider. |
| 1946 |
t2ddir=$build_dir/`echo "$out_dir_abs/$out_noext.t2d" | |
| 1947 |
$SED "s,^$orig_pwd/,,;s,^\./,,;s,/,!,g"` |
| 1948 |
esac |
| 1949 |
# Remove it at exit if clean mode. |
| 1950 |
trap "cleanup" 0 1 2 15 |
| 1951 |
|
| 1952 |
ensure_dir "$build_dir" "$t2ddir" |
| 1953 |
|
| 1954 |
# Sometimes there are incompatibilities between auxiliary files for |
| 1955 |
# DVI and PDF. The contents can also change whether we work on PDF |
| 1956 |
# and/or DVI. So keep separate spaces for each. |
| 1957 |
workdir=$t2ddir/`out_lang_tex` |
| 1958 |
ensure_dir "$workdir" |
| 1959 |
|
| 1960 |
# _build. In a tidy build, where the auxiliary files are output. |
| 1961 |
if $tidy; then |
| 1962 |
work_build=$workdir/build |
| 1963 |
else |
| 1964 |
work_build=. |
| 1965 |
fi |
| 1966 |
|
| 1967 |
# _bak. Copies of the previous auxiliary files (another round is |
| 1968 |
# run if they differ from the new ones). |
| 1969 |
work_bak=$workdir/bak |
| 1970 |
|
| 1971 |
# Make those directories. |
| 1972 |
ensure_dir "$work_build" "$work_bak" |
| 1973 |
|
| 1974 |
# Decide how to find auxiliary files created by TeX. |
| 1975 |
decide_aux_files_method |
| 1976 |
|
| 1977 |
case $action in |
| 1978 |
compile) |
| 1979 |
# Compile the document. |
| 1980 |
compile |
| 1981 |
cleanup |
| 1982 |
;; |
| 1983 |
|
| 1984 |
mostly-clean) |
| 1985 |
xref_files_new=`generated_files_get` |
| 1986 |
mostly_clean |
| 1987 |
;; |
| 1988 |
esac |
| 1989 |
done |
| 1990 |
|
| 1991 |
verbose "done." |
| 1992 |
exit 0 # exit successfully, not however we ended the loop. |
| 1993 |
# Local Variables: |
| 1994 |
# sh-basic-offset: 2 |
| 1995 |
# sh-indentation: 2 |
| 1996 |
# End: |