/*
 *  /MathJax/jax/output/SVG/autoload/mtable.js
 *  
 *  Copyright (c) 2012 Design Science, Inc.
 *
 *  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("SVG Jax Ready",function(){var c="2.1";var a=MathJax.ElementJax.mml,d=MathJax.OutputJax.SVG,b=d.BBOX;a.mtable.Augment({toSVG:function(U){this.SVGgetStyles();var l=this.SVG();if(this.data.length===0){return l}var aG=this.getValues("columnalign","rowalign","columnspacing","rowspacing","columnwidth","equalcolumns","equalrows","columnlines","rowlines","frame","framespacing","align","useHeight","width","side","minlabelspacing");if(aG.width.match(/%$/)){l.width=aG.width=Math.floor(d.cwidth*parseFloat(aG.width)/100)+"px"}var aj=this.SVGgetScale(),r=this.SVGgetMu(l);var aD=-1;var u=[],B=[],h=[],K=[],E=[],aB,aA,t=-1,ay,q,at,N,ai,w;var aI=d.FONTDATA.baselineskip*aj*aG.useHeight,au,X=d.FONTDATA.lineH*aj,ac=d.FONTDATA.lineD*aj;for(aB=0,ay=this.data.length;aB<ay;aB++){N=this.data[aB];at=(N.type==="mlabeledtr"?aD:0);K[aB]=[];u[aB]=B[aB]=0;for(aA=at,q=N.data.length+at;aA<q;aA++){if(h[aA]==null){if(aA>t){t=aA}E[aA]=b.G();h[aA]=-d.BIGDIMEN}ai=N.data[aA-at];K[aB][aA]=ai.toSVG();if(ai.isEmbellished()){w=ai.CoreMO();var aF=w.Get("minsize",true);if(aF){if(w.SVGcanStretch("Vertical")){au=w.SVGdata.h+w.SVGdata.d;if(au){aF=d.length2em(aF,r,au);if(aF*w.SVGdata.h/au>u[aA]){u[aA]=aF*w.SVGdata.h/au}if(aF*w.SVGdata.d/au>B[aA]){B[aA]=aF*w.SVGdata.d/au}}}else{if(w.SVGcanStretch("Horizontal")){aF=d.length2em(aF,r,w.SVGdata.w);if(aF>h[aA]){h[aA]=aF}}}}}if(K[aB][aA].h>u[aB]){u[aB]=K[aB][aA].h}if(K[aB][aA].d>B[aB]){B[aB]=K[aB][aA].d}if(K[aB][aA].w>h[aA]){h[aA]=K[aB][aA].w}}}if(u[0]+B[0]){u[0]=Math.max(u[0],X)}if(u[K.length-1]+B[K.length-1]){B[K.length-1]=Math.max(B[K.length-1],ac)}var ah=aG.columnspacing.split(/ /),O=aG.rowspacing.split(/ /),ae=aG.columnalign.split(/ /),G=aG.rowalign.split(/ /),I=aG.columnlines.split(/ /),g=aG.rowlines.split(/ /),al=aG.columnwidth.split(/ /),ap=[];for(aB=0,ay=ah.length;aB<ay;aB++){ah[aB]=d.length2em(ah[aB],r)}for(aB=0,ay=O.length;aB<ay;aB++){O[aB]=d.length2em(O[aB],r)}while(ah.length<t){ah.push(ah[ah.length-1])}while(ae.length<=t){ae.push(ae[ae.length-1])}while(I.length<t){I.push(I[I.length-1])}while(al.length<=t){al.push(al[al.length-1])}while(O.length<K.length){O.push(O[O.length-1])}while(G.length<=K.length){G.push(G[G.length-1])}while(g.length<K.length){g.push(g[g.length-1])}if(E[aD]){ae[aD]=(aG.side.substr(0,1)==="l"?"left":"right");ah[aD]=-h[aD]}for(aB=0,ay=K.length;aB<ay;aB++){N=this.data[aB];ap[aB]=[];if(N.rowalign){G[aB]=N.rowalign}if(N.columnalign){ap[aB]=N.columnalign.split(/ /);while(ap[aB].length<=t){ap[aB].push(ap[aB][ap[aB].length-1])}}}if(aG.equalrows){var Q=Math.max.apply(Math,u),ak=Math.max.apply(Math,B);for(aB=0,ay=K.length;aB<ay;aB++){at=((Q+ak)-(u[aB]+B[aB]))/2;u[aB]+=at;B[aB]+=at}}au=u[0]+B[K.length-1];for(aB=0,ay=K.length-1;aB<ay;aB++){au+=Math.max((u[aB]+B[aB]?aI:0),B[aB]+u[aB+1]+O[aB])}var aa=0,V=0,av,aE=au;if(aG.frame!=="none"||(aG.columnlines+aG.rowlines).match(/solid|dashed/)){aa=d.length2em(aG.framespacing.split(/[, ]+/)[0],r);V=d.length2em(aG.framespacing.split(/[, ]+/)[1],r);aE=au+2*V}var e,ar,ax="";if(typeof(aG.align)!=="string"){aG.align=String(aG.align)}if(aG.align.match(/(top|bottom|center|baseline|axis)( +(-?\d+))?/)){ax=RegExp.$3;aG.align=RegExp.$1}else{aG.align=this.defaults.align}if(ax!==""){ax=parseInt(ax);if(ax<0){ax=K.length+1+ax}if(ax<1){ax=1}else{if(ax>K.length){ax=K.length}}e=0;ar=-(au+V)+u[0];for(aB=0,ay=ax-1;aB<ay;aB++){var T=Math.max((u[aB]+B[aB]?aI:0),B[aB]+u[aB+1]+O[aB]);e+=T;ar+=T}}else{e=({top:-(u[0]+V),bottom:au+V-u[0],center:au/2-u[0],baseline:au/2-u[0],axis:au/2+d.TeX.axis_height*aj-u[0]})[aG.align];ar=({top:-(au+2*V),bottom:0,center:-(au/2+V),baseline:-(au/2+V),axis:d.TeX.axis_height*aj-au/2-V})[aG.align]}var am,aq=0,R=0,S=0,aw=0,aC=0,o=[],v=[],af=1;if(aG.equalcolumns&&aG.width!=="auto"){am=d.length2em(aG.width,r);for(aB=0,ay=Math.min(t+1,ah.length);aB<ay;aB++){am-=ah[aB]}am/=t+1;for(aB=0,ay=Math.min(t+1,al.length);aB<ay;aB++){h[aB]=am}}else{for(aB=0,ay=Math.min(t+1,al.length);aB<ay;aB++){if(al[aB]==="auto"){R+=h[aB]}else{if(al[aB]==="fit"){v[aC]=aB;aC++;R+=h[aB]}else{if(al[aB].match(/%$/)){o[aw]=aB;aw++;S+=h[aB];aq+=d.length2em(al[aB],r,1)}else{h[aB]=d.length2em(al[aB],r);R+=h[aB]}}}}if(aG.width==="auto"){if(aq>0.98){af=S/(R+S);am=R+S}else{am=R/(1-aq)}}else{am=d.length2em(aG.width,r);for(aB=0,ay=Math.min(t+1,ah.length);aB<ay;aB++){am-=ah[aB]}}for(aB=0,ay=o.length;aB<ay;aB++){h[o[aB]]=d.length2em(al[o[aB]],r,am*af);R+=h[o[aB]]}if(Math.abs(am-R)>0.01){if(aC&&am>R){am=(am-R)/aC;for(aB=0,ay=v.length;aB<ay;aB++){h[v[aB]]+=am}}else{am=am/R;for(aA=0;aA<=t;aA++){h[aA]*=am}}}if(aG.equalcolumns){var ab=Math.max.apply(Math,h);for(aA=0;aA<=t;aA++){h[aA]=ab}}}var an=e,k,az;at=(E[aD]?aD:0);for(aA=at;aA<=t;aA++){E[aA].w=h[aA];for(aB=0,ay=K.length;aB<ay;aB++){if(K[aB][aA]){at=(this.data[aB].type==="mlabeledtr"?aD:0);ai=this.data[aB].data[aA-at];if(ai.SVGcanStretch("Horizontal")){K[aB][aA]=ai.SVGstretchH(h[aA])}else{if(ai.SVGcanStretch("Vertical")){w=ai.CoreMO();var Z=w.symmetric;w.symmetric=false;K[aB][aA]=ai.SVGstretchV(u[aB],B[aB]);w.symmetric=Z}}az=ai.rowalign||this.data[aB].rowalign||G[aB];k=({top:u[aB]-K[aB][aA].h,bottom:K[aB][aA].d-B[aB],center:((u[aB]-B[aB])-(K[aB][aA].h-K[aB][aA].d))/2,baseline:0,axis:0})[az]||0;az=(ai.columnalign||ap[aB][aA]||ae[aA]);E[aA].Align(K[aB][aA],az,0,an+k)}if(aB<K.length-1){an-=Math.max((u[aB]+B[aB]?aI:0),B[aB]+u[aB+1]+O[aB])}}an=e}var ad=1.5*d.em;var ao=aa-ad/2;for(aA=0;aA<=t;aA++){l.Add(E[aA],ao,0);ao+=h[aA]+ah[aA];if(I[aA]!=="none"&&aA<t&&aA!==aD){l.Add(b.VLINE(aE,ad,I[aA]),ao-ah[aA]/2,ar)}}l.w+=aa;l.d=-ar;l.h=aE+ar;av=l.w;if(aG.frame!=="none"){l.Add(b.HLINE(av,ad,aG.frame),0,ar+aE-ad);l.Add(b.HLINE(av,ad,aG.frame),0,ar);l.Add(b.VLINE(aE,ad,aG.frame),0,ar);l.Add(b.VLINE(aE,ad,aG.frame),av-ad,ar)}an=e-ad/2;for(aB=0,ay=K.length-1;aB<ay;aB++){k=Math.max(aI,B[aB]+u[aB+1]+O[aB]);if(g[aB]!=="none"){l.Add(b.HLINE(av,ad,g[aB]),0,an-B[aB]-(k-B[aB]-u[aB+1])/2)}an-=k}l.Clean();this.SVGhandleSpace(l);this.SVGhandleColor(l);if(E[aD]){var L=this.getValues("indentalignfirst","indentshiftfirst","indentalign","indentshift");if(L.indentalignfirst!==a.INDENTALIGN.INDENTALIGN){L.indentalign=L.indentalignfirst}if(L.indentalign===a.INDENTALIGN.AUTO){L.indentalign=this.displayAlign}if(L.indentshiftfirst!==a.INDENTSHIFT.INDENTSHIFT){L.indentshift=L.indentshiftfirst}if(L.indentshift==="auto"){L.indentshift=this.displayIndent}var ag=(L.indentshift?d.length2em(L.indentshift,r):0);var aH=d.length2em(aG.minlabelspacing,r);var z=l;l=this.SVG();if(L.indentalign===a.INDENTALIGN.CENTER){l.w=l.r=d.length2em(d.cwidth+"px");ag=0;l.hasIndent=true}else{if(ae[aD]!==L.indentalign){l.w=l.r=d.length2em(d.cwidth+"px")-ag-aH;ag=aH=0}else{l.w=l.r=z.w+ag;l.hasIndent=true}}l.Align(z,L.indentalign,ag,0);l.Align(E[aD],ae[aD],aH,0)}this.SVGsaveData(l);return l},SVGhandleSpace:function(e){if(!this.hasFrame&&!e.width){e.x=e.X=167}this.SUPER(arguments).SVGhandleSpace.call(this,e)}});a.mtd.Augment({toSVG:function(e,g){var f=this.svg=this.SVG();if(this.data[0]){f.Add(this.SVGdataStretched(0,e,g));f.Clean()}this.SVGhandleColor(f);this.SVGsaveData(f);return f}});MathJax.Hub.Startup.signal.Post("SVG mtable Ready");MathJax.Ajax.loadComplete(d.autoloadDir+"/mtable.js")});

