/*
 *  /MathJax/jax/output/CommonHTML/autoload/mtable.js
 *
 *  Copyright (c) 2009-2015 The MathJax Consortium
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function(){var g="2.6.0";var b=MathJax.ElementJax.mml,a=MathJax.Hub.config,e=MathJax.OutputJax.CommonHTML,d=MathJax.Hub.SplitList;var c=-1,f=1000000;b.mtable.Augment({toCommonHTML:function(l){var m={rows:[],labels:[],labeled:false};l=this.CHTMLdefaultNode(l,{noBBox:true,childOptions:m});var k=e.Element("mjx-table");while(l.firstChild){k.appendChild(l.firstChild)}l.appendChild(k);var h=this.getValues("columnalign","rowalign","columnspacing","rowspacing","columnwidth","equalcolumns","equalrows","columnlines","rowlines","frame","framespacing","align","width","side","minlabelspacing","useHeight");var j=e.TEX.min_rule_thickness/e.em;m.t=e.Px(j*this.CHTML.scale,1);this.CHTMLgetBoxSizes(h,m);this.CHTMLgetAttributes(h,m);if(h.equalrows){m.HD=true;m.HH=Math.max.apply(Math,m.H);m.DD=Math.max.apply(Math,m.D)}this.CHTMLadjustCells(h,m);if(h.frame){k.style.border=m.t+" "+h.frame}this.CHTMLalignV(h,m,l);this.CHTMLcolumnWidths(h,m,l);this.CHTMLstretchCells(h,m);if(m.labeled){this.CHTMLaddLabels(h,m,l,k)}var i=this.CHTML;i.w=i.r=m.R;i.h=i.t=m.T-m.B;i.d=i.b=m.B;if(!h.frame&&!i.pwidth){l.style.padding="0 "+e.Em(1/6);i.L=i.R=1/6}this.CHTMLhandleSpace(l);this.CHTMLhandleBBox(l);this.CHTMLhandleColor(l);return l},CHTMLgetBoxSizes:function(x,k){var q=e.FONTDATA.lineH*x.useHeight,r=e.FONTDATA.lineD*x.useHeight;var w=[],h=[],l=[],v=-1;for(var p=0,n=this.data.length;p<n;p++){var z=this.data[p],y=(z.type==="mtr"?0:c);w[p]=q;h[p]=r;for(var o=y,u=z.data.length+y;o<u;o++){if(l[o]==null){l[o]=-f;if(o>v){v=o}}var t=z.data[o-y].CHTML;if(t.h>w[p]){w[p]=t.h}if(t.d>h[p]){h[p]=t.d}if(t.w>l[o]){l[o]=t.w}}}k.H=w;k.D=h;k.W=l,k.J=v},CHTMLgetAttributes:function(v,j){var l=d(v.columnspacing),x=d(v.rowspacing),t=d(v.columnalign),r=d(v.rowalign),k=d(v.columnlines),w=d(v.rowlines),o=d(v.columnwidth),n=[],q,p,u=j.J,s=j.rows.length-1;for(q=0,p=l.length;q<p;q++){l[q]=this.CHTMLlength2em(l[q])}for(q=0,p=x.length;q<p;q++){x[q]=this.CHTMLlength2em(x[q])}while(l.length<u){l.push(l[l.length-1])}while(t.length<=u){t.push(t[t.length-1])}while(k.length<u){k.push(k[k.length-1])}while(o.length<=u){o.push(o[o.length-1])}while(x.length<s){x.push(x[x.length-1])}while(r.length<=s){r.push(r[r.length-1])}while(w.length<s){w.push(w[w.length-1])}t[c]=(v.side.substr(0,1)==="l"?"left":"right");for(q=0;q<=s;q++){var y=this.data[q];n[q]=[];if(y.rowalign){r[q]=y.rowalign}if(y.columnalign){n[q]=d(y.columnalign);while(n[q].length<=u){n[q].push(n[q][n[q].length-1])}}}var h=d(v.framespacing);if(h.length!=2){h=d(this.defaults.framespacing)}h[0]=Math.max(0,this.CHTMLlength2em(h[0]));h[1]=Math.max(0,this.CHTMLlength2em(h[1]));if(v.columnlines.replace(/none/g,"").replace(/ /g,"")!==""||v.rowlines.replace(/none/g,"").replace(/ /g,"")!==""){v.fspace=true}if(v.frame===b.LINES.NONE){delete v.frame}else{v.fspace=true}if(v.frame){h[0]=Math.max(0,h[0]);h[1]=Math.max(0,h[1])}if(v.fspace){l[u]=h[0];x[s]=h[1]}else{l[u]=x[s]=0}k[u]=w[s]=b.LINES.NONE;j.CSPACE=l;j.RSPACE=x;j.CALIGN=t;j.RALIGN=r;j.CLINES=k;j.RLINES=w;j.CWIDTH=o;j.RCALIGN=n;j.FSPACE=h},CHTMLadjustCells:function(h,p){var J=p.rows,N=p.CSPACE,l=p.CLINES,u=p.RSPACE,A=p.RLINES,K=p.CALIGN,o=p.RALIGN,C=p.RCALIGN;N[p.J]*=2;u[J.length-1]*=2;var v=e.FONTDATA.lineH*h.useHeight,y=e.FONTDATA.lineD*h.useHeight;var n="0",D,q,x,F,k,H;if(h.fspace){n=e.Em(p.FSPACE[1])}for(var I=0,E=J.length;I<E;I++){var t=J[I],r=this.data[I];D=u[I]/2;F=null;x="0";if(A[I]!==b.LINES.NONE){F=p.t+" "+A[I];D-=1/e.em/2}D=e.Em(Math.max(0,D));if(h.fspace){x=e.Em(p.FSPACE[0])}for(var G=0,w=t.length;G<w;G++){var z=(r.type==="mtr"?0:c);cell=t[G].style;k=r.data[G-z].CHTML;q=N[G]/2;if(l[G]!==b.LINES.NONE){cell.borderRight=p.t+" "+l[G];q-=1/e.em/2}q=e.Em(Math.max(0,q));cell.padding=n+" "+q+" "+D+" "+x;if(F){cell.borderBottom=F}x=q;H=(r.data[G-z].rowalign||this.data[I].rowalign||o[I]);H=({top:"top",bottom:"bottom",center:"middle"})[H];if(H){cell.verticalAlign=H}H=(r.data[G-z].columnalign||C[I][G]||K[G]);if(H!==b.ALIGN.CENTER){cell.textAlign=H}if(p.HD&&G===0){e.addElement(t[G].parentNode,"mjx-mtd",{style:{padding:n+" 0 "+D}},[["mjx-box",{style:{height:e.Em(p.HH+p.DD),"vertical-align":e.Em(-p.DD)}}]])}cell=t[G].firstChild.style;if(k.h<v){cell.marginTop=e.Em(v-k.h)}if(k.d<y){cell.marginBottom=e.Em(y-k.d)}}n=D}N[p.J]/=2;u[J.length-1]/=2},CHTMLalignV:function(w,k,o){var m,t=k.rows.length,v=k.H,j=k.D,x=k.RSPACE;if(typeof(w.align)!=="string"){w.align=String(w.align)}if(w.align.match(/(top|bottom|center|baseline|axis)( +(-?\d+))?/)){m=parseInt(RegExp.$3||"0");w.align=RegExp.$1;if(m<0){m+=k.rows.length+1}if(m>t||m<=0){m=null}}else{w.align=this.defaults.align}var p=0,l=0,u=e.TEX.axis_height;if(w.fspace){p+=k.FSPACE[1]}if(w.frame){p+=2/e.em;l+=1/e.em}var r=k.HH,s=k.DD;for(var q=0;q<t;q++){if(!k.HD){r=v[q];s=j[q]}p+=r+s+x[q];if(m){if(q===m-1){l+=({top:r+s,bottom:0,center:(r+s)/2,baseline:s,axis:u+s})[w.align]+x[q]}if(q>=m){l+=r+s+x[q]}}}if(!m){l=({top:p,bottom:0,center:p/2,baseline:p/2,axis:p/2-u})[w.align]}if(l){o.style.verticalAlign=e.Em(-l)}k.T=p;k.B=l},CHTMLcolumnWidths:function(l,r,A){var I=r.CWIDTH,K=r.CSPACE,u=r.J,F;var G=0,n=false,y=l.width.match(/%$/);var H,B,v;if(l.width!=="auto"&&!y){G=Math.max(0,this.CHTMLlength2em(l.width,r.R));n=true}if(l.equalcolumns){if(y){var z=e.Percent(1/(u+1));for(F=0;F<=u;F++){I[F]=z}}else{v=Math.max.apply(Math,r.W);if(l.width!=="auto"){var q=(l.fspace?r.FSPACE[0]+(l.frame?2/e.em:0):0);for(F=0;F<=u;F++){q+=K[F]}v=Math.max((G-q)/(u+1),v)}v=e.Em(v);for(F=0;F<=u;F++){I[F]=v}}n=true}var E=0;if(l.fspace){E=r.FSPACE[0]}var s=[],D=[],h=[],o=[];var t=r.rows[0];for(F=0;F<=u;F++){o[F]=r.W[F];if(I[F]==="auto"){s.push(F)}else{if(I[F]==="fit"){D.push(F)}else{if(I[F].match(/%$/)){h.push(F)}else{o[F]=this.CHTMLlength2em(I[F],o[F])}}}E+=o[F]+K[F];if(t[F]){t[F].style.width=e.Em(o[F])}}if(l.frame){E+=2/e.em}var C=(D.length>0);if(n){if(y){for(F=0;F<=u;F++){cell=t[F].style;if(I[F]==="auto"&&!C){cell.width=""}else{if(I[F]==="fit"){cell.width=""}else{if(I[F].match(/%$/)){cell.width=I[F]}else{cell.minWidth=cell.maxWidth=cell.width}}}}}else{if(G>E){var k=0;for(H=0,B=h.length;H<B;H++){F=h[H];v=Math.max(o[F],this.CHTMLlength2em(I[F],G));k+=v-o[F];o[F]=v;t[F].style.width=e.Em(v)}E+=k}if(!C){D=s}if(G>E&&D.length){var x=(G-E)/D.length;for(H=0,B=D.length;H<B;H++){F=D[H];o[F]+=x;t[F].style.width=e.Em(o[F])}E=G}}}o[c]=r.W[c];r.W=o;r.R=E;if(y){this.CHTML.pwidth=l.width;this.CHTML.mwidth=e.Em(E);A.style.width=A.firstChild.style.width="100%"}},CHTMLstretchCells:function(x,l){var y=l.rows,w=l.H,k=l.D,m=l.W,t=l.J,s=y.length-1;var p=l.HH,r=l.DD;for(var o=0;o<=s;o++){var z=y[o],q=this.data[o];if(!l.HD){p=w[o];r=k[o]}for(var n=0;n<=t;n++){var v=z[n],u=q.data[n];if(!u){continue}if(u.CHTML.stretch==="V"){u.CHTMLstretchV(p,r)}else{if(u.CHTML.stretch==="H"){u.CHTMLstretchH(v,m[n])}}}}},CHTMLaddLabels:function(j,l,A,I){var u=this.getValues("indentalignfirst","indentshiftfirst","indentalign","indentshift");if(u.indentalignfirst!==b.INDENTALIGN.INDENTALIGN){u.indentalign=u.indentalignfirst}if(u.indentalign===b.INDENTALIGN.AUTO){u.indentalign=a.displayAlign}if(u.indentshiftfirst!==b.INDENTSHIFT.INDENTSHIFT){u.indentshift=u.indentshiftfirst}if(u.indentshift==="auto"){u.indentshift="0"}var F=this.CHTMLlength2em(u.indentshift,e.cwidth);var G=this.CHTMLlength2em(j.minlabelspacing,0.8);var t=G+l.W[c],C=0,L=l.R;var p=this.CHTMLlength2em(a.displayIndent,e.cwidth);var x=(l.CALIGN[c]===b.INDENTALIGN.RIGHT?-1:1);if(u.indentalign===b.INDENTALIGN.CENTER){L+=2*(t-x*(F+p));F+=p}else{if(l.CALIGN[c]===u.indentalign){if(p<0){C=x*p;p=0}F+=x*p;if(t>x*F){F=x*t}F+=C;F*=x;L+=F}else{L+=t-x*F+p;F-=x*p;F*=-x}}var q=e.addElement(A,"mjx-box",{style:{width:"100%","text-align":u.indentalign}});q.appendChild(I);var K=e.Element("mjx-stack");I.style.display="inline-table";if(!I.style.width){I.style.width="auto"}K.style.verticalAlign="top";I.style.verticalAlign=e.Em(l.T-l.B-l.H[0]);A.style.verticalAlign="";if(F){if(u.indentalign===b.INDENTALIGN.CENTER){I.style.marginLeft=e.Em(F);I.style.marginRight=e.Em(-F)}else{var y="margin"+(u.indentalign===b.INDENTALIGN.RIGHT?"Right":"Left");I.style[y]=e.Em(F)}}if(l.CALIGN[c]==="left"){A.insertBefore(K,q);K.style.marginRight=e.Em(-l.W[c]-C);if(C){K.style.marginLeft=e.Em(C)}}else{A.appendChild(K);K.style.marginLeft=e.Em(-l.W[c]+C)}var o=l.labels,k=0,r=l.H,w=l.D,n=l.RSPACE;if(j.fspace){k=l.FSPACE[0]+(j.frame?1/e.em:0)}var E=l.HH,J=l.DD;for(var B=0,z=o.length;B<z;B++){if(!l.HD){E=r[B];J=w[B]}if(o[B]&&this.data[B].data[0]){K.appendChild(o[B]);var v=this.data[B].data[0].CHTML;k+=E-v.h;if(k){o[B].style.marginTop=e.Em(k)}k=J-v.d}else{k+=E+J}k+=n[B]}A.style.width=this.CHTML.pwidth="100%";A.style.minWidth=this.CHTML.mwidth=e.Em(Math.max(0,L))}});b.mtr.Augment({toCommonHTML:function(l,j){l=this.CHTMLcreateNode(l);this.CHTMLhandleStyle(l);this.CHTMLhandleScale(l);if(!j){j={rows:[],labels:[]}}var n=[];j.rows.push(n);j.labels.push(null);for(var k=0,h=this.data.length;k<h;k++){n.push(this.CHTMLaddChild(l,k,j))}this.CHTMLhandleColor(l);return l}});b.mlabeledtr.Augment({toCommonHTML:function(n,k){n=this.CHTMLcreateNode(n);this.CHTMLhandleStyle(n);this.CHTMLhandleScale(n);if(!k){k={rows:[],labels:[]}}var o=[];k.rows.push(o);var j=e.Element("mjx-label");k.labels.push(j);this.CHTMLaddChild(j,0,k);if(this.data[0]){k.labeled=true}for(var l=1,h=this.data.length;l<h;l++){o.push(this.CHTMLaddChild(n,l,k))}this.CHTMLhandleColor(n);return n}});b.mtd.Augment({toCommonHTML:function(l,i){l=this.CHTMLdefaultNode(l,i);if(this.isEmbellished()){var m=this.CoreMO(),h=this.CHTML;if(m.CHTMLcanStretch("Vertical")){h.stretch="V"}else{if(m.CHTMLcanStretch("Horizontal")){h.stretch="H"}}if(h.stretch){var j=m.Get("minsize",true);if(j){if(h.stretch==="V"){var n=h.h+h.d;if(n){var k=this.CHTMLlength2em(j,n)/n;if(k>1){h.h*=k;h.d*=k}}}else{h.w=Math.max(h.w,this.CHTMLlength2em(j,h.w))}}}}return l}});MathJax.Hub.Startup.signal.Post("CommonHTML mtable Ready");MathJax.Ajax.loadComplete(e.autoloadDir+"/mtable.js")});
