x-mathml-basics.mkiv /size: 6427 b    last modification: 2021-10-28 13:51
 1% macros=mkvi 2 3% makes sense (but rel vs op ...): 4 5% \unexpanded\def\stackrel#1#2{\mathematics{\mathop{\let\limits\relax\mover{#2}{#1}}}} 6 7% this can become a core helper 8 9% we could do all of them in lua 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% mrow 53 54\let\mrow\mathematics 55 56% msub msup msubsup 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% mn mo mi 77 78\let\mn\mathematics 79\let\mo\mathematics 80\let\mi\mathematics 81 82% ms mtext 83 84\starttexdefinition ms #1 85 \text { 86 "#1" 87 } 88\stoptexdefinition 89 90% \starttexdefinition mtext #1 91% \text { 92% #1 93% } 94% \stoptexdefinition 95 96% mover 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 % \mathtriplet {\mathstylehbox{#1}} {#2} {} 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% munder 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 % \mathtriplet {\mathstylehbox{#1}} {} {#2} 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% munderover 167 168% mfenced 169 170% \mfenced{x,y} 171% \mfenced{{x}{y}} 172% \mfenced[separators]{{x}{y}} 173% \mfenced[left][right]{{x}{y}} 174% \mfenced[left][separators][right]{{x}{y}} 175 176\starttexdefinition unexpanded mfenced 177 \dotripleempty\do_mfenced 178\stoptexdefinition 179 180\starttexdefinition unexpanded do_mfenced [#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% mfrac 192 193\starttexdefinition unexpanded mfrac #1#2 194 \mathematics { 195 \frac{#1}{#2} 196 } 197\stoptexdefinition 198 199% mroot msqrt 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% menclose 214 215% merror 216 217% mglyph 218 219% mmultiscripts 220 221% mpadded 222 223% mphantom 224 225% mspace 226 227% mstyle 228 229% mtable mtr mlabeledtr mtd 230 231% maction 232 233% semantics 234 235\protect 236 237\continueifinputfile{x-mathml-basics.mkiv} 238 239\starttext 240 241$\mfenced{1+a}$\par 242$\mfenced[,]{1+a}$\par 243$\mfenced[,]{{1+a}{1+b}}$\par 244 245% $\mover{←}{test}$\par 246% $\mover{\utfchar{"2190}}{test}$\par 247% $\mover{e:leftarrow}{test}$\par 248% $\mover{x:2190}{test}$\par 249 250% $\mover{test}{⏞}$\par 251% $\mover{test}{\utfchar{"23DE}}$\par 252% $\mover{test}{e:overbrace}$\par 253% $\mover{test}{x:23DE}$\par 254% $\mover{test}{over}$\par 255 256% \mover{test}{⏞}\par 257% \mover{test}{\utfchar{"23DE}}\par 258% \mover{test}{e:overbrace}\par 259% \mover{test}{x:23DE}\par 260 261% $\munder{←}{test}$\par 262% $\munder{\utfchar{"2190}}{test}$\par 263% $\munder{e:leftarrow}{test}$\par 264% $\munder{x:2190}{test}$\par 265 266% $\munder{test}{⏟}$\par 267% $\munder{test}{\utfchar{"23DF}}$\par 268% $\munder{test}{e:underbrace}$\par 269% $\munder{test}{x:23DF}$\par 270% $\munder{test}{under}$\par 271 272% \math{{\msup{x}{2}\mo{+}\mn{2}\mi{x}\mo{+}\mi{b}}} 273 274% \mrow{\msup{x}{2}\mo{+}\mn{2}\mi{x}\mo{+}\mi{b}} 275 276\stoptext 277