Merge branch 'linebreaks' into new-features (adds automatic line breaking)

This commit is contained in:
Davide P. Cervone 2011-09-11 10:26:28 -04:00
commit 4937810570
20 changed files with 689 additions and 143 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -472,6 +472,42 @@ MathJax.Hub.Config({
// if it doesn't contain the needed character), so order these carefully.
//
undefinedFamily: "STIXGeneral,'Arial Unicode MS',serif",
//
// These settings control automatic line breaking. It is off by
// default, so only explicit line breaks are performed (via
// linebreak="newline" attributes on <mo> and <mspace> elements). To
// perform automatic line breaking on line expressions, set
// 'automatic' to 'true' below. The line breaks will be applied via a
// penalty-based heuristic, which does well, but isn't perfect. You
// might need to use linebreak="goodbreak" or linebreak="badbreak" by
// hand in order to get better effects. It is also possible to modify
// the penalty values; contact the MathJax user's forum for details.
//
linebreaks: {
//
// This controls the automatic breaking of expressions:
// when false, only process linebreak="newline",
// when true, line breaks are inserted automatically in long expressions.
//
automatic: false,
//
// This controls how wide the lines of mathematics can be
//
// Use an explicit with like "30em" for a fixed width.
// Use "container" to compute size from containing element.
// Use "nn% container" for a portion of the container.
// Use "nn%" for a portion of the window size.
//
// The container-based widths may be slower, and may not produce the
// expected results if the layout width changes due to the removal
// of previews or inclusion of mathematics during typesetting.
//
width: "container"
},
//
// This controls whether the MathJax contextual menu will be available

File diff suppressed because one or more lines are too long

View File

@ -12,5 +12,5 @@
* http://www.apache.org/licenses/LICENSE-2.0
*/
MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function(){var g="1.1.2";var c=MathJax.ElementJax.mml,e=MathJax.OutputJax["HTML-CSS"];var d,f,b;var a=e.config.tooltip=MathJax.Hub.Insert({delayPost:600,delayClear:600,offsetX:10,offsetY:5},e.config.tooltip||{});c.maction.Augment({HTMLtooltip:e.addElement(document.body,"div",{id:"MathJax_Tooltip"}),toHTML:function(k,h,m){k=this.HTMLhandleSize(this.HTMLcreateSpan(k));k.bbox=null;var i=this.getValues("actiontype","selection"),n;var j=this.data[i.selection-1];if(j){e.Measured(j.toHTML(k),k);if(m!=null){e.Remeasured(j.HTMLstretchV(k,h,m),k)}else{if(h!=null){e.Remeasured(j.HTMLstretchH(k,h),k)}}if(e.msieHitBoxBug){var l=e.addElement(k,"span");n=e.createFrame(l,k.bbox.h,k.bbox.d,k.bbox.w,0,"none");k.insertBefore(l,k.firstChild);l.style.marginRight=e.Em(-k.bbox.w);if(e.msieInlineBlockAlignBug){n.style.verticalAlign=e.Em(e.getHD(k).d-k.bbox.d)}}else{n=e.createFrame(k,k.bbox.h,k.bbox.d,k.bbox.w,0,"none");k.insertBefore(n,k.firstChild);n.style.marginRight=e.Em(-k.bbox.w)}n.className="MathJax_HitBox";n.id="MathJax-HitBox-"+this.spanID;if(this.HTMLaction[i.actiontype]){this.HTMLaction[i.actiontype].call(this,k,n,i.selection)}}this.HTMLhandleSpace(k);this.HTMLhandleColor(k);return k},HTMLstretchH:c.mbase.HTMLstretchH,HTMLstretchV:c.mbase.HTMLstretchV,HTMLaction:{toggle:function(i,j,h){this.selection=h;j.onclick=i.childNodes[1].onclick=MathJax.Callback(["HTMLclick",this]);j.style.cursor=i.childNodes[1].style.cursor="pointer"},statusline:function(i,j,h){j.onmouseover=i.childNodes[1].onmouseover=MathJax.Callback(["HTMLsetStatus",this]);j.onmouseout=i.childNodes[1].onmouseout=MathJax.Callback(["HTMLclearStatus",this]);j.onmouseover.autoReset=j.onmouseout.autoReset=true},tooltip:function(i,j,h){if(this.data[1]&&this.data[1].isToken){j.title=j.alt=i.childNodes[1].title=i.childNodes[1].alt=this.data[1].data.join("")}else{j.onmouseover=i.childNodes[1].onmouseover=MathJax.Callback(["HTMLtooltipOver",this]);j.onmouseout=i.childNodes[1].onmouseout=MathJax.Callback(["HTMLtooltipOut",this]);j.onmouseover.autoReset=j.onmouseout.autoReset=true}}},HTMLclick:function(i){this.selection++;if(this.selection>this.data.length){this.selection=1}var h=this;while(h.type!=="math"){h=h.inherit}MathJax.Hub.getJaxFor(h.inputID).Update();if(!i){i=window.event}if(i.preventDefault){i.preventDefault()}if(i.stopPropagation){i.stopPropagation()}i.cancelBubble=true;i.returnValue=false;return false},HTMLsetStatus:function(h){window.status=((this.data[1]&&this.data[1].isToken)?this.data[1].data.join(""):this.data[1].toString())},HTMLclearStatus:function(h){window.status=""},HTMLtooltipOver:function(i){if(!i){i=window.event}if(b){clearTimeout(b);b=null}if(f){clearTimeout(f)}var h=i.pageX;var k=i.pageY;if(h==null){h=i.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;k=i.clientY+document.body.scrollTop+document.documentElement.scrollTop}var j=MathJax.Callback(["HTMLtooltipPost",this,h+a.offsetX,k+a.offsetY]);f=setTimeout(j,a.delayPost)},HTMLtooltipOut:function(h){if(f){clearTimeout(f);f=null}if(b){clearTimeout(b)}var i=MathJax.Callback(["HTMLtooltipClear",this,80]);b=setTimeout(i,a.delayClear)},HTMLtooltipPost:function(i,m){f=null;if(b){clearTimeout(b);b=null}var l=this.HTMLtooltip;l.style.display="block";l.style.opacity="";l.style.filter=e.config.styles["#MathJax_Tooltip"].filter;if(this===d){return}l.style.left=i+"px";l.style.top=m+"px";l.innerHTML='<span class="MathJax"><nobr></nobr></span>';e.getScales(l.firstChild,l.firstChild);var h=e.createStack(l.firstChild.firstChild);var k=e.createBox(h);try{e.Measured(this.data[1].toHTML(k),k)}catch(j){if(!j.restart){throw j}l.style.display="none";MathJax.Callback.After(["HTMLtooltipPost",this,i,m],j.restart)}e.placeBox(k,0,0);e.createRule(l.firstChild.firstChild,k.bbox.h,k.bbox.d,0);d=this},HTMLtooltipClear:function(i){var h=this.HTMLtooltip;if(i<=0){h.style.display="none";h.style.opacity=h.style.filter="";b=null}else{h.style.opacity=i/100;h.style.filter="alpha(opacity="+i+")";b=setTimeout(MathJax.Callback(["HTMLtooltipClear",this,i-20]),50)}}});MathJax.Hub.Browser.Select({MSIE:function(h){e.msieHitBoxBug=true}});MathJax.Hub.Startup.signal.Post("HTML-CSS maction Ready");MathJax.Ajax.loadComplete(e.autoloadDir+"/maction.js")});
MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function(){var g="1.1.2";var c=MathJax.ElementJax.mml,e=MathJax.OutputJax["HTML-CSS"];var d,f,b;var a=e.config.tooltip=MathJax.Hub.Insert({delayPost:600,delayClear:600,offsetX:10,offsetY:5},e.config.tooltip||{});c.maction.Augment({HTMLtooltip:e.addElement(document.body,"div",{id:"MathJax_Tooltip"}),toHTML:function(j,h,k){j=this.HTMLhandleSize(this.HTMLcreateSpan(j));j.bbox=null;var i=this.selected();if(i){e.Measured(i.toHTML(j),j);if(k!=null){e.Remeasured(i.HTMLstretchV(j,h,k),j)}else{if(h!=null){e.Remeasured(i.HTMLstretchH(j,h),j)}}this.HTMLhandleHitBox(j)}this.HTMLhandleSpace(j);this.HTMLhandleColor(j);return j},HTMLhandleHitBox:function(i,l){var k;if(e.msieHitBoxBug){var j=e.addElement(i,"span");k=e.createFrame(j,i.bbox.h,i.bbox.d,i.bbox.w,0,"none");i.insertBefore(j,i.firstChild);j.style.marginRight=e.Em(-i.bbox.w);if(e.msieInlineBlockAlignBug){k.style.verticalAlign=e.Em(e.getHD(i).d-i.bbox.d)}}else{k=e.createFrame(i,i.bbox.h,i.bbox.d,i.bbox.w,0,"none");i.insertBefore(k,i.firstChild);k.style.marginRight=e.Em(-i.bbox.w)}k.className="MathJax_HitBox";k.id="MathJax-HitBox-"+this.spanID+(l||"")+e.idPostfix;var h=this.Get("actiontype");if(this.HTMLaction[h]){this.HTMLaction[h].call(this,i,k,this.Get("selection"))}},HTMLstretchH:c.mbase.HTMLstretchH,HTMLstretchV:c.mbase.HTMLstretchV,HTMLaction:{toggle:function(i,j,h){this.selection=h;j.onclick=i.childNodes[1].onclick=MathJax.Callback(["HTMLclick",this]);j.style.cursor=i.childNodes[1].style.cursor="pointer"},statusline:function(i,j,h){j.onmouseover=i.childNodes[1].onmouseover=MathJax.Callback(["HTMLsetStatus",this]);j.onmouseout=i.childNodes[1].onmouseout=MathJax.Callback(["HTMLclearStatus",this]);j.onmouseover.autoReset=j.onmouseout.autoReset=true},tooltip:function(i,j,h){if(this.data[1]&&this.data[1].isToken){j.title=j.alt=i.childNodes[1].title=i.childNodes[1].alt=this.data[1].data.join("")}else{j.onmouseover=i.childNodes[1].onmouseover=MathJax.Callback(["HTMLtooltipOver",this]);j.onmouseout=i.childNodes[1].onmouseout=MathJax.Callback(["HTMLtooltipOut",this]);j.onmouseover.autoReset=j.onmouseout.autoReset=true}}},HTMLclick:function(i){this.selection++;if(this.selection>this.data.length){this.selection=1}var h=this;while(h.type!=="math"){h=h.inherit}MathJax.Hub.getJaxFor(h.inputID).Update();if(!i){i=window.event}if(i.preventDefault){i.preventDefault()}if(i.stopPropagation){i.stopPropagation()}i.cancelBubble=true;i.returnValue=false;return false},HTMLsetStatus:function(h){window.status=((this.data[1]&&this.data[1].isToken)?this.data[1].data.join(""):this.data[1].toString())},HTMLclearStatus:function(h){window.status=""},HTMLtooltipOver:function(i){if(!i){i=window.event}if(b){clearTimeout(b);b=null}if(f){clearTimeout(f)}var h=i.pageX;var k=i.pageY;if(h==null){h=i.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;k=i.clientY+document.body.scrollTop+document.documentElement.scrollTop}var j=MathJax.Callback(["HTMLtooltipPost",this,h+a.offsetX,k+a.offsetY]);f=setTimeout(j,a.delayPost)},HTMLtooltipOut:function(h){if(f){clearTimeout(f);f=null}if(b){clearTimeout(b)}var i=MathJax.Callback(["HTMLtooltipClear",this,80]);b=setTimeout(i,a.delayClear)},HTMLtooltipPost:function(i,m){f=null;if(b){clearTimeout(b);b=null}var l=this.HTMLtooltip;l.style.display="block";l.style.opacity="";l.style.filter=e.config.styles["#MathJax_Tooltip"].filter;if(this===d){return}l.style.left=i+"px";l.style.top=m+"px";l.innerHTML='<span class="MathJax"><nobr></nobr></span>';e.getScales(l.firstChild,l.firstChild);var h=e.createStack(l.firstChild.firstChild);var k=e.createBox(h);try{e.Measured(this.data[1].toHTML(k),k)}catch(j){if(!j.restart){throw j}l.style.display="none";MathJax.Callback.After(["HTMLtooltipPost",this,i,m],j.restart)}e.placeBox(k,0,0);e.createRule(l.firstChild.firstChild,k.bbox.h,k.bbox.d,0);d=this},HTMLtooltipClear:function(i){var h=this.HTMLtooltip;if(i<=0){h.style.display="none";h.style.opacity=h.style.filter="";b=null}else{h.style.opacity=i/100;h.style.filter="alpha(opacity="+i+")";b=setTimeout(MathJax.Callback(["HTMLtooltipClear",this,i-20]),50)}}});MathJax.Hub.Browser.Select({MSIE:function(h){e.msieHitBoxBug=true}});MathJax.Hub.Startup.signal.Post("HTML-CSS maction Ready");MathJax.Ajax.loadComplete(e.autoloadDir+"/maction.js")});

File diff suppressed because one or more lines are too long

View File

@ -12,5 +12,5 @@
* http://www.apache.org/licenses/LICENSE-2.0
*/
MathJax.OutputJax["HTML-CSS"]=MathJax.OutputJax({id:"HTML-CSS",version:"1.1.9",directory:MathJax.OutputJax.directory+"/HTML-CSS",extensionDir:MathJax.OutputJax.extensionDir+"/HTML-CSS",autoloadDir:MathJax.OutputJax.directory+"/HTML-CSS/autoload",fontDir:MathJax.OutputJax.directory+"/HTML-CSS/fonts",webfontDir:MathJax.OutputJax.fontDir+"/HTML-CSS",config:{scale:100,minScaleAdjust:50,availableFonts:["STIX","TeX"],preferredFont:"TeX",webFont:"TeX",imageFont:"TeX",undefinedFamily:"STIXGeneral,'Arial Unicode MS',serif",showMathMenu:true,styles:{".MathJax_Display":{"text-align":"center",margin:"1em 0em"},".MathJax .merror":{"background-color":"#FFFF88",color:"#CC0000",border:"1px solid #CC0000",padding:"1px 3px","font-family":"serif","font-style":"normal","font-size":"90%"},".MathJax_Preview":{color:"#888888"},"#MathJax_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",filter:"progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')",padding:"3px 4px"}}}});if(MathJax.Hub.Browser.isMSIE&&document.documentMode>=9){delete MathJax.OutputJax["HTML-CSS"].config.styles["#MathJax_Tooltip"].filter}if(!MathJax.Hub.config.delayJaxRegistration){MathJax.OutputJax["HTML-CSS"].Register("jax/mml")}MathJax.Hub.Register.StartupHook("End Config",[function(b,c){var a=b.Insert({minBrowserVersion:{Firefox:3,Opera:9.52,MSIE:6,Chrome:0.3,Safari:2,Konqueror:4},inlineMathDelimiters:["$","$"],displayMathDelimiters:["$$","$$"],multilineDisplay:true,minBrowserTranslate:function(f){var e=b.getJaxFor(f),k=["[Math]"],j;var h=document.createElement("span",{className:"MathJax_Preview"});if(e.inputJax==="TeX"){if(e.root.Get("displaystyle")){j=a.displayMathDelimiters;k=[j[0]+e.originalText+j[1]];if(a.multilineDisplay){k=k[0].split(/\n/)}}else{j=a.inlineMathDelimiters;k=[j[0]+e.originalText.replace(/^\s+/,"").replace(/\s+$/,"")+j[1]]}}for(var g=0,d=k.length;g<d;g++){h.appendChild(document.createTextNode(k[g]));if(g<d-1){h.appendChild(document.createElement("br"))}}f.parentNode.insertBefore(h,f)}},(b.config["HTML-CSS"]||{}));if(b.Browser.version!=="0.0"&&!b.Browser.versionAtLeast(a.minBrowserVersion[b.Browser]||0)){c.Translate=a.minBrowserTranslate;b.Config({showProcessingMessages:false});MathJax.Message.Set("Your browser does not support MathJax",null,4000);b.Startup.signal.Post("MathJax not supported")}},MathJax.Hub,MathJax.OutputJax["HTML-CSS"]]);MathJax.OutputJax["HTML-CSS"].loadComplete("config.js");
MathJax.OutputJax["HTML-CSS"]=MathJax.OutputJax({id:"HTML-CSS",version:"1.1.10",directory:MathJax.OutputJax.directory+"/HTML-CSS",extensionDir:MathJax.OutputJax.extensionDir+"/HTML-CSS",autoloadDir:MathJax.OutputJax.directory+"/HTML-CSS/autoload",fontDir:MathJax.OutputJax.directory+"/HTML-CSS/fonts",webfontDir:MathJax.OutputJax.fontDir+"/HTML-CSS",config:{scale:100,minScaleAdjust:50,availableFonts:["STIX","TeX"],preferredFont:"TeX",webFont:"TeX",imageFont:"TeX",undefinedFamily:"STIXGeneral,'Arial Unicode MS',serif",linebreaks:{automatic:false,width:"container"},showMathMenu:true,styles:{".MathJax_Display":{"text-align":"center",margin:"1em 0em"},".MathJax .merror":{"background-color":"#FFFF88",color:"#CC0000",border:"1px solid #CC0000",padding:"1px 3px","font-family":"serif","font-style":"normal","font-size":"90%"},".MathJax_Preview":{color:"#888888"},"#MathJax_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",filter:"progid:DXImageTransform.Microsoft.dropshadow(OffX=2, OffY=2, Color='gray', Positive='true')",padding:"3px 4px"}}}});if(MathJax.Hub.Browser.isMSIE&&document.documentMode>=9){delete MathJax.OutputJax["HTML-CSS"].config.styles["#MathJax_Tooltip"].filter}if(!MathJax.Hub.config.delayJaxRegistration){MathJax.OutputJax["HTML-CSS"].Register("jax/mml")}MathJax.Hub.Register.StartupHook("End Config",[function(b,c){var a=b.Insert({minBrowserVersion:{Firefox:3,Opera:9.52,MSIE:6,Chrome:0.3,Safari:2,Konqueror:4},inlineMathDelimiters:["$","$"],displayMathDelimiters:["$$","$$"],multilineDisplay:true,minBrowserTranslate:function(f){var e=b.getJaxFor(f),k=["[Math]"],j;var h=document.createElement("span",{className:"MathJax_Preview"});if(e.inputJax==="TeX"){if(e.root.Get("displaystyle")){j=a.displayMathDelimiters;k=[j[0]+e.originalText+j[1]];if(a.multilineDisplay){k=k[0].split(/\n/)}}else{j=a.inlineMathDelimiters;k=[j[0]+e.originalText.replace(/^\s+/,"").replace(/\s+$/,"")+j[1]]}}for(var g=0,d=k.length;g<d;g++){h.appendChild(document.createTextNode(k[g]));if(g<d-1){h.appendChild(document.createElement("br"))}}f.parentNode.insertBefore(h,f)}},(b.config["HTML-CSS"]||{}));if(b.Browser.version!=="0.0"&&!b.Browser.versionAtLeast(a.minBrowserVersion[b.Browser]||0)){c.Translate=a.minBrowserTranslate;b.Config({showProcessingMessages:false});MathJax.Message.Set("Your browser does not support MathJax",null,4000);b.Startup.signal.Post("MathJax not supported")}},MathJax.Hub,MathJax.OutputJax["HTML-CSS"]]);MathJax.OutputJax["HTML-CSS"].loadComplete("config.js");

File diff suppressed because one or more lines are too long

View File

@ -472,6 +472,42 @@ MathJax.Hub.Config({
// if it doesn't contain the needed character), so order these carefully.
//
undefinedFamily: "STIXGeneral,'Arial Unicode MS',serif",
//
// These settings control automatic line breaking. It is off by
// default, so only explicit line breaks are performed (via
// linebreak="newline" attributes on <mo> and <mspace> elements). To
// perform automatic line breaking on line expressions, set
// 'automatic' to 'true' below. The line breaks will be applied via a
// penalty-based heuristic, which does well, but isn't perfect. You
// might need to use linebreak="goodbreak" or linebreak="badbreak" by
// hand in order to get better effects. It is also possible to modify
// the penalty values; contact the MathJax user's forum for details.
//
linebreaks: {
//
// This controls the automatic breaking of expressions:
// when false, only process linebreak="newline",
// when true, line breaks are inserted automatically in long expressions.
//
automatic: false,
//
// This controls how wide the lines of mathematics can be
//
// Use an explicit with like "30em" for a fixed width.
// Use "container" to compute size from containing element.
// Use "nn% container" for a portion of the container.
// Use "nn%" for a portion of the window size.
//
// The container-based widths may be slower, and may not produce the
// expected results if the layout width changes due to the removal
// of previews or inclusion of mathematics during typesetting.
//
width: "container"
},
//
// This controls whether the MathJax contextual menu will be available

View File

@ -27,7 +27,7 @@ MathJax.ElementJax.mml = MathJax.ElementJax({
mimeType: "jax/mml"
},{
id: "mml",
version: "1.1.1",
version: "1.1.2",
directory: MathJax.ElementJax.directory + "/mml",
extensionDir: MathJax.ElementJax.extensionDir + "/mml",
optableDir: MathJax.ElementJax.directory + "/mml/optable"
@ -215,6 +215,7 @@ MathJax.ElementJax.mml.Augment({
mathcolor: MML.INHERIT
},
noInherit: {},
linebreakContainer: FALSE,
Init: function () {
this.data = [];
@ -343,16 +344,23 @@ MathJax.ElementJax.mml.Augment({
isEmbellished: function () {return FALSE},
Core: function () {return this},
CoreMO: function () {return this},
lineBreak: function () {
lineBreak: function () { // FIXME: should be removed (and from elements below) when SVG is converted to new linebreak style
if (this.isEmbellished()) {return this.CoreMO().lineBreak()} else {return "none"}
},
hasNewline: function () {
if (this.isEmbellished()) {return this.CoreMO().hasNewline()}
if (this.isToken || this.linebreakContainer) {return FALSE}
for (var i = 0, m = this.data.length; i < m; i++) {
if (this.data[i] && this.data[i].hasNewline()) {return TRUE}
}
return FALSE;
},
array: function () {if (this.inferred) {return this.data} else {return [this]}},
toString: function () {return this.type+"("+this.data.join(",")+")"}
},{
childrenSpacelike: function () {
for (var i = 0; i < this.data.length; i++) {
if (!this.data[i].isSpacelike()) {return FALSE}
}
for (var i = 0, m = this.data.length; i < m; i++)
{if (!this.data[i].isSpacelike()) {return FALSE}}
return TRUE;
},
childEmbellished: function () {
@ -533,6 +541,7 @@ MathJax.ElementJax.mml.Augment({
return MML.FORM.INFIX;
},
isEmbellished: function () {return TRUE},
hasNewline: function () {return (this.Get("linebreak") === MML.LINEBREAK.NEWLINE)},
lineBreak: function () {
var values = this.getValues("linebreak","linebreakstyle");
if (values.linebreak === MML.LINEBREAK.NEWLINE) {
@ -589,6 +598,7 @@ MathJax.ElementJax.mml.Augment({
depth: "0ex",
linebreak: MML.LINEBREAK.AUTO
},
hasNewline: function () {return (this.Get("linebreak") === MML.LINEBREAK.NEWLINE)},
lineBreak: function () {
return (this.Get("linebreak") === MML.LINEBREAK.NEWLINE ?
MML.LINEBREAKSTYLE.AFTER : "none");
@ -675,6 +685,7 @@ MathJax.ElementJax.mml.Augment({
MML.mfrac = MML.mbase.Subclass({
type: "mfrac", num: 0, den: 1,
linebreakContainer: TRUE,
texClass: MML.TEXCLASS.INNER,
isEmbellished: MML.mbase.childEmbellished,
Core: MML.mbase.childCore,
@ -703,6 +714,7 @@ MathJax.ElementJax.mml.Augment({
MML.msqrt = MML.mbase.Subclass({
type: "msqrt",
inferRow: TRUE,
linebreakContainer: TRUE,
texClass: MML.TEXCLASS.ORD,
setTeXclass: MML.mbase.setSeparateTeXclasses,
adjustChild_texprimestyle: function (n) {return TRUE}
@ -710,6 +722,7 @@ MathJax.ElementJax.mml.Augment({
MML.mroot = MML.mbase.Subclass({
type: "mroot",
linebreakContainer: TRUE,
texClass: MML.TEXCLASS.ORD,
adjustChild_displaystyle: function (n) {
if (n === 1) {return FALSE}
@ -767,6 +780,7 @@ MathJax.ElementJax.mml.Augment({
MML.merror = MML.mbase.Subclass({
type: "merror",
inferRow: TRUE,
linebreakContainer: TRUE,
texClass: MML.TEXCLASS.ORD
});
@ -852,6 +866,7 @@ MathJax.ElementJax.mml.Augment({
MML.menclose = MML.mbase.Subclass({
type: "menclose",
inferRow: TRUE,
linebreakContainer: TRUE,
defaults: {
mathbackground: MML.INHERIT,
mathcolor: MML.INHERIT,
@ -863,6 +878,7 @@ MathJax.ElementJax.mml.Augment({
MML.msubsup = MML.mbase.Subclass({
type: "msubsup", base: 0, sub: 1, sup: 2,
linebreakContainer: TRUE,
isEmbellished: MML.mbase.childEmbellished,
Core: MML.mbase.childCore,
CoreMO: MML.mbase.childCoreMO,
@ -910,6 +926,7 @@ MathJax.ElementJax.mml.Augment({
type: "munderover",
base: 0, under: 1, over: 2, sub: 1, sup: 2,
ACCENTS: ["", "accentunder", "accent"],
linebreakContainer: TRUE,
isEmbellished: MML.mbase.childEmbellished,
Core: MML.mbase.childCore,
CoreMO: MML.mbase.childCoreMO,
@ -989,6 +1006,7 @@ MathJax.ElementJax.mml.Augment({
side: TRUE, minlabelspacing: TRUE, texClass: TRUE, useHeight: 1
}
},
linebreakContainer: TRUE,
Append: function () {
for (var i = 0, m = arguments.length; i < m; i++) {
if (!((arguments[i] instanceof MML.mtr) ||
@ -1013,6 +1031,7 @@ MathJax.ElementJax.mml.Augment({
mrow: {rowalign: TRUE, columnalign: TRUE, groupalign: TRUE},
mtable: {rowalign: TRUE, columnalign: TRUE, groupalign: TRUE}
},
linebreakContainer: TRUE,
Append: function () {
for (var i = 0, m = arguments.length; i < m; i++) {
if (!(arguments[i] instanceof MML.mtd)) {arguments[i] = MML.mtd(arguments[i])}
@ -1025,6 +1044,7 @@ MathJax.ElementJax.mml.Augment({
MML.mtd = MML.mbase.Subclass({
type: "mtd",
inferRow: TRUE,
linebreakContainer: TRUE,
isEmbellished: MML.mbase.childEmbellished,
Core: MML.mbase.childCore,
CoreMO: MML.mbase.childCoreMO,
@ -1098,6 +1118,7 @@ MathJax.ElementJax.mml.Augment({
});
MML.annotation = MML.mbase.Subclass({
type: "annotation", isToken: TRUE,
linebreakContainer: TRUE,
defaults: {
definitionURL: null,
encoding: null,
@ -1143,6 +1164,8 @@ MathJax.ElementJax.mml.Augment({
indentalign: MML.INDENTALIGN.AUTO,
indentalignfirst: MML.INDENTALIGN.INDENTALIGN,
indentshiftfirst: MML.INDENTSHIFT.INDENTSHIFT,
indentalignlast: MML.INDENTALIGN.INDENTALIGN,
indentshiftlast: MML.INDENTSHIFT.INDENTSHIFT,
decimalseparator: ".",
texprimestyle: FALSE // is it in TeX's C' style?
},
@ -1150,6 +1173,7 @@ MathJax.ElementJax.mml.Augment({
if (name === "displaystyle") {return this.Get("display") === "block"}
return "";
},
linebreakContainer: TRUE,
setTeXclass: MML.mbase.setChildTeXclass
});
@ -1374,6 +1398,7 @@ MathJax.ElementJax.mml.Augment({
'~': MO.WIDEACCENT // tilde
},
infix: {
'': MO.ORD, // empty <mo>
'%': [3,3,TEXCLASS.ORD], // percent sign
'\u2022': MO.BIN4, // bullet
'\u2026': MO.INNER, // horizontal ellipsis

View File

@ -42,35 +42,38 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
toHTML: function (span,HW,D) {
span = this.HTMLhandleSize(this.HTMLcreateSpan(span)); span.bbox = null;
var values = this.getValues("actiontype","selection"), frame;
var selected = this.data[values.selection-1];
var selected = this.selected();
if (selected) {
HTMLCSS.Measured(selected.toHTML(span),span);
if (D != null) {HTMLCSS.Remeasured(selected.HTMLstretchV(span,HW,D),span)}
else if (HW != null) {HTMLCSS.Remeasured(selected.HTMLstretchH(span,HW),span)}
if (HTMLCSS.msieHitBoxBug) {
// margin-left doesn't work on inline-block elements in IE, so put it in a SPAN
var box = HTMLCSS.addElement(span,"span");
frame = HTMLCSS.createFrame(box,span.bbox.h,span.bbox.d,span.bbox.w,0,"none");
span.insertBefore(box,span.firstChild); // move below the content
box.style.marginRight = HTMLCSS.Em(-span.bbox.w);
if (HTMLCSS.msieInlineBlockAlignBug)
{frame.style.verticalAlign = HTMLCSS.Em(HTMLCSS.getHD(span).d-span.bbox.d)}
} else {
frame = HTMLCSS.createFrame(span,span.bbox.h,span.bbox.d,span.bbox.w,0,"none");
span.insertBefore(frame,span.firstChild); // move below the content
frame.style.marginRight = HTMLCSS.Em(-span.bbox.w);
}
frame.className = "MathJax_HitBox";
frame.id = "MathJax-HitBox-"+this.spanID;
if (this.HTMLaction[values.actiontype])
{this.HTMLaction[values.actiontype].call(this,span,frame,values.selection)}
this.HTMLhandleHitBox(span);
}
this.HTMLhandleSpace(span);
this.HTMLhandleColor(span);
return span;
},
HTMLhandleHitBox: function (span,postfix) {
var frame;
if (HTMLCSS.msieHitBoxBug) {
// margin-left doesn't work on inline-block elements in IE, so put it in a SPAN
var box = HTMLCSS.addElement(span,"span");
frame = HTMLCSS.createFrame(box,span.bbox.h,span.bbox.d,span.bbox.w,0,"none");
span.insertBefore(box,span.firstChild); // move below the content
box.style.marginRight = HTMLCSS.Em(-span.bbox.w);
if (HTMLCSS.msieInlineBlockAlignBug)
{frame.style.verticalAlign = HTMLCSS.Em(HTMLCSS.getHD(span).d-span.bbox.d)}
} else {
frame = HTMLCSS.createFrame(span,span.bbox.h,span.bbox.d,span.bbox.w,0,"none");
span.insertBefore(frame,span.firstChild); // move below the content
frame.style.marginRight = HTMLCSS.Em(-span.bbox.w);
}
frame.className = "MathJax_HitBox";
frame.id = "MathJax-HitBox-" + this.spanID + (postfix||"") + HTMLCSS.idPostfix;
var type = this.Get("actiontype");
if (this.HTMLaction[type]) {this.HTMLaction[type].call(this,span,frame,this.Get("selection"))}
},
HTMLstretchH: MML.mbase.HTMLstretchH,
HTMLstretchV: MML.mbase.HTMLstretchV,

View File

@ -2,7 +2,7 @@
*
* MathJax/jax/output/HTML-CSS/autoload/multiline.js
*
* Implements the HTML-CSS output <mrow>'s that contain line breaks.
* Implements the HTML-CSS output for <mrow>'s that contain line breaks.
*
* ---------------------------------------------------------------------
*
@ -25,59 +25,97 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
var VERSION = "1.1";
var MML = MathJax.ElementJax.mml,
HTMLCSS = MathJax.OutputJax["HTML-CSS"];
//
// Penalties for the various line breaks
//
var PENALTY = {
newline: 0,
nobreak: 1000000,
goodbreak: [-200],
badbreak: [+200],
auto: [0],
toobig: 500,
nestfactor: 400,
fence: 500
};
var ENDVALUES = {linebreakstyle: "after"};
/**************************************************************************/
MML.mbase.Augment({
toHTMLmultiline: function (span,split) {
span = this.HTMLcreateSpan(span); if (!this.type !== "mrow") {span = this.HTMLhandleSize(span)}
var stack = HTMLCSS.createStack(span);
var box = [], stretchy = [], H = -HTMLCSS.BIGDIMEN, D = -HTMLCSS.BIGDIMEN, i, j, m, M;
for (j = 0, M = split.length-1; j < M; j++) {
box[j] = HTMLCSS.createBox(stack);
for (i = split[j][0], m = split[j+1][0]; i < m; i++)
{if (this.data[i]) {this.data[i].toHTML(box[j])}}
// remove inter-object spacing
if (this.data[split[j][0]]) {this.data[split[j][0]].HTMLspanElement().style.paddingLeft = ""}
if (this.data[split[j][m-1]]) {this.data[split[j][m-1]].HTMLspanElement().style.paddingRight = ""}
//
stretchy[j] = this.HTMLcomputeBBox(box[j],null,split[j][0],split[j+1][0]);
if (box[j].bbox.h > H) {H = box[j].bbox.h}
if (box[j].bbox.d > D) {D = box[j].bbox.d}
}
var y = 0, scale = this.HTMLgetScale(), LHD = HTMLCSS.FONTDATA.baselineskip * scale;
var parent = this, first;
HTMLlinebreakPenalty: PENALTY,
/****************************************************************/
//
// Handle breaking an mrow into separate lines
//
HTMLmultiline: function (span) {
//
// Find the parent element and mark it as multiline
//
var parent = this;
while (parent.inferred || (parent.parent && parent.parent.type === "mrow" &&
parent.parent.data.length === 1)) {parent = parent.parent}
var isTop = (parent.type === "math" || parent.type === "mtd"); parent.isMultiline = true;
for (j = 0, M = split.length-1; j < M; j++) {
for (i = 0, m = stretchy[j].length; i < m; i++) {stretchy[j][i].HTMLstretchV(box[j],H,D)}
if (stretchy[j].length) {this.HTMLcomputeBBox(box[j],true,split[j][0],split[j+1][0])}
var values = split[j][1].getValues("indentalign","indentshift");
values.lineleading = HTMLCSS.length2em(split[j+1][1].Get("lineleading"),.5);
// handle first/last special cases
if (j === 0) {
first = split[j+1][1].getValues("indentalignfirst","indentshiftfirst");
values.ALIGN = first.indentalignfirst; values.SHIFT = first.indentshiftfirst;
} else if (j === M-1) {
first = split[j][1].getValues("indentalignlast","indentshiftlast");
values.ALIGN = first.indentalignlast; values.SHIFT = first.indentshiftlast;
}
if (values.ALIGN && values.ALIGN !== MML.INDENTALIGN.INDENTALIGN)
{values.indentalign = values.ALIGN}
if (values.SHIFT && values.SHIFT !== MML.INDENTSHIFT.INDENTSHIFT)
{values.indentshift = values.SHIFT}
//
if (values.indentalign == MML.INDENTALIGN.AUTO)
{values.indentalign = (isTop ? this.displayAlign : MML.INDENTALIGN.LEFT)}
if (values.indentshift === "auto" || values.indentshift === "")
{values.indentshift = (isTop ? this.displayIndent : "0")}
values.indentshift = HTMLCSS.length2em(values.indentshift,0);
if (values.indentshift && values.indentalign !== MML.INDENTALIGN.CENTER) {
HTMLCSS.createBlank(box[j],values.indentshift,(values.indentalign !== MML.INDENTALIGN.RIGHT));
box[j].bbox.w += values.indentshift; box[j].bbox.rw += values.indentshift;
}
HTMLCSS.alignBox(box[j],values.indentalign,y);
if (j < M-1) {y -= Math.max(LHD,box[j].bbox.d + box[j+1].bbox.h + values.lineleading)}
var isTop = ((parent.type === "math" && parent.Get("display") === "block") ||
parent.type === "mtd");
parent.isMultiline = true;
//
// Default values for the line-breaking parameters
//
var VALUES = this.getValues(
"linebreak","linebreakstyle","lineleading","linebreakmultchar",
"indentalign","indentshift",
"indentalignfirst","indentshiftfirst",
"indentalignlast","indentshiftlast"
);
if (VALUES.linebreakstyle === MML.LINEBREAKSTYLE.INFIXLINEBREAKSTYLE)
{VALUES.linebreakstyle = this.Get("infixlinebreakstyle")}
VALUES.lineleading = HTMLCSS.length2em(VALUES.lineleading,0.5);
//
// Remove old color and break the span at its best line breaks
//
this.HTMLremoveColor(span);
var stack = HTMLCSS.createStack(span);
var state = {
n: 0, Y: 0,
scale: this.HTMLgetScale(),
isTop: isTop,
values: {},
VALUES: VALUES
},
align = this.HTMLgetAlign(state,{}),
shift = this.HTMLgetShift(state,{},align),
start = [],
end = {
index:[], penalty:PENALTY.nobreak,
w:0, W:shift, shift:shift, scanW:shift,
nest: 0
},
broken = false;
while (this.HTMLbetterBreak(end,state) &&
(end.scanW >= HTMLCSS.linebreakWidth || end.penalty == PENALTY.newline)) {
this.HTMLaddLine(stack,start,end.index,state,end.values,broken);
start = end.index.slice(0); broken = true;
align = this.HTMLgetAlign(state,end.values);
shift = this.HTMLgetShift(state,end.values,align);
if (align === MML.INDENTALIGN.CENTER) {shift = 0}
end.W = end.shift = end.scanW = shift; end.penalty = PENALTY.nobreak;
}
state.isLast = true;
this.HTMLaddLine(stack,start,[],state,ENDVALUES,broken);
//
// Make top-level spans 100% wide.
// Finish up the space and add the color again
//
if (isTop) {
stack.style.width = "100%";
if (parent.type === "math") {span.bbox.width = "100%"}
@ -85,10 +123,399 @@ MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function () {
this.HTMLhandleSpace(span);
this.HTMLhandleColor(span);
span.bbox.isMultiline = true;
return span;
},
/****************************************************************/
//
// Locate the next linebreak that is better than the current one
//
HTMLbetterBreak: function (info,state) {
if (this.isToken) {return false} // FIXME: handle breaking of token elements
if (this.isEmbellished()) {
info.embellished = this;
return this.CoreMO().HTMLbetterBreak(info,state);
}
if (this.linebreakContainer) {return false}
//
// Get the current breakpoint position and other data
//
var index = info.index.slice(0), i = info.index.shift(),
m = this.data.length, W, scanW = info.W,
broken = (info.index.length > 0), better = false;
if (i == null) {i = -1}; if (!broken) {i++; info.W += info.w};
info.w = 0; info.nest++;
//
// Look through the line for breakpoints,
// (as long as we are not too far past the breaking width)
//
while (i < m && info.W < 1.33*HTMLCSS.linebreakWidth) {
if (this.data[i]) {
if (this.data[i].HTMLbetterBreak(info,state)) {
better = true; index = [i].concat(info.index); W = info.W;
if (info.penalty === PENALTY.newline) {info.index = index; info.nest--; return true}
}
if (!broken) {
var span = this.data[i].HTMLspanElement();
scanW += span.bbox.w;
if (span.style.paddingLeft) {scanW += parseFloat(span.style.paddingLeft)}
if (span.style.paddingRight) {scanW += parseFloat(span.style.paddingRight)}
info.W = info.scanW = scanW;
}
}
info.index = []; i++; broken = false;
}
info.nest--; info.index = index;
if (better) {info.W = W}
return better;
},
/****************************************************************/
//
// Create a new line and move the required elements into it
// Position it using proper alignment and indenting
//
HTMLaddLine: function (stack,start,end,state,values,broken) {
//
// Create a box for the line, with empty BBox
// fill it with the proper elements,
// and clean up the bbox
//
line = HTMLCSS.createBox(stack);
line.bbox = this.HTMLemptyBBox({});
state.first = broken; state.last = true;
this.HTMLmoveLine(start,end,line,state,values);
this.HTMLcleanBBox(line.bbox);
//
// Get the alignment and shift values
//
var align = this.HTMLgetAlign(state,values),
shift = this.HTMLgetShift(state,values,align);
//
// Add in space for the shift
//
if (shift) {
HTMLCSS.createBlank(line,shift,(align !== MML.INDENTALIGN.RIGHT));
line.bbox.w += shift; line.bbox.rw += shift;
}
//
// Set the Y offset based on previous depth, leading, and current height
//
if (state.n > 0) {
var LHD = HTMLCSS.FONTDATA.baselineskip * state.scale;
var leading = (state.values.lineleading == null ? state.VALUES : state.values).lineleading;
state.Y -= Math.max(LHD,state.d + line.bbox.h + leading);
}
//
// Place the new line
//
HTMLCSS.alignBox(line,align,state.Y);
//
// Save the values needed for the future
//
state.d = line.bbox.d; state.values = values; state.n++;
},
/****************************************************************/
//
// Get alignment and shift values from the given data
//
HTMLgetAlign: function (state,values) {
var cur = values, prev = state.values, def = state.VALUES, align;
if (state.n === 0) {align = cur.indentalignfirst || prev.indentalignfirst || def.indentalignfirst}
else if (state.isLast) {align = prev.indentalignlast || def.indentalignlast}
else {align = prev.indentalign || def.indentalign}
if (align === MML.INDENTALIGN.INDENTALIGN) {align = prev.indentalign || def.indentalign}
if (align === MML.INDENTALIGN.AUTO) {align = (state.isTop ? this.displayAlign : MML.INDENTALIGN.LEFT)}
return align;
},
HTMLgetShift: function (state,values,align) {
if (align === MML.INDENTALIGN.CENTER) {return 0}
var cur = values, prev = state.values, def = state.VALUES, shift;
if (state.n === 0) {shift = cur.indentshiftfirst || prev.indentshiftfirst || def.indentshiftfirst}
else if (state.isLast) {shift = prev.indentshiftlast || def.indentshiftlast}
else {shift = prev.indentshift || def.indentshift}
if (shift === MML.INDENTSHIFT.INDENTSHIFT) {shift = prev.indentshift || def.indentshift}
if (shift === "auto" || shift === "") {shift = (state.isTSop ? this.displayIndent : "0")}
return HTMLCSS.length2em(shift,0);
},
/****************************************************************/
//
// Move the selected elements into the new line's span,
// moving whole items when possible, and parts of ones
// that are split by a line break.
//
HTMLmoveLine: function (start,end,span,state,values) {
var i = start[0], j = end[0];
if (i == null) {i = -1}; if (j == null) {j = this.data.length-1}
if (i === j && start.length > 1) {
//
// If starting and ending in the same element move the subpiece to the new line
//
this.data[i].HTMLmoveSlice(start.slice(1),end.slice(1),span,state,values,"paddingLeft");
} else {
//
// Otherwise, move the remainder of the initial item
// and any others up tp the last one
//
var last = state.last; state.last = false;
while (i < j) {
if (this.data[i]) {
if (start.length <= 1) {this.data[i].HTMLmoveSpan(span,state,values)}
else {this.data[i].HTMLmoveSlice(start.slice(1),[],span,state,values,"paddingLeft")}
}
i++; state.first = false; start = [];
}
//
// If the last item is complete, move it,
// otherwise move the first part of it up to the split
//
state.last = last;
if (this.data[i]) {
if (end.length <= 1) {this.data[i].HTMLmoveSpan(span,state,values)}
else {this.data[i].HTMLmoveSlice([],end.slice(1),span,state,values,"paddingRight")}
}
}
},
/****************************************************************/
//
// Split an element and copy the selected items into the new part
//
HTMLmoveSlice: function (start,end,span,state,values,padding) {
//
// Get rid of color, if any (added back in later)
// Create a new span for the slice of the element
// Move the selected portion into the slice
// If it is the last slice
// Remove the original (now empty) span
// Rename the Continue-0 span with the original name (for HTMLspanElement)
// Add back the color
//
this.HTMLremoveColor();
var slice = this.HTMLcreateSliceSpan(span);
this.HTMLmoveLine(start,end,slice,state,values);
slice.style[padding] = "";
this.HTMLcombineBBoxes(slice,span.bbox);
this.HTMLcleanBBox(slice.bbox);
if (end.length === 0) {
span = this.HTMLspanElement();
span.parentNode.removeChild(span);
span.nextMathJaxSpan.id = span.id; var n = 0;
while (span = span.nextMathJaxSpan) {
var color = this.HTMLhandleColor(span);
if (color) {color.id += "-MathJax-Continue-"+n; n++}
}
}
return slice;
},
/****************************************************************/
//
// Create a new span for an element that is split in two
// Clone the original and update its ID.
// Link the old span to the new one so we can find it later
//
HTMLcreateSliceSpan: function (span) {
var SPAN = this.HTMLspanElement(), n = 0;
var LAST = SPAN; while (LAST.nextMathJaxSpan) {LAST = LAST.nextMathJaxSpan; n++}
var SLICE = SPAN.cloneNode(false); LAST.nextMathJaxSpan = SLICE;
SLICE.id += "-MathJax-Continue-"+n;
SLICE.bbox = this.HTMLemptyBBox({});
return span.appendChild(SLICE);
},
/****************************************************************/
//
// Move an element from its original span to its new location in
// a split element or the new line's span
//
HTMLmoveSpan: function (line,state,values) {
// FIXME: handle linebreakstyle === "duplicate"
// FIXME: handle linebreakmultchar
if (!(state.first || state.last) ||
(state.first && state.values.linebreakstyle === MML.LINEBREAKSTYLE.BEFORE) ||
(state.last && values.linebreakstyle === MML.LINEBREAKSTYLE.AFTER)) {
//
// Move color and span
//
var color = document.getElementById("MathJax-Color-"+this.spanID+HTMLCSS.idPostfix);
if (color) {line.appendChild(color)}
var span = this.HTMLspanElement();
line.appendChild(span);
//
// If it is last, remove right padding
// If it is first, remove left padding and recolor
//
if (state.last) {span.style.paddingRight = ""}
if (state.first || state.nextIsFirst) {
delete state.nextIsFirst;
span.style.paddingLeft = "";
if (color) {this.HTMLremoveColor(span); this.HTMLhandleColor(span)}
}
//
// Update bounding box
//
this.HTMLcombineBBoxes(this,line.bbox);
} else if (state.first) {state.nextIsFirst = true} else {delete state.nextIsFirst}
}
});
/**************************************************************************/
MML.mo.Augment({
//
// Override the method for checking line breaks to properly handle <mo>
//
HTMLbetterBreak: function (info,state) {
var values = this.getValues(
"linebreak","linebreakstyle","lineleading","linebreakmultchar",
"indentalign","indentshift",
"indentalignfirst","indentshiftfirst",
"indentalignlast","indentshiftlast"
);
if (values.linebreakstyle === MML.LINEBREAKSTYLE.INFIXLINEBREAKSTYLE)
{values.linebreakstyle = this.Get("infixlinebreakstyle")}
//
// Get the default penalty for this location
//
var W = info.W, mo = (info.embellished||this); delete info.embellished;
var span = mo.HTMLspanElement(), w = span.bbox.w;
if (span.style.paddingLeft) {w += parseFloat(span.style.paddingLeft)}
if (values.linebreakstyle === MML.LINEBREAKSTYLE.AFTER) {W += w; w = 0}
if (W - info.shift === 0) {return false} // don't break at zero width (FIXME?)
var offset = HTMLCSS.linebreakWidth - W;
// adjust offest for explicit first-line indent and align
if (state.n === 0 && (values.indentshiftfirst !== state.VALUES.indentshiftfirst ||
values.indentalignfirst !== state.VALUES.indentalignfirst)) {
var align = this.HTMLgetAlign(state,values),
shift = this.HTMLgetShift(state,values,align);
offset += (info.shift - shift);
}
//
var penalty = Math.floor(offset / HTMLCSS.linebreakWidth * 1000);
if (penalty < 0) {penalty = PENALTY.toobig - 3*penalty}
if (this.Get("fence")) {penalty += PENALTY.fence}
penalty += info.nest * PENALTY.nestfactor;
//
// Get the penalty for this type of break and
// use it to modify the default penalty
//
var linebreak = PENALTY[values.linebreak||MML.LINEBREAK.AUTO];
if (!(linebreak instanceof Array)) {
// for breaks past the width, don't modify penalty
if (offset >= 0) {penalty = linebreak * info.nest}
} else {penalty = Math.max(1,penalty + linebreak[0] * info.nest)}
//
// If the penalty is no better than the current one, return false
// Otherwise save the data for this breakpoint and return true
//
if (penalty >= info.penalty) {return false}
info.penalty = penalty; info.values = values; info.W = W; info.w = w;
values.lineleading = HTMLCSS.length2em(values.lineleading,state.VALUES.lineleading);
return true;
}
});
/**************************************************************************/
MML.mspace.Augment({
//
// Override the method for checking line breaks to properly handle <mspace>
//
HTMLbetterBreak: function (info,state) {
var values = this.getValues("linebreak");
//
// Get the default penalty for this location
//
var W = info.W, span = this.HTMLspanElement(), w = span.bbox.w;
if (span.style.paddingLeft) {w += parseFloat(span.style.paddingLeft)}
if (values.linebreakstyle === MML.LINEBREAKSTYLE.AFTER) {W += w; w = 0}
if (W - info.shift === 0) {return false} // don't break at zero width (FIXME?)
var offset = HTMLCSS.linebreakWidth - W;
//
var penalty = Math.floor(offset / HTMLCSS.linebreakWidth * 1000);
if (penalty < 0) {penalty = PENALTY.toobig - 3*penalty}
penalty += info.nest * PENALTY.nestfactor;
//
// Get the penalty for this type of break and
// use it to modify the default penalty
//
var linebreak = PENALTY[values.linebreak||MML.LINEBREAK.AUTO];
if (!(linebreak instanceof Array)) {
// for breaks past the width, don't modify penalty
if (offset >= 0) {penalty = linebreak * info.nest}
} else {penalty = Math.max(1,penalty + linebreak[0] * info.nest)}
//
// If the penalty is no better than the current one, return false
// Otherwise save the data for this breakpoint and return true
//
if (penalty >= info.penalty) {return false}
info.penalty = penalty; info.values = values; info.W = W; info.w = w;
values.lineleading = state.VALUES.lineleading; values.linebreakstyle = "before";
return true;
}
});
//
// Hook into the mathchoice extension
//
MathJax.Hub.Register.StartupHook("TeX mathchoice Ready",function () {
MML.TeXmathchoice.Augment({
HTMLbetterBreak: function (info,state) {
return this.Core().HTMLbetterBreak(info,state);
},
HTMLmoveLine: function (start,end,span,state,values) {
return this.Core().HTMLmoveSlice(start,end,span,state,values);
}
});
});
//
// Have maction process only the selected item
//
MML.maction.Augment({
HTMLbetterBreak: function (info,state) {
return this.Core().HTMLbetterBreak(info,state);
},
HTMLmoveLine: function (start,end,span,state,values) {
return this.Core().HTMLmoveSlice(start,end,span,state,values);
},
//
// Split and move the hit boxes as well
//
HTMLmoveSlice: function (start,end,span,state,values,padding) {
var hitbox = document.getElementById("MathJax-HitBox-"+this.spanID+HTMLCSS.idPostfix);
if (hitbox) {hitbox.parentNode.removeChild(hitbox)}
var slice = this.SUPER(arguments).HTMLmoveSlice.apply(this,arguments);
if (end.length === 0) {
span = this.HTMLspanElement(); var n = 0;
while (span) {
hitbox = this.HTMLhandleHitBox(span,"-Continue-"+n);
span = span.nextMathJaxSpan; n++;
}
}
return slice;
}
});
//
// Have semantics only do the first element
// (FIXME: do we need to do anything special about annotation-xml?)
//
MML.semantics.Augment({
HTMLbetterBreak: function (info,state) {
return (this.data[0] ? this.data[0].HTMLbetterBreak(info,state) : false);
},
HTMLmoveLine: function (start,end,span,state,values) {
return (this.data[0] ? this.data[0].HTMLmoveSlice(start,end,span,state,values) : null);
}
});
/**************************************************************************/
MathJax.Hub.Startup.signal.Post("HTML-CSS multiline Ready");
MathJax.Ajax.loadComplete(HTMLCSS.autoloadDir+"/multiline.js");

View File

@ -24,7 +24,7 @@
MathJax.OutputJax["HTML-CSS"] = MathJax.OutputJax({
id: "HTML-CSS",
version: "1.1.9",
version: "1.1.10",
directory: MathJax.OutputJax.directory + "/HTML-CSS",
extensionDir: MathJax.OutputJax.extensionDir + "/HTML-CSS",
autoloadDir: MathJax.OutputJax.directory + "/HTML-CSS/autoload",
@ -39,6 +39,16 @@ MathJax.OutputJax["HTML-CSS"] = MathJax.OutputJax({
imageFont: "TeX",
undefinedFamily: "STIXGeneral,'Arial Unicode MS',serif",
linebreaks: {
automatic: false, // when false, only process linebreak="newline",
// when true, insert line breaks automatically in long expressions.
width: "container" // maximum width of a line for automatic line breaks (e.g. "30em").
// use "container" to compute size from containing element,
// use "nn% container" for a portion of the container,
// use "nn%" for a portion of the window size
},
showMathMenu: true,
styles: {
@ -58,7 +68,7 @@ MathJax.OutputJax["HTML-CSS"] = MathJax.OutputJax({
},
".MathJax_Preview": {color: "#888888"},
"#MathJax_Tooltip": {
"background-color": "InfoBackground", color: "InfoText",
border: "1px solid black",

View File

@ -242,7 +242,12 @@
},
".MathJax .MathJax_HitBox": {
cursor: "text"
cursor: "text",
background: "white",
opacity:0, filter:"alpha(opacity=0)"
},
".MathJax .MathJax_HitBox *": {
filter: "none", opacity:1, background:"transparent" // for IE
},
"#MathJax_Tooltip": {
@ -251,7 +256,7 @@
display: "none"
},
"#MathJax_Tooltip *": {
filter: "none", background:"transparent" // for IE
filter: "none", opacity:1, background:"transparent" // for IE
}
}
@ -362,6 +367,10 @@
[["span",{style: {display:"inline-block", width:"5em"}}]]);
this.marginMove = HTMLCSS.addElement(this.marginCheck,"span",
{style: {display:"inline-block", width:"5em", marginLeft:"-5em"}});
// Used in getLinebreakWidth
this.linebreakSpan = HTMLCSS.Element("span",null,
[["hr",{style: {width:"100%", size:1, padding:0, border:0, margin:0}}]]);
// Set up styles and preload web fonts
return AJAX.Styles(this.config.styles,["PreloadWebFonts",this]);
@ -410,6 +419,7 @@
script.parentNode.insertBefore(frame,script); var isHidden;
try {this.getScales(span); isHidden = (this.em === 0 || String(this.em) === "NaN")} catch (err) {isHidden = true}
if (isHidden) {this.hiddenDiv.appendChild(frame); this.getScales(span)}
this.getLinebreakWidth(frame);
this.initImg(span);
this.initHTML(math,span);
math.setTeXclass();
@ -493,6 +503,21 @@
span = span.previousSibling; if (!span) return;
if (span.className.match(/^MathJax/)) {span.parentNode.removeChild(span)}
},
getLinebreakWidth: function (div) {
if (this.config.linebreaks.automatic) {
var width = this.config.linebreaks.width, maxwidth;
if (width.match(/^\s*(\d+(\.\d*)?%\s*)?container\s*$/)) {
div.parentNode.insertBefore(this.linebreakSpan,div);
maxwidth = this.linebreakSpan.firstChild.offsetWidth / this.em;
this.linebreakSpan.parentNode.removeChild(this.linebreakSpan);
width = width.replace(/\s*container\s*/,"");
} else {maxwidth = document.body.offsetWidth / this.em}
this.linebreakWidth = (width === "" ? maxwidth : this.length2em(width,maxwidth));
} else {
this.linebreakWidth = 100000; // a big width, so no implicit line breaks
}
},
getScales: function (span) {
span.parentNode.insertBefore(this.HDMspan,span);
@ -1238,8 +1263,6 @@
MML.mbase.Augment({
toHTML: function (span) {
var split = this.HTMLlineBreaks();
if (split.length > 2) {return this.toHTMLmultiline(span,split)}
span = this.HTMLcreateSpan(span); if (this.type != "mrow") {span = this.HTMLhandleSize(span)}
for (var i = 0, m = this.data.length; i < m; i++)
{if (this.data[i]) {this.data[i].toHTML(span)}}
@ -1247,26 +1270,13 @@
var h = span.bbox.h, d = span.bbox.d;
for (i = 0, m = stretchy.length; i < m; i++) {stretchy[i].HTMLstretchV(span,h,d)}
if (stretchy.length) {this.HTMLcomputeBBox(span,true)}
if (this.HTMLlineBreaks(span)) {span = this.HTMLmultiline(span)}
this.HTMLhandleSpace(span);
this.HTMLhandleColor(span);
return span;
},
HTMLlineBreaks: function () {
var split = [[0,this]];
for (var i = 0, m = this.data.length; i < m; i++) {
if (this.data[i]) {
var lb = this.data[i].lineBreak();
if (lb !== "none") {
var j = (lb === "after" ? i+1 : i);
if (split.length === 0 || split[split.length-1] !== j)
{split.push([j,this.data[i]])} else {split[split.length-1] = [j,this.data[i]]}
}
}
}
split.push([this.data.length,split[split.length-1][1]]);
return split;
},
toHTMLmultiline: function (span) {MML.mbase.HTMLautoloadFile("multiline")},
HTMLlineBreaks: function () {return false},
HTMLmultiline: function () {MML.mbase.HTMLautoloadFile("multiline")},
HTMLcomputeBBox: function (span,full,i,m) {
if (i == null) {i = 0}; if (m == null) {m = this.data.length}
var BBOX = span.bbox = {}, stretchy = [];
@ -1281,7 +1291,8 @@
},
HTMLcombineBBoxes: function (core,BBOX) {
if (BBOX.w == null) {this.HTMLemptyBBox(BBOX)}
var child = core.HTMLspanElement(); if (!child || !child.bbox) return;
var child = (core.bbox ? core : core.HTMLspanElement());
if (!child || !child.bbox) return;
var bbox = child.bbox;
if (bbox.d > BBOX.d) {BBOX.d = bbox.d}
if (bbox.h > BBOX.h) {BBOX.h = bbox.h}
@ -1410,7 +1421,9 @@
marginLeft: HTMLCSS.Em(lW), marginRight: HTMLCSS.Em(rW)}
});
HTMLCSS.setBorders(frame,borders);
if (span.bbox.width) {frame.style.width = span.bbox.width; frame.style.marginRight = "-"+span.bbox.width}
if (HTMLCSS.msieInlineBlockAlignBug) {
// FIXME: handle variable width background
frame.style.position = "relative"; frame.style.width = frame.style.height = 0;
frame.style.verticalAlign = frame.style.marginLeft = frame.style.marginRight = "";
frame.style.border = frame.style.padding = "";
@ -1763,6 +1776,11 @@
});
MML.mrow.Augment({
HTMLlineBreaks: function (span) {
if (!this.parent.linebreakContainer) {return false}
return (HTMLCSS.config.linebreaks.automatic &&
span.bbox.w > HTMLCSS.linebreakWidth) || this.hasNewline();
},
HTMLstretchH: function (box,w) {
this.HTMLremoveColor();
var span = this.HTMLspanElement();
@ -1782,30 +1800,20 @@
});
MML.mstyle.Augment({
toHTML: function (span) {
toHTML: function (span,HW,D) {
span = this.HTMLcreateSpan(span);
if (this.data[0] != null) {
if (this.style) {
span = this.HTMLcreateSpan(span);
span.bbox = this.data[0].toHTML(span).bbox;
} else {
span = this.data[0].toHTML(span);
this.spanID = this.data[0].spanID;
}
this.HTMLhandleSpace(span);
this.HTMLhandleColor(span);
var SPAN = this.data[0].toHTML(span);
if (D != null) {this.data[0].HTMLstretchV(span,HW,D)}
else if (HW != null) {this.data[0].HTMLstretchH(span,HW)}
span.bbox = SPAN.bbox;
}
this.HTMLhandleSpace(span);
this.HTMLhandleColor(span);
return span;
},
HTMLspanElement: function () {
if (this.style) {return this.SUPER(arguments).HTMLspanElement.call(this)}
return (this.data[0] != null ? this.data[0].HTMLspanElement() : null);
},
HTMLstretchH: function (box,w) {
return (this.data[0] != null ? this.data[0].HTMLstretchH(box,w) : box);
},
HTMLstretchV: function (box,h,d) {
return (this.data[0] != null ? this.data[0].HTMLstretchV(box,h,d) : box);
}
HTMLstretchH: MML.mbase.HTMLstretchH,
HTMLstretchV: MML.mbase.HTMLstretchV
});
MML.mfrac.Augment({
@ -2140,7 +2148,8 @@
MML.math.Augment({
toHTML: function (span,node) {
var alttext = this.Get("alttext"); if (alttext) {node.setAttribute("aria-label",alttext)}
var alttext = this.Get("alttext");
if (alttext && alttext !== "") {node.setAttribute("aria-label",alttext)}
var nobr = HTMLCSS.addElement(span,"nobr");
span = this.HTMLcreateSpan(nobr);
var stack = HTMLCSS.createStack(span), box = HTMLCSS.createBox(stack), math;