summaryrefslogtreecommitdiff
path: root/tex/context/base/x-mathml-basics.mkiv
blob: e166995b0c8f6772620714865df1a2c34497992f (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
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
% macros=mkvi

% makes sense (but rel vs op ...):

% \unexpanded\def\stackrel#1#2{\mathematics{\mathop{\let\limits\relax\mover{#2}{#1}}}}

% this can become a core helper

% bwe could do all of them in lua

\startluacode
local find = string.find
local lpegmatch = lpeg.match

local splitter = lpeg.Ct(lpeg.C(lpeg.patterns.nestedbraces + lpeg.patterns.utf8character)^1)

function commands.xmfenced(left,middle,right,content)
    local l = left   ~= "" and left   or "("
    local r = right  ~= "" and right  or ")"
    local m = middle ~= "" and middle and lpegmatch(splitter,middle) or { "," }
    local c = find(content,"{") and lpegmatch(splitter,content) or { content }
    local n = #c
    if n > 1 then
        context("\\left%s",l)
        for i=1,n do
            if i > 1 then
                context("%s %s",m[i] or m[#m],c[i])
            else
                context(c[i])
            end
        end
        context("\\right%s",r)
    else
        context("\\left%s %s \\right%s",l,content,r)
    end
end

\stopluacode

\unprotect

\unexpanded\def\mexecuteifdefined#1%
  {\ifx#1\empty
     \expandafter\secondoftwoarguments
   \else\ifcsname#1\endcsname
     \doubleexpandafter\firstoftwoarguments
   \else
     \doubleexpandafter\secondoftwoarguments
   \fi\fi
   {\csname#1\endcsname}}

% mrow

\let\mrow\mathematics

% msub msup  msubsup

\starttexdefinition msub #1#2
    \mathematics {
        #1_{#2}
    }
\stoptexdefinition

\starttexdefinition msup #1#2
    \mathematics {
        #1^{#2}
    }
\stoptexdefinition

\starttexdefinition msubsup #1#2#3
    \mathematics {
        #1_{#2}^{#3}
    }
\stoptexdefinition

% mn mo mi

\let\mn\mathematics
\let\mo\mathematics
\let\mi\mathematics

% ms  mtext

\starttexdefinition ms #1
    \text {
        "#1"
    }
\stoptexdefinition

\starttexdefinition mtext #1
    \text {
        #1
    }
\stoptexdefinition

% mover

\starttexdefinition unexpanded moverabove #1
    \edef\movercommand{\utfmathfiller\movertoken}
    \mexecuteifdefined\movercommand {#1} \relax
\stoptexdefinition
\starttexdefinition unexpanded moverbase #1
    \edef\mbasecommand{\utfmathfiller\mbasetoken}
    \mexecuteifdefined\mbasecommand {#1}
    \relax
\stoptexdefinition
\starttexdefinition unexpanded moverbasefiller #1#2
    \edef\mbasecommand{e\utfmathcommandfiller\mbasetoken}
    \mexecuteifdefined\mbasecommand \relax {#2} {}
\stoptexdefinition
\starttexdefinition unexpanded moveraccent #1#2
    \edef\movercommand{\utfmathcommandabove\movertoken}
    \mexecuteifdefined\movercommand \relax {#1}
\stoptexdefinition
\starttexdefinition unexpanded movertext #1#2
  % \mathtriplet {\mathstylehbox{#1}} {#2} {}
    \mathtriplet {\mathematics{#1}} {#2} {}
\stoptexdefinition
\starttexdefinition unexpanded moveraccentchecker #1#2
    \edef\movertoken{\tochar{#2}}
    \doifelseutfmathabove\movertoken \moveraccent \movertext {#1}{#2}
\stoptexdefinition

\starttexdefinition unexpanded mover #1#2
    \mathematics {
        \edef\mbasetoken{\tochar{#1}}
        \doifelseutfmathfiller\mbasetoken \moverbasefiller \moveraccentchecker {#1}{#2}
    }
\stoptexdefinition

% munder

\starttexdefinition unexpanded munderbelow #1
    \edef\mundercommand{\utfmathfiller\mundertoken}
    \mexecuteifdefined\mundercommand {#1} \relax
\stoptexdefinition
\starttexdefinition unexpanded munderbase #1
    \edef\mbasecommand{\utfmathfiller\mbasetoken}
    \mexecuteifdefined\mbasecommand {#1}
    \relax
\stoptexdefinition
\starttexdefinition unexpanded munderbasefiller #1#2
    \edef\mbasecommand{e\utfmathcommandfiller\mbasetoken}
    \mexecuteifdefined\mbasecommand \relax {#2} {}
\stoptexdefinition
\starttexdefinition unexpanded munderaccent #1#2
    \edef\mundercommand{\utfmathcommandbelow\mundertoken}
    \mexecuteifdefined\mundercommand \relax {#1}
\stoptexdefinition
\starttexdefinition unexpanded mundertext #1#2
  % \mathtriplet {\mathstylehbox{#1}} {} {#2}
    \mathtriplet {\mathematics{#1}} {} {#2}
\stoptexdefinition
\starttexdefinition unexpanded munderaccentchecker #1#2
    \edef\mundertoken{\tochar{#2}}
    \doifelseutfmathbelow\mundertoken \munderaccent \mundertext {#1}{#2}
\stoptexdefinition

\starttexdefinition unexpanded munder #1#2
    \mathematics {
        \edef\mbasetoken{\tochar{#1}}
        \doifelseutfmathfiller\mbasetoken \munderbasefiller \munderaccentchecker {#1}{#2}
    }
\stoptexdefinition

% munderover

% mfenced

% \mfenced{x,y}
% \mfenced{{x}{y}}
% \mfenced[separators]{{x}{y}}
% \mfenced[left][right]{{x}{y}}
% \mfenced[left][separators][right]{{x}{y}}

\starttexdefinition unexpanded mfenced
    \dotripleempty\do_mfenced
\stoptexdefinition

\starttexdefinition unexpanded do_mfenced [#1][#2][#3]#4
    \mathematics {
        \ctxcommand{xmfenced(
            \ifthirdargument  "#1","#2","#3"\else
            \ifsecondargument  "#1",",","#2"\else
            \iffirstargument    "(","#1",")"\else
                                 "(",",",")"\fi\fi\fi
        ,"#4")}
    }
\stoptexdefinition

% mfrac

\starttexdefinition unexpanded mfrac #1#2
    \mathematics {
        \frac{#1}{#2}
    }
\stoptexdefinition

% mroot msqrt

\starttexdefinition unexpanded mroot #1#2
    \mathematics {
        \sqrt[#1]{#2}
    }
\stoptexdefinition

\starttexdefinition unexpanded msqrt #1
    \mathematics {
        \sqrt{#1}
    }
\stoptexdefinition

% menclose

% merror

% mglyph

% mmultiscripts

% mpadded

% mphantom

% mspace

% mstyle

% mtable mtr mlabeledtr mtd

% maction

% semantics

\protect

\continueifinputfile{x-mathml-basics.mkiv}

\starttext

$\mfenced{1+a}$\par
$\mfenced[,]{1+a}$\par
$\mfenced[,]{{1+a}{1+b}}$\par

% $\mover{←}{test}$\par
% $\mover{\utfchar{"2190}}{test}$\par
% $\mover{e:leftarrow}{test}$\par
% $\mover{x:2190}{test}$\par

% $\mover{test}{⏞}$\par
% $\mover{test}{\utfchar{"23DE}}$\par
% $\mover{test}{e:overbrace}$\par
% $\mover{test}{x:23DE}$\par
% $\mover{test}{over}$\par

% \mover{test}{⏞}\par
% \mover{test}{\utfchar{"23DE}}\par
% \mover{test}{e:overbrace}\par
% \mover{test}{x:23DE}\par

% $\munder{←}{test}$\par
% $\munder{\utfchar{"2190}}{test}$\par
% $\munder{e:leftarrow}{test}$\par
% $\munder{x:2190}{test}$\par

% $\munder{test}{⏟}$\par
% $\munder{test}{\utfchar{"23DF}}$\par
% $\munder{test}{e:underbrace}$\par
% $\munder{test}{x:23DF}$\par
% $\munder{test}{under}$\par

% \math{{\msup{x}{2}\mo{+}\mn{2}\mi{x}\mo{+}\mi{b}}}

% \mrow{\msup{x}{2}\mo{+}\mn{2}\mi{x}\mo{+}\mi{b}}

\stoptext