summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/cweb/examples/tex-it
blob: 07a8e98ad31208ed4d93f2070543bbba96c87f0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/sh
# $ITI: tex-it,v 1.3 1995/06/14 10:49:12 schrod Exp $
#----------------------------------------------------------------------

#
# tex-it  ---  transform a TeX document to a final DVI file
#
# (history at end)


# SYNOPSIS
#
#	tex-it [-bi] tex-cmd file
#
# tex-it runs 'tex-cmd' on 'file' as often as necessary to produce a
# DVI file where all cross references are resolved. That convergence
# is reached by analyzing auxilliary files:
#  -- If file.toc has changed, the table of contents is not up to date.
#  -- If file.idx has changed, the index is not up to date.
#     MakeIndex is assumed to be used for creating the index.
#  -- If file.aux has changed, cross references are not up to date.
#  -- If file.aux contains a "\bibdata" tag and if the set of
#     "\citation" tags have changed, then BibTeX is run.
#
# No other auxilliary files are handled. No subdocuments (via
# "\include") are supported.
#
# 'tex-cmd' may be more than one word.
#
#
# OPTIONS
#   `-b'	skip test for BibTeX
#   `-i'	skip test for MakeIndex

# NOTE: On HP-UX this script is not functional, you have to substitute
# /bin/sh by /bin/ksh in the first line. (/bin/sh doesn't have the
# getopts builtin.)


cmd=`basename $0`
usage()
{
	echo "usage: $cmd [-bi] tex-cmd file" >&2
	exit 1
}


# Normalize and check arguments.

do_bibtex=true
do_makeindex=true
while getopts 'bi' option
   do	case "$option" in
	    b)	do_bibtex=''
		;;
	    i)	do_makeindex=''
		;;
	    *)	usage
		;;
	esac
   done

shift `expr $OPTIND - 1`
test $# -gt 0  ||  usage


# Get file name (last argument), discard extension if necessary.

file=`eval "echo \\$$#"`
file=`echo $file | sed 's/\.[^.]*//'`


# Create temporary directory for auxilliary files to compare. Discard
# that directory if the script is terminated. Note that trap handler
# for 0 is executed at the end of the trap handler for the other
# signals.

tmp=/tmp/tex$$
trap "/bin/rm -rf $tmp" 0
trap "exit 4" 1 2 3 15
mkdir $tmp


# ------------------------------------------------------------
#
# Set up functions that save auxilliary information and check if they
# have changed. Save functions are called `save_<type>', check
# functions are called `check_<type>'. Check functions set $run_tex to
# "true" if TeX must be run anew. Check functions may run programs to
# create other auxilliary files.


# aux: table of contents & cross references
#
# We don't check for *.toc files. LaTeX stores the information in the
# AUX file anyhow, and plain-based macros typically produce the table
# of contents at the end of the document, when it's guaranteed to be
# OK.

save_aux()
{
	if [ -f "$file.aux" ]
	   then	cp "$file.aux" $tmp
	   else	touch "$tmp/$file.aux"
	fi
}

check_aux()
{
	test -f "$file.aux"  ||  return 0
	cmp -s "$file.aux" "$tmp/$file.aux"  ||  run_tex=true
}


# bibtex: Citations

save_bibtex()
{
	if [ -f "$file.aux" ]
	   then	egrep '^\\(citation|bibdata)' "$file.aux"  |
			sort >"$tmp/$file.bib"
	   else	touch "$tmp/$file.bib"
	fi
}


check_bibtex()
{
	test "$do_bibtex" -a -f "$file.aux"  ||  return 0
	egrep '^\\(citation|bibdata)' "$file.aux"  |  sort >$tmp/bib.new
	if grep '^\\bibdata' $tmp/bib.new >/dev/null
	   then	if cmp -s "$tmp/$file.bib" $tmp/bib.new
		   then	: do nothing
		   else	bibtex "$file"
			run_tex=true
		fi
	fi
}


# idx: raw index data

save_idx()
{
	if [ -f "$file.idx" ]
	   then	cp "$file.idx" $tmp
	   else	touch "$tmp/$file.idx"
	fi
}

check_idx()
{
	test "$do_makeindex" -a -f "$file.idx"  ||  return 0
	if cmp -s "$file.idx" "$tmp/$file.idx"
	   then	: do nothing
	   else	makeindex "$file"
		run_tex=true
	fi
}


# Two functions that collect the functions above.

save_aux_info()
{
	save_aux
	save_bibtex
	save_idx
}

check_aux_info()
{
	check_aux
	check_bibtex
	check_idx
}


# Process the document by TeX. Determine if TeX must be run anew by
# the functions realized above.

run_tex=true
while [ "$run_tex" ]
   do	save_aux_info
	"$@"
	run_tex=''
	check_aux_info
   done



#======================================================================
#
# $ITIlog: tex-it,v $
# Revision 1.3  1995/06/14  10:49:12  schrod
#     HP-UX /bin/sh doesn't grok getopts, use ksh instead.
#
# Revision 1.2  1995/04/19  14:31:06  schrod
#     Support MakeIndex call, too.
#
# Revision 1.1  1995/03/14  17:07:26  schrod
#     Added script to process a TeX document.
#