22
22
*/
23
23
24
24
MathJax . Hub . Register . StartupHook ( "HTML-CSS Jax Ready" , function ( ) {
25
- var VERSION = "2.0.2 " ;
25
+ var VERSION = "2.0.3 " ;
26
26
var MML = MathJax . ElementJax . mml ,
27
27
HTMLCSS = MathJax . OutputJax [ "HTML-CSS" ] ;
28
28
@@ -146,10 +146,10 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
146
146
// Get the current breakpoint position and other data
147
147
//
148
148
var index = info . index . slice ( 0 ) , i = info . index . shift ( ) ,
149
- m = this . data . length , W , scanW = info . W ,
150
- broken = ( info . index . length > 0 ) , better = false ;
149
+ m = this . data . length , W , broken = ( info . index . length > 0 ) , better = false ;
150
+ info . scanW = info . W ;
151
151
if ( i == null ) { i = - 1 } ; if ( ! broken ) { i ++ ; info . W += info . w } ;
152
- info . w = 0 ; info . nest ++ ; info . scanW = scanW ;
152
+ info . w = 0 ; info . nest ++ ;
153
153
//
154
154
// Look through the line for breakpoints,
155
155
// (as long as we are not too far past the breaking width)
@@ -160,20 +160,21 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
160
160
better = true ; index = [ i ] . concat ( info . index ) ; W = info . W ;
161
161
if ( info . penalty === PENALTY . newline ) { info . index = index ; info . nest -- ; return true }
162
162
}
163
- if ( ! broken ) {
164
- var span = this . data [ i ] . HTMLspanElement ( ) ;
165
- scanW += span . bbox . w ;
166
- if ( span . style . paddingLeft ) { scanW += HTMLCSS . unEm ( span . style . paddingLeft ) }
167
- if ( span . style . paddingRight ) { scanW += HTMLCSS . unEm ( span . style . paddingRight ) }
168
- info . W = info . scanW = scanW ;
169
- }
163
+ if ( ! broken ) { this . HTMLaddWidth ( i , info ) }
170
164
}
171
165
info . index = [ ] ; i ++ ; broken = false ;
172
166
}
173
167
info . nest -- ; info . index = index ;
174
168
if ( better ) { info . W = W }
175
169
return better ;
176
170
} ,
171
+ HTMLaddWidth : function ( i , info ) {
172
+ var span = this . data [ i ] . HTMLspanElement ( ) ;
173
+ info . scanW += span . bbox . w ;
174
+ if ( span . style . paddingLeft ) { info . scanW += HTMLCSS . unEm ( span . style . paddingLeft ) }
175
+ if ( span . style . paddingRight ) { info . scanW += HTMLCSS . unEm ( span . style . paddingRight ) }
176
+ info . W = info . scanW ;
177
+ } ,
177
178
178
179
/****************************************************************/
179
180
//
@@ -262,7 +263,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
262
263
} else {
263
264
//
264
265
// Otherwise, move the remainder of the initial item
265
- // and any others up tp the last one
266
+ // and any others up to the last one
266
267
//
267
268
var last = state . last ; state . last = false ;
268
269
while ( i < j ) {
@@ -366,7 +367,84 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
366
367
} else if ( state . first ) { state . nextIsFirst = true } else { delete state . nextIsFirst }
367
368
}
368
369
} ) ;
370
+
371
+ /**************************************************************************/
372
+
373
+ MML . mfenced . Augment ( {
374
+ HTMLbetterBreak : function ( info , state ) {
375
+ //
376
+ // Get the current breakpoint position and other data
377
+ //
378
+ var index = info . index . slice ( 0 ) , i = info . index . shift ( ) ,
379
+ m = this . data . length , W , broken = ( info . index . length > 0 ) , better = false ;
380
+ info . scanW = info . W ;
381
+ if ( i == null ) { i = - 1 } ; if ( ! broken ) { i ++ ; info . W += info . w } ;
382
+ info . w = 0 ; info . nest ++ ;
383
+ //
384
+ // Look through the line for breakpoints, including the open, close, and separators
385
+ // (as long as we are not too far past the breaking width)
386
+ //
387
+ if ( ! broken && this . data . open ) { this . HTMLaddWidth ( "open" , info ) }
388
+ while ( i < m && info . scanW < 1.33 * HTMLCSS . linebreakWidth ) {
389
+ if ( this . data [ i ] ) {
390
+ if ( this . data [ i ] . HTMLbetterBreak ( info , state ) ) {
391
+ better = true ; index = [ i ] . concat ( info . index ) ; W = info . W ;
392
+ if ( info . penalty === PENALTY . newline ) { info . index = index ; info . nest -- ; return true }
393
+ }
394
+ if ( ! broken ) { this . HTMLaddWidth ( i , info ) }
395
+ }
396
+ info . index = [ ] ; i ++ ; broken = false ;
397
+ // FIXME: should be able to break at the following (but don't have index for it)
398
+ if ( this . data [ "sep" + i ] ) { this . HTMLaddWidth ( "sep" + i , info ) }
399
+ }
400
+ if ( this . data . close ) { this . HTMLaddWidth ( "close" , info ) }
401
+ info . nest -- ; info . index = index ;
402
+ if ( better ) { info . W = W }
403
+ return better ;
404
+ } ,
369
405
406
+ HTMLmoveLine : function ( start , end , span , state , values ) {
407
+ var i = start [ 0 ] , j = end [ 0 ] ;
408
+ if ( i == null ) { i = - 1 } ; if ( j == null ) { j = this . data . length - 1 }
409
+ if ( i === j && start . length > 1 ) {
410
+ //
411
+ // If starting and ending in the same element move the subpiece to the new line
412
+ // Add the closing fence, if present
413
+ //
414
+ this . data [ i ] . HTMLmoveSlice ( start . slice ( 1 ) , end . slice ( 1 ) , span , state , values , "paddingLeft" ) ;
415
+ if ( i === this . data . length - 1 && this . data . close )
416
+ { this . data . close . HTMLmoveSpan ( span , state , values ) }
417
+ } else {
418
+ //
419
+ // Otherwise, move the remainder of the initial item
420
+ // and any others (including open and separators) up to the last one
421
+ //
422
+ var last = state . last ; state . last = false ;
423
+ if ( i < 0 && this . data . open ) { this . data . open . HTMLmoveSpan ( span , state , values ) }
424
+ while ( i < j ) {
425
+ if ( this . data [ i ] ) {
426
+ if ( start . length <= 1 ) { this . data [ i ] . HTMLmoveSpan ( span , state , values ) }
427
+ else { this . data [ i ] . HTMLmoveSlice ( start . slice ( 1 ) , [ ] , span , state , values , "paddingLeft" ) }
428
+ }
429
+ i ++ ; state . first = false ; start = [ ] ;
430
+ if ( this . data [ "sep" + i ] ) { this . data [ "sep" + i ] . HTMLmoveSpan ( span , state , values ) }
431
+ }
432
+ //
433
+ // If the last item is complete, move it and the closing fence,
434
+ // otherwise move the first part of it up to the split
435
+ //
436
+ state . last = last ;
437
+ if ( this . data [ i ] ) {
438
+ if ( end . length <= 1 ) {
439
+ this . data [ i ] . HTMLmoveSpan ( span , state , values ) ;
440
+ if ( this . data . close ) { this . data . close . HTMLmoveSpan ( span , state , values ) }
441
+ } else { this . data [ i ] . HTMLmoveSlice ( [ ] , end . slice ( 1 ) , span , state , values , "paddingRight" ) }
442
+ }
443
+ }
444
+ }
445
+
446
+ } ) ;
447
+
370
448
/**************************************************************************/
371
449
372
450
MML . mo . Augment ( {
0 commit comments