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
|
#### MAKEFILE CONFIG ####
SHELL = /bin/sh
.SILENT:
.SUFFIXES:
#### BEGIN ####
help:
echo 'UNICODE-MATH makefile targets:'
echo ' '
echo ' help - (this message)'
echo ' ctan - generate archive for CTAN'
echo ' doc - compile documentation inside build/'
echo ' clean - remove build directory and compiled files'
echo ' all - clean & doc & ctan'
echo ' '
echo ' install - install the package into your home texmf tree'
echo ' install-sys - install the package into the system-wide texmf tree'
echo ' (may require administration privileges)'
echo ' install TEXMF=<texmf> - install the package into the path <texmf>'
echo ' '
echo ' check - run the test suite'
echo ' initest - initialise any new tests'
echo ' '
echo ' xfile F=<abc> - compile file <abc> with XeLaTeX'
echo ' lfile F=<abc> - compile file <abc> with LuaLaTeX'
echo ' '
echo 'To add a new test, add a file called X****.ltx to'
echo 'directory testfiles/, run `make initest` and ensure'
echo 'that the output X****.safe.pdf is correct.'
echo ' '
echo '`make test` will then compare future compilations of the'
echo 'test file against this original and warn against any changes.'
echo '`make build/X****.diff.pdf` will check a single test.'
echo ' '
echo 'I recommend `make -j4 check` or thereabouts to parallelise'
echo 'the testing.'
#### SETUP ####
# file and folder names:
PKG = unicode-math
TBL = $(PKG)-table.tex
SUITE = $(PKG)-testsuite
XMPL = unimath-example.ltx
SYM = unimath-symbols
COPY = cp -a
testdir=testfiles
builddir=build
tds=$(builddir)/$(PKG).tds
UPDATE = `which dtx-update` || true # TODO: generalise
# these files end up in the CTAN directory:
PKGSOURCE = $(PKG).dtx $(TBL) Makefile
DOC = $(PKG).pdf $(SUITE).pdf README $(XMPL) $(SYM).pdf
CTANFILES = $(PKGSOURCE) $(DOC) $(testdir)
BUILDCTAN = $(addprefix $(builddir)/,$(CTANFILES))
BUILDDOC = $(addprefix $(builddir)/,$(DOC))
# these are what's needed to compile and make stuff:
LTXSOURCE = $(PKG).sty $(TBL)
SUITESOURCE = \
umtest-preamble.tex \
umtest-suite-X.tex \
umtest-suite-L.tex
TESTOUT = $(shell ls $(testdir)/*.safe.pdf)
BUILDTESTSRC = $(subst $(testdir)/,$(builddir)/,$(subst .safe.pdf,.ltx,$(TESTOUT)))
BUILDTESTTARGET = $(subst $(testdir)/,$(builddir)/,$(subst .safe.pdf,.diff.pdf,$(TESTOUT)))
BUILDSOURCE = $(addprefix $(builddir)/,$(LTXSOURCE))
BUILDSUITE = $(addprefix $(builddir)/,$(SUITESOURCE))
BUILDFILES = $(BUILDSOURCE) $(BUILDSUITE) $(BUILDTESTSRC)
# and this is how the TDS zip file is produced:
INSFILES = \
$(tds)/tex/latex/$(PKG)/unicode-math.sty \
$(tds)/tex/latex/$(PKG)/unicode-math-table.tex
OTHERFILES = \
$(tds)/source/latex/$(PKG)/$(PKG).dtx \
$(tds)/source/latex/$(PKG)/$(SUITE).ltx \
$(tds)/source/latex/$(PKG)/$(SYM).ltx \
$(tds)/source/latex/$(PKG)/Makefile \
$(tds)/source/latex/$(PKG)/$(testdir) \
$(tds)/doc/latex/$(PKG)/unicode-math.pdf \
$(tds)/doc/latex/$(PKG)/unicode-math-testsuite.pdf \
$(tds)/doc/latex/$(PKG)/README \
$(tds)/doc/latex/$(PKG)/$(XMPL) \
$(tds)/doc/latex/$(PKG)/$(SYM).pdf \
TDSFILES = $(INSFILES) $(OTHERFILES)
#### BASICS ####
doc: $(BUILDDOC)
README:
$(XMPL):
clean:
rm -rf $(builddir)
rm -f $(PKG).zip $(PKG).pdf $(SUITE).pdf
all: clean doc ctan
#### BUILD FILES
$(builddir)/$(PKG).dtx: $(PKG).dtx
mkdir -p $(builddir)
$(UPDATE)
$(COPY) $< $@
$(builddir)/$(PKG).sty: $(builddir)/$(PKG).dtx
echo "Updating $@"
cd $(builddir); \
tex $(PKG).dtx > /dev/null ;
$(builddir)/$(PKG).pdf: $(builddir)/$(PKG).dtx $(BUILDSOURCE)
cd $(builddir); \
xelatex $(PKG).dtx && \
makeindex -s gind.ist $(PKG) && \
xelatex $(PKG).dtx;
$(builddir)/$(SYM).pdf: $(builddir)/$(SYM).ltx
cd $(builddir); \
xelatex $(SYM).ltx && \
xelatex $(SYM).ltx;
$(builddir)/%.ltx: $(testdir)/%.ltx
$(COPY) $< $@
$(builddir)/%.tex: $(testdir)/%.tex
$(COPY) $< $@
$(builddir)/$(testdir): $(testdir)
$(COPY) $< $@
$(builddir)/%: %
$(COPY) $< $@
$(builddir)/README: $(builddir)/README.markdown
mv -f $< $@
# Test suite PDF
$(builddir)/$(SUITE).pdf: $(builddir)/$(SUITE).ltx $(BUILDSUITE) $(builddir)/$(testdir)
cd $(builddir); \
xelatex $(SUITE).ltx
##### CTAN INSTALLATION #####
tds: $(builddir)/$(PKG).tds.zip
$(builddir)/$(PKG).tds.zip: $(tds)/$(PKG).tds.zip
$(COPY) $< $@
$(tds)/$(PKG).tds.zip: $(TDSFILES)
cd $(tds); \
zip -r $(PKG).tds.zip ./* -x *.DS_Store -x *.safe.pdf
ctan: $(BUILDCTAN) tds
cd $(builddir); \
zip -r \
../$(PKG).zip $(CTANFILES) $(PKG).tds.zip \
-x *.DS_Store -x *.safe.pdf
$(tds)/doc/latex/$(PKG)/% \
$(tds)/tex/latex/$(PKG)/% \
$(tds)/source/latex/$(PKG)/% : $(builddir)/%
mkdir -p $(shell dirname $@)
$(COPY) $< $@
$(tds)/source/latex/$(PKG)/$(testdir):
$(COPY) $(testdir) $(tds)/source/latex/$(PKG)/
##### LOCAL TEXMF INSTALLATION #####
TEXMFHOME=$(shell kpsewhich --var-value TEXMFHOME)
TEXMFLOCAL=$(shell kpsewhich --var-value TEXMFLOCAL)
install: $(INSFILES)
if test -n "$(TEXMFHOME)" ; then \
echo "Installing in '$(TEXMFHOME)'."; \
$(COPY) $(tds)/* $(TEXMFHOME); \
else \
echo "Cannot locate your home texmf tree. Specify manually with\n\n make install TEXMFHOME=/path/to/texmf\n" ; \
false ; \
fi ;
install-sys: $(INSFILES)
if test -n "$(TEXMFLOCAL)" ; then \
echo "Installing in '$(TEXMFLOCAL)'."; \
$(COPY) $(tds)/* $(TEXMFLOCAL); \
else \
echo "Cannot locate your system-wide local texmf tree. Specify manually with\n\n make install TEXMFLOCAL=/path/to/texmf\n" ; \
false ; \
fi ;
##### USEFUL FOR TEST FILES #####
xfile: $(F) $(BUILDSOURCE)
if test -z "$(F)" ; then \
echo "Need a filename!\nE.g. \`make xfile F=test.ltx\`" ; \
false ; \
fi
echo Typesetting $(F):
$(COPY) $(F) $(builddir)/$(F)
cd $(builddir); xelatex $(F)
lfile: $(F) $(BUILDSOURCE)
if test -z "$(F)" ; then \
echo "Need a filename!\nE.g. \`make lfile F=test.ltx\`" ; \
false ; \
fi
echo Typesetting $(F):
$(COPY) $(F) $(builddir)/$(F)
cd $(builddir); lualatex $(F)
#############
# TESTSUITE #
#############
#### All tests ####
check: $(BUILDFILES) $(BUILDTESTTARGET)
cd $(testdir); \
ls X*.ltx | sed -e 's/\(.*\).ltx/\\inserttest{\1}/g' > umtest-suite-X.tex; \
ls L*.ltx | sed -e 's/\(.*\).ltx/\\inserttest{\1}/g' > umtest-suite-L.tex;
#### Each step of the process ####
COMPARE_OPTS = -metric AE -density 300x300
PIXEL_TOLERANCE = 1
$(builddir)/%.diff.pdf: $(builddir)/%.pdf
echo '$*: Comparing with reference PDF.'
if [ ${shell compare $(COMPARE_OPTS) $(builddir)/$*.pdf $(testdir)/$*.safe.pdf $(builddir)/$*.diff.pdf 2>&1} -le $(PIXEL_TOLERANCE) ] ; then \
echo '$*: Test passed.' ; \
else \
echo '$*: Test failed.' ; \
false ; \
fi
$(builddir)/X%.pdf: $(BUILDSOURCE) $(BUILDSUITE) $(builddir)/X%.ltx
echo 'X$*: Generating PDF output from XeLaTeX.'
cd $(builddir); xelatex -interaction=batchmode X$*.ltx > /dev/null
$(builddir)/L%.pdf: $(BUILDSOURCE) $(BUILDSUITE) $(builddir)/L%.ltx
echo 'L$*: Generating PDF output from LuaLaTeX.'
cd $(builddir); lualatex -interaction=batchmode L$*.ltx > /dev/null
#### Generating new tests ####
lonelystub = $(shell cd $(testdir); ls | egrep '(.*\.ltx)|(.*\.safe.pdf)' | cut -d . -f 1 | uniq -u)
lonelytest = $(addprefix $(testdir)/,$(addsuffix .safe.pdf,$(lonelystub)))
lonelytesttarget = $(addprefix $(builddir)/,$(addsuffix .pdf,$(lonelystub)))
initest: $(lonelytest)
$(lonelytest): $(lonelytesttarget)
$(COPY) `echo $@ | sed -e s/$(testdir)/$(builddir)/ -e s/.safe.pdf/.pdf/` $@
|