| 1 |
#!/bin/sh |
| 2 |
# $ITI: tex-it,v 1.3 1995/06/14 10:49:12 schrod Exp $ |
| 3 |
#---------------------------------------------------------------------- |
| 4 |
|
| 5 |
# |
| 6 |
# tex-it --- transform a TeX document to a final DVI file |
| 7 |
# |
| 8 |
# (history at end) |
| 9 |
|
| 10 |
|
| 11 |
# SYNOPSIS |
| 12 |
# |
| 13 |
# tex-it [-bi] tex-cmd file |
| 14 |
# |
| 15 |
# tex-it runs 'tex-cmd' on 'file' as often as necessary to produce a |
| 16 |
# DVI file where all cross references are resolved. That convergence |
| 17 |
# is reached by analyzing auxilliary files: |
| 18 |
# -- If file.toc has changed, the table of contents is not up to date. |
| 19 |
# -- If file.idx has changed, the index is not up to date. |
| 20 |
# MakeIndex is assumed to be used for creating the index. |
| 21 |
# -- If file.aux has changed, cross references are not up to date. |
| 22 |
# -- If file.aux contains a "\bibdata" tag and if the set of |
| 23 |
# "\citation" tags have changed, then BibTeX is run. |
| 24 |
# |
| 25 |
# No other auxilliary files are handled. No subdocuments (via |
| 26 |
# "\include") are supported. |
| 27 |
# |
| 28 |
# 'tex-cmd' may be more than one word. |
| 29 |
# |
| 30 |
# |
| 31 |
# OPTIONS |
| 32 |
# `-b' skip test for BibTeX |
| 33 |
# `-i' skip test for MakeIndex |
| 34 |
|
| 35 |
# NOTE: On HP-UX this script is not functional, you have to substitute |
| 36 |
# /bin/sh by /bin/ksh in the first line. (/bin/sh doesn't have the |
| 37 |
# getopts builtin.) |
| 38 |
|
| 39 |
|
| 40 |
cmd=`basename $0` |
| 41 |
usage() |
| 42 |
{ |
| 43 |
echo "usage: $cmd [-bi] tex-cmd file" >&2 |
| 44 |
exit 1 |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
# Normalize and check arguments. |
| 49 |
|
| 50 |
do_bibtex=true |
| 51 |
do_makeindex=true |
| 52 |
while getopts 'bi' option |
| 53 |
do case "$option" in |
| 54 |
b) do_bibtex='' |
| 55 |
;; |
| 56 |
i) do_makeindex='' |
| 57 |
;; |
| 58 |
*) usage |
| 59 |
;; |
| 60 |
esac |
| 61 |
done |
| 62 |
|
| 63 |
shift `expr $OPTIND - 1` |
| 64 |
test $# -gt 0 || usage |
| 65 |
|
| 66 |
|
| 67 |
# Get file name (last argument), discard extension if necessary. |
| 68 |
|
| 69 |
file=`eval "echo \\$$#"` |
| 70 |
file=`echo $file | sed 's/\.[^.]*//'` |
| 71 |
|
| 72 |
|
| 73 |
# Create temporary directory for auxilliary files to compare. Discard |
| 74 |
# that directory if the script is terminated. Note that trap handler |
| 75 |
# for 0 is executed at the end of the trap handler for the other |
| 76 |
# signals. |
| 77 |
|
| 78 |
tmp=/tmp/tex$$ |
| 79 |
trap "/bin/rm -rf $tmp" 0 |
| 80 |
trap "exit 4" 1 2 3 15 |
| 81 |
mkdir $tmp |
| 82 |
|
| 83 |
|
| 84 |
# ------------------------------------------------------------ |
| 85 |
# |
| 86 |
# Set up functions that save auxilliary information and check if they |
| 87 |
# have changed. Save functions are called `save_<type>', check |
| 88 |
# functions are called `check_<type>'. Check functions set $run_tex to |
| 89 |
# "true" if TeX must be run anew. Check functions may run programs to |
| 90 |
# create other auxilliary files. |
| 91 |
|
| 92 |
|
| 93 |
# aux: table of contents & cross references |
| 94 |
# |
| 95 |
# We don't check for *.toc files. LaTeX stores the information in the |
| 96 |
# AUX file anyhow, and plain-based macros typically produce the table |
| 97 |
# of contents at the end of the document, when it's guaranteed to be |
| 98 |
# OK. |
| 99 |
|
| 100 |
save_aux() |
| 101 |
{ |
| 102 |
if [ -f "$file.aux" ] |
| 103 |
then cp "$file.aux" $tmp |
| 104 |
else touch "$tmp/$file.aux" |
| 105 |
fi |
| 106 |
} |
| 107 |
|
| 108 |
check_aux() |
| 109 |
{ |
| 110 |
test -f "$file.aux" || return 0 |
| 111 |
cmp -s "$file.aux" "$tmp/$file.aux" || run_tex=true |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
# bibtex: Citations |
| 116 |
|
| 117 |
save_bibtex() |
| 118 |
{ |
| 119 |
if [ -f "$file.aux" ] |
| 120 |
then egrep '^\\(citation|bibdata)' "$file.aux" | |
| 121 |
sort >"$tmp/$file.bib" |
| 122 |
else touch "$tmp/$file.bib" |
| 123 |
fi |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
check_bibtex() |
| 128 |
{ |
| 129 |
test "$do_bibtex" -a -f "$file.aux" || return 0 |
| 130 |
egrep '^\\(citation|bibdata)' "$file.aux" | sort >$tmp/bib.new |
| 131 |
if grep '^\\bibdata' $tmp/bib.new >/dev/null |
| 132 |
then if cmp -s "$tmp/$file.bib" $tmp/bib.new |
| 133 |
then : do nothing |
| 134 |
else bibtex "$file" |
| 135 |
run_tex=true |
| 136 |
fi |
| 137 |
fi |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
# idx: raw index data |
| 142 |
|
| 143 |
save_idx() |
| 144 |
{ |
| 145 |
if [ -f "$file.idx" ] |
| 146 |
then cp "$file.idx" $tmp |
| 147 |
else touch "$tmp/$file.idx" |
| 148 |
fi |
| 149 |
} |
| 150 |
|
| 151 |
check_idx() |
| 152 |
{ |
| 153 |
test "$do_makeindex" -a -f "$file.idx" || return 0 |
| 154 |
if cmp -s "$file.idx" "$tmp/$file.idx" |
| 155 |
then : do nothing |
| 156 |
else makeindex "$file" |
| 157 |
run_tex=true |
| 158 |
fi |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
# Two functions that collect the functions above. |
| 163 |
|
| 164 |
save_aux_info() |
| 165 |
{ |
| 166 |
save_aux |
| 167 |
save_bibtex |
| 168 |
save_idx |
| 169 |
} |
| 170 |
|
| 171 |
check_aux_info() |
| 172 |
{ |
| 173 |
check_aux |
| 174 |
check_bibtex |
| 175 |
check_idx |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
# Process the document by TeX. Determine if TeX must be run anew by |
| 180 |
# the functions realized above. |
| 181 |
|
| 182 |
run_tex=true |
| 183 |
while [ "$run_tex" ] |
| 184 |
do save_aux_info |
| 185 |
"$@" |
| 186 |
run_tex='' |
| 187 |
check_aux_info |
| 188 |
done |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
#====================================================================== |
| 193 |
# |
| 194 |
# $ITIlog: tex-it,v $ |
| 195 |
# Revision 1.3 1995/06/14 10:49:12 schrod |
| 196 |
# HP-UX /bin/sh doesn't grok getopts, use ksh instead. |
| 197 |
# |
| 198 |
# Revision 1.2 1995/04/19 14:31:06 schrod |
| 199 |
# Support MakeIndex call, too. |
| 200 |
# |
| 201 |
# Revision 1.1 1995/03/14 17:07:26 schrod |
| 202 |
# Added script to process a TeX document. |
| 203 |
# |