texi2dvi 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. #! /bin/sh
  2. # texi2dvi --- produce DVI (or PDF) files from Texinfo (or LaTeX) sources.
  3. # $Id$
  4. #
  5. # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001,
  6. # 2002, 2003 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, or
  11. # (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 <friedman@gnu.org>.
  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. # This string is expanded by rcs automatically when this file is checked out.
  27. rcs_revision='$Revision$'
  28. rcs_version=`set - $rcs_revision; echo $2`
  29. program=`echo $0 | sed -e 's!.*/!!'`
  30. version="texi2dvi (GNU Texinfo 4.5) $rcs_version
  31. Copyright (C) 2003 Free Software Foundation, Inc.
  32. There is NO warranty. You may redistribute this software
  33. under the terms of the GNU General Public License.
  34. For more information about these matters, see the files named COPYING."
  35. usage="Usage: $program [OPTION]... FILE...
  36. Run each Texinfo or LaTeX FILE through TeX in turn until all
  37. cross-references are resolved, building all indices. The directory
  38. containing each FILE is searched for included files. The suffix of FILE
  39. is used to determine its language (LaTeX or Texinfo).
  40. Makeinfo is used to perform Texinfo macro expansion before running TeX
  41. when needed.
  42. Operation modes:
  43. -b, --batch no interaction
  44. -c, --clean remove all auxiliary files
  45. -D, --debug turn on shell debugging (set -x)
  46. -h, --help display this help and exit successfully
  47. -o, --output=OFILE leave output in OFILE (implies --clean);
  48. Only one input FILE may be specified in this case
  49. -q, --quiet no output unless errors (implies --batch)
  50. -s, --silent same as --quiet
  51. -v, --version display version information and exit successfully
  52. -V, --verbose report on what is done
  53. TeX tuning:
  54. -@ use @input instead of \input; for preloaded Texinfo
  55. -e, -E, --expand force macro expansion using makeinfo
  56. -I DIR search DIR for Texinfo files
  57. -l, --language=LANG specify the LANG of FILE (LaTeX or Texinfo)
  58. -p, --pdf use pdftex or pdflatex for processing
  59. -t, --texinfo=CMD insert CMD after @setfilename in copy of input file
  60. multiple values accumulate
  61. The values of the BIBTEX, LATEX (or PDFLATEX), MAKEINDEX, MAKEINFO,
  62. TEX (or PDFTEX), and TEXINDEX environment variables are used to run
  63. those commands, if they are set.
  64. Email bug reports to <bug-texinfo@gnu.org>,
  65. general questions and discussion to <help-texinfo@gnu.org>.
  66. Texinfo home page: http://www.gnu.org/software/texinfo/"
  67. # Initialize variables for option overriding and otherwise.
  68. # Don't use `unset' since old bourne shells don't have this command.
  69. # Instead, assign them an empty value.
  70. batch=false # eval for batch mode
  71. clean=
  72. debug=
  73. escape='\'
  74. expand= # t for expansion via makeinfo
  75. miincludes= # makeinfo include path
  76. oformat=dvi
  77. oname= # --output
  78. quiet= # by default let the tools' message be displayed
  79. set_language=
  80. textra=
  81. tmpdir=${TMPDIR:-/tmp}/t2d$$ # avoid collisions on 8.3 filesystems.
  82. txincludes= # TEXINPUTS extensions, with trailing colon
  83. txiprereq=19990129 # minimum texinfo.tex version to have macro expansion
  84. verbose=false # echo for verbose mode
  85. orig_pwd=`pwd`
  86. # Systems which define $COMSPEC or $ComSpec use semicolons to separate
  87. # directories in TEXINPUTS.
  88. if test -n "$COMSPEC$ComSpec"; then
  89. path_sep=";"
  90. else
  91. path_sep=":"
  92. fi
  93. # Pacify verbose cds.
  94. CDPATH=${ZSH_VERSION+.}$path_sep
  95. # In case someone crazy insists on using grep -E.
  96. : ${EGREP=egrep}
  97. # Save this so we can construct a new TEXINPUTS path for each file.
  98. TEXINPUTS_orig="$TEXINPUTS"
  99. # Unfortunately makeindex does not read TEXINPUTS.
  100. INDEXSTYLE_orig="$INDEXSTYLE"
  101. export TEXINPUTS INDEXSTYLE
  102. # Push a token among the arguments that will be used to notice when we
  103. # ended options/arguments parsing.
  104. # Use "set dummy ...; shift" rather than 'set - ..." because on
  105. # Solaris set - turns off set -x (but keeps set -e).
  106. # Use ${1+"$@"} rather than "$@" because Digital Unix and Ultrix 4.3
  107. # still expand "$@" to a single argument (the empty string) rather
  108. # than nothing at all.
  109. arg_sep="$$--$$"
  110. set dummy ${1+"$@"} "$arg_sep"; shift
  111. #
  112. # Parse command line arguments.
  113. while test x"$1" != x"$arg_sep"; do
  114. # Handle --option=value by splitting apart and putting back on argv.
  115. case "$1" in
  116. --*=*)
  117. opt=`echo "$1" | sed -e 's/=.*//'`
  118. val=`echo "$1" | sed -e 's/[^=]*=//'`
  119. shift
  120. set dummy "$opt" "$val" ${1+"$@"}; shift
  121. ;;
  122. esac
  123. # This recognizes --quark as --quiet. So what.
  124. case "$1" in
  125. -@ ) escape=@;;
  126. # Silently and without documentation accept -b and --b[atch] as synonyms.
  127. -b | --b*) batch=eval;;
  128. -q | -s | --q* | --s*) quiet=t; batch=eval;;
  129. -c | --c*) clean=t;;
  130. -D | --d*) debug=t;;
  131. -e | -E | --e*) expand=t;;
  132. -h | --h*) echo "$usage"; exit 0;;
  133. -I | --I*)
  134. shift
  135. miincludes="$miincludes -I $1"
  136. txincludes="$txincludes$1$path_sep"
  137. ;;
  138. -l | --l*) shift; set_language=$1;;
  139. -o | --o*)
  140. shift
  141. clean=t
  142. case "$1" in
  143. /* | ?:/*) oname=$1;;
  144. *) oname="$orig_pwd/$1";;
  145. esac;;
  146. -p | --p*) oformat=pdf;;
  147. -t | --t*) shift; textra="$textra\\
  148. $1";;
  149. -v | --vers*) echo "$version"; exit 0;;
  150. -V | --verb*) verbose=echo;;
  151. --) # What remains are not options.
  152. shift
  153. while test x"$1" != x"$arg_sep"; do
  154. set dummy ${1+"$@"} "$1"; shift
  155. shift
  156. done
  157. break;;
  158. -*)
  159. echo "$0: Unknown or ambiguous option \`$1'." >&2
  160. echo "$0: Try \`--help' for more information." >&2
  161. exit 1;;
  162. *) set dummy ${1+"$@"} "$1"; shift;;
  163. esac
  164. shift
  165. done
  166. # Pop the token
  167. shift
  168. # Interpret remaining command line args as filenames.
  169. case $# in
  170. 0)
  171. echo "$0: Missing file arguments." >&2
  172. echo "$0: Try \`--help' for more information." >&2
  173. exit 2
  174. ;;
  175. 1) ;;
  176. *)
  177. if test -n "$oname"; then
  178. echo "$0: Can't use option \`--output' with more than one argument." >&2
  179. exit 2
  180. fi
  181. ;;
  182. esac
  183. # Prepare the temporary directory. Remove it at exit, unless debugging.
  184. if test -z "$debug"; then
  185. trap "cd / && rm -rf $tmpdir" 0 1 2 15
  186. fi
  187. # Create the temporary directory with strict rights
  188. (umask 077 && mkdir $tmpdir) || exit 1
  189. # Prepare the tools we might need. This may be extra work in some
  190. # cases, but improves the readibility of the script.
  191. utildir=$tmpdir/utils
  192. mkdir $utildir || exit 1
  193. # A sed script that preprocesses Texinfo sources in order to keep the
  194. # iftex sections only. We want to remove non TeX sections, and
  195. # comment (with `@c texi2dvi') TeX sections so that makeinfo does not
  196. # try to parse them. Nevertheless, while commenting TeX sections,
  197. # don't comment @macro/@end macro so that makeinfo does propagate
  198. # them. Unfortunately makeinfo --iftex --no-ifhtml --no-ifinfo
  199. # doesn't work well enough (yet) to use that, so work around with sed.
  200. comment_iftex_sed=$utildir/comment.sed
  201. cat <<EOF >$comment_iftex_sed
  202. /^@tex/,/^@end tex/{
  203. s/^/@c texi2dvi/
  204. }
  205. /^@iftex/,/^@end iftex/{
  206. s/^/@c texi2dvi/
  207. /^@c texi2dvi@macro/,/^@c texi2dvi@end macro/{
  208. s/^@c texi2dvi//
  209. }
  210. }
  211. /^@html/,/^@end html/{
  212. s/^/@c (texi2dvi)/
  213. }
  214. /^@ifhtml/,/^@end ifhtml/{
  215. s/^/@c (texi2dvi)/
  216. }
  217. /^@ifnottex/,/^@end ifnottex/{
  218. s/^/@c (texi2dvi)/
  219. }
  220. /^@ifinfo/,/^@end ifinfo/{
  221. /^@node/p
  222. /^@menu/,/^@end menu/p
  223. t
  224. s/^/@c (texi2dvi)/
  225. }
  226. s/^@ifnotinfo/@c texi2dvi@ifnotinfo/
  227. s/^@end ifnotinfo/@c texi2dvi@end ifnotinfo/
  228. EOF
  229. # Uncommenting is simple: Remove any leading `@c texi2dvi'.
  230. uncomment_iftex_sed=$utildir/uncomment.sed
  231. cat <<EOF >$uncomment_iftex_sed
  232. s/^@c texi2dvi//
  233. EOF
  234. # A shell script that computes the list of xref files.
  235. # Takes the filename (without extension) of which we look for xref
  236. # files as argument. The index files must be reported last.
  237. get_xref_files=$utildir/get_xref.sh
  238. cat <<\EOF >$get_xref_files
  239. #! /bin/sh
  240. # Get list of xref files (indexes, tables and lists).
  241. # Find all files having root filename with a two-letter extension,
  242. # saves the ones that are really Texinfo-related files. .?o? catches
  243. # many files: .toc, .log, LaTeX tables and lists, FiXme's .lox, maybe more.
  244. for this_file in "$1".?o? "$1".aux "$1".?? "$1".idx; do
  245. # If file is empty, skip it.
  246. test -s "$this_file" || continue
  247. # If the file is not suitable to be an index or xref file, don't
  248. # process it. The file can't be if its first character is not a
  249. # backslash or single quote.
  250. first_character=`sed -n '1s/^\(.\).*$/\1/p;q' $this_file`
  251. if test "x$first_character" = "x\\" \
  252. || test "x$first_character" = "x'"; then
  253. xref_files="$xref_files ./$this_file"
  254. fi
  255. done
  256. echo "$xref_files"
  257. EOF
  258. chmod 500 $get_xref_files
  259. # File descriptor usage:
  260. # 0 standard input
  261. # 1 standard output (--verbose messages)
  262. # 2 standard error
  263. # 3 some systems may open it to /dev/tty
  264. # 4 used on the Kubota Titan
  265. # 5 tools output (turned off by --quiet)
  266. # Tools' output. If quiet, discard, else redirect to the message flow.
  267. if test "$quiet" = t; then
  268. exec 5>/dev/null
  269. else
  270. exec 5>&1
  271. fi
  272. # Enable tracing
  273. test "$debug" = t && set -x
  274. #
  275. # TeXify files.
  276. for command_line_filename in ${1+"$@"}; do
  277. $verbose "Processing $command_line_filename ..."
  278. # If the COMMAND_LINE_FILENAME is not absolute (e.g., --debug.tex),
  279. # prepend `./' in order to avoid that the tools take it as an option.
  280. echo "$command_line_filename" | $EGREP '^(/|[A-z]:/)' >/dev/null \
  281. || command_line_filename="./$command_line_filename"
  282. # See if the file exists. If it doesn't we're in trouble since, even
  283. # though the user may be able to reenter a valid filename at the tex
  284. # prompt (assuming they're attending the terminal), this script won't
  285. # be able to find the right xref files and so forth.
  286. if test ! -r "$command_line_filename"; then
  287. echo "$0: Could not read $command_line_filename, skipping." >&2
  288. continue
  289. fi
  290. # Get the name of the current directory. We want the full path
  291. # because in clean mode we are in tmp, in which case a relative
  292. # path has no meaning.
  293. filename_dir=`echo $command_line_filename | sed 's!/[^/]*$!!;s!^$!.!'`
  294. filename_dir=`cd "$filename_dir" >/dev/null && pwd`
  295. # Strip directory part but leave extension.
  296. filename_ext=`basename "$command_line_filename"`
  297. # Strip extension.
  298. filename_noext=`echo "$filename_ext" | sed 's/\.[^.]*$//'`
  299. ext=`echo "$filename_ext" | sed 's/^.*\.//'`
  300. # _src. Use same basename since we want to generate aux files with
  301. # the same basename as the manual. If --expand, then output the
  302. # macro-expanded file to here, else copy the original file.
  303. tmpdir_src=$tmpdir/src
  304. filename_src=$tmpdir_src/$filename_noext.$ext
  305. # _xtr. The file with the user's extra commands.
  306. tmpdir_xtr=$tmpdir/xtr
  307. filename_xtr=$tmpdir_xtr/$filename_noext.$ext
  308. # _bak. Copies of the previous xref files (another round is run if
  309. # they differ from the new one).
  310. tmpdir_bak=$tmpdir/bak
  311. # Make all those directories and give up if we can't succeed.
  312. mkdir $tmpdir_src $tmpdir_xtr $tmpdir_bak || exit 1
  313. # Source file might include additional sources.
  314. # We want `.:$orig_pwd' before anything else. (We'll add `.:' later
  315. # after all other directories have been turned into absolute paths.)
  316. # `.' goes first to ensure that any old .aux, .cps,
  317. # etc. files in ${directory} don't get used in preference to fresher
  318. # files in `.'. Include orig_pwd in case we are in clean mode, where
  319. # we've cd'd to a temp directory.
  320. common="$orig_pwd$path_sep$filename_dir$path_sep$txincludes"
  321. TEXINPUTS="$common$TEXINPUTS_orig"
  322. INDEXSTYLE="$common$INDEXSTYLE_orig"
  323. # Convert relative paths to absolute paths, so we can run in another
  324. # directory (e.g., in --clean mode, or during the macro-support
  325. # detection.)
  326. #
  327. # Empty path components are meaningful to tex. We rewrite them
  328. # as `EMPTY' so they don't get lost when we split on $path_sep.
  329. TEXINPUTS=`echo $TEXINPUTS |sed 's/^:/EMPTY:/;s/:$/:EMPTY/;s/::/:EMPTY:/g'`
  330. INDEXSTYLE=`echo $INDEXSTYLE |sed 's/^:/EMPTY:/;s/:$/:EMPTY/;s/::/:EMPTY:/g'`
  331. save_IFS=$IFS
  332. IFS=$path_sep
  333. set x $TEXINPUTS; shift
  334. TEXINPUTS=.
  335. for dir
  336. do
  337. case $dir in
  338. EMPTY)
  339. TEXINPUTS=$TEXINPUTS$path_sep
  340. ;;
  341. [\\/]* | ?:[\\/]*) # Absolute paths don't need to be expansed.
  342. TEXINPUTS=$TEXINPUTS$path_sep$dir
  343. ;;
  344. *)
  345. abs=`cd "$dir" && pwd` && TEXINPUTS=$TEXINPUTS$path_sep$abs
  346. ;;
  347. esac
  348. done
  349. set x $INDEXSTYLE; shift
  350. INDEXSTYLE=.
  351. for dir
  352. do
  353. case $dir in
  354. EMPTY)
  355. INDEXSTYLE=$INDEXSTYLE$path_sep
  356. ;;
  357. [\\/]* | ?:[\\/]*) # Absolute paths don't need to be expansed.
  358. INDEXSTYLE=$INDEXSTYLE$path_sep$dir
  359. ;;
  360. *)
  361. abs=`cd "$dir" && pwd` && INDEXSTYLE=$INDEXSTYLE$path_sep$abs
  362. ;;
  363. esac
  364. done
  365. IFS=$save_IFS
  366. # If the user explicitly specified the language, use that.
  367. # Otherwise, if the first line is \input texinfo, assume it's texinfo.
  368. # Otherwise, guess from the file extension.
  369. if test -n "$set_language"; then
  370. language=$set_language
  371. elif sed 1q "$command_line_filename" | grep 'input texinfo' >/dev/null; then
  372. language=texinfo
  373. else
  374. language=
  375. fi
  376. # Get the type of the file (latex or texinfo) from the given language
  377. # we just guessed, or from the file extension if not set yet.
  378. case ${language:-$filename_ext} in
  379. [lL]a[tT]e[xX] | *.ltx | *.tex)
  380. # Assume a LaTeX file. LaTeX needs bibtex and uses latex for
  381. # compilation. No makeinfo.
  382. bibtex=${BIBTEX:-bibtex}
  383. makeinfo= # no point in running makeinfo on latex source.
  384. texindex=${MAKEINDEX:-makeindex}
  385. if test $oformat = dvi; then
  386. tex=${LATEX:-latex}
  387. else
  388. tex=${PDFLATEX:-pdflatex}
  389. fi
  390. ;;
  391. *)
  392. # Assume a Texinfo file. Texinfo files need makeinfo, texindex and tex.
  393. bibtex=
  394. texindex=${TEXINDEX:-texindex}
  395. if test $oformat = dvi; then
  396. tex=${TEX:-tex}
  397. else
  398. tex=${PDFTEX:-pdftex}
  399. fi
  400. # Unless required by the user, makeinfo expansion is wanted only
  401. # if texinfo.tex is too old.
  402. if test "$expand" = t; then
  403. makeinfo=${MAKEINFO:-makeinfo}
  404. else
  405. # Check if texinfo.tex performs macro expansion by looking for
  406. # its version. The version is a date of the form YEAR-MO-DA.
  407. # We don't need to use [0-9] to match the digits since anyway
  408. # the comparison with $txiprereq, a number, will fail with non
  409. # digits.
  410. txiversion_tex=txiversion.tex
  411. echo '\input texinfo.tex @bye' >$tmpdir/$txiversion_tex
  412. # Run in the tmpdir to avoid leaving files.
  413. eval `cd $tmpdir >/dev/null &&
  414. $tex $txiversion_tex 2>/dev/null |
  415. sed -n 's/^.*\[\(.*\)version \(....\)-\(..\)-\(..\).*$/txiformat=\1 txiversion="\2\3\4"/p'`
  416. $verbose "texinfo.tex preloaded as \`$txiformat', version is \`$txiversion' ..."
  417. if test "$txiprereq" -le "$txiversion" >/dev/null 2>&1; then
  418. makeinfo=
  419. else
  420. makeinfo=${MAKEINFO:-makeinfo}
  421. fi
  422. # As long as we had to run TeX, offer the user this convenience
  423. if test "$txiformat" = Texinfo; then
  424. escape=@
  425. fi
  426. fi
  427. ;;
  428. esac
  429. # Expand macro commands in the original source file using Makeinfo.
  430. # Always use `end' footnote style, since the `separate' style
  431. # generates different output (arguably this is a bug in -E).
  432. # Discard main info output, the user asked to run TeX, not makeinfo.
  433. if test -n "$makeinfo"; then
  434. $verbose "Macro-expanding $command_line_filename to $filename_src ..."
  435. sed -f $comment_iftex_sed "$command_line_filename" \
  436. | $makeinfo --footnote-style=end -I "$filename_dir" $miincludes \
  437. -o /dev/null --macro-expand=- \
  438. | sed -f $uncomment_iftex_sed >"$filename_src"
  439. filename_input=$filename_src
  440. fi
  441. # If makeinfo failed (or was not even run), use the original file as input.
  442. if test $? -ne 0 \
  443. || test ! -r "$filename_src"; then
  444. $verbose "Reverting to $command_line_filename ..."
  445. filename_input=$filename_dir/$filename_ext
  446. fi
  447. # Used most commonly for @finalout, @smallbook, etc.
  448. if test -n "$textra"; then
  449. $verbose "Inserting extra commands: $textra"
  450. sed '/^@setfilename/a\
  451. '"$textra" "$filename_input" >$filename_xtr
  452. filename_input=$filename_xtr
  453. fi
  454. # If clean mode was specified, then move to the temporary directory.
  455. if test "$clean" = t; then
  456. $verbose "cd $tmpdir_src"
  457. cd "$tmpdir_src" || exit 1
  458. fi
  459. while :; do # will break out of loop below
  460. orig_xref_files=`$get_xref_files "$filename_noext"`
  461. # Save copies of originals for later comparison.
  462. if test -n "$orig_xref_files"; then
  463. $verbose "Backing up xref files: `echo $orig_xref_files | sed 's|\./||g'`"
  464. cp $orig_xref_files $tmpdir_bak
  465. fi
  466. # Run bibtex on current file.
  467. # - If its input (AUX) exists.
  468. # - If AUX contains both `\bibdata' and `\bibstyle'.
  469. # - If some citations are missing (LOG contains `Citation').
  470. # or the LOG complains of a missing .bbl
  471. #
  472. # We run bibtex first, because I can see reasons for the indexes
  473. # to change after bibtex is run, but I see no reason for the
  474. # converse.
  475. #
  476. # Don't try to be too smart. Running bibtex only if the bbl file
  477. # exists and is older than the LaTeX file is wrong, since the
  478. # document might include files that have changed. Because there
  479. # can be several AUX (if there are \include's), but a single LOG,
  480. # looking for missing citations in LOG is easier, though we take
  481. # the risk to match false messages.
  482. if test -n "$bibtex" \
  483. && test -r "$filename_noext.aux" \
  484. && test -r "$filename_noext.log" \
  485. && (grep '^\\bibdata[{]' "$filename_noext.aux" \
  486. && grep '^\\bibstyle[{]' "$filename_noext.aux" \
  487. && (grep 'Warning:.*Citation.*undefined' "$filename_noext.log" \
  488. || grep 'No file .*\.bbl\.' "$filename_noext.log")) \
  489. >/dev/null 2>&1; \
  490. then
  491. $verbose "Running $bibtex $filename_noext ..."
  492. if $bibtex "$filename_noext" >&5; then :; else
  493. echo "$0: $bibtex exited with bad status, quitting." >&2
  494. exit 1
  495. fi
  496. fi
  497. # What we'll run texindex on -- exclude non-index files.
  498. # Since we know index files are last, it is correct to remove everything
  499. # before .aux and .?o?. But don't really do <anything>o<anything>
  500. # -- don't match whitespace as <anything>.
  501. # Otherwise, if orig_xref_files contains something like
  502. # foo.xo foo.whatever
  503. # the space after the o will get matched.
  504. index_files=`echo "$orig_xref_files" \
  505. | sed "s!.*\.aux!!g;
  506. s!./$filename_noext\.[^ ]o[^ ]!!g;
  507. s/^[ ]*//;s/[ ]*$//"`
  508. # Run texindex (or makeindex) on current index files. If they
  509. # already exist, and after running TeX a first time the index
  510. # files don't change, then there's no reason to run TeX again.
  511. # But we won't know that if the index files are out of date or
  512. # nonexistent.
  513. if test -n "$texindex" && test -n "$index_files"; then
  514. $verbose "Running $texindex $index_files ..."
  515. if $texindex $index_files 2>&5 1>&2; then :; else
  516. echo "$0: $texindex exited with bad status, quitting." >&2
  517. exit 1
  518. fi
  519. fi
  520. # Finally, run TeX.
  521. # Prevent $ESCAPE from being interpreted by the shell if it happens
  522. # to be `/'.
  523. $batch tex_args="\\${escape}nonstopmode\ \\${escape}input"
  524. cmd="$tex $tex_args $filename_input"
  525. $verbose "Running $cmd ..."
  526. if $cmd >&5; then :; else
  527. echo "$0: $tex exited with bad status, quitting." >&2
  528. echo "$0: see $filename_noext.log for errors." >&2
  529. test "$clean" = t \
  530. && cp "$filename_noext.log" "$orig_pwd"
  531. exit 1
  532. fi
  533. # Decide if looping again is needed.
  534. finished=t
  535. # LaTeX (and the package changebar) report in the LOG file if it
  536. # should be rerun. This is needed for files included from
  537. # subdirs, since texi2dvi does not try to compare xref files in
  538. # subdirs. Performing xref files test is still good since LaTeX
  539. # does not report changes in xref files.
  540. if grep "Rerun to get" "$filename_noext.log" >/dev/null 2>&1; then
  541. finished=
  542. fi
  543. # Check if xref files changed.
  544. new_xref_files=`$get_xref_files "$filename_noext"`
  545. $verbose "Original xref files = `echo $orig_xref_files | sed 's|\./||g'`"
  546. $verbose "New xref files = `echo $new_xref_files | sed 's|\./||g'`"
  547. # If old and new lists don't at least have the same file list,
  548. # then one file or another has definitely changed.
  549. test "x$orig_xref_files" != "x$new_xref_files" && finished=
  550. # File list is the same. We must compare each file until we find
  551. # a difference.
  552. if test -n "$finished"; then
  553. for this_file in $new_xref_files; do
  554. $verbose "Comparing xref file `echo $this_file | sed 's|\./||g'` ..."
  555. # cmp -s returns nonzero exit status if files differ.
  556. if cmp -s "$this_file" "$tmpdir_bak/$this_file"; then :; else
  557. # We only need to keep comparing until we find one that
  558. # differs, because we'll have to run texindex & tex again no
  559. # matter how many more there might be.
  560. finished=
  561. $verbose "xref file `echo $this_file | sed 's|\./||g'` differed ..."
  562. test "$debug" = t && diff -c "$tmpdir_bak/$this_file" "$this_file"
  563. break
  564. fi
  565. done
  566. fi
  567. # If finished, exit the loop, else rerun the loop.
  568. test -n "$finished" && break
  569. done
  570. # If we were in clean mode, compilation was in a tmp directory.
  571. # Copy the DVI (or PDF) file into the directory where the compilation
  572. # has been done. (The temp dir is about to get removed anyway.)
  573. # We also return to the original directory so that
  574. # - the next file is processed in correct conditions
  575. # - the temporary file can be removed
  576. if test -n "$clean"; then
  577. if test -n "$oname"; then
  578. dest=$oname
  579. else
  580. dest=$orig_pwd
  581. fi
  582. $verbose "Copying $oformat file from `pwd` to $dest"
  583. cp -p "./$filename_noext.$oformat" "$dest"
  584. cd / # in case $orig_pwd is on a different drive (for DOS)
  585. cd $orig_pwd || exit 1
  586. fi
  587. # Remove temporary files.
  588. if test "x$debug" = "x"; then
  589. $verbose "Removing $tmpdir_src $tmpdir_xtr $tmpdir_bak ..."
  590. cd /
  591. rm -rf $tmpdir_src $tmpdir_xtr $tmpdir_bak
  592. fi
  593. done
  594. $verbose "$0 done."
  595. exit 0 # exit successfully, not however we ended the loop.