1
2
3
4
5
6
7
8
9
10
11
12
13
14\registerctxluafile { x asciimath }{}
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\usemodule [ mathml basics ]
131
132\startmodule [ asciimath ]
133
134\unprotect
135
136\writestatus { asciimath }{ beware , this is an experimental ( m 4 all only ) module }
137
138
139
140\unexpanded \def \asciimathoptext # 1 { \ifmmode \mathoptext { # 1 } \else # 1 \fi }
141\unexpanded \def \asciimathoptexttraced # 1 { \ifmmode \mathoptext { \color [ darkgreen ] { # 1 }} \else \color [ darkgreen ] { # 1 } \fi }
142\unexpanded \def \asciimathstackrel # 1 # 2 { \mathematics { \mathop { \let\limits\relax \mover { # 2 }{ # 1 }}}}
143\unexpanded \def \asciimathroot # 1 # 2 { \sqrt [# 1 ] { # 2 }}
144\unexpanded \def \asciimathsqrt # 1 { \sqrt { # 1 }}
145
146
147
148
149
150\installsetuponlycommandhandler { asciimath } { asciimath }
151
152\appendtoks
153 \ctxlua{ moduledata . asciimath . setup {
154 splitmethod = " \asciimathparameter\c!splitmethod " ,
155 separator = " \asciimathparameter\c!separator " ,
156 symbol = " \asciimathparameter\c!symbol " ,
157 } }
158\to \everysetupasciimath
159
160\newtoks \everyasciimath
161
162
163
164
165
166\appendtoks
167 \enableautofences
168 \enableautofencemode
169\to \everyasciimath
170
171\unexpanded \def \asciimath
172 { \doifnextoptionalelse \asciimath_yes \asciimath_nop }
173
174\def \asciimath_yes [# 1 ]# 2
175 { \mathematics
176 [# 1 ]
177 { \the \everyasciimath
178 \clf_justasciimath { \detokenize\expandafter { \normalexpanded { # 2 }}}}}
179
180\def \asciimath_nop # 1
181 { \mathematics
182 { \the \everyasciimath
183 \clf_justasciimath { \detokenize\expandafter { \normalexpanded { # 1 }}}}}
184
185
186
187
188\unexpanded \def \xmlasciimath
189 { \doifnextoptionalelse \xmlasciimath yes \xmlasciimath nop }
190
191\def \xmlasciimath yes [# 1 ]# 2
192 { \mathematics
193 [# 1 ]
194 { \the \everyasciimath
195 \clf_xmlasciimath { # 2 }}}
196
197\def \xmlasciimath nop # 1
198 { \mathematics
199 { \the \everyasciimath
200 \clf_xmlasciimath { # 1 }}}
201
202\unexpanded \def \ctxmoduleasciimath # 1
203 { \ctxlua{ moduledata . asciimath . # 1 } }
204
205
206
207
208\unexpanded \def \ShowAsciiMathLoad [# 1 ] { \ctxlua{ moduledata . asciimath . show . load ( " #1 " ) } }
209\unexpanded \def \ShowAsciiMathIgnore [# 1 ] { \ctxlua{ moduledata . asciimath . show . ignore ( " #1 " ) } }
210\unexpanded \def \ShowAsciiMathXML # 1 # 2 { \ctxlua{ moduledata . asciimath . show . filter ( " #1 " , " #2 " ) } }
211\unexpanded \def \ShowAsciiMathStats { \ctxlua{ moduledata . asciimath . show . statistics ( ) } }
212\unexpanded \def \ShowAsciiMathMax { \ctxlua{ moduledata . asciimath . show . max ( ) } }
213
214\unexpanded \def \ShowAsciiMathResult # 1
215 { \begingroup
216 \blank
217
218 \inleft { \ttbf # 1 \hfill \ctxlua{ moduledata . asciimath . show . count ( # 1 , true ) } }
219 \dontleavehmode
220 \begingroup
221 \ttbf
222 \ctxlua{ moduledata . asciimath . show . files ( # 1 ) }
223 \endgroup
224 \blank [ medium , samepage ]
225 \startcolor [ darkblue ]
226 \ctxlua{ moduledata . asciimath . show . input ( # 1 , true ) }
227 \stopcolor
228 \blank [ medium , samepage ]
229 \doifmode { asciimath : show : dirty } {
230 \dorecurse { \ctxlua{ moduledata . asciimath . show . nofdirty ( # 1 ) } } {
231 \ctxlua{ moduledata . asciimath . show . dirty ( \recurselevel , true ) }
232 \blank [ medium , samepage ]
233 }
234 }
235 \ctxlua{ moduledata . asciimath . show . result ( # 1 ) }
236 \blank
237 \endgroup }
238
239\unexpanded \def \ShowAsciiMathStart
240 { \begingroup
241 \let \asciimathoptext \asciimathoptexttraced
242 \setuptyping [ \v!buffer ][ \c!before = , \c!after =]
243 \setupmargindata [ \v!left ][ \c!style =] }
244
245\unexpanded \def \ShowAsciiMathStop
246 { \endgroup }
247
248\unexpanded \def \ShowAsciiMath
249 { \dodoubleempty \doShowAsciiMath }
250
251\unexpanded \def \doShowAsciiMath [# 1 ][# 2 ]
252 { \iffirstargument
253 \ShowAsciiMathStart
254 \ShowAsciiMathLoad [# 1 ]
255 \ifsecondargument
256 \ShowAsciiMathIgnore [# 2 ]
257 \fi
258 \dorecurse { \ShowAsciiMathMax }{ \ShowAsciiMathResult \recurselevel }
259 \page
260 \ShowAsciiMathStats
261 \ShowAsciiMathStop
262 \fi }
263
264\unexpanded \def \xmlShowAsciiMath # 1 # 2
265 { \iffirstargument
266 \ShowAsciiMathStart
267 \ShowAsciiMathXML { # 1 }{ # 2 }
268 \dorecurse { \ShowAsciiMathMax }{ \ShowAsciiMathResult \recurselevel }
269 \page
270 \ShowAsciiMathStats
271 \ShowAsciiMathStop
272 \fi }
273
274\unexpanded \def \ShowAsciiMathSave
275 { \dosingleempty \doShowAsciiMathSave }
276
277\unexpanded \def \doShowAsciiMathSave [# 1 ]
278 { \ctxlua{ moduledata . asciimath . show . save ( " #1 " ) } }
279
280\protect
281
282\startsetups asciimath : layout
283
284 \setupbodyfont
285
286 [ dejavu , 1 0 pt ]
287
288 \setuplayout
289 [ backspace = 3 5 mm ,
290 leftmargin = 2 0 mm ,
291 rightmargindistance = 0 pt ,
292 leftmargindistance = 5 mm ,
293 cutspace = 1 cm ,
294 topspace = 1 cm ,
295 bottomspace = 1 cm ,
296 width = middle ,
297 height = middle ,
298 header = 0 cm ,
299 footer = 1 cm ]
300
301 \setupheadertexts
302 []
303
304 \setupfootertexts
305 [ \currentdate ][ \pagenumber ]
306
307 \setupalign
308 [ flushleft , verytolerant , stretch ]
309
310 \dontcomplain
311
312\stopsetups
313
314\stopmodule
315
316\continueifinputfile { x asciimath . mkiv }
317
318
319
320\starttext
321
322\setups [ asciimath : layout ]
323
324
325
326
327
328
329
330
331
332
333\subject { Some tests }
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500\stoptext
501 |