summaryrefslogtreecommitdiff
path: root/support/kamal/TEX
blob: 149b69bf687db75fb984ae7c56e8c3e44dc81c83 (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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#! /bin/csh -f
#
# Usage: TEX [-flags ...] filename
#
# The various flags are described below, but only one filename should
# be given; stdin is not used. File types are indicated by the filename
# suffix. Input files may have one of the following suffixes:
#	.tex -- a file with tex commands, equations.
#	.dvi -- device independent format.
#	.ver -- output of verser1 (for the varian or AED)
#	.imp -- output of dvi-imagen (or dviimp)
# Anything else is assumed to be in .tex format.
# If TEX sees a .dvi, .ver, or .imp suffix, it will skip ahead to the right
# point in the processing sequence. Specifically,
#	texeqn	accepts .tex, outputs .tex
#	tex	accepts .tex, outputs .dvi and .log
#	latex	accepts .tex, outputs .dvi and .log
#	verser1	accepts .dvi, outputs .ver (for the varian or AED, not on hanuma).
#	lpr	accepts .ver, outputs raster
#	ipr	accepts	.imp, outputs raster
#
# Flags:
# -latex uses LaTeX.
# -log	 saves a log file from the tex run in filename.log.
# -d	 quits once the .dvi file has been made.
# -x	 makes two passes on the (latex) input, so cross-references
#	 are resolved.
# -v	 output device is the varian (imagen is the default)
# -q	 quits once the .imp file has been made if the imagen is the target printer
#	 or after the .ver file	(i.e. after verser1 stage) if the AED or the varian
#	 is the target printer.
# -eqn	 strips out the equations with texeqn and typeset them.
#
# Authors: Kamal Al-Yahya, Jeff Thorson, and Chuck Sword, Stanfor University
#
umask 0
onintr removal
set name=() host=()
set destdir = /usr/local
set tmp = TEX$$
set device = imagen
set st = 0
unset latex x d q eqn log

if ($#argv == 0) then
	echo "usage: TEX [-latex] [-eqn] [-log] [-d] [-q] [-x] filename"
	exit(-1)
endif

while ($#argv > 0 && !($?inf))
	switch ($argv[1])
		case -latex:
			set latex
			breaksw

		case -x:
			set x
			breaksw

		case -q:
			set q
			breaksw

		case -d:
			set d
			breaksw

		case -v:
			set device = varian
			breaksw

		case -eqn:
			set eqn
			breaksw

		case -log:
			set log
			breaksw

		case -*:
			echo unknown flag $argv[1], ignored
			breaksw
                default:
			set inf = $argv[1]
			if !(-e $inf) then

#  filename not found, try with .tex ending

				if !(-e $inf.tex) then 
					echo $0 'cannot find file' $inf.
					exit(-1)
				else
					set inf = ($inf.tex)
				endif
			endif
			breaksw
		endsw
	shift argv
end

set name = $inf:t
set sname = $name:r
set name = $cwd/$name
set suffix = $name:e

if ($suffix == dvi) then
	echo TEX: starting with .dvi file
	set name = $name:r
	set dvifile = $inf
	goto dvi
endif

if ($suffix == ver) then
	echo TEX: starting with .ver file
	set name = $name:r
	set verfile = $inf
	goto ver
endif

if ($suffix == imp) then
	echo TEX: starting with .imp file
	set name = $name:r
	set impfile = $inf
	goto imp
endif

if ($suffix == tex || $suffix == eqn) then
	set name = $name:r
endif

echo "\batchmode" > $tmp.tex

if ($?eqn) then
	$destdir/texeqn < $inf >> $tmp.tex
else
	cat $inf >> $tmp.tex
endif

echo "\bye" >> $tmp.tex

# Choose tex or latex

if ($?latex) then
	if (-e $name.aux) then
		cp $name.aux $tmp.aux
	endif
	$destdir/latex $tmp:t
	if ($status != 0) then
		goto oops
	else
		if (-e $tmp.aux) then
			cp $tmp.aux $name.aux
		endif
	endif

	if ($?x) then
		echo "Starting second pass"
		$destdir/latex $tmp
		if ($status != 0) then
			goto oops
		endif
		if (-e $tmp.aux) then
			cp $tmp.aux $name.aux
		endif
	endif

else	$destdir/tex $tmp
	if ($status != 0) then
oops:
		echo TEX could not process your file.
		echo Error messages are in $name.log
		mv -f $tmp.log $name.log
		set st = -1
		goto removal
	endif
endif

if ($?log) then
	mv -f $tmp.log $name.log
	if (-e $tmp.aux) then
		mv -f $tmp.aux $name.aux
	endif
endif

set dvifile = $tmp.dvi

if ($?d) then
	mv -f $dvifile $name.dvi
	goto removal
endif

dvi:

if($device == imagen) then
	$destdir/dvi-imagen -s $dvifile > $tmp.imp
	if ($?q) then
		mv -f $tmp.imp $name.imp
		goto removal
	endif
	set impfile = $tmp.imp
imp:
	(echo -n \@document\(owner \"$user\", site \"$host\", spooldate \
	\"`date`\", language \"imPress\", jobheader off, \
	jamresistance on\) ; cat $impfile ) | $destdir/ipr
	goto removal
endif

if($device == varian) then
	$destdir/verser1 < $dvifile > $tmp.ver
	if ($status != 0) then
		echo TEX bombed out on verser1.
		set st = -1
		goto removal
	endif
	set verfile = $tmp.ver

	if ($?q) then
		mv -f $verfile $name.ver
		goto removal
	endif
ver:
	lpr -d -s -Pvarian $tmp.ver
endif

removal:
/bin/rm -f $tmp.tex $tmp.log $tmp.dvi $tmp.ver $tmp.imp $tmp.aux
exit($st)