@@ -128,6 +128,30 @@ export const getVariant = function(
128
128
return null ;
129
129
} ;
130
130
131
+ /**
132
+ * Check for <mi>.</mi> which is how a dot renders in MathML,
133
+ * or <mo separator="true" lspace="0em" rspace="0em">,</mo>
134
+ * which is how a braced comma {,} renders in MathML
135
+ */
136
+ function isNumberPunctuation ( group : ?MathNode ) : boolean {
137
+ if ( ! group ) {
138
+ return false ;
139
+ }
140
+ if ( group . type === 'mi' && group . children . length === 1 ) {
141
+ const child = group . children [ 0 ] ;
142
+ return child instanceof TextNode && child . text === '.' ;
143
+ } else if ( group . type === 'mo' && group . children . length === 1 &&
144
+ group . getAttribute ( 'separator' ) === 'true' &&
145
+ group . getAttribute ( 'lspace' ) === '0em' &&
146
+ group . getAttribute ( 'rspace' ) === '0em'
147
+ ) {
148
+ const child = group . children [ 0 ] ;
149
+ return child instanceof TextNode && child . text === ',' ;
150
+ } else {
151
+ return false ;
152
+ }
153
+ }
154
+
131
155
/**
132
156
* Takes a list of nodes, builds them, and returns a list of the generated
133
157
* MathML nodes. Also combine consecutive <mtext> outputs into a single
@@ -165,13 +189,25 @@ export const buildExpression = function(
165
189
lastGroup . children . push ( ...group . children ) ;
166
190
continue ;
167
191
// Concatenate <mn>...</mn> followed by <mi>.</mi>
168
- } else if ( group . type === 'mi' && group . children . length === 1 &&
169
- lastGroup . type === 'mn' ) {
170
- const child = group . children [ 0 ] ;
171
- if ( child instanceof TextNode && child . text === '.' ) {
172
- lastGroup . children . push ( ...group . children ) ;
173
- continue ;
192
+ } else if ( isNumberPunctuation ( group ) && lastGroup . type === 'mn ') {
193
+ lastGroup . children . push ( ...group . children ) ;
194
+ continue ;
195
+ // Concatenate <mi>.</mi> followed by <mn>...</mn>
196
+ } else if ( group . type === 'mn ' && isNumberPunctuation ( lastGroup ) ) {
197
+ group . children = [ ...lastGroup . children , ...group . children ] ;
198
+ groups . pop ( ) ;
199
+ // Put preceding <mn>...</mn> or <mi>.</mi> inside base of
200
+ // <msup><mn>...base...</mn>...exponent...</msup> (or <msub>)
201
+ } else if ( ( group . type === 'msup' || group . type === 'msub' ) &&
202
+ group . children . length >= 1 &&
203
+ ( lastGroup . type === 'mn' || isNumberPunctuation ( lastGroup ) )
204
+ ) {
205
+ const base = group . children [ 0 ] ;
206
+ if ( base instanceof MathNode && base . type === 'mn' ) {
207
+ base . children = [ ...lastGroup . children , ...base . children ] ;
208
+ groups . pop ( ) ;
174
209
}
210
+ // \not
175
211
} else if ( lastGroup . type === 'mi' && lastGroup . children . length === 1 ) {
176
212
const lastChild = lastGroup . children [ 0 ] ;
177
213
if ( lastChild instanceof TextNode && lastChild . text === '\u0338' &&
0 commit comments