Skip to content

Commit 34a9af5

Browse files
committed
Fix mfenced so that when it contains a line break the delimiters and separators are not lost. Resolves issue #255 (but separators currently aren't able to be breakpoints, so more needs to be done).
1 parent 037e5eb commit 34a9af5

File tree

10 files changed

+197
-34
lines changed

10 files changed

+197
-34
lines changed

config/TeX-AMS-MML_SVG-full.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/TeX-AMS-MML_SVG.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jax/output/HTML-CSS/autoload/multiline.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jax/output/SVG/autoload/multiline.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jax/output/SVG/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
* http://www.apache.org/licenses/LICENSE-2.0
1313
*/
1414

15-
MathJax.OutputJax.SVG=MathJax.OutputJax({id:"SVG",version:"2.0.7",directory:MathJax.OutputJax.directory+"/SVG",extensionDir:MathJax.OutputJax.extensionDir+"/SVG",autoloadDir:MathJax.OutputJax.directory+"/SVG/autoload",fontDir:MathJax.OutputJax.directory+"/SVG/fonts",config:{scale:100,minScaleAdjust:50,font:"TeX",blacker:10,mtextFontInherit:false,undefinedFamily:"STIXGeneral,'Arial Unicode MS',serif",addMMLclasses:false,EqnChunk:(MathJax.Hub.Browser.isMobile?10:50),EqnChunkFactor:1.5,EqnChunkDelay:100,linebreaks:{automatic:false,width:"container"},styles:{".MathJax_SVG_Display":{"text-align":"center",margin:"1em 0em"},"#MathJax_SVG_Tooltip":{"background-color":"InfoBackground",color:"InfoText",border:"1px solid black","box-shadow":"2px 2px 5px #AAAAAA","-webkit-box-shadow":"2px 2px 5px #AAAAAA","-moz-box-shadow":"2px 2px 5px #AAAAAA","-khtml-box-shadow":"2px 2px 5px #AAAAAA",padding:"3px 4px"}}}});if(!MathJax.Hub.config.delayJaxRegistration){MathJax.OutputJax.SVG.Register("jax/mml")}MathJax.OutputJax.SVG.loadComplete("config.js");
15+
MathJax.OutputJax.SVG=MathJax.OutputJax({id:"SVG",version:"2.0.8",directory:MathJax.OutputJax.directory+"/SVG",extensionDir:MathJax.OutputJax.extensionDir+"/SVG",autoloadDir:MathJax.OutputJax.directory+"/SVG/autoload",fontDir:MathJax.OutputJax.directory+"/SVG/fonts",config:{scale:100,minScaleAdjust:50,font:"TeX",blacker:10,mtextFontInherit:false,undefinedFamily:"STIXGeneral,'Arial Unicode MS',serif",addMMLclasses:false,EqnChunk:(MathJax.Hub.Browser.isMobile?10:50),EqnChunkFactor:1.5,EqnChunkDelay:100,linebreaks:{automatic:false,width:"container"},styles:{".MathJax_SVG_Display":{"text-align":"center",margin:"1em 0em"},"#MathJax_SVG_Tooltip":{"background-color":"InfoBackground",color:"InfoText",border:"1px solid black","box-shadow":"2px 2px 5px #AAAAAA","-webkit-box-shadow":"2px 2px 5px #AAAAAA","-moz-box-shadow":"2px 2px 5px #AAAAAA","-khtml-box-shadow":"2px 2px 5px #AAAAAA",padding:"3px 4px"}}}});if(!MathJax.Hub.config.delayJaxRegistration){MathJax.OutputJax.SVG.Register("jax/mml")}MathJax.OutputJax.SVG.loadComplete("config.js");
1616

jax/output/SVG/jax.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unpacked/jax/output/HTML-CSS/autoload/multiline.js

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323

2424
MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
25-
var VERSION = "2.0.2";
25+
var VERSION = "2.0.3";
2626
var MML = MathJax.ElementJax.mml,
2727
HTMLCSS = MathJax.OutputJax["HTML-CSS"];
2828

@@ -146,10 +146,10 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
146146
// Get the current breakpoint position and other data
147147
//
148148
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;
151151
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++;
153153
//
154154
// Look through the line for breakpoints,
155155
// (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 () {
160160
better = true; index = [i].concat(info.index); W = info.W;
161161
if (info.penalty === PENALTY.newline) {info.index = index; info.nest--; return true}
162162
}
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)}
170164
}
171165
info.index = []; i++; broken = false;
172166
}
173167
info.nest--; info.index = index;
174168
if (better) {info.W = W}
175169
return better;
176170
},
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+
},
177178

178179
/****************************************************************/
179180
//
@@ -262,7 +263,7 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
262263
} else {
263264
//
264265
// 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
266267
//
267268
var last = state.last; state.last = false;
268269
while (i < j) {
@@ -366,7 +367,84 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
366367
} else if (state.first) {state.nextIsFirst = true} else {delete state.nextIsFirst}
367368
}
368369
});
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+
},
369405

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+
370448
/**************************************************************************/
371449

372450
MML.mo.Augment({

0 commit comments

Comments
 (0)