1
2
3
4
5
6
7
8
9
10
11\startluacode
12local find = string.find
13local lpegmatch = lpeg.match
14
15local splitter = lpeg.Ct(lpeg.C(lpeg.patterns.nestedbraces + lpeg.patterns.utf8character)^1)
16
17function commands.xmfenced(left,middle,right,content)
18 local l = left ~= "" and left or "("
19 local r = right ~= "" and right or ")"
20 local m = middle ~= "" and middle and lpegmatch(splitter,middle) or { "," }
21 local c = find(content,"{") and lpegmatch(splitter,content) or { content }
22 local n = #c
23 if n > 1 then
24 context("\\left%s",l)
25 for i=1,n do
26 if i > 1 then
27 context("%s %s",m[i] or m[#m],c[i])
28 else
29 context(c[i])
30 end
31 end
32 context("\\right%s",r)
33 else
34 context("\\left%s %s \\right%s",l,content,r)
35 end
36end
37
38\stopluacode
39
40\unprotect
41
42\unexpanded\def\mexecuteifdefined#1
43 {\ifx#1\empty
44 \expandafter\secondoftwoarguments
45 \else\ifcsname#1\endcsname
46 \doubleexpandafter\firstoftwoarguments
47 \else
48 \doubleexpandafter\secondoftwoarguments
49 \fi\fi
50 {\csname#1\endcsname}}
51
52
53
54\let\mrow\mathematics
55
56
57
58\starttexdefinition msub #1#2
59 \mathematics {
60 #1{#2}
61 }
62\stoptexdefinition
63
64\starttexdefinition msup #1#2
65 \mathematics {
66 #1{#2}
67 }
68\stoptexdefinition
69
70\starttexdefinition msubsup #1#2#3
71 \mathematics {
72 #1{#2}{#3}
73 }
74\stoptexdefinition
75
76
77
78\let\mn\mathematics
79\let\mo\mathematics
80\let\mi\mathematics
81
82
83
84\starttexdefinition ms #1
85 \text {
86 "#1"
87 }
88\stoptexdefinition
89
90
91
92
93
94
95
96
97
98\starttexdefinition unexpanded moverabove #1
99 \edef\movercommand{\utfmathfiller\movertoken}
100 \mexecuteifdefined\movercommand {#1} \relax
101\stoptexdefinition
102\starttexdefinition unexpanded moverbase #1
103 \edef\mbasecommand{\utfmathfiller\mbasetoken}
104 \mexecuteifdefined\mbasecommand {#1}
105 \relax
106\stoptexdefinition
107\starttexdefinition unexpanded moverbasefiller #1#2
108 \edef\mbasecommand{e\utfmathcommandfiller\mbasetoken}
109 \mexecuteifdefined\mbasecommand \relax {#2} {}
110\stoptexdefinition
111\starttexdefinition unexpanded moveraccent #1#2
112 \edef\movercommand{\utfmathcommandabove\movertoken}
113 \mexecuteifdefined\movercommand \relax {#1}
114\stoptexdefinition
115\starttexdefinition unexpanded movertext #1#2
116
117 \mathtriplet {\mathematics{#1}} {#2} {}
118\stoptexdefinition
119\starttexdefinition unexpanded moveraccentchecker #1#2
120 \edef\movertoken{\tochar{#2}}
121 \doifelseutfmathabove\movertoken \moveraccent \movertext {#1}{#2}
122\stoptexdefinition
123
124\starttexdefinition unexpanded mover #1#2
125 \mathematics {
126 \edef\mbasetoken{\tochar{#1}}
127 \doifelseutfmathfiller\mbasetoken \moverbasefiller \moveraccentchecker {#1}{#2}
128 }
129\stoptexdefinition
130
131
132
133\starttexdefinition unexpanded munderbelow #1
134 \edef\mundercommand{\utfmathfiller\mundertoken}
135 \mexecuteifdefined\mundercommand {#1} \relax
136\stoptexdefinition
137\starttexdefinition unexpanded munderbase #1
138 \edef\mbasecommand{\utfmathfiller\mbasetoken}
139 \mexecuteifdefined\mbasecommand {#1}
140 \relax
141\stoptexdefinition
142\starttexdefinition unexpanded munderbasefiller #1#2
143 \edef\mbasecommand{e\utfmathcommandfiller\mbasetoken}
144 \mexecuteifdefined\mbasecommand \relax {#2} {}
145\stoptexdefinition
146\starttexdefinition unexpanded munderaccent #1#2
147 \edef\mundercommand{\utfmathcommandbelow\mundertoken}
148 \mexecuteifdefined\mundercommand \relax {#1}
149\stoptexdefinition
150\starttexdefinition unexpanded mundertext #1#2
151
152 \mathtriplet {\mathematics{#1}} {} {#2}
153\stoptexdefinition
154\starttexdefinition unexpanded munderaccentchecker #1#2
155 \edef\mundertoken{\tochar{#2}}
156 \doifelseutfmathbelow\mundertoken \munderaccent \mundertext {#1}{#2}
157\stoptexdefinition
158
159\starttexdefinition unexpanded munder #1#2
160 \mathematics {
161 \edef\mbasetoken{\tochar{#1}}
162 \doifelseutfmathfiller\mbasetoken \munderbasefiller \munderaccentchecker {#1}{#2}
163 }
164\stoptexdefinition
165
166
167
168
169
170
171
172
173
174
175
176\starttexdefinition unexpanded mfenced
177 \dotripleempty\do_mfenced
178\stoptexdefinition
179
180\starttexdefinition unexpanded domfenced [#1][#2][#3]#4
181 \mathematics {
182 \ctxcommand{xmfenced(
183 \ifthirdargument "#1","#2","#3"\else
184 \ifsecondargument "#1",",","#2"\else
185 \iffirstargument "(","#1",")"\else
186 "(",",",")"\fi\fi\fi
187 ,"#4")}
188 }
189\stoptexdefinition
190
191
192
193\starttexdefinition unexpanded mfrac #1#2
194 \mathematics {
195 \frac{#1}{#2}
196 }
197\stoptexdefinition
198
199
200
201\starttexdefinition unexpanded mroot #1#2
202 \mathematics {
203 \sqrt[#1]{#2}
204 }
205\stoptexdefinition
206
207\starttexdefinition unexpanded msqrt #1
208 \mathematics {
209 \sqrt{#1}
210 }
211\stoptexdefinition
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235\protect
236
237\continueifinputfile{xmathmlbasics.mkiv}
238
239\starttext
240
241$\mfenced{1a}$\par
242$\mfenced[,]{1a}$\par
243$\mfenced[,]{{1a}{1b}}$\par
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\stoptext
277 |