/*
* /MathJax/jax/output/HTML-CSS/autoload/multiline.js
*
* Copyright (c) 2009-2013 The MathJax Consortium
*
* Part of the MathJax library.
* See http://www.mathjax.org for details.
*
* Licensed under the Apache License, Version 2.0;
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*/MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function(){var l=MathJax.ElementJax.mml,m=MathJax.OutputJax["HTML-CSS"],n={newline:0,nobreak:1E6,goodbreak:[-200],badbreak:[200],auto:[0],toobig:800,nestfactor:400,spacefactor:-100,spaceoffset:2,spacelimit:1,fence:500,close:500},r={linebreakstyle:"after"};l.mbase.Augment({HTMLlinebreakPenalty:n,HTMLmultiline:function(a){for(var c=this;c.inferred||c.parent&&"mrow"===c.parent.type&&1===c.parent.data.length;)c=c.parent;var d="math"===c.type&&"block"===c.Get("display")||"mtd"===c.type;c.isMultiline=!0;var b=this.getValues("linebreak","linebreakstyle","lineleading","linebreakmultchar","indentalign","indentshift","indentalignfirst","indentshiftfirst","indentalignlast","indentshiftlast");b.linebreakstyle===l.LINEBREAKSTYLE.INFIXLINEBREAKSTYLE&&(b.linebreakstyle=this.Get("infixlinebreakstyle"));b.lineleading=m.length2em(b.lineleading,1,.5);this.HTMLremoveColor(a);for(var e=m.createStack(a),b={n:0,Y:0,scale:this.HTMLgetScale(),isTop:d,values:{},VALUES:b},g=this.HTMLgetAlign(b,{}),f=this.HTMLgetShift(b,{},g),k=[],h={index:[],penalty:n.nobreak,w:0,W:f,shift:f,scanW:f,nest:0},q=!1;this.HTMLbetterBreak(h,b)&&(h.scanW>=m.linebreakWidth||h.penalty==n.newline);)this.HTMLaddLine(e,k,h.index,b,h.values,q),k=h.index.slice(0),q=!0,g=this.HTMLgetAlign(b,h.values),f=this.HTMLgetShift(b,h.values,g),g===l.INDENTALIGN.CENTER&&(f=0),h.W=h.shift=h.scanW=f,h.penalty=n.nobreak;b.isLast=!0;this.HTMLaddLine(e,k,[],b,r,q);d&&(e.style.width="100%","math"===c.type&&(a.bbox.width="100%"));this.HTMLhandleSpace(a);this.HTMLhandleColor(a);a.bbox.isMultiline=!0;return a},HTMLbetterBreak:function(a,c){if(this.isToken)return!1;if(this.isEmbellished())return a.embellished=this,this.CoreMO().HTMLbetterBreak(a,c);if(this.linebreakContainer)return!1;var d=a.index.slice(0),b=a.index.shift(),e=this.data.length,g,f,k,h=0=a.length?this.data[g].HTMLmoveSpan(d,b,e):this.data[g].HTMLmoveSlice(a.slice(1),[],d,b,e,"paddingLeft")),g++,b.first=!1,a=[];b.last=k;this.data[g]&&(1>=c.length?this.data[g].HTMLmoveSpan(d,b,e):this.data[g].HTMLmoveSlice([],c.slice(1),d,b,e,"paddingRight"))}},HTMLmoveSlice:function(a,c,d,b,e,g){this.HTMLremoveColor();var f=this.HTMLcreateSliceSpan(d);this.HTMLmoveLine(a,c,f,b,e);f.style[g]="";this.HTMLcombineBBoxes(f,d.bbox);this.HTMLcleanBBox(f.bbox);if(0===c.length)for(d=this.HTMLspanElement(),d.parentNode.removeChild(d),d.nextMathJaxSpan.id=d.id,a=0;d=d.nextMathJaxSpan;)if(c=this.HTMLhandleColor(d))c.id+="-MathJax-Continue-"+a,a++;return f},HTMLcreateSliceSpan:function(a){for(var c=this.HTMLspanElement(),d=0,b=c;b.nextMathJaxSpan;)b=b.nextMathJaxSpan,d++;c=c.cloneNode(!1);b.nextMathJaxSpan=c;c.nextMathJaxSpan=null;c.id+="-MathJax-Continue-"+d;c.bbox=this.HTMLemptyBBox({});return a.appendChild(c)},HTMLmoveSpan:function(a,c,d){if(!c.first&&!c.last||c.first&&c.values.linebreakstyle===l.LINEBREAKSTYLE.BEFORE||c.last&&d.linebreakstyle===l.LINEBREAKSTYLE.AFTER){(d=document.getElementById("MathJax-Color-"+this.spanID+m.idPostfix))&&a.appendChild(d);var b=this.HTMLspanElement();a.appendChild(b);c.last&&(b.style.paddingRight="");if(c.first||c.nextIsFirst)delete c.nextIsFirst,b.style.paddingLeft="",d&&(this.HTMLremoveColor(b),this.HTMLhandleColor(b));this.HTMLcombineBBoxes(this,a.bbox)}else c.first?c.nextIsFirst=!0:delete c.nextIsFirst}});l.mfenced.Augment({HTMLbetterBreak:function(a,c){var d=a.index.slice(0),b=a.index.shift(),e=this.data.length,g,f,k,h=0=a.length?this.data[h].HTMLmoveSpan(d,b,e):this.data[h].HTMLmoveSlice(a.slice(1),[],d,b,e,"paddingLeft")),g++,h=this.dataI[g],b.first=!1,a=[];b.last=k;this.data[h]&&(1>=c.length?this.data[h].HTMLmoveSpan(d,b,e):this.data[h].HTMLmoveSlice([],c.slice(1),d,b,e,"paddingRight"))}}});l.msubsup.Augment({HTMLbetterBreak:function(a,c){if(!this.data[this.base])return!1;var d=a.index.slice(0),b=a.index.shift(),e,g,f,k=0=c.length?this.data[this.base].HTMLmoveSpan(d,b,e):this.data[this.base].HTMLmoveSlice([],c.slice(1),d,b,e,"paddingRight"));if(0===c.length&&(a=this.data[this.sup]||this.data[this.sub])){a=a.HTMLspanElement().parentNode;c=a.parentNode;this.data[this.base]&&c.removeChild(c.firstChild);for(a=c.firstChild;a;a=a.nextSibling)a.style.left=m.Em(m.unEm(a.style.left)-this.HTMLbaseW);c.bbox.w-=this.HTMLbaseW;c.style.width=m.Em(c.bbox.w);this.HTMLcombineBBoxes(c,d.bbox);d.appendChild(c)}}});l.mo.Augment({HTMLbetterBreak:function(a,c){if(a.values&&a.values.id===this.spanID)return!1;var d=this.getValues("linebreak","linebreakstyle","lineleading","linebreakmultchar","indentalign","indentshift","indentalignfirst","indentshiftfirst","indentalignlast","indentshiftlast","texClass","fence");d.linebreakstyle===l.LINEBREAKSTYLE.INFIXLINEBREAKSTYLE&&(d.linebreakstyle=this.Get("infixlinebreakstyle"));d.texClass===l.TEXCLASS.OPEN&&a.nest++;d.texClass===l.TEXCLASS.CLOSE&&a.nest--;var b=a.scanW,e=a.embellished||this;delete a.embellished;var g=e.HTMLspanElement(),e=g.bbox.w;g.style.paddingLeft&&(e+=m.unEm(g.style.paddingLeft));d.linebreakstyle===l.LINEBREAKSTYLE.AFTER&&(b+=e,e=0);if(0===b-a.shift)return!1;g=m.linebreakWidth-b;if(0===c.n&&(d.indentshiftfirst!==c.VALUES.indentshiftfirst||d.indentalignfirst!==c.VALUES.indentalignfirst))var f=this.HTMLgetAlign(c,d),f=this.HTMLgetShift(c,d,f),g=g+(a.shift-f);f=Math.floor(g/m.linebreakWidth*1E3);0>f&&(f=n.toobig-3*f);d.fence&&(f+=n.fence);if(d.linebreakstyle===l.LINEBREAKSTYLE.AFTER&&d.texClass===l.TEXCLASS.OPEN||d.texClass===l.TEXCLASS.CLOSE)f+=n.close;var f=f+a.nest*n.nestfactor,k=n[d.linebreak||l.LINEBREAK.AUTO];k instanceof Array?f=Math.max(1,f+k[0]*a.nest):0<=g&&(f=k*a.nest);if(f>=a.penalty)return!1;a.penalty=f;a.values=d;a.W=b;a.w=e;d.lineleading=m.length2em(d.lineleading,c.VALUES.lineleading);d.id=this.spanID;return!0}});l.mspace.Augment({HTMLbetterBreak:function(a,c){if(a.values&&a.values.id===this.spanID)return!1;var d=this.getValues("linebreak"),b=d.linebreak;if(!b||this.hasDimAttr())b=l.LINEBREAK.AUTO;var e=a.scanW,g=this.HTMLspanElement(),f=g.bbox.w;g.style.paddingLeft&&(f+=m.unEm(g.style.paddingLeft));if(0===e-a.shift)return!1;var g=m.linebreakWidth-e,k=Math.floor(g/m.linebreakWidth*1E3);0>k&&(k=n.toobig-3*k);var k=k+a.nest*n.nestfactor,h=n[b];b===l.LINEBREAK.AUTO&&f>=n.spacelimit&&(h=[(f+n.spaceoffset)*n.spacefactor]);h instanceof Array?k=Math.max(1,k+h[0]*a.nest):0<=g&&(k=h*a.nest);if(k>=a.penalty)return!1;a.penalty=k;a.values=d;a.W=e;a.w=f;d.lineleading=c.VALUES.lineleading;d.linebreakstyle="before";d.id=this.spanID;return!0}});MathJax.Hub.Register.StartupHook("TeX mathchoice Ready",function(){l.TeXmathchoice.Augment({HTMLbetterBreak:function(a,c){return this.Core().HTMLbetterBreak(a,c)},HTMLmoveLine:function(a,c,d,b,e){return this.Core().HTMLmoveSlice(a,c,d,b,e)}})});l.maction.Augment({HTMLbetterBreak:function(a,c){return this.Core().HTMLbetterBreak(a,c)},HTMLmoveLine:function(a,c,d,b,e){return this.Core().HTMLmoveSlice(a,c,d,b,e)},HTMLmoveSlice:function(a,c,d,b,e,g){var f=document.getElementById("MathJax-HitBox-"+this.spanID+m.idPostfix);f&&f.parentNode.removeChild(f);f=this.SUPER(arguments).HTMLmoveSlice.apply(this,arguments);if(0===c.length){d=this.HTMLspanElement();for(var k=0;d;)this.HTMLhandleHitBox(d,"-Continue-"+k),d=d.nextMathJaxSpan,k++}return f}});l.semantics.Augment({HTMLbetterBreak:function(a,c){return this.data[0]?this.data[0].HTMLbetterBreak(a,c):!1},HTMLmoveLine:function(a,c,d,b,e){return this.data[0]?this.data[0].HTMLmoveSlice(a,c,d,b,e):null}});MathJax.Hub.Startup.signal.Post("HTML-CSS multiline Ready");MathJax.Ajax.loadComplete(m.autoloadDir+"/multiline.js")});