cape" # Run without interaction, stopping at the first error. tex_cmd="$tex_cmd , \ and any whitespace characters are not supported # filenames. in_input_funnies=`echo "$in_input" \ | $SED -e 's![^}#$%&^_{~]!!g' -e 's!\(.\)!\1\'' !g' | uniq` if test -n "$in_input_funnies" ; then # Make > an end group character, as it's unlikely to appear in # a filename. tex_cmd="$tex_cmd '${escape}bgroup${escape}catcode62=2${escape}relax'" # If the filename has funny characters, change the TeX category codes of # some characters within a group, and use \expandafter to input the file # outside of the group. for w in $in_input_funnies ; do tex_cmd="$tex_cmd '${escape}catcode\`${escape}$w=12${escape}relax'" done # Set \toks0 to "\input FILENAME\relax" tex_cmd="$tex_cmd '${escape}toks0${escape}bgroup${escape}input' '$rel$in_input' '${escape}relax>" # Expand \toks0 after the end of the group tex_cmd="$tex_cmd${escape}expandafter${escape}egroup" tex_cmd="$tex_cmd${escape}the${escape}toks0${escape}relax'" else # In the case of a simple filename, just pass the filename # with no funny tricks. tex_cmd="$tex_cmd '${escape}input' '$rel$in_input'" fi verbose "$0: Running $tex_cmd ..." if (eval "$tex_cmd" >&5); then case $out_lang in dvi | pdf ) move_to_dest "$in_noext.$out_lang";; esac else tex_failed=true fi } # run_bibtex - Run bibtex (or biber) on current file # - if its input (AUX) exists, # - or if some citations are missing (LOG contains `Citation'), # - or if the LOG complains of a missing .bbl. # # Don't try to be too smart: # 1. Running bibtex only if the bbl file exists and is older than # the LaTeX file is wrong, since the document might include files # that have changed. # # 2. Because there can be several AUX (if there are \include's), # but a single LOG, looking for missing citations in LOG is # easier, though we take the risk of matching false messages. run_bibtex () { case $in_lang in latex) bibtex=${BIBTEX:-bibtex};; texinfo) return;; esac # "Citation undefined" is for LaTeX, "Undefined citation" for btxmac.tex. # The no .aux && \bibdata test is also for btxmac, in case it was the # first run of a bibtex-using document. Otherwise, it's possible that # bibtex would never be run. if test -r "$in_noext.aux" \ && test -r "$in_noext.log" \ && ( (grep 'Warning:.*Citation.*undefined' "$in_noext.log" \ || grep '.*Undefined citation' "$in_noext.log" \ || grep 'No file .*\.bbl\.' "$in_noext.log") \ || (grep 'No \.aux file' "$in_noext.log" \ && grep '^\\bibdata' "$in_noext.aux") ) \ >&6 2>&1; \ then bibtex_aux=`filter_files bibaux_file_p` for f in $bibtex_aux; do run $bibtex "$f" done fi # biber(+biblatex) check. if test -r "$in_noext.bcf" \ && grep '' "$in_noext.bcf" >/dev/null; then run ${BIBER:-biber} "$in_noext" fi } # filter_file PREDICATE - Go through the list of files in xref_files_new # and use PREDICATE on each one to optionally print it or print other files # based on the filename. filter_files () { test -n "$xref_files_new" || return 0 echo "$xref_files_new" | # Filter existing files matching the criterion. # while read file; do $1 "$file" done | sort | # Some files are opened several times, e.g., listings.sty's *.vrb. uniq } # run_index - Run texindex (or makeindex or texindy) on current index # files. If they already exist, and after running TeX a first time the # index files don't change, then there's no reason to run TeX again. # But we won't know that if the index files are out of date or nonexistent. run_index () { index_files=`filter_files index_file_p` test -n "$index_files" \ || return 0 : ${MAKEINDEX:=makeindex} : ${TEXINDEX:=texindex} : ${TEXINDY:=texindy} case $in_lang in latex) if $TEXINDY --version >&6 2>&1; then run $TEXINDY $index_files else run $MAKEINDEX $index_files fi ;; texinfo) run $TEXINDEX $index_files ;; esac } # run_thumbpdf - Run thumbpdf. run_thumbpdf () { if test `out_lang_tex` = pdf \ && test -r "$in_noext.log" \ && grep 'thumbpdf\.sty' "$in_noext.log" >&6 2>&1; \ then thumbpdf=${THUMBPDF_CMD:-thumbpdf} thumbcmd="$thumbpdf $in_dir/$in_noext" verbose "Running $thumbcmd ..." if $thumbcmd >&5; then run_tex else report "$thumbpdf exited with bad status." \ "Ignoring its output." fi fi } # run_dvipdf FILE.dvi - Convert FILE.dvi to FILE.pdf. run_dvipdf () { # Find which dvi->pdf program is available. if test -n "$DVIPDF"; then dvipdf=$DVIPDF # user envvar, use it without checking elif test -z "$dvipdf"; then for i in dvipdfmx dvipdfm dvipdf dvi2pdf dvitopdf; do if findprog $i; then dvipdf=$i fi done fi # These tools have varying interfaces, some 'input output', others # 'input -o output'. They all seem to accept 'input' only, # outputting using the expected file name. run $dvipdf "$1" if test ! -f `echo "$1" | $SED -e 's/\.dvi$/.pdf/'`; then error 1 "cannot find output file" fi } # run_tex_suite - Run the TeX tools until a stable point is reached. run_tex_suite () { make_tex_cmd # Move to the working directory. if $tidy; then verbose "cd $work_build" cd_dir "$work_build" || exit 1 fi # Count the number of cycles. suite_cycle=0 # Start by checking the log files for what files were created last # time. This will mean that if they don't change, we finish in 1 cycle. xref_files_new=`generated_files_get` xref_files_save while :; do # check for (probably) LaTeX loop (e.g. varioref) if test $suite_cycle -eq "$max_iters"; then error 0 "Maximum of $max_iters cycles exceeded" break fi # report progress suite_cycle=`expr $suite_cycle + 1` verbose "Cycle $suite_cycle for $command_line_filename" tex_failed=false run_tex xref_files_changed || break xref_files_save # We run bibtex first, because it's more likely for the indexes # to change after bibtex is run than the reverse, though either # would be rare. run_bibtex run_index done if $tex_failed ; then # TeX failed, and the xref files did not change. error 1 "$tex exited with bad status, quitting." fi # If we were using thumbpdf and producing PDF, then run thumbpdf # and TeX one last time. run_thumbpdf # Install the result if we didn't already (i.e., if the output is # dvipdf or ps). case $out_lang in dvipdf) run_dvipdf "$in_noext.`out_lang_tex`" move_to_dest "$in_noext.`out_lang_ext`" ;; ps) : ${DVIPS:=dvips} run $DVIPS -o "$in_noext.`out_lang_ext`" "$in_noext.`out_lang_tex`" move_to_dest "$in_noext.`out_lang_ext`" ;; esac cd_orig } #