@@ -239,9 +239,10 @@ AbstractOutputJax<N, T, D> {
239239 public getMetrics ( html : MathDocument < N , T , D > ) {
240240 this . setDocument ( html ) ;
241241 const adaptor = this . adaptor ;
242- const map = this . getMetricMap ( html ) ;
242+ const maps = this . getMetricMaps ( html ) ;
243243 for ( const math of html . math ) {
244- const { em, ex, containerWidth, lineWidth, scale} = map . get ( math . start . node as N ) ;
244+ const map = maps [ math . display ? 1 : 0 ] ;
245+ const { em, ex, containerWidth, lineWidth, scale} = map . get ( adaptor . parent ( math . start . node ) ) ;
245246 math . setMetrics ( em , ex , containerWidth , lineWidth , scale ) ;
246247 }
247248 }
@@ -250,32 +251,41 @@ AbstractOutputJax<N, T, D> {
250251 * Get a MetricMap for the math list
251252 *
252253 * @param {MathDocument } html The math document whose math list is to be processed.
253- * @return {MetricMap } The node-to-metrics map for all the containers that have math
254+ * @return {MetricMap[] } The node-to-metrics maps for all the containers that have math
254255 */
255- protected getMetricMap ( html : MathDocument < N , T , D > ) {
256+ protected getMetricMaps ( html : MathDocument < N , T , D > ) {
256257 const adaptor = this . adaptor ;
257- const domMap = new Map ( ) as MetricDomMap < N > ;
258+ const domMaps = [ new Map ( ) as MetricDomMap < N > , new Map ( ) as MetricDomMap < N > ] ;
258259 //
259260 // Add the test elements all at once (so only one reflow)
261+ // Currently, we do one test for each container element for in-line and one for display math
262+ // (since we need different techniques for the two forms to avoid a WebKit bug).
263+ // This may need to be changed to handle floating elements better, since that has to be
264+ // done at the location of the math itself, not necessarily the end of the container.
260265 //
261266 for ( const math of html . math ) {
262- const node = math . start . node as N ;
263- domMap . set ( node , this . getTestElement ( node , math . display ) ) ;
267+ const node = adaptor . parent ( math . start . node ) ;
268+ const map = domMaps [ math . display ? 1 : 0 ] ;
269+ map . set ( node , this . getTestElement ( node , math . display ) ) ;
264270 }
265271 //
266272 // Measure the metrics for all the mapped elements
267273 //
268- const map = new Map ( ) as MetricMap < N > ;
269- for ( const node of domMap . keys ( ) ) {
270- map . set ( node , this . measureMetrics ( domMap . get ( node ) ) ) ;
274+ const maps = [ new Map ( ) as MetricMap < N > , new Map ( ) as MetricMap < N > ] ;
275+ for ( const i of maps . keys ( ) ) {
276+ for ( const node of domMaps [ i ] . keys ( ) ) {
277+ maps [ i ] . set ( node , this . measureMetrics ( domMaps [ 0 ] . get ( node ) ) ) ;
278+ }
271279 }
272280 //
273281 // Remove the test elements
274282 //
275- for ( const node of domMap . values ( ) ) {
276- adaptor . remove ( node ) ;
283+ for ( const i of maps . keys ( ) ) {
284+ for ( const node of domMaps [ i ] . values ( ) ) {
285+ adaptor . remove ( node ) ;
286+ }
277287 }
278- return map ;
288+ return maps ;
279289 }
280290
281291 /**
@@ -325,9 +335,7 @@ AbstractOutputJax<N, T, D> {
325335 adaptor . setStyle ( right , 'width' , '10000em' ) ;
326336 adaptor . setStyle ( right , 'float' , '' ) ;
327337 }
328- const test = adaptor . clone ( display ? this . testDisplay : this . testInline ) as N ;
329- adaptor . insert ( test , node ) ;
330- return test ;
338+ return adaptor . append ( node , adaptor . clone ( display ? this . testDisplay : this . testInline ) as N ) ;
331339 }
332340
333341 /**
0 commit comments