-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetbsd_dolatex.csh
289 lines (256 loc) · 6.31 KB
/
netbsd_dolatex.csh
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/bin/csh
#
# Time-stamp: <2022/03/24 12:41:33 (CST) daisuke>
#
#
# NetBSD utils
#
# utility to carry out LaTeX commands and produce PS and PDF files
#
# author: Kinoshita Daisuke
#
# version 1.0: 19/Mar/2022
#
#
# usage:
#
# % netbsd_dolatex.csh foo.tex
#
# commands
set cat = /bin/cat
set rm = /bin/rm
set stat = /usr/bin/stat
set touch = /usr/bin/touch
set bibtex = /usr/pkg/bin/bibtex
set dvipdfmx = /usr/pkg/bin/dvipdfmx
set dvips = /usr/pkg/bin/dvips
set gs = /usr/pkg/bin/gs
set latex = /usr/pkg/bin/latex
set ps2pdfwr = /usr/pkg/bin/ps2pdfwr
# list of commands
set list_commands = ( $latex $bibtex $dvips $dvipdfmx $gs $ps2pdfwr )
# existence check of LaTeX and related commands
foreach command ($list_commands)
if (! -e $command) then
echo "ERROR: command '$command' is not found!"
echo "ERROR: install the command '$command' on your computer!"
exit
endif
end
# files and directories
set dir_tmp = /tmp
set file_usage = ${dir_tmp}/netbsd_dolatex_usage.$$
set file_commands = ${dir_tmp}/netbsd_dolatex_commands.$$
# initial values of parameters
set verbosity = 0
set do_bibtex = 0
set do_dvipdfmx = 0
set paper_size = "a4"
set list_files = ( )
set list_executed = ( )
set list_products = ( )
# usage message
$cat <<EOF > $file_usage
netbsd_dolatex.csh
Author: Kinoshita Daisuke (c) 2022
Usage:
-h : print usage
Examples:
execute latex and make a PDF file
% netbsd_dolatex.csh foo.tex
printing help
% netbsd_dolatex.csh -h
EOF
# command-line argument analysis
while ($#argv != 0)
switch ($argv[1])
# -h option
case "-h":
# printing usage
cat $file_usage
# deleting usage file
$rm -f $file_usage
# stop the script
exit
case "-b":
set do_bibtex = 1
breaksw
case "-d":
set do_dvipdfmx = 1
breaksw
case "-p":
set paper_size = $argv[2]
shift
breaksw
case "-v":
set verbosity = 1
breaksw
case -*:
# printing message
echo ""
echo "ERROR: '$argv[1]' is an invalid option!"
echo ""
# printing usage
cat $file_usage
# deleting usage file
$rm -f $file_usage
# stop the script
exit
default:
set list_files = ($list_files $argv[1])
endsw
shift
end
if !( ($paper_size == "a4") || ($paper_size == "letter") ) then
echo "ERROR: wrong value for paper size!"
echo "ERROR: value specified for paper size = $paper_size"
exit
endif
# option for ps2pdfwr
set opt_ps2pdfwr = "-sPAPERSIZE=$paper_size -dALLOWPSTRANSPARENCY"
# removing file_command if exists
if (-e $file_commands) then
$rm -f $file_commands
endif
# making an empty file
$touch $file_commands
# processing files one-by-one
foreach file_tex ($list_files)
# if the file is not TeX file, the skip
if ($file_tex:e != 'tex') then
echo "ERROR: the file '$file_tex' is not a LaTeX source file!"
echo "ERROR: skipping the file '$file_tex'..."
continue
endif
# DVI, PS, and PDF file names
set file_aux = ${file_tex:r}.aux
set file_bbl = ${file_tex:r}.bbl
set file_blg = ${file_tex:r}.blg
set file_dvi = ${file_tex:r}.dvi
set file_log = ${file_tex:r}.log
set file_nav = ${file_tex:r}.nav
set file_out = ${file_tex:r}.out
set file_ps = ${file_tex:r}.ps
set file_snm = ${file_tex:r}.snm
set file_pdf = ${file_tex:r}.pdf
set file_toc = ${file_tex:r}.toc
# intermediate files
set list_intermediate = ( $file_aux $file_bbl $file_blg \
$file_dvi $file_log $file_nav \
$file_out $file_snm $file_toc )
# all files
set list_all_files = ( $list_intermediate $file_ps $file_pdf )
# printing information
if ($verbosity) then
echo "# file names"
echo "# aux file = $file_aux"
echo "# bbl file = $file_bbl"
echo "# blg file = $file_blg"
echo "# dvi file = $file_dvi"
echo "# log file = $file_log"
echo "# nav file = $file_nav"
echo "# out file = $file_out"
echo "# ps file = $file_ps"
echo "# snm file = $file_snm"
echo "# pdf file = $file_pdf"
echo "# toc file = $file_toc"
endif
# removing intermediate files
foreach file_intermediate ($list_intermediate)
if ($verbosity) then
echo "# deleting file '$file_intermediate'..."
endif
$rm -f $file_intermediate
end
# latex commands
set command_latex = "$latex $file_tex"
set command_bibtex = "$bibtex $file_tex"
set command_dvips = "$dvips -o $file_ps $file_dvi"
set command_dvipdfmx = "$dvipdfmx $file_dvi"
set command_ps2pdfwr = "$ps2pdfwr $opt_ps2pdfwr $file_ps"
# bibtex
if ($do_bibtex) then
echo "#"
echo "# executing '$command_latex'"
echo "#"
$command_latex
$cat <<EOF >> $file_commands
# $command_latex
EOF
echo "#"
echo "# executing '$command_bibtex'"
echo "#"
$command_bibtex
$cat <<EOF >> $file_commands
# $command_bibtex
EOF
endif
# making PS file
echo "#"
echo "# executing '$command_latex'"
echo "#"
$command_latex
$cat <<EOF >> $file_commands
# $command_latex
EOF
echo "#"
echo "# executing '$command_latex'"
echo "#"
$command_latex
$cat <<EOF >> $file_commands
# $command_latex
EOF
echo "#"
echo "# executing '$command_dvips'"
echo "#"
$command_dvips
$cat <<EOF >> $file_commands
# $command_dvips
EOF
# making PDF file
if ($do_dvipdfmx) then
echo "#"
echo "# executing '$command_dvipdfmx'"
echo "#"
$command_dvipdfmx
$cat <<EOF >> $file_commands
# $command_dvipdfmx
EOF
else
echo "#"
echo "# executing '$command_ps2pdfwr'"
echo "#"
$command_ps2pdfwr
$cat <<EOF >> $file_commands
# $command_ps2pdfwr
EOF
endif
# products
foreach file ($list_all_files)
if (-e $file) then
set list_products = ( $list_products $file )
endif
end
end
echo "#"
echo "# Summary"
echo "#"
echo "# Executed commands"
echo "#"
$cat $file_commands
echo "#"
echo "# Created files"
echo "#"
foreach file ($list_products)
set size_byte = `$stat -f %z $file`
set mtime = `$stat -f %Sm $file`
printf "# %-32s %12d byte $mtime\n" $file $size_byte
end
echo "#"
# removing temporary files
if (-e $file_commands) then
$rm -f $file_commands
endif
if (-e $file_usage) then
$rm -f $file_usage
endif