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