texi2dvi 57 KB

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