class v{constructor(t,r){let o=" "+t,s;const i=r&&r.loc;if(i&&i.start<=i.end){const u=i.lexer.input;s=i.start;const m=i.end;s===u.length?o+=" at end of input: ":o+=" at position "+(s+1)+`: `;const f=u.slice(s,m).replace(/[^]/g,"$&̲");let A;s>15?A="…"+u.slice(s-15,s):A=u.slice(0,s);let x;m+15":">","<":"<",'"':""","'":"'"},_r=/[&><"']/g;function Tr(e){return String(e).replace(_r,t=>qr[t])}const de=function(e){return e.type==="ordgroup"||e.type==="color"?e.body.length===1?de(e.body[0]):e:e.type==="font"?de(e.body):e},Dr=function(e){const t=de(e);return t.type==="mathord"||t.type==="textord"||t.type==="atom"},Cr=function(e){if(!e)throw new Error("Expected non-null, but got "+String(e));return e},Nr=function(e){const t=/^[\x00-\x20]*([^\\/#?]*?)(:|�*58|�*3a|&colon)/i.exec(e);return t?t[2]!==":"||!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(t[1])?null:t[1].toLowerCase():"_relative"},Br=function(e){return+e.toFixed(4)};var O={deflt:Ar,escape:Tr,hyphenate:Sr,getBaseElem:de,isCharacterBox:Dr,protocolFromUrl:Nr,round:Br};class We{constructor(t){t=t||{},this.displayMode=O.deflt(t.displayMode,!1),this.annotate=O.deflt(t.annotate,!1),this.leqno=O.deflt(t.leqno,!1),this.throwOnError=O.deflt(t.throwOnError,!1),this.errorColor=O.deflt(t.errorColor,"#b22222"),this.macros=t.macros||{},this.wrap=O.deflt(t.wrap,"tex"),this.xml=O.deflt(t.xml,!1),this.colorIsTextColor=O.deflt(t.colorIsTextColor,!1),this.strict=O.deflt(t.strict,!1),this.trust=O.deflt(t.trust,!1),this.maxSize=t.maxSize===void 0?[1/0,1/0]:Array.isArray(t.maxSize)?t.maxSize:[1/0,1/0],this.maxExpand=Math.max(0,O.deflt(t.maxExpand,1e3))}isTrusted(t){if(t.url&&!t.protocol){const o=O.protocolFromUrl(t.url);if(o==null)return!1;t.protocol=o}return!!(typeof this.trust=="function"?this.trust(t):this.trust)}}const Rt={},_e={};function S({type:e,names:t,props:r,handler:o,mathmlBuilder:s}){const i={type:e,numArgs:r.numArgs,argTypes:r.argTypes,allowedInArgument:!!r.allowedInArgument,allowedInText:!!r.allowedInText,allowedInMath:r.allowedInMath===void 0?!0:r.allowedInMath,numOptionalArgs:r.numOptionalArgs||0,infix:!!r.infix,primitive:!!r.primitive,handler:o};for(let l=0;lr.toText();return this.children.map(t).join("")}}const ue=function(e){return e.filter(t=>t).join(" ")},$r=function(e,t){this.classes=e||[],this.attributes={},this.style=t||{}},Or=function(e){const t=document.createElement(e);t.className=ue(this.classes);for(const r in this.style)Object.prototype.hasOwnProperty.call(this.style,r)&&(t.style[r]=this.style[r]);for(const r in this.attributes)Object.prototype.hasOwnProperty.call(this.attributes,r)&&t.setAttribute(r,this.attributes[r]);for(let r=0;r`,t};class jt{constructor(t,r,o){$r.call(this,t,o),this.children=r||[]}setAttribute(t,r){this.attributes[t]=r}toNode(){return Or.call(this,"span")}toMarkup(){return Mr.call(this,"span")}}let Er=class{constructor(t){this.text=t}toNode(){return document.createTextNode(this.text)}toMarkup(){return O.escape(this.text)}};class Ut{constructor(t,r,o){this.href=t,this.classes=r,this.children=o||[]}toNode(){const t=document.createElement("a");t.setAttribute("href",this.href),this.classes.length>0&&(t.className=ue(this.classes));for(let r=0;r0&&(t+=` class="${O.escape(ue(this.classes))}"`),t+=">";for(let r=0;r0&&(t.className=ue(this.classes));for(const r in this.style)Object.prototype.hasOwnProperty.call(this.style,r)&&(t.style[r]=this.style[r]);for(let r=0;r0&&(t+=` class="${O.escape(ue(this.classes))}"`);let r="";for(const o in this.style)Object.prototype.hasOwnProperty.call(this.style,o)&&(r+=`${O.hyphenate(o)}:${this.style[o]};`);r&&(t+=` style="${r}"`),t+=">";for(let o=0;o",t}toText(){return this.children.map(t=>t.toText()).join("")}}class he{constructor(t){this.text=t}toNode(){return document.createTextNode(this.text)}toMarkup(){return O.escape(this.toText())}toText(){return this.text}}const Xe=e=>{let t;return e.length===1&&e[0].type==="mrow"?(t=e.pop(),t.type="mstyle"):t=new V("mstyle",e),t};var p={MathNode:V,TextNode:he,newDocumentFragment:zr};const le=e=>{let t=0;if(e.body&&Array.isArray(e.body))for(const r of e.body)t+=le(r);else if(e.body)t+=le(e.body);else if(e.type==="supsub")t+=le(e.base),e.sub&&(t+=.7*le(e.sub)),e.sup&&(t+=.7*le(e.sup));else if(e.type==="mathord"||e.type==="textord")for(const r of e.text.split("")){const o=r.codePointAt(0);96{const t=Vt(e.label);if(Ir.includes(e.label)){const r=le(e.base);1","\\gt",!0);n(a,h,"∈","\\in",!0);n(a,h,"∉","\\notin",!0);n(a,h,"","\\@not");n(a,h,"⊂","\\subset",!0);n(a,h,"⊃","\\supset",!0);n(a,h,"⊆","\\subseteq",!0);n(a,h,"⊇","\\supseteq",!0);n(a,h,"⊈","\\nsubseteq",!0);n(a,h,"⊈","\\nsubseteqq");n(a,h,"⊉","\\nsupseteq",!0);n(a,h,"⊉","\\nsupseteqq");n(a,h,"⊨","\\models");n(a,h,"←","\\leftarrow",!0);n(a,h,"≤","\\le");n(a,h,"≤","\\leq",!0);n(a,h,"<","\\lt",!0);n(a,h,"→","\\rightarrow",!0);n(a,h,"→","\\to");n(a,h,"≱","\\ngeq",!0);n(a,h,"≱","\\ngeqq");n(a,h,"≱","\\ngeqslant");n(a,h,"≰","\\nleq",!0);n(a,h,"≰","\\nleqq");n(a,h,"≰","\\nleqslant");n(a,h,"⫫","\\Perp",!0);n(a,te," ","\\ ");n(a,te," ","\\space");n(a,te," ","\\nobreakspace");n(g,te," ","\\ ");n(g,te," "," ");n(g,te," ","\\space");n(g,te," ","\\nobreakspace");n(a,te,null,"\\nobreak");n(a,te,null,"\\allowbreak");n(a,be,",",",");n(g,be,":",":");n(a,be,";",";");n(a,b,"⊼","\\barwedge");n(a,b,"⊻","\\veebar");n(a,b,"⊙","\\odot",!0);n(a,b,"⊕︎","\\oplus");n(a,b,"⊗","\\otimes",!0);n(a,d,"∂","\\partial",!0);n(a,b,"⊘","\\oslash",!0);n(a,b,"⊚","\\circledcirc",!0);n(a,b,"⊡","\\boxdot",!0);n(a,b,"△","\\bigtriangleup");n(a,b,"▽","\\bigtriangledown");n(a,b,"†","\\dagger");n(a,b,"⋄","\\diamond");n(a,b,"◃","\\triangleleft");n(a,b,"▹","\\triangleright");n(a,R,"{","\\{");n(g,d,"{","\\{");n(g,d,"{","\\textbraceleft");n(a,F,"}","\\}");n(g,d,"}","\\}");n(g,d,"}","\\textbraceright");n(a,R,"{","\\lbrace");n(a,F,"}","\\rbrace");n(a,R,"[","\\lbrack",!0);n(g,d,"[","\\lbrack",!0);n(a,F,"]","\\rbrack",!0);n(g,d,"]","\\rbrack",!0);n(a,R,"(","\\lparen",!0);n(a,F,")","\\rparen",!0);n(a,R,"⦇","\\llparenthesis",!0);n(a,F,"⦈","\\rrparenthesis",!0);n(g,d,"<","\\textless",!0);n(g,d,">","\\textgreater",!0);n(a,R,"⌊","\\lfloor",!0);n(a,F,"⌋","\\rfloor",!0);n(a,R,"⌈","\\lceil",!0);n(a,F,"⌉","\\rceil",!0);n(a,d,"\\","\\backslash");n(a,d,"|","|");n(a,d,"|","\\vert");n(g,d,"|","\\textbar",!0);n(a,d,"‖","\\|");n(a,d,"‖","\\Vert");n(g,d,"‖","\\textbardbl");n(g,d,"~","\\textasciitilde");n(g,d,"\\","\\textbackslash");n(g,d,"^","\\textasciicircum");n(a,h,"↑","\\uparrow",!0);n(a,h,"⇑","\\Uparrow",!0);n(a,h,"↓","\\downarrow",!0);n(a,h,"⇓","\\Downarrow",!0);n(a,h,"↕","\\updownarrow",!0);n(a,h,"⇕","\\Updownarrow",!0);n(a,B,"∐","\\coprod");n(a,B,"⋁","\\bigvee");n(a,B,"⋀","\\bigwedge");n(a,B,"⨄","\\biguplus");n(a,B,"⨄","\\bigcupplus");n(a,B,"⨃","\\bigcupdot");n(a,B,"⨇","\\bigdoublevee");n(a,B,"⨈","\\bigdoublewedge");n(a,B,"⋂","\\bigcap");n(a,B,"⋃","\\bigcup");n(a,B,"∫","\\int");n(a,B,"∫","\\intop");n(a,B,"∬","\\iint");n(a,B,"∭","\\iiint");n(a,B,"∏","\\prod");n(a,B,"∑","\\sum");n(a,B,"⨂","\\bigotimes");n(a,B,"⨁","\\bigoplus");n(a,B,"⨀","\\bigodot");n(a,B,"⨉","\\bigtimes");n(a,B,"∮","\\oint");n(a,B,"∯","\\oiint");n(a,B,"∰","\\oiiint");n(a,B,"∱","\\intclockwise");n(a,B,"∲","\\varointclockwise");n(a,B,"⨌","\\iiiint");n(a,B,"⨍","\\intbar");n(a,B,"⨎","\\intBar");n(a,B,"⨏","\\fint");n(a,B,"⨒","\\rppolint");n(a,B,"⨓","\\scpolint");n(a,B,"⨕","\\pointint");n(a,B,"⨖","\\sqint");n(a,B,"⨗","\\intlarhk");n(a,B,"⨘","\\intx");n(a,B,"⨙","\\intcap");n(a,B,"⨚","\\intcup");n(a,B,"⨅","\\bigsqcap");n(a,B,"⨆","\\bigsqcup");n(a,B,"∫","\\smallint");n(g,ae,"…","\\textellipsis");n(a,ae,"…","\\mathellipsis");n(g,ae,"…","\\ldots",!0);n(a,ae,"…","\\ldots",!0);n(a,ae,"⋰","\\iddots",!0);n(a,ae,"⋯","\\@cdots",!0);n(a,ae,"⋱","\\ddots",!0);n(a,d,"⋮","\\varvdots");n(g,d,"⋮","\\varvdots");n(a,$,"´","\\acute");n(a,$,"`","\\grave");n(a,$,"¨","\\ddot");n(a,$,"…","\\dddot");n(a,$,"….","\\ddddot");n(a,$,"~","\\tilde");n(a,$,"‾","\\bar");n(a,$,"˘","\\breve");n(a,$,"ˇ","\\check");n(a,$,"^","\\hat");n(a,$,"→","\\vec");n(a,$,"˙","\\dot");n(a,$,"˚","\\mathring");n(a,k,"ı","\\imath",!0);n(a,k,"ȷ","\\jmath",!0);n(a,d,"ı","ı");n(a,d,"ȷ","ȷ");n(g,d,"ı","\\i",!0);n(g,d,"ȷ","\\j",!0);n(g,d,"ø","\\o",!0);n(a,k,"ø","\\o",!0);n(g,d,"Ø","\\O",!0);n(a,k,"Ø","\\O",!0);n(g,$,"ˊ","\\'");n(g,$,"ˋ","\\`");n(g,$,"ˆ","\\^");n(g,$,"~","\\~");n(g,$,"ˉ","\\=");n(g,$,"˘","\\u");n(g,$,"˙","\\.");n(g,$,"¸","\\c");n(g,$,"˚","\\r");n(g,$,"ˇ","\\v");n(g,$,"¨",'\\"');n(g,$,"˝","\\H");n(a,$,"ˊ","\\'");n(a,$,"ˋ","\\`");n(a,$,"ˆ","\\^");n(a,$,"~","\\~");n(a,$,"ˉ","\\=");n(a,$,"˘","\\u");n(a,$,"˙","\\.");n(a,$,"¸","\\c");n(a,$,"˚","\\r");n(a,$,"ˇ","\\v");n(a,$,"¨",'\\"');n(a,$,"˝","\\H");const jr={"--":!0,"---":!0,"``":!0,"''":!0};n(g,d,"–","--",!0);n(g,d,"–","\\textendash");n(g,d,"—","---",!0);n(g,d,"—","\\textemdash");n(g,d,"‘","`",!0);n(g,d,"‘","\\textquoteleft");n(g,d,"’","'",!0);n(g,d,"’","\\textquoteright");n(g,d,"“","``",!0);n(g,d,"“","\\textquotedblleft");n(g,d,"”","''",!0);n(g,d,"”","\\textquotedblright");n(a,d,"°","\\degree",!0);n(g,d,"°","\\degree");n(g,d,"°","\\textdegree",!0);n(a,d,"£","\\pounds");n(a,d,"£","\\mathsterling",!0);n(g,d,"£","\\pounds");n(g,d,"£","\\textsterling",!0);n(a,d,"✠","\\maltese");n(g,d,"✠","\\maltese");n(a,d,"€","\\euro",!0);n(g,d,"€","\\euro",!0);n(g,d,"€","\\texteuro");n(a,d,"©","\\copyright",!0);n(g,d,"©","\\textcopyright");n(a,d,"⌀","\\diameter",!0);n(g,d,"⌀","\\diameter");n(a,d,"𝛤","\\varGamma");n(a,d,"𝛥","\\varDelta");n(a,d,"𝛩","\\varTheta");n(a,d,"𝛬","\\varLambda");n(a,d,"𝛯","\\varXi");n(a,d,"𝛱","\\varPi");n(a,d,"𝛴","\\varSigma");n(a,d,"𝛶","\\varUpsilon");n(a,d,"𝛷","\\varPhi");n(a,d,"𝛹","\\varPsi");n(a,d,"𝛺","\\varOmega");n(g,d,"𝛤","\\varGamma");n(g,d,"𝛥","\\varDelta");n(g,d,"𝛩","\\varTheta");n(g,d,"𝛬","\\varLambda");n(g,d,"𝛯","\\varXi");n(g,d,"𝛱","\\varPi");n(g,d,"𝛴","\\varSigma");n(g,d,"𝛶","\\varUpsilon");n(g,d,"𝛷","\\varPhi");n(g,d,"𝛹","\\varPsi");n(g,d,"𝛺","\\varOmega");const st='0123456789/@."';for(let e=0;e0&&s.push(new p.MathNode("mrow",i)),s.push(f),i=[];const A=new p.MathNode("mtd",s);A.style.textAlign="left",o.push(new p.MathNode("mtr",[A])),s=[],u+=1;continue}if(i.push(f),f.type&&f.type==="mo"&&f.children.length===1&&!Object.prototype.hasOwnProperty.call(f.attributes,"movablelimits")){const A=f.children[0].text;if(Ur.indexOf(A)>-1)m+=1;else if(Vr.indexOf(A)>-1)m-=1;else if(m===0&&t==="="&&A==="="){if(l+=1,l>1){i.pop();const x=new p.MathNode("mrow",i);s.push(x),i=[f]}}else if(m===0&&t==="tex"&&A!=="∇"){const x=u0){const f=new p.MathNode("mrow",i);s.push(f)}if(o.length>0){const f=new p.MathNode("mtd",s);f.style.textAlign="left";const A=new p.MathNode("mtr",[f]);o.push(A);const x=new p.MathNode("mtable",o);return r||(x.setAttribute("columnalign","left"),x.setAttribute("rowspacing","0em")),x}return p.newDocumentFragment(s)}const W=function(e,t,r){return G[t][e]&&G[t][e].replace&&e.charCodeAt(0)!==55349&&!(Object.prototype.hasOwnProperty.call(jr,e)&&r&&(r.fontFamily&&r.fontFamily.slice(4,6)==="tt"||r.font&&r.font.slice(4,6)==="tt"))&&(e=G[t][e].replace),new p.TextNode(e)},ut=(e,t)=>{if(e.children.length===0||e.children[e.children.length-1].type!=="mtext"){const r=new p.MathNode("mtext",[new p.TextNode(t.children[0].text)]);e.children.push(r)}else e.children[e.children.length-1].children[0].text+=t.children[0].text},Ne=e=>{if(e.type!=="mrow"&&e.type!=="mstyle"||e.children.length===0)return e;const t=new p.MathNode("mrow");for(let r=0;r0&&o.children[0].text.charAt(s-1)===" "&&(o.children[0].text=o.children[0].text.slice(0,-1)+" ");for(const[i,l]of Object.entries(e.attributes))o.attributes[i]=l}return t.children.length===1&&t.children[0].type==="mtext"?t.children[0]:t},Ye=function(e,t=!1){if(e.length===1&&!(e[0]instanceof Ze))return e[0];if(!t){e[0]instanceof V&&e[0].type==="mo"&&!e[0].attributes.fence&&(e[0].attributes.lspace="0em",e[0].attributes.rspace="0em");const r=e.length-1;e[r]instanceof V&&e[r].type==="mo"&&!e[r].attributes.fence&&(e[r].attributes.lspace="0em",e[r].attributes.rspace="0em")}return new p.MathNode("mrow",e)};function Me(e){if(!e)return!1;if(e.type==="mi"&&e.children.length===1){const t=e.children[0];return t instanceof he&&t.text==="."}else if(e.type==="mtext"&&e.children.length===1){const t=e.children[0];return t instanceof he&&t.text===" "}else if(e.type==="mo"&&e.children.length===1&&e.getAttribute("separator")==="true"&&e.getAttribute("lspace")==="0em"&&e.getAttribute("rspace")==="0em"){const t=e.children[0];return t instanceof he&&t.text===","}else return!1}const Wr=(e,t)=>{const r=e[t],o=e[t+1];return r.type==="atom"&&r.text===","&&r.loc&&o.loc&&r.loc.end===o.loc.start},ve=e=>e.type==="atom"&&e.family==="rel"||e.type==="mclass"&&e.mclass==="mrel",U=function(e,t,r=!1){if(!r&&e.length===1){const l=M(e[0],t);return l instanceof V&&l.type==="mo"&&(l.setAttribute("lspace","0em"),l.setAttribute("rspace","0em")),[l]}const o=[],s=[];let i;for(let l=0;l0&&ve(e[l])&&ve(e[l-1])&&u.setAttribute("lspace","0em"),u.type==="mn"&&i&&i.type==="mn"){i.children.push(...u.children);continue}else if(Me(u)&&i&&i.type==="mn"){i.children.push(...u.children);continue}else if(i&&i.type==="mn"&&l=1&&i&&(i.type==="mn"||Me(i))){const m=u.children[0];m instanceof V&&m.type==="mn"&&i&&(m.children=[...i.children,...m.children],o.pop())}o.push(u),i=u}return o},re=function(e,t,r=!1){return Ye(U(e,t,r),r)},M=function(e,t){if(!e)return new p.MathNode("mrow");if(_e[e.type])return _e[e.type](e,t);throw new v("Got group of unknown type: '"+e.type+"'")},ct=e=>new p.MathNode("mtd",[],[],{padding:"0",width:"50%"}),Zr=["mrow","mtd","mtable","mtr"],Pe=e=>{for(const t of e.children)if(t.type&&Zr.includes(t.type)){if(t.classes&&t.classes[0]==="tml-label")return t.label;{const r=Pe(t);if(r)return r}}else if(!t.type){const r=Pe(t);if(r)return r}},Xr=(e,t,r,o)=>{t=re(t[0].body,r),t=Ne(t),t.classes.push("tml-tag");const s=Pe(e);e=new p.MathNode("mtd",[e]);const i=[ct(),e,ct()];i[o?0:2].classes.push(o?"tml-left":"tml-right"),i[o?0:2].children.push(t);const l=new p.MathNode("mtr",i,["tml-tageqn"]);s&&l.setAttribute("id",s);const u=new p.MathNode("mtable",[l]);return u.style.width="100%",u.setAttribute("displaystyle","true"),u};function Yr(e,t,r,o){let s=null;e.length===1&&e[0].type==="tag"&&(s=e[0].tag,e=e[0].body);const i=U(e,r);if(i.length===1&&i[0]instanceof Ut)return i[0];const l=o.displayMode||o.annotate?"none":o.wrap,u=i.length===0?null:i[0];let m=i.length===1&&s===null&&u instanceof V?i[0]:Hr(i,l,o.displayMode);if(s&&(m=Xr(m,s,r,o.leqno)),o.annotate){const A=new p.MathNode("annotation",[new p.TextNode(t)]);A.setAttribute("encoding","application/x-tex"),m=new p.MathNode("semantics",[m,A])}const f=new p.MathNode("math",[m]);return o.xml&&f.setAttribute("xmlns","http://www.w3.org/1998/Math/MathML"),o.displayMode&&(f.setAttribute("display","block"),f.style.display="block math",f.classes=["tml-display"]),f}const Kr="acegıȷmnopqrsuvwxyzαγεηικμνοπρςστυχωϕ𝐚𝐜𝐞𝐠𝐦𝐧𝐨𝐩𝐪𝐫𝐬𝐮𝐯𝐰𝐱𝐲𝐳",Jr="DHKLUcegorsuvxyzΠΥΨαδηιμνοτυχϵ",Qr="BCEGIMNOPQRSTXZlpqtwΓΘΞΣΦΩβεζθξρςφψϑϕϱ",en="AFJdfΔΛ",Ht=(e,t)=>{const r=e.isStretchy?Ce.accentNode(e):new p.MathNode("mo",[W(e.label,e.mode)]);e.isStretchy||r.setAttribute("stretchy","false"),e.label!=="\\vec"&&(r.style.mathDepth="0");const o=e.label==="\\c"?"munder":"mover",s=rn.has(e.label);if(o==="mover"&&e.mode==="math"&&!e.isStretchy&&e.base.text&&e.base.text.length===1){const l=e.base.text,u=e.label==="\\vec",m=u==="\\vec"?"-vec":"";u&&r.classes.push("tml-vec");const f=u?"-vec":s?"-acc":"";Jr.indexOf(l)>-1?(r.classes.push(`chr-sml${m}`),r.classes.push(`wbk-sml${f}`)):Qr.indexOf(l)>-1?(r.classes.push(`chr-med${m}`),r.classes.push(`wbk-med${f}`)):en.indexOf(l)>-1?(r.classes.push(`chr-lrg${m}`),r.classes.push(`wbk-lrg${f}`)):u?r.classes.push("wbk-vec"):s&&r.classes.push("wbk-acc")}else s&&r.classes.push("wbk-acc");return new p.MathNode(o,[M(e.base,t),r])},tn=new Set(["\\acute","\\check","\\grave","\\ddot","\\dddot","\\ddddot","\\tilde","\\bar","\\breve","\\check","\\hat","\\vec","\\dot","\\mathring"]),rn=new Set(["\\acute","\\bar","\\breve","\\check","\\dot","\\ddot","\\grave","\\hat","\\mathring","\\`","\\'","\\^","\\=","\\u","\\.",'\\"',"\\r","\\H","\\v"]),dt={"\\`":"̀","\\'":"́","\\^":"̂","\\~":"̃","\\=":"̄","\\u":"̆","\\.":"̇",'\\"':"̈","\\r":"̊","\\H":"̋","\\v":"̌","\\c":"̧"};S({type:"accent",names:["\\acute","\\grave","\\ddot","\\dddot","\\ddddot","\\tilde","\\bar","\\breve","\\check","\\hat","\\vec","\\dot","\\mathring","\\overparen","\\widecheck","\\widehat","\\wideparen","\\widetilde","\\overrightarrow","\\overleftarrow","\\Overrightarrow","\\overleftrightarrow","\\overgroup","\\overleftharpoon","\\overrightharpoon"],props:{numArgs:1},handler:(e,t)=>{const r=pe(t[0]),o=!tn.has(e.funcName);return{type:"accent",mode:e.parser.mode,label:e.funcName,isStretchy:o,base:r}},mathmlBuilder:Ht});S({type:"accent",names:["\\'","\\`","\\^","\\~","\\=","\\c","\\u","\\.",'\\"',"\\r","\\H","\\v"],props:{numArgs:1,allowedInText:!0,allowedInMath:!0,argTypes:["primitive"]},handler:(e,t)=>{const r=pe(t[0]),o=e.parser.mode;return o==="math"&&e.parser.settings.strict&&console.log(`Temml parse error: Command ${e.funcName} is invalid in math mode.`),o==="text"&&r.text&&r.text.length===1&&e.funcName in dt&&Kr.indexOf(r.text)>-1?{type:"textord",mode:"text",text:r.text+dt[e.funcName]}:e.funcName==="\\c"&&o==="text"&&r.text&&r.text.length===1?{type:"textord",mode:"text",text:r.text+"̧"}:{type:"accent",mode:o,label:e.funcName,isStretchy:!1,base:r}},mathmlBuilder:Ht});S({type:"accentUnder",names:["\\underleftarrow","\\underrightarrow","\\underleftrightarrow","\\undergroup","\\underparen","\\utilde"],props:{numArgs:1},handler:({parser:e,funcName:t},r)=>{const o=r[0];return{type:"accentUnder",mode:e.mode,label:t,base:o}},mathmlBuilder:(e,t)=>{const r=Ce.accentNode(e);return r.style["math-depth"]=0,new p.MathNode("munder",[M(e.base,t),r])}});const ht={pt:800/803,pc:12*800/803,dd:1238/1157*800/803,cc:14856/1157*800/803,nd:685/642*800/803,nc:1370/107*800/803,sp:1/65536*800/803,mm:25.4/72,cm:2.54/72,in:1/72,px:96/72},nn=["em","ex","mu","pt","mm","cm","in","px","bp","pc","dd","cc","nd","nc","sp"],Wt=function(e){return typeof e!="string"&&(e=e.unit),nn.indexOf(e)>-1},Zt=e=>{const t=Math.max(e-1,0);return[1,.7,.5][t]},Q=function(e,t){let r=e.number;if(t.maxSize[0]<0&&r>0)return{number:0,unit:"em"};const o=e.unit;switch(o){case"mm":case"cm":case"in":case"px":return r*ht[o]>t.maxSize[1]?{number:t.maxSize[1],unit:"pt"}:{number:r,unit:o};case"em":case"ex":return o==="ex"&&(r*=.431),r=Math.min(r/Zt(t.level),t.maxSize[0]),{number:O.round(r),unit:"em"};case"bp":return r>t.maxSize[1]&&(r=t.maxSize[1]),{number:r,unit:"pt"};case"pt":case"pc":case"dd":case"cc":case"nd":case"nc":case"sp":return r=Math.min(r*ht[o],t.maxSize[1]),{number:O.round(r),unit:"pt"};case"mu":return r=Math.min(r/18,t.maxSize[0]),{number:O.round(r),unit:"em"};default:throw new v("Invalid unit: '"+o+"'")}},I=e=>{const t=new p.MathNode("mspace");return t.setAttribute("width",e+"em"),t},Ae=(e,t=.3,r=0,o=!1)=>{if(e==null&&r===0)return I(t);const s=e?[e]:[];if(t!==0&&s.unshift(I(t)),r>0&&s.push(I(r)),o){const i=new p.MathNode("mpadded",s);return i.setAttribute("height","0"),i}else return new p.MathNode("mrow",s)},Ee=(e,t)=>Number(e)/Zt(t),Ge=(e,t,r,o)=>{const s=Ce.mathMLnode(e),i=e.slice(1,3)==="eq",l=e.charAt(1)==="x"?"1.75":e.slice(2,4)==="cd"?"3.0":i?"1.0":"2.0";s.setAttribute("lspace","0"),s.setAttribute("rspace",i?"0.5em":"0");const u=o.withLevel(o.level<2?2:3),m=Ee(l,u.level),f=Ee(l,3),A=Ae(null,m.toFixed(4),0),x=Ae(null,f.toFixed(4),0),y=Ee(i?0:.3,u.level).toFixed(4);let _,D;const E=t&&t.body&&(t.body.body||t.body.length>0);if(E){let N=M(t,u);N=Ae(N,y,y,e==="\\\\cdrightarrow"||e==="\\\\cdleftarrow"),_=new p.MathNode("mover",[N,x])}const z=r&&r.body&&(r.body.body||r.body.length>0);if(z){let N=M(r,u);N=Ae(N,y,y),D=new p.MathNode("munder",[N,x])}let T;return!E&&!z?T=new p.MathNode("mover",[s,A]):E&&z?T=new p.MathNode("munderover",[s,D,_]):E?T=new p.MathNode("mover",[s,_]):T=new p.MathNode("munder",[s,D]),l==="3.0"&&(T.style.height="1em"),T.setAttribute("accent","false"),T};S({type:"xArrow",names:["\\xleftarrow","\\xrightarrow","\\xLeftarrow","\\xRightarrow","\\xleftrightarrow","\\xLeftrightarrow","\\xhookleftarrow","\\xhookrightarrow","\\xmapsto","\\xrightharpoondown","\\xrightharpoonup","\\xleftharpoondown","\\xleftharpoonup","\\xlongequal","\\xtwoheadrightarrow","\\xtwoheadleftarrow","\\xtofrom","\\xleftrightharpoons","\\xrightleftharpoons","\\yields","\\yieldsLeft","\\mesomerism","\\longrightharpoonup","\\longleftharpoondown","\\yieldsLeftRight","\\chemequilibrium","\\\\cdrightarrow","\\\\cdleftarrow","\\\\cdlongequal"],props:{numArgs:1,numOptionalArgs:1},handler({parser:e,funcName:t},r,o){return{type:"xArrow",mode:e.mode,name:t,body:r[0],below:o[0]}},mathmlBuilder(e,t){const o=[Ge(e.name,e.body,e.below,t)];return o.unshift(I(.2778)),o.push(I(.2778)),new p.MathNode("mrow",o)}});const mt={"\\equilibriumRight":["\\longrightharpoonup","\\eqleftharpoondown"],"\\equilibriumLeft":["\\eqrightharpoonup","\\longleftharpoondown"]};S({type:"stackedArrow",names:["\\equilibriumRight","\\equilibriumLeft"],props:{numArgs:1,numOptionalArgs:1},handler({parser:e,funcName:t},r,o){const s=r[0]?{type:"hphantom",mode:e.mode,body:r[0]}:null,i=o[0]?{type:"hphantom",mode:e.mode,body:o[0]}:null;return{type:"stackedArrow",mode:e.mode,name:t,body:r[0],upperArrowBelow:i,lowerArrowBody:s,below:o[0]}},mathmlBuilder(e,t){const r=mt[e.name][0],o=mt[e.name][1],s=Ge(r,e.body,e.upperArrowBelow,t),i=Ge(o,e.lowerArrowBody,e.below,t);let l;const u=new p.MathNode("mpadded",[s]);if(u.setAttribute("voffset","0.3em"),u.setAttribute("height","+0.3em"),u.setAttribute("depth","-0.3em"),e.name==="\\equilibriumLeft"){const m=new p.MathNode("mpadded",[i]);m.setAttribute("width","0.5em"),l=new p.MathNode("mpadded",[I(.2778),m,u,I(.2778)])}else u.setAttribute("width",e.name==="\\equilibriumRight"?"0.5em":"0"),l=new p.MathNode("mpadded",[I(.2778),u,i,I(.2778)]);return l.setAttribute("voffset","-0.18em"),l.setAttribute("height","-0.18em"),l.setAttribute("depth","+0.18em"),l}});const Xt={};function Y({type:e,names:t,props:r,handler:o,mathmlBuilder:s}){const i={type:e,numArgs:r.numArgs||0,allowedInText:!1,numOptionalArgs:0,handler:o};for(let l=0;l":"\\\\cdrightarrow","<":"\\\\cdleftarrow","=":"\\\\cdlongequal",A:"\\uparrow",V:"\\downarrow","|":"\\Vert",".":"no arrow"},pt=()=>({type:"styling",body:[],mode:"math",scriptLevel:"display"}),ft=e=>e.type==="textord"&&e.text==="@",an=(e,t)=>(e.type==="mathord"||e.type==="atom")&&e.text===t;function sn(e,t,r){const o=on[e];switch(o){case"\\\\cdrightarrow":case"\\\\cdleftarrow":return r.callFunction(o,[t[0]],[t[1]]);case"\\uparrow":case"\\downarrow":{const s=r.callFunction("\\\\cdleft",[t[0]],[]),i={type:"atom",text:o,mode:"math",family:"rel"},l=r.callFunction("\\Big",[i],[]),u=r.callFunction("\\\\cdright",[t[1]],[]),m={type:"ordgroup",mode:"math",body:[s,l,u],semisimple:!0};return r.callFunction("\\\\cdparent",[m],[])}case"\\\\cdlongequal":return r.callFunction("\\\\cdlongequal",[],[]);case"\\Vert":{const s={type:"textord",text:"\\Vert",mode:"math"};return r.callFunction("\\Big",[s],[])}default:return{type:"textord",text:" ",mode:"math"}}}function ln(e){const t=[];for(e.gullet.beginGroup(),e.gullet.macros.set("\\cr","\\\\\\relax"),e.gullet.beginGroup();;){t.push(e.parseExpression(!1,"\\\\")),e.gullet.endGroup(),e.gullet.beginGroup();const s=e.fetch().text;if(s==="&"||s==="\\\\")e.consume();else if(s==="\\end"){t[t.length-1].length===0&&t.pop();break}else throw new v("Expected \\\\ or \\cr or \\end",e.nextToken)}let r=[];const o=[r];for(let s=0;s-1))if("<>AV".indexOf(m)>-1)for(let x=0;x<2;x++){let y=!0;for(let _=u+1;_AV=|." after @.');const A=sn(m,f,e);r.push(A),l=pt()}s%2===0?r.push(l):r.shift(),r=[],o.push(r)}return o.pop(),e.gullet.endGroup(),e.gullet.endGroup(),{type:"array",mode:"math",body:o,tags:null,labels:new Array(o.length+1).fill(""),envClasses:["jot","cd"],cols:[],hLinesBeforeRow:new Array(o.length+1).fill([])}}S({type:"cdlabel",names:["\\\\cdleft","\\\\cdright"],props:{numArgs:1},handler({parser:e,funcName:t},r){return{type:"cdlabel",mode:e.mode,side:t.slice(4),label:r[0]}},mathmlBuilder(e,t){if(e.label.body.length===0)return new p.MathNode("mrow",t);const r=new p.MathNode("mtd",[M(e.label,t)]);r.style.padding="0";const o=new p.MathNode("mtr",[r]),s=new p.MathNode("mtable",[o]),i=new p.MathNode("mpadded",[s]);return i.setAttribute("width","0"),i.setAttribute("displaystyle","false"),i.setAttribute("scriptlevel","1"),e.side==="left"&&(i.style.display="flex",i.style.justifyContent="flex-end"),i}});S({type:"cdlabelparent",names:["\\\\cdparent"],props:{numArgs:1},handler({parser:e},t){return{type:"cdlabelparent",mode:e.mode,fragment:t[0]}},mathmlBuilder(e,t){return new p.MathNode("mrow",[M(e.fragment,t)])}});const Yt=e=>({type:"ordgroup",mode:"math",body:e,semisimple:!0}),Le=(e,t)=>({type:t,mode:"math",body:Yt(e)}),un=(e,t)=>{const r=e.body;r[0].shift();const o=new Array(r.length-1).fill().map(()=>[]);for(let x=1;x[]);for(let x=0;x[]),envClasses:[],scriptLevel:"text",arraystretch:1,labels:new Array(o.length).fill(""),arraycolsep:{number:.04,unit:"em"}},u={type:"styling",mode:"math",scriptLevel:"text",body:[{type:"array",mode:"math",body:s,cols:new Array(s.length).fill({type:"align",align:"c"}),rowGaps:new Array(s.length-1).fill(null),hLinesBeforeRow:new Array(s.length+1).fill().map(()=>[]),envClasses:[],scriptLevel:"text",arraystretch:1,labels:new Array(s.length).fill(""),arraycolsep:null}]},A={type:"supsub",mode:"math",stack:!0,base:{type:"op",mode:"math",limits:!0,alwaysHandleSupSub:!0,parentIsSupSub:!0,symbol:!1,suppressBaseShift:!0,body:[{type:"leftright",mode:"math",body:[e],left:t?t[0]:"(",right:t?t[1]:")",rightColor:void 0}]},sup:u,sub:null};return Yt([i,A])};class H{constructor(t,r,o){this.lexer=t,this.start=r,this.end=o}static range(t,r){return r?!t||!t.loc||!r.loc||t.loc.lexer!==r.loc.lexer?null:new H(t.loc.lexer,t.loc.start,r.loc.end):t&&t.loc}}class J{constructor(t,r){this.text=t,this.loc=r}range(t,r){return new J(r,H.range(this,t))}}const P={DISPLAY:0,TEXT:1,SCRIPT:2,SCRIPTSCRIPT:3},Kt={};function c(e,t){Kt[e]=t}const cn=Kt;c("\\noexpand",function(e){const t=e.popToken();return e.isExpandable(t.text)&&(t.noexpand=!0,t.treatAsRelax=!0),{tokens:[t],numArgs:0}});c("\\expandafter",function(e){const t=e.popToken();return e.expandOnce(!0),{tokens:[t],numArgs:0}});c("\\@firstoftwo",function(e){return{tokens:e.consumeArgs(2)[0],numArgs:0}});c("\\@secondoftwo",function(e){return{tokens:e.consumeArgs(2)[1],numArgs:0}});c("\\@ifnextchar",function(e){const t=e.consumeArgs(3);e.consumeSpaces();const r=e.future();return t[0].length===1&&t[0][0].text===r.text?{tokens:t[1],numArgs:0}:{tokens:t[2],numArgs:0}});c("\\@ifstar","\\@ifnextchar *{\\@firstoftwo{#1}}");c("\\TextOrMath",function(e){const t=e.consumeArgs(2);return e.mode==="text"?{tokens:t[0],numArgs:0}:{tokens:t[1],numArgs:0}});const Re=e=>{let t="";for(let r=e.length-1;r>-1;r--)t+=e[r].text;return t},Je={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,A:10,b:11,B:11,c:12,C:12,d:13,D:13,e:14,E:14,f:15,F:15},gt=e=>{const t=e.future().text;return t==="EOF"?[null,""]:[Je[t.charAt(0)],t]},bt=(e,t,r)=>{for(let o=1;o=r)throw new v(`Invalid base-${r} digit ${t.text}`);o=bt(o,s,r);let i;for([i,s]=gt(e);i!=null&&i=0;s--){const i=t[s].loc.start;i>o&&(r+=" ",o=i),r+=t[s].text,o+=t[s].text.length}return r}c("\\surd","\\sqrt{\\vphantom{|}}");c("⊕","\\oplus");c("\\long","");c("\\bgroup","{");c("\\egroup","}");c("~","\\nobreakspace");c("\\lq","`");c("\\rq","'");c("\\aa","\\r a");c("\\Bbbk","\\Bbb{k}");c("\\mathstrut","\\vphantom{(}");c("\\underbar","\\underline{\\text{#1}}");c("\\vdots","{\\varvdots\\rule{0pt}{15pt}}");c("⋮","\\vdots");c("\\arraystretch","1");c("\\arraycolsep","6pt");c("\\substack","\\begin{subarray}{c}#1\\end{subarray}");c("\\iff","\\DOTSB\\;\\Longleftrightarrow\\;");c("\\implies","\\DOTSB\\;\\Longrightarrow\\;");c("\\impliedby","\\DOTSB\\;\\Longleftarrow\\;");const xt={",":"\\dotsc","\\not":"\\dotsb","+":"\\dotsb","=":"\\dotsb","<":"\\dotsb",">":"\\dotsb","-":"\\dotsb","*":"\\dotsb",":":"\\dotsb","\\DOTSB":"\\dotsb","\\coprod":"\\dotsb","\\bigvee":"\\dotsb","\\bigwedge":"\\dotsb","\\biguplus":"\\dotsb","\\bigcap":"\\dotsb","\\bigcup":"\\dotsb","\\prod":"\\dotsb","\\sum":"\\dotsb","\\bigotimes":"\\dotsb","\\bigoplus":"\\dotsb","\\bigodot":"\\dotsb","\\bigsqcap":"\\dotsb","\\bigsqcup":"\\dotsb","\\bigtimes":"\\dotsb","\\And":"\\dotsb","\\longrightarrow":"\\dotsb","\\Longrightarrow":"\\dotsb","\\longleftarrow":"\\dotsb","\\Longleftarrow":"\\dotsb","\\longleftrightarrow":"\\dotsb","\\Longleftrightarrow":"\\dotsb","\\mapsto":"\\dotsb","\\longmapsto":"\\dotsb","\\hookrightarrow":"\\dotsb","\\doteq":"\\dotsb","\\mathbin":"\\dotsb","\\mathrel":"\\dotsb","\\relbar":"\\dotsb","\\Relbar":"\\dotsb","\\xrightarrow":"\\dotsb","\\xleftarrow":"\\dotsb","\\DOTSI":"\\dotsi","\\int":"\\dotsi","\\oint":"\\dotsi","\\iint":"\\dotsi","\\iiint":"\\dotsi","\\iiiint":"\\dotsi","\\idotsint":"\\dotsi","\\DOTSX":"\\dotsx"};c("\\dots",function(e){let t="\\dotso";const r=e.expandAfterFuture().text;return r in xt?t=xt[r]:(r.slice(0,4)==="\\not"||r in G.math&&["bin","rel"].includes(G.math[r].group))&&(t="\\dotsb"),t});const et={")":!0,"]":!0,"\\rbrack":!0,"\\}":!0,"\\rbrace":!0,"\\rangle":!0,"\\rceil":!0,"\\rfloor":!0,"\\rgroup":!0,"\\rmoustache":!0,"\\right":!0,"\\bigr":!0,"\\biggr":!0,"\\Bigr":!0,"\\Biggr":!0,$:!0,";":!0,".":!0,",":!0};c("\\dotso",function(e){return e.future().text in et?"\\ldots\\,":"\\ldots"});c("\\dotsc",function(e){const t=e.future().text;return t in et&&t!==","?"\\ldots\\,":"\\ldots"});c("\\cdots",function(e){return e.future().text in et?"\\@cdots\\,":"\\@cdots"});c("\\dotsb","\\cdots");c("\\dotsm","\\cdots");c("\\dotsi","\\!\\cdots");c("\\idotsint","\\dotsi");c("\\dotsx","\\ldots\\,");c("\\DOTSI","\\relax");c("\\DOTSB","\\relax");c("\\DOTSX","\\relax");c("\\tmspace","\\TextOrMath{\\kern#1#3}{\\mskip#1#2}\\relax");c("\\,","{\\tmspace+{3mu}{.1667em}}");c("\\thinspace","\\,");c("\\>","\\mskip{4mu}");c("\\:","{\\tmspace+{4mu}{.2222em}}");c("\\medspace","\\:");c("\\;","{\\tmspace+{5mu}{.2777em}}");c("\\thickspace","\\;");c("\\!","{\\tmspace-{3mu}{.1667em}}");c("\\negthinspace","\\!");c("\\negmedspace","{\\tmspace-{4mu}{.2222em}}");c("\\negthickspace","{\\tmspace-{5mu}{.277em}}");c("\\enspace","\\kern.5em ");c("\\enskip","\\hskip.5em\\relax");c("\\quad","\\hskip1em\\relax");c("\\qquad","\\hskip2em\\relax");c("\\AA","\\TextOrMath{\\Angstrom}{\\mathring{A}}\\relax");c("\\tag","\\@ifstar\\tag@literal\\tag@paren");c("\\tag@paren","\\tag@literal{({#1})}");c("\\tag@literal",e=>{if(e.macros.get("\\df@tag"))throw new v("Multiple \\tag");return"\\gdef\\df@tag{\\text{#1}}"});c("\\notag","\\nonumber");c("\\nonumber","\\gdef\\@eqnsw{0}");c("\\bmod","\\mathbin{\\text{mod}}");c("\\pod","\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern8mu}{\\mkern8mu}{\\mkern8mu}(#1)");c("\\pmod","\\pod{{\\rm mod}\\mkern6mu#1}");c("\\mod","\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern12mu}{\\mkern12mu}{\\mkern12mu}{\\rm mod}\\,\\,#1");c("\\newline","\\\\\\relax");c("\\TeX","\\textrm{T}\\kern-.1667em\\raisebox{-.5ex}{E}\\kern-.125em\\textrm{X}");c("\\LaTeX","\\textrm{L}\\kern-.35em\\raisebox{0.2em}{\\scriptstyle A}\\kern-.15em\\TeX");c("\\Temml","\\textrm{T}\\kern-0.2em\\lower{0.2em}{\\textrm{E}}\\kern-0.08em{\\textrm{M}\\kern-0.08em\\raise{0.2em}\\textrm{M}\\kern-0.08em\\textrm{L}}");c("\\hspace","\\@ifstar\\@hspacer\\@hspace");c("\\@hspace","\\hskip #1\\relax");c("\\@hspacer","\\rule{0pt}{0pt}\\hskip #1\\relax");c("\\colon",'\\mathpunct{\\char"3a}');c("\\prescript","\\pres@cript{_{#1}^{#2}}{}{#3}");c("\\ordinarycolon",'\\char"3a');c("\\vcentcolon","\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}}");c("\\coloneq",'\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}\\char"2212}');c("\\Coloneq",'\\mathrel{\\char"2237\\char"2212}');c("\\Eqqcolon",'\\mathrel{\\char"3d\\char"2237}');c("\\Eqcolon",'\\mathrel{\\char"2212\\char"2237}');c("\\colonapprox",'\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}\\char"2248}');c("\\Colonapprox",'\\mathrel{\\char"2237\\char"2248}');c("\\colonsim",'\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}\\char"223c}');c("\\Colonsim",'\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}\\char"223c}');c("\\ratio","\\vcentcolon");c("\\coloncolon","\\dblcolon");c("\\colonequals","\\coloneqq");c("\\coloncolonequals","\\Coloneqq");c("\\equalscolon","\\eqqcolon");c("\\equalscoloncolon","\\Eqqcolon");c("\\colonminus","\\coloneq");c("\\coloncolonminus","\\Coloneq");c("\\minuscolon","\\eqcolon");c("\\minuscoloncolon","\\Eqcolon");c("\\coloncolonapprox","\\Colonapprox");c("\\coloncolonsim","\\Colonsim");c("\\notni","\\mathrel{\\char`∌}");c("\\limsup","\\DOTSB\\operatorname*{lim\\,sup}");c("\\liminf","\\DOTSB\\operatorname*{lim\\,inf}");c("\\injlim","\\DOTSB\\operatorname*{inj\\,lim}");c("\\projlim","\\DOTSB\\operatorname*{proj\\,lim}");c("\\varlimsup","\\DOTSB\\operatorname*{\\overline{\\text{lim}}}");c("\\varliminf","\\DOTSB\\operatorname*{\\underline{\\text{lim}}}");c("\\varinjlim","\\DOTSB\\operatorname*{\\underrightarrow{\\text{lim}}}");c("\\varprojlim","\\DOTSB\\operatorname*{\\underleftarrow{\\text{lim}}}");c("\\centerdot","{\\medspace\\rule{0.167em}{0.189em}\\medspace}");c("\\argmin","\\DOTSB\\operatorname*{arg\\,min}");c("\\argmax","\\DOTSB\\operatorname*{arg\\,max}");c("\\plim","\\DOTSB\\operatorname*{plim}");c("\\leftmodels","\\mathop{\\reflectbox{$\\models$}}");c("\\bra","\\mathinner{\\langle{#1}|}");c("\\ket","\\mathinner{|{#1}\\rangle}");c("\\braket","\\mathinner{\\langle{#1}\\rangle}");c("\\Bra","\\left\\langle#1\\right|");c("\\Ket","\\left|#1\\right\\rangle");const Jt=(e,t)=>{const o=`}\\,\\middle${t[0]==="|"?"\\vert":"\\Vert"}\\,{`;return e.slice(0,t.index)+o+e.slice(t.index+t[0].length)};c("\\Braket",function(e){let t=Qe(e);const r=/\|\||\||\\\|/g;let o;for(;(o=r.exec(t))!==null;)t=Jt(t,o);return"\\left\\langle{"+t+"}\\right\\rangle"});c("\\Set",function(e){let t=Qe(e);const r=/\|\||\||\\\|/.exec(t);return r&&(t=Jt(t,r)),"\\left\\{\\:{"+t+"}\\:\\right\\}"});c("\\set",function(e){return"\\{{"+Qe(e).replace(/\|/,"}\\mid{")+"}\\}"});c("\\angln","{\\angl n}");c("\\odv","\\@ifstar\\odv@next\\odv@numerator");c("\\odv@numerator","\\frac{\\mathrm{d}#1}{\\mathrm{d}#2}");c("\\odv@next","\\frac{\\mathrm{d}}{\\mathrm{d}#2}#1");c("\\pdv","\\@ifstar\\pdv@next\\pdv@numerator");const Qt=e=>{const t=e[0][0].text,r=Re(e[1]).split(","),o=String(r.length),s=o==="1"?"\\partial":`\\partial^${o}`;let i="";return r.map(l=>{i+="\\partial "+l.trim()+"\\,"}),[t,s,i.replace(/\\,$/,"")]};c("\\pdv@numerator",function(e){const[t,r,o]=Qt(e.consumeArgs(2));return`\\frac{${r} ${t}}{${o}}`});c("\\pdv@next",function(e){const[t,r,o]=Qt(e.consumeArgs(2));return`\\frac{${r}}{${o}} ${t}`});c("\\upalpha","\\up@greek{\\alpha}");c("\\upbeta","\\up@greek{\\beta}");c("\\upgamma","\\up@greek{\\gamma}");c("\\updelta","\\up@greek{\\delta}");c("\\upepsilon","\\up@greek{\\epsilon}");c("\\upzeta","\\up@greek{\\zeta}");c("\\upeta","\\up@greek{\\eta}");c("\\uptheta","\\up@greek{\\theta}");c("\\upiota","\\up@greek{\\iota}");c("\\upkappa","\\up@greek{\\kappa}");c("\\uplambda","\\up@greek{\\lambda}");c("\\upmu","\\up@greek{\\mu}");c("\\upnu","\\up@greek{\\nu}");c("\\upxi","\\up@greek{\\xi}");c("\\upomicron","\\up@greek{\\omicron}");c("\\uppi","\\up@greek{\\pi}");c("\\upalpha","\\up@greek{\\alpha}");c("\\uprho","\\up@greek{\\rho}");c("\\upsigma","\\up@greek{\\sigma}");c("\\uptau","\\up@greek{\\tau}");c("\\upupsilon","\\up@greek{\\upsilon}");c("\\upphi","\\up@greek{\\phi}");c("\\upchi","\\up@greek{\\chi}");c("\\uppsi","\\up@greek{\\psi}");c("\\upomega","\\up@greek{\\omega}");c("\\invamp",'\\mathbin{\\char"214b}');c("\\parr",'\\mathbin{\\char"214b}');c("\\with",'\\mathbin{\\char"26}');c("\\multimapinv",'\\mathrel{\\char"27dc}');c("\\multimapboth",'\\mathrel{\\char"29df}');c("\\scoh",'{\\mkern5mu\\char"2322\\mkern5mu}');c("\\sincoh",'{\\mkern5mu\\char"2323\\mkern5mu}');c("\\coh",`{\\mkern5mu\\rule{}{0.7em}\\mathrlap{\\smash{\\raise2mu{\\char"2322}}} {\\smash{\\lower4mu{\\char"2323}}}\\mkern5mu}`);c("\\incoh",`{\\mkern5mu\\rule{}{0.7em}\\mathrlap{\\smash{\\raise2mu{\\char"2323}}} {\\smash{\\lower4mu{\\char"2322}}}\\mkern5mu}`);c("\\standardstate","\\text{\\tiny\\char`⦵}");c("\\ce",function(e){return er(e.consumeArgs(1)[0],"ce")});c("\\pu",function(e){return er(e.consumeArgs(1)[0],"pu")});c("\\uniDash","{\\rule{0.672em}{0.06em}}");c("\\triDash","{\\rule{0.15em}{0.06em}\\kern2mu\\rule{0.15em}{0.06em}\\kern2mu\\rule{0.15em}{0.06em}}");c("\\tripleDash","\\kern0.075em\\raise0.25em{\\triDash}\\kern0.075em");c("\\tripleDashOverLine","\\kern0.075em\\mathrlap{\\raise0.125em{\\uniDash}}\\raise0.34em{\\triDash}\\kern0.075em");c("\\tripleDashOverDoubleLine","\\kern0.075em\\mathrlap{\\mathrlap{\\raise0.48em{\\triDash}}\\raise0.27em{\\uniDash}}{\\raise0.05em{\\uniDash}}\\kern0.075em");c("\\tripleDashBetweenDoubleLine","\\kern0.075em\\mathrlap{\\mathrlap{\\raise0.48em{\\uniDash}}\\raise0.27em{\\triDash}}{\\raise0.05em{\\uniDash}}\\kern0.075em");var er=function(e,t){for(var r="",o=e.length&&e[e.length-1].loc.start,s=e.length-1;s>=0;s--)e[s].loc.start>o&&(r+=" ",o=e[s].loc.start),r+=e[s].text,o+=e[s].text.length;var i=L.go(w.go(r,t));return i},w={go:function(e,t){if(!e)return[];t===void 0&&(t="ce");var r="0",o={};o.parenthesisLevel=0,e=e.replace(/\n/g," "),e=e.replace(/[\u2212\u2013\u2014\u2010]/g,"-"),e=e.replace(/[\u2026]/g,"...");for(var s,i=10,l=[];;){s!==e?(i=10,s=e):i--;var u=w.stateMachines[t],m=u.transitions[r]||u.transitions["*"];e:for(var f=0;f0){if(x.revisit||(e=A.remainder),!x.toContinue)break e}else return l}}if(i<=0)throw["MhchemBugU","mhchem bug U. Please report."]}},concatArray:function(e,t){if(t)if(Array.isArray(t))for(var r=0;r":/^[=<>]/,"#":/^[#\u2261]/,"+":/^\+/,"-$":/^-(?=[\s_},;\]/]|$|\([a-z]+\))/,"-9":/^-(?=[0-9])/,"- orbital overlap":/^-(?=(?:[spd]|sp)(?:$|[\s,;\)\]\}]))/,"-":/^-/,"pm-operator":/^(?:\\pm|\$\\pm\$|\+-|\+\/-)/,operator:/^(?:\+|(?:[\-=<>]|<<|>>|\\approx|\$\\approx\$)(?=\s|$|-?[0-9]))/,arrowUpDown:/^(?:v|\(v\)|\^|\(\^\))(?=$|[\s,;\)\]\}])/,"\\bond{(...)}":function(e){return w.patterns.findObserveGroups(e,"\\bond{","","","}")},"->":/^(?:<->|<-->|->|<-|<=>>|<<=>|<=>|[\u2192\u27F6\u21CC])/,CMT:/^[CMT](?=\[)/,"[(...)]":function(e){return w.patterns.findObserveGroups(e,"[","","","]")},"1st-level escape":/^(&|\\\\|\\hline)\s*/,"\\,":/^(?:\\[,\ ;:])/,"\\x{}{}":function(e){return w.patterns.findObserveGroups(e,"",/^\\[a-zA-Z]+\{/,"}","","","{","}","",!0)},"\\x{}":function(e){return w.patterns.findObserveGroups(e,"",/^\\[a-zA-Z]+\{/,"}","")},"\\ca":/^\\ca(?:\s+|(?![a-zA-Z]))/,"\\x":/^(?:\\[a-zA-Z]+\s*|\\[_&{}%])/,orbital:/^(?:[0-9]{1,2}[spdfgh]|[0-9]{0,2}sp)(?=$|[^a-zA-Z])/,others:/^[\/~|]/,"\\frac{(...)}":function(e){return w.patterns.findObserveGroups(e,"\\frac{","","","}","{","","","}")},"\\overset{(...)}":function(e){return w.patterns.findObserveGroups(e,"\\overset{","","","}","{","","","}")},"\\underset{(...)}":function(e){return w.patterns.findObserveGroups(e,"\\underset{","","","}","{","","","}")},"\\underbrace{(...)}":function(e){return w.patterns.findObserveGroups(e,"\\underbrace{","","","}_","{","","","}")},"\\color{(...)}0":function(e){return w.patterns.findObserveGroups(e,"\\color{","","","}")},"\\color{(...)}{(...)}1":function(e){return w.patterns.findObserveGroups(e,"\\color{","","","}","{","","","}")},"\\color(...){(...)}2":function(e){return w.patterns.findObserveGroups(e,"\\color","\\","",/^(?=\{)/,"{","","","}")},"\\ce{(...)}":function(e){return w.patterns.findObserveGroups(e,"\\ce{","","","}")},oxidation$:/^(?:[+-][IVX]+|\\pm\s*0|\$\\pm\$\s*0)$/,"d-oxidation$":/^(?:[+-]?\s?[IVX]+|\\pm\s*0|\$\\pm\$\s*0)$/,"roman numeral":/^[IVX]+/,"1/2$":/^[+\-]?(?:[0-9]+|\$[a-z]\$|[a-z])\/[0-9]+(?:\$[a-z]\$|[a-z])?$/,amount:function(e){var t;if(t=e.match(/^(?:(?:(?:\([+\-]?[0-9]+\/[0-9]+\)|[+\-]?(?:[0-9]+|\$[a-z]\$|[a-z])\/[0-9]+|[+\-]?[0-9]+[.,][0-9]+|[+\-]?\.[0-9]+|[+\-]?[0-9]+)(?:[a-z](?=\s*[A-Z]))?)|[+\-]?[a-z](?=\s*[A-Z])|\+(?!\s))/),t)return{match_:t[0],remainder:e.substr(t[0].length)};var r=w.patterns.findObserveGroups(e,"","$","$","");return r&&(t=r.match_.match(/^\$(?:\(?[+\-]?(?:[0-9]*[a-z]?[+\-])?[0-9]*[a-z](?:[+\-][0-9]*[a-z]?)?\)?|\+|-)\$$/),t)?{match_:t[0],remainder:e.substr(t[0].length)}:null},amount2:function(e){return this.amount(e)},"(KV letters),":/^(?:[A-Z][a-z]{0,2}|i)(?=,)/,formula$:function(e){if(e.match(/^\([a-z]+\)$/))return null;var t=e.match(/^(?:[a-z]|(?:[0-9\ \+\-\,\.\(\)]+[a-z])+[0-9\ \+\-\,\.\(\)]*|(?:[a-z][0-9\ \+\-\,\.\(\)]+)+[a-z]?)$/);return t?{match_:t[0],remainder:e.substr(t[0].length)}:null},uprightEntities:/^(?:pH|pOH|pC|pK|iPr|iBu)(?=$|[^a-zA-Z])/,"/":/^\s*(\/)\s*/,"//":/^\s*(\/\/)\s*/,"*":/^\s*[*.]\s*/},findObserveGroups:function(e,t,r,o,s,i,l,u,m,f){var A=function(T,N){if(typeof N=="string")return T.indexOf(N)!==0?null:N;var Z=T.match(N);return Z?Z[0]:null},x=function(T,N,Z){for(var X=0;N0,null},y=A(e,t);if(y===null||(e=e.substr(y.length),y=A(e,r),y===null))return null;var _=x(e,y.length,o||s);if(_===null)return null;var D=e.substring(0,o?_.endMatchEnd:_.endMatchBegin);if(i||l){var E=this.findObserveGroups(e.substr(_.endMatchEnd),i,l,u,m);if(E===null)return null;var z=[D,E.match_];return{match_:f?z.join(""):z,remainder:E.remainder}}else return{match_:D,remainder:e.substr(_.endMatchEnd)}},match_:function(e,t){var r=w.patterns.patterns[e];if(r===void 0)throw["MhchemBugP","mhchem bug P. Please report. ("+e+")"];if(typeof r=="function")return w.patterns.patterns[e](t);var o=t.match(r);if(o){var s;return o[2]?s=[o[1],o[2]]:o[1]?s=o[1]:s=o[0],{match_:s,remainder:t.substr(o[0].length)}}return null}},actions:{"a=":function(e,t){e.a=(e.a||"")+t},"b=":function(e,t){e.b=(e.b||"")+t},"p=":function(e,t){e.p=(e.p||"")+t},"o=":function(e,t){e.o=(e.o||"")+t},"q=":function(e,t){e.q=(e.q||"")+t},"d=":function(e,t){e.d=(e.d||"")+t},"rm=":function(e,t){e.rm=(e.rm||"")+t},"text=":function(e,t){e.text_=(e.text_||"")+t},insert:function(e,t,r){return{type_:r}},"insert+p1":function(e,t,r){return{type_:r,p1:t}},"insert+p1+p2":function(e,t,r){return{type_:r,p1:t[0],p2:t[1]}},copy:function(e,t){return t},rm:function(e,t){return{type_:"rm",p1:t||""}},text:function(e,t){return w.go(t,"text")},"{text}":function(e,t){var r=["{"];return w.concatArray(r,w.go(t,"text")),r.push("}"),r},"tex-math":function(e,t){return w.go(t,"tex-math")},"tex-math tight":function(e,t){return w.go(t,"tex-math tight")},bond:function(e,t,r){return{type_:"bond",kind_:r||t}},"color0-output":function(e,t){return{type_:"color0",color:t[0]}},ce:function(e,t){return w.go(t)},"1/2":function(e,t){var r=[];t.match(/^[+\-]/)&&(r.push(t.substr(0,1)),t=t.substr(1));var o=t.match(/^([0-9]+|\$[a-z]\$|[a-z])\/([0-9]+)(\$[a-z]\$|[a-z])?$/);return o[1]=o[1].replace(/\$/g,""),r.push({type_:"frac",p1:o[1],p2:o[2]}),o[3]&&(o[3]=o[3].replace(/\$/g,""),r.push({type_:"tex-math",p1:o[3]})),r},"9,9":function(e,t){return w.go(t,"9,9")}},createTransitions:function(e){var t,r,o,s,i={};for(t in e)for(r in e[t])for(o=r.split("|"),e[t][r].stateArray=o,s=0;s":{"0|1|2|3":{action_:"r=",nextState:"r"},"a|as":{action_:["output","r="],nextState:"r"},"*":{action_:["output","r="],nextState:"r"}},"+":{o:{action_:"d= kv",nextState:"d"},"d|D":{action_:"d=",nextState:"d"},q:{action_:"d=",nextState:"qd"},"qd|qD":{action_:"d=",nextState:"qd"},dq:{action_:["output","d="],nextState:"d"},3:{action_:["sb=false","output","operator"],nextState:"0"}},amount:{"0|2":{action_:"a=",nextState:"a"}},"pm-operator":{"0|1|2|a|as":{action_:["sb=false","output",{type_:"operator",option:"\\pm"}],nextState:"0"}},operator:{"0|1|2|a|as":{action_:["sb=false","output","operator"],nextState:"0"}},"-$":{"o|q":{action_:["charge or bond","output"],nextState:"qd"},d:{action_:"d=",nextState:"d"},D:{action_:["output",{type_:"bond",option:"-"}],nextState:"3"},q:{action_:"d=",nextState:"qd"},qd:{action_:"d=",nextState:"qd"},"qD|dq":{action_:["output",{type_:"bond",option:"-"}],nextState:"3"}},"-9":{"3|o":{action_:["output",{type_:"insert",option:"hyphen"}],nextState:"3"}},"- orbital overlap":{o:{action_:["output",{type_:"insert",option:"hyphen"}],nextState:"2"},d:{action_:["output",{type_:"insert",option:"hyphen"}],nextState:"2"}},"-":{"0|1|2":{action_:[{type_:"output",option:1},"beginsWithBond=true",{type_:"bond",option:"-"}],nextState:"3"},3:{action_:{type_:"bond",option:"-"}},a:{action_:["output",{type_:"insert",option:"hyphen"}],nextState:"2"},as:{action_:[{type_:"output",option:2},{type_:"bond",option:"-"}],nextState:"3"},b:{action_:"b="},o:{action_:{type_:"- after o/d",option:!1},nextState:"2"},q:{action_:{type_:"- after o/d",option:!1},nextState:"2"},"d|qd|dq":{action_:{type_:"- after o/d",option:!0},nextState:"2"},"D|qD|p":{action_:["output",{type_:"bond",option:"-"}],nextState:"3"}},amount2:{"1|3":{action_:"a=",nextState:"a"}},letters:{"0|1|2|3|a|as|b|p|bp|o":{action_:"o=",nextState:"o"},"q|dq":{action_:["output","o="],nextState:"o"},"d|D|qd|qD":{action_:"o after d",nextState:"o"}},digits:{o:{action_:"q=",nextState:"q"},"d|D":{action_:"q=",nextState:"dq"},q:{action_:["output","o="],nextState:"o"},a:{action_:"o=",nextState:"o"}},"space A":{"b|p|bp":{}},space:{a:{nextState:"as"},0:{action_:"sb=false"},"1|2":{action_:"sb=true"},"r|rt|rd|rdt|rdq":{action_:"output",nextState:"0"},"*":{action_:["output","sb=true"],nextState:"1"}},"1st-level escape":{"1|2":{action_:["output",{type_:"insert+p1",option:"1st-level escape"}]},"*":{action_:["output",{type_:"insert+p1",option:"1st-level escape"}],nextState:"0"}},"[(...)]":{"r|rt":{action_:"rd=",nextState:"rd"},"rd|rdt":{action_:"rq=",nextState:"rdq"}},"...":{"o|d|D|dq|qd|qD":{action_:["output",{type_:"bond",option:"..."}],nextState:"3"},"*":{action_:[{type_:"output",option:1},{type_:"insert",option:"ellipsis"}],nextState:"1"}},". |* ":{"*":{action_:["output",{type_:"insert",option:"addition compound"}],nextState:"1"}},"state of aggregation $":{"*":{action_:["output","state of aggregation"],nextState:"1"}},"{[(":{"a|as|o":{action_:["o=","output","parenthesisLevel++"],nextState:"2"},"0|1|2|3":{action_:["o=","output","parenthesisLevel++"],nextState:"2"},"*":{action_:["output","o=","output","parenthesisLevel++"],nextState:"2"}},")]}":{"0|1|2|3|b|p|bp|o":{action_:["o=","parenthesisLevel--"],nextState:"o"},"a|as|d|D|q|qd|qD|dq":{action_:["output","o=","parenthesisLevel--"],nextState:"o"}},", ":{"*":{action_:["output","comma"],nextState:"0"}},"^_":{"*":{}},"^{(...)}|^($...$)":{"0|1|2|as":{action_:"b=",nextState:"b"},p:{action_:"b=",nextState:"bp"},"3|o":{action_:"d= kv",nextState:"D"},q:{action_:"d=",nextState:"qD"},"d|D|qd|qD|dq":{action_:["output","d="],nextState:"D"}},"^a|^\\x{}{}|^\\x{}|^\\x|'":{"0|1|2|as":{action_:"b=",nextState:"b"},p:{action_:"b=",nextState:"bp"},"3|o":{action_:"d= kv",nextState:"d"},q:{action_:"d=",nextState:"qd"},"d|qd|D|qD":{action_:"d="},dq:{action_:["output","d="],nextState:"d"}},"_{(state of aggregation)}$":{"d|D|q|qd|qD|dq":{action_:["output","q="],nextState:"q"}},"_{(...)}|_($...$)|_9|_\\x{}{}|_\\x{}|_\\x":{"0|1|2|as":{action_:"p=",nextState:"p"},b:{action_:"p=",nextState:"bp"},"3|o":{action_:"q=",nextState:"q"},"d|D":{action_:"q=",nextState:"dq"},"q|qd|qD|dq":{action_:["output","q="],nextState:"q"}},"=<>":{"0|1|2|3|a|as|o|q|d|D|qd|qD|dq":{action_:[{type_:"output",option:2},"bond"],nextState:"3"}},"#":{"0|1|2|3|a|as|o":{action_:[{type_:"output",option:2},{type_:"bond",option:"#"}],nextState:"3"}},"{}":{"*":{action_:{type_:"output",option:1},nextState:"1"}},"{...}":{"0|1|2|3|a|as|b|p|bp":{action_:"o=",nextState:"o"},"o|d|D|q|qd|qD|dq":{action_:["output","o="],nextState:"o"}},"$...$":{a:{action_:"a="},"0|1|2|3|as|b|p|bp|o":{action_:"o=",nextState:"o"},"as|o":{action_:"o="},"q|d|D|qd|qD|dq":{action_:["output","o="],nextState:"o"}},"\\bond{(...)}":{"*":{action_:[{type_:"output",option:2},"bond"],nextState:"3"}},"\\frac{(...)}":{"*":{action_:[{type_:"output",option:1},"frac-output"],nextState:"3"}},"\\overset{(...)}":{"*":{action_:[{type_:"output",option:2},"overset-output"],nextState:"3"}},"\\underset{(...)}":{"*":{action_:[{type_:"output",option:2},"underset-output"],nextState:"3"}},"\\underbrace{(...)}":{"*":{action_:[{type_:"output",option:2},"underbrace-output"],nextState:"3"}},"\\color{(...)}{(...)}1|\\color(...){(...)}2":{"*":{action_:[{type_:"output",option:2},"color-output"],nextState:"3"}},"\\color{(...)}0":{"*":{action_:[{type_:"output",option:2},"color0-output"]}},"\\ce{(...)}":{"*":{action_:[{type_:"output",option:2},"ce"],nextState:"3"}},"\\,":{"*":{action_:[{type_:"output",option:1},"copy"],nextState:"1"}},"\\x{}{}|\\x{}|\\x":{"0|1|2|3|a|as|b|p|bp|o|c0":{action_:["o=","output"],nextState:"3"},"*":{action_:["output","o=","output"],nextState:"3"}},others:{"*":{action_:[{type_:"output",option:1},"copy"],nextState:"3"}},else2:{a:{action_:"a to o",nextState:"o",revisit:!0},as:{action_:["output","sb=true"],nextState:"1",revisit:!0},"r|rt|rd|rdt|rdq":{action_:["output"],nextState:"0",revisit:!0},"*":{action_:["output","copy"],nextState:"3"}}}),actions:{"o after d":function(e,t){var r;if((e.d||"").match(/^[0-9]+$/)){var o=e.d;e.d=void 0,r=this.output(e),e.b=o}else r=this.output(e);return w.actions["o="](e,t),r},"d= kv":function(e,t){e.d=t,e.dType="kv"},"charge or bond":function(e,t){if(e.beginsWithBond){var r=[];return w.concatArray(r,this.output(e)),w.concatArray(r,w.actions.bond(e,t,"-")),r}else e.d=t},"- after o/d":function(e,t,r){var o=w.patterns.match_("orbital",e.o||""),s=w.patterns.match_("one lowercase greek letter $",e.o||""),i=w.patterns.match_("one lowercase latin letter $",e.o||""),l=w.patterns.match_("$one lowercase latin letter$ $",e.o||""),u=t==="-"&&(o&&o.remainder===""||s||i||l);u&&!e.a&&!e.b&&!e.p&&!e.d&&!e.q&&!o&&i&&(e.o="$"+e.o+"$");var m=[];return u?(w.concatArray(m,this.output(e)),m.push({type_:"hyphen"})):(o=w.patterns.match_("digits",e.d||""),r&&o&&o.remainder===""?(w.concatArray(m,w.actions["d="](e,t)),w.concatArray(m,this.output(e))):(w.concatArray(m,this.output(e)),w.concatArray(m,w.actions.bond(e,t,"-")))),m},"a to o":function(e){e.o=e.a,e.a=void 0},"sb=true":function(e){e.sb=!0},"sb=false":function(e){e.sb=!1},"beginsWithBond=true":function(e){e.beginsWithBond=!0},"beginsWithBond=false":function(e){e.beginsWithBond=!1},"parenthesisLevel++":function(e){e.parenthesisLevel++},"parenthesisLevel--":function(e){e.parenthesisLevel--},"state of aggregation":function(e,t){return{type_:"state of aggregation",p1:w.go(t,"o")}},comma:function(e,t){var r=t.replace(/\s*$/,""),o=r!==t;return o&&e.parenthesisLevel===0?{type_:"comma enumeration L",p1:r}:{type_:"comma enumeration M",p1:r}},output:function(e,t,r){var o;if(!e.r)o=[],!e.a&&!e.b&&!e.p&&!e.o&&!e.q&&!e.d&&!r||(e.sb&&o.push({type_:"entitySkip"}),!e.o&&!e.q&&!e.d&&!e.b&&!e.p&&r!==2?(e.o=e.a,e.a=void 0):!e.o&&!e.q&&!e.d&&(e.b||e.p)?(e.o=e.a,e.d=e.b,e.q=e.p,e.a=e.b=e.p=void 0):e.o&&e.dType==="kv"&&w.patterns.match_("d-oxidation$",e.d||"")?e.dType="oxidation":e.o&&e.dType==="kv"&&!e.q&&(e.dType=void 0),o.push({type_:"chemfive",a:w.go(e.a,"a"),b:w.go(e.b,"bd"),p:w.go(e.p,"pq"),o:w.go(e.o,"o"),q:w.go(e.q,"pq"),d:w.go(e.d,e.dType==="oxidation"?"oxidation":"bd"),dType:e.dType}));else{var s;e.rdt==="M"?s=w.go(e.rd,"tex-math"):e.rdt==="T"?s=[{type_:"text",p1:e.rd||""}]:s=w.go(e.rd);var i;e.rqt==="M"?i=w.go(e.rq,"tex-math"):e.rqt==="T"?i=[{type_:"text",p1:e.rq||""}]:i=w.go(e.rq),o={type_:"arrow",r:e.r,rd:s,rq:i}}for(var l in e)l!=="parenthesisLevel"&&l!=="beginsWithBond"&&delete e[l];return o},"oxidation-output":function(e,t){var r=["{"];return w.concatArray(r,w.go(t,"oxidation")),r.push("}"),r},"frac-output":function(e,t){return{type_:"frac-ce",p1:w.go(t[0]),p2:w.go(t[1])}},"overset-output":function(e,t){return{type_:"overset",p1:w.go(t[0]),p2:w.go(t[1])}},"underset-output":function(e,t){return{type_:"underset",p1:w.go(t[0]),p2:w.go(t[1])}},"underbrace-output":function(e,t){return{type_:"underbrace",p1:w.go(t[0]),p2:w.go(t[1])}},"color-output":function(e,t){return{type_:"color",color1:t[0],color2:w.go(t[1])}},"r=":function(e,t){e.r=t},"rdt=":function(e,t){e.rdt=t},"rd=":function(e,t){e.rd=t},"rqt=":function(e,t){e.rqt=t},"rq=":function(e,t){e.rq=t},operator:function(e,t,r){return{type_:"operator",kind_:r||t}}}},a:{transitions:w.createTransitions({empty:{"*":{}},"1/2$":{0:{action_:"1/2"}},else:{0:{nextState:"1",revisit:!0}},"$(...)$":{"*":{action_:"tex-math tight",nextState:"1"}},",":{"*":{action_:{type_:"insert",option:"commaDecimal"}}},else2:{"*":{action_:"copy"}}}),actions:{}},o:{transitions:w.createTransitions({empty:{"*":{}},"1/2$":{0:{action_:"1/2"}},else:{0:{nextState:"1",revisit:!0}},letters:{"*":{action_:"rm"}},"\\ca":{"*":{action_:{type_:"insert",option:"circa"}}},"\\x{}{}|\\x{}|\\x":{"*":{action_:"copy"}},"${(...)}$|$(...)$":{"*":{action_:"tex-math"}},"{(...)}":{"*":{action_:"{text}"}},else2:{"*":{action_:"copy"}}}),actions:{}},text:{transitions:w.createTransitions({empty:{"*":{action_:"output"}},"{...}":{"*":{action_:"text="}},"${(...)}$|$(...)$":{"*":{action_:"tex-math"}},"\\greek":{"*":{action_:["output","rm"]}},"\\,|\\x{}{}|\\x{}|\\x":{"*":{action_:["output","copy"]}},else:{"*":{action_:"text="}}}),actions:{output:function(e){if(e.text_){var t={type_:"text",p1:e.text_};for(var r in e)delete e[r];return t}}}},pq:{transitions:w.createTransitions({empty:{"*":{}},"state of aggregation $":{"*":{action_:"state of aggregation"}},i$:{0:{nextState:"!f",revisit:!0}},"(KV letters),":{0:{action_:"rm",nextState:"0"}},formula$:{0:{nextState:"f",revisit:!0}},"1/2$":{0:{action_:"1/2"}},else:{0:{nextState:"!f",revisit:!0}},"${(...)}$|$(...)$":{"*":{action_:"tex-math"}},"{(...)}":{"*":{action_:"text"}},"a-z":{f:{action_:"tex-math"}},letters:{"*":{action_:"rm"}},"-9.,9":{"*":{action_:"9,9"}},",":{"*":{action_:{type_:"insert+p1",option:"comma enumeration S"}}},"\\color{(...)}{(...)}1|\\color(...){(...)}2":{"*":{action_:"color-output"}},"\\color{(...)}0":{"*":{action_:"color0-output"}},"\\ce{(...)}":{"*":{action_:"ce"}},"\\,|\\x{}{}|\\x{}|\\x":{"*":{action_:"copy"}},else2:{"*":{action_:"copy"}}}),actions:{"state of aggregation":function(e,t){return{type_:"state of aggregation subscript",p1:w.go(t,"o")}},"color-output":function(e,t){return{type_:"color",color1:t[0],color2:w.go(t[1],"pq")}}}},bd:{transitions:w.createTransitions({empty:{"*":{}},x$:{0:{nextState:"!f",revisit:!0}},formula$:{0:{nextState:"f",revisit:!0}},else:{0:{nextState:"!f",revisit:!0}},"-9.,9 no missing 0":{"*":{action_:"9,9"}},".":{"*":{action_:{type_:"insert",option:"electron dot"}}},"a-z":{f:{action_:"tex-math"}},x:{"*":{action_:{type_:"insert",option:"KV x"}}},letters:{"*":{action_:"rm"}},"'":{"*":{action_:{type_:"insert",option:"prime"}}},"${(...)}$|$(...)$":{"*":{action_:"tex-math"}},"{(...)}":{"*":{action_:"text"}},"\\color{(...)}{(...)}1|\\color(...){(...)}2":{"*":{action_:"color-output"}},"\\color{(...)}0":{"*":{action_:"color0-output"}},"\\ce{(...)}":{"*":{action_:"ce"}},"\\,|\\x{}{}|\\x{}|\\x":{"*":{action_:"copy"}},else2:{"*":{action_:"copy"}}}),actions:{"color-output":function(e,t){return{type_:"color",color1:t[0],color2:w.go(t[1],"bd")}}}},oxidation:{transitions:w.createTransitions({empty:{"*":{}},"roman numeral":{"*":{action_:"roman-numeral"}},"${(...)}$|$(...)$":{"*":{action_:"tex-math"}},else:{"*":{action_:"copy"}}}),actions:{"roman-numeral":function(e,t){return{type_:"roman numeral",p1:t||""}}}},"tex-math":{transitions:w.createTransitions({empty:{"*":{action_:"output"}},"\\ce{(...)}":{"*":{action_:["output","ce"]}},"{...}|\\,|\\x{}{}|\\x{}|\\x":{"*":{action_:"o="}},else:{"*":{action_:"o="}}}),actions:{output:function(e){if(e.o){var t={type_:"tex-math",p1:e.o};for(var r in e)delete e[r];return t}}}},"tex-math tight":{transitions:w.createTransitions({empty:{"*":{action_:"output"}},"\\ce{(...)}":{"*":{action_:["output","ce"]}},"{...}|\\,|\\x{}{}|\\x{}|\\x":{"*":{action_:"o="}},"-|+":{"*":{action_:"tight operator"}},else:{"*":{action_:"o="}}}),actions:{"tight operator":function(e,t){e.o=(e.o||"")+"{"+t+"}"},output:function(e){if(e.o){var t={type_:"tex-math",p1:e.o};for(var r in e)delete e[r];return t}}}},"9,9":{transitions:w.createTransitions({empty:{"*":{}},",":{"*":{action_:"comma"}},else:{"*":{action_:"copy"}}}),actions:{comma:function(){return{type_:"commaDecimal"}}}},pu:{transitions:w.createTransitions({empty:{"*":{action_:"output"}},space$:{"*":{action_:["output","space"]}},"{[(|)]}":{"0|a":{action_:"copy"}},"(-)(9)^(-9)":{0:{action_:"number^",nextState:"a"}},"(-)(9.,9)(e)(99)":{0:{action_:"enumber",nextState:"a"}},space:{"0|a":{}},"pm-operator":{"0|a":{action_:{type_:"operator",option:"\\pm"},nextState:"0"}},operator:{"0|a":{action_:"copy",nextState:"0"}},"//":{d:{action_:"o=",nextState:"/"}},"/":{d:{action_:"o=",nextState:"/"}},"{...}|else":{"0|d":{action_:"d=",nextState:"d"},a:{action_:["space","d="],nextState:"d"},"/|q":{action_:"q=",nextState:"q"}}}),actions:{enumber:function(e,t){var r=[];return t[0]==="+-"||t[0]==="+/-"?r.push("\\pm "):t[0]&&r.push(t[0]),t[1]&&(w.concatArray(r,w.go(t[1],"pu-9,9")),t[2]&&(t[2].match(/[,.]/)?w.concatArray(r,w.go(t[2],"pu-9,9")):r.push(t[2])),t[3]=t[4]||t[3],t[3]&&(t[3]=t[3].trim(),t[3]==="e"||t[3].substr(0,1)==="*"?r.push({type_:"cdot"}):r.push({type_:"times"}))),t[3]&&r.push("10^{"+t[5]+"}"),r},"number^":function(e,t){var r=[];return t[0]==="+-"||t[0]==="+/-"?r.push("\\pm "):t[0]&&r.push(t[0]),w.concatArray(r,w.go(t[1],"pu-9,9")),r.push("^{"+t[2]+"}"),r},operator:function(e,t,r){return{type_:"operator",kind_:r||t}},space:function(){return{type_:"pu-space-1"}},output:function(e){var t,r=w.patterns.match_("{(...)}",e.d||"");r&&r.remainder===""&&(e.d=r.match_);var o=w.patterns.match_("{(...)}",e.q||"");if(o&&o.remainder===""&&(e.q=o.match_),e.d&&(e.d=e.d.replace(/\u00B0C|\^oC|\^{o}C/g,"{}^{\\circ}C"),e.d=e.d.replace(/\u00B0F|\^oF|\^{o}F/g,"{}^{\\circ}F")),e.q){e.q=e.q.replace(/\u00B0C|\^oC|\^{o}C/g,"{}^{\\circ}C"),e.q=e.q.replace(/\u00B0F|\^oF|\^{o}F/g,"{}^{\\circ}F");var s={d:w.go(e.d,"pu"),q:w.go(e.q,"pu")};e.o==="//"?t={type_:"pu-frac",p1:s.d,p2:s.q}:(t=s.d,s.d.length>1||s.q.length>1?t.push({type_:" / "}):t.push({type_:"/"}),w.concatArray(t,s.q))}else t=w.go(e.d,"pu-2");for(var i in e)delete e[i];return t}}},"pu-2":{transitions:w.createTransitions({empty:{"*":{action_:"output"}},"*":{"*":{action_:["output","cdot"],nextState:"0"}},"\\x":{"*":{action_:"rm="}},space:{"*":{action_:["output","space"],nextState:"0"}},"^{(...)}|^(-1)":{1:{action_:"^(-1)"}},"-9.,9":{0:{action_:"rm=",nextState:"0"},1:{action_:"^(-1)",nextState:"0"}},"{...}|else":{"*":{action_:"rm=",nextState:"1"}}}),actions:{cdot:function(){return{type_:"tight cdot"}},"^(-1)":function(e,t){e.rm+="^{"+t+"}"},space:function(){return{type_:"pu-space-2"}},output:function(e){var t=[];if(e.rm){var r=w.patterns.match_("{(...)}",e.rm||"");r&&r.remainder===""?t=w.go(r.match_,"pu"):t={type_:"rm",p1:e.rm}}for(var o in e)delete e[o];return t}}},"pu-9,9":{transitions:w.createTransitions({empty:{0:{action_:"output-0"},o:{action_:"output-o"}},",":{0:{action_:["output-0","comma"],nextState:"o"}},".":{0:{action_:["output-0","copy"],nextState:"o"}},else:{"*":{action_:"text="}}}),actions:{comma:function(){return{type_:"commaDecimal"}},"output-0":function(e){var t=[];if(e.text_=e.text_||"",e.text_.length>4){var r=e.text_.length%3;r===0&&(r=3);for(var o=e.text_.length-3;o>0;o-=3)t.push(e.text_.substr(o,3)),t.push({type_:"1000 separator"});t.push(e.text_.substr(0,r)),t.reverse()}else t.push(e.text_);for(var s in e)delete e[s];return t},"output-o":function(e){var t=[];if(e.text_=e.text_||"",e.text_.length>4){for(var r=e.text_.length-3,o=0;o":return"\\yields";case"→":return"\\yields";case"⟶":return"\\yields";case"<-":return"\\yieldsLeft";case"<->":return"\\mesomerism";case"<-->":return"\\yieldsLeftRight";case"<=>":return"\\chemequilibrium";case"⇌":return"\\chemequilibrium";case"<=>>":return"\\equilibriumRight";case"<<=>":return"\\equilibriumLeft";default:throw["MhchemBugT","mhchem bug T. Please report."]}},_getBond:function(e){switch(e){case"-":return"{-}";case"1":return"{-}";case"=":return"{=}";case"2":return"{=}";case"#":return"{\\equiv}";case"3":return"{\\equiv}";case"~":return"{\\tripleDash}";case"~-":return"{\\tripleDashOverLine}";case"~=":return"{\\tripleDashOverDoubleLine}";case"~--":return"{\\tripleDashOverDoubleLine}";case"-~-":return"{\\tripleDashBetweenDoubleLine}";case"...":return"{{\\cdot}{\\cdot}{\\cdot}}";case"....":return"{{\\cdot}{\\cdot}{\\cdot}{\\cdot}}";case"->":return"{\\rightarrow}";case"<-":return"{\\leftarrow}";case"<":return"{<}";case">":return"{>}";default:throw["MhchemBugT","mhchem bug T. Please report."]}},_getOperator:function(e){switch(e){case"+":return" {}+{} ";case"-":return" {}-{} ";case"=":return" {}={} ";case"<":return" {}<{} ";case">":return" {}>{} ";case"<<":return" {}\\ll{} ";case">>":return" {}\\gg{} ";case"\\pm":return" {}\\pm{} ";case"\\approx":return" {}\\approx{} ";case"$\\approx$":return" {}\\approx{} ";case"v":return" \\downarrow{} ";case"(v)":return" \\downarrow{} ";case"^":return" \\uparrow{} ";case"(^)":return" \\uparrow{} ";default:throw["MhchemBugT","mhchem bug T. Please report."]}}};c("\\darr","\\downarrow");c("\\dArr","\\Downarrow");c("\\Darr","\\Downarrow");c("\\lang","\\langle");c("\\rang","\\rangle");c("\\uarr","\\uparrow");c("\\uArr","\\Uparrow");c("\\Uarr","\\Uparrow");c("\\N","\\mathbb{N}");c("\\R","\\mathbb{R}");c("\\Z","\\mathbb{Z}");c("\\alef","\\aleph");c("\\alefsym","\\aleph");c("\\bull","\\bullet");c("\\clubs","\\clubsuit");c("\\cnums","\\mathbb{C}");c("\\Complex","\\mathbb{C}");c("\\Dagger","\\ddagger");c("\\diamonds","\\diamondsuit");c("\\empty","\\emptyset");c("\\exist","\\exists");c("\\harr","\\leftrightarrow");c("\\hArr","\\Leftrightarrow");c("\\Harr","\\Leftrightarrow");c("\\hearts","\\heartsuit");c("\\image","\\Im");c("\\infin","\\infty");c("\\isin","\\in");c("\\larr","\\leftarrow");c("\\lArr","\\Leftarrow");c("\\Larr","\\Leftarrow");c("\\lrarr","\\leftrightarrow");c("\\lrArr","\\Leftrightarrow");c("\\Lrarr","\\Leftrightarrow");c("\\natnums","\\mathbb{N}");c("\\plusmn","\\pm");c("\\rarr","\\rightarrow");c("\\rArr","\\Rightarrow");c("\\Rarr","\\Rightarrow");c("\\real","\\Re");c("\\reals","\\mathbb{R}");c("\\Reals","\\mathbb{R}");c("\\sdot","\\cdot");c("\\sect","\\S");c("\\spades","\\spadesuit");c("\\sub","\\subset");c("\\sube","\\subseteq");c("\\supe","\\supseteq");c("\\thetasym","\\vartheta");c("\\weierp","\\wp");c("\\quantity","{\\left\\{ #1 \\right\\}}");c("\\qty","{\\left\\{ #1 \\right\\}}");c("\\pqty","{\\left( #1 \\right)}");c("\\bqty","{\\left[ #1 \\right]}");c("\\vqty","{\\left\\vert #1 \\right\\vert}");c("\\Bqty","{\\left\\{ #1 \\right\\}}");c("\\absolutevalue","{\\left\\vert #1 \\right\\vert}");c("\\abs","{\\left\\vert #1 \\right\\vert}");c("\\norm","{\\left\\Vert #1 \\right\\Vert}");c("\\evaluated","{\\left.#1 \\right\\vert}");c("\\eval","{\\left.#1 \\right\\vert}");c("\\order","{\\mathcal{O} \\left( #1 \\right)}");c("\\commutator","{\\left[ #1 , #2 \\right]}");c("\\comm","{\\left[ #1 , #2 \\right]}");c("\\anticommutator","{\\left\\{ #1 , #2 \\right\\}}");c("\\acomm","{\\left\\{ #1 , #2 \\right\\}}");c("\\poissonbracket","{\\left\\{ #1 , #2 \\right\\}}");c("\\pb","{\\left\\{ #1 , #2 \\right\\}}");c("\\vectorbold","{\\boldsymbol{ #1 }}");c("\\vb","{\\boldsymbol{ #1 }}");c("\\vectorarrow","{\\vec{\\boldsymbol{ #1 }}}");c("\\va","{\\vec{\\boldsymbol{ #1 }}}");c("\\vectorunit","{{\\boldsymbol{\\hat{ #1 }}}}");c("\\vu","{{\\boldsymbol{\\hat{ #1 }}}}");c("\\dotproduct","\\mathbin{\\boldsymbol\\cdot}");c("\\vdot","{\\boldsymbol\\cdot}");c("\\crossproduct","\\mathbin{\\boldsymbol\\times}");c("\\cross","\\mathbin{\\boldsymbol\\times}");c("\\cp","\\mathbin{\\boldsymbol\\times}");c("\\gradient","{\\boldsymbol\\nabla}");c("\\grad","{\\boldsymbol\\nabla}");c("\\divergence","{\\grad\\vdot}");c("\\curl","{\\grad\\cross}");c("\\laplacian","\\nabla^2");c("\\tr","{\\operatorname{tr}}");c("\\Tr","{\\operatorname{Tr}}");c("\\rank","{\\operatorname{rank}}");c("\\erf","{\\operatorname{erf}}");c("\\Res","{\\operatorname{Res}}");c("\\principalvalue","{\\mathcal{P}}");c("\\pv","{\\mathcal{P}}");c("\\PV","{\\operatorname{P.V.}}");c("\\qqtext","{\\quad\\text{ #1 }\\quad}");c("\\qq","{\\quad\\text{ #1 }\\quad}");c("\\qcomma","{\\text{,}\\quad}");c("\\qc","{\\text{,}\\quad}");c("\\qcc","{\\quad\\text{c.c.}\\quad}");c("\\qif","{\\quad\\text{if}\\quad}");c("\\qthen","{\\quad\\text{then}\\quad}");c("\\qelse","{\\quad\\text{else}\\quad}");c("\\qotherwise","{\\quad\\text{otherwise}\\quad}");c("\\qunless","{\\quad\\text{unless}\\quad}");c("\\qgiven","{\\quad\\text{given}\\quad}");c("\\qusing","{\\quad\\text{using}\\quad}");c("\\qassume","{\\quad\\text{assume}\\quad}");c("\\qsince","{\\quad\\text{since}\\quad}");c("\\qlet","{\\quad\\text{let}\\quad}");c("\\qfor","{\\quad\\text{for}\\quad}");c("\\qall","{\\quad\\text{all}\\quad}");c("\\qeven","{\\quad\\text{even}\\quad}");c("\\qodd","{\\quad\\text{odd}\\quad}");c("\\qinteger","{\\quad\\text{integer}\\quad}");c("\\qand","{\\quad\\text{and}\\quad}");c("\\qor","{\\quad\\text{or}\\quad}");c("\\qas","{\\quad\\text{as}\\quad}");c("\\qin","{\\quad\\text{in}\\quad}");c("\\differential","{\\text{d}}");c("\\dd","{\\text{d}}");c("\\derivative","{\\frac{\\text{d}{ #1 }}{\\text{d}{ #2 }}}");c("\\dv","{\\frac{\\text{d}{ #1 }}{\\text{d}{ #2 }}}");c("\\partialderivative","{\\frac{\\partial{ #1 }}{\\partial{ #2 }}}");c("\\variation","{\\delta}");c("\\var","{\\delta}");c("\\functionalderivative","{\\frac{\\delta{ #1 }}{\\delta{ #2 }}}");c("\\fdv","{\\frac{\\delta{ #1 }}{\\delta{ #2 }}}");c("\\innerproduct","{\\left\\langle {#1} \\mid { #2} \\right\\rangle}");c("\\outerproduct","{\\left\\vert { #1 } \\right\\rangle\\left\\langle { #2} \\right\\vert}");c("\\dyad","{\\left\\vert { #1 } \\right\\rangle\\left\\langle { #2} \\right\\vert}");c("\\ketbra","{\\left\\vert { #1 } \\right\\rangle\\left\\langle { #2} \\right\\vert}");c("\\op","{\\left\\vert { #1 } \\right\\rangle\\left\\langle { #2} \\right\\vert}");c("\\expectationvalue","{\\left\\langle {#1 } \\right\\rangle}");c("\\expval","{\\left\\langle {#1 } \\right\\rangle}");c("\\ev","{\\left\\langle {#1 } \\right\\rangle}");c("\\matrixelement","{\\left\\langle{ #1 }\\right\\vert{ #2 }\\left\\vert{#3}\\right\\rangle}");c("\\matrixel","{\\left\\langle{ #1 }\\right\\vert{ #2 }\\left\\vert{#3}\\right\\rangle}");c("\\mel","{\\left\\langle{ #1 }\\right\\vert{ #2 }\\left\\vert{#3}\\right\\rangle}");function yt(e){const t=[];e.consumeSpaces();let r=e.fetch().text;for(r==="\\relax"&&(e.consume(),e.consumeSpaces(),r=e.fetch().text);r==="\\hline"||r==="\\hdashline";)e.consume(),t.push(r==="\\hdashline"),e.consumeSpaces(),r=e.fetch().text;return t}const xe=e=>{if(!e.parser.settings.displayMode)throw new v(`{${e.envName}} can be used only in display mode.`)},dn=/([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/,tr=e=>{let t=e.get("\\arraystretch");typeof t!="string"&&(t=Re(t.tokens)),t=isNaN(t)?null:Number(t);let r=e.get("\\arraycolsep");typeof r!="string"&&(r=Re(r.tokens));const o=dn.exec(r),s=o?{number:+(o[1]+o[2]),unit:o[3]}:null;return[t,s]},wt=e=>{let t="";for(let r=0;r1||!i)&&_.pop(),E.push(wt(X.body)),z.length<_.length+1&&z.push([]);break}else if(se==="\\\\"){e.consume();let ie;e.gullet.future().text!==" "&&(ie=e.parseSizeGroup(!0)),D.push(ie?ie.value:null),Z(),E.push(wt(X.body)),z.push(yt(e)),y=[],_.push(y),N()}else throw new v("Expected & or \\\\ or \\cr or "+x,e.nextToken)}return e.gullet.endGroup(),e.gullet.endGroup(),{type:"array",mode:e.mode,body:_,cols:t,rowGaps:D,hLinesBeforeRow:z,envClasses:r,autoTag:o,scriptLevel:A,tags:T,labels:E,leqno:u,arraystretch:m,arraycolsep:f}}function rr(e){return e.slice(0,1)==="d"?"display":"text"}const hn={c:"center ",l:"left ",r:"right "},vt=e=>{const t=new p.MathNode("mtd",[]);return t.style={padding:"0",width:"50%"},e.envClasses.includes("multline")&&(t.style.width="7.5%"),t},K=function(e,t){const r=[],o=e.body.length,s=e.hLinesBeforeRow;for(let f=0;f0&&(s[0].length===2?D.children.forEach(T=>{T.style.borderTop="0.15em double"}):D.children.forEach(T=>{T.style.borderTop=s[0][0]?"0.06em dashed":"0.06em solid"})),s[f+1].length>0&&(s[f+1].length===2?D.children.forEach(T=>{T.style.borderBottom="0.15em double"}):D.children.forEach(T=>{T.style.borderBottom=s[f+1][0]?"0.06em dashed":"0.06em solid"}));let z=!0;for(let T=0;T0&&(i=e.envClasses.includes("abut")||e.envClasses.includes("cases")?"0":e.envClasses.includes("small")?"0.1389":e.envClasses.includes("cd")?"0.25":"0.4",l="em"),e.arraycolsep){const f=Q(e.arraycolsep,t);i=f.number.toFixed(4),l=f.unit}if(i){const f=r.length===0?0:r[0].children.length,A=(x,y)=>x===0&&y===0||x===f-1&&y===1?"0":e.envClasses[0]!=="align"?i:y===1?"0":e.autoTag?x%2?"1":"0":x%2?"0":"1";for(let x=0;x0){const f=e.envClasses.includes("align")||e.envClasses.includes("alignat");for(let A=0;A1&&e.envClasses.includes("cases")&&(x.children[1].style.paddingLeft="1em"),e.envClasses.includes("cases")||e.envClasses.includes("subarray"))for(const y of x.children)y.classes.push("tml-left")}}let u=new p.MathNode("mtable",r);e.envClasses.length>0&&(e.envClasses.includes("jot")?u.classes.push("tml-jot"):e.envClasses.includes("small")&&u.classes.push("tml-small")),e.scriptLevel==="display"&&u.setAttribute("displaystyle","true"),(e.autoTag||e.envClasses.includes("multline"))&&(u.style.width="100%");let m="";if(e.cols&&e.cols.length>0){const f=e.cols;let A=!1,x=0,y=f.length;for(;f[x].type==="separator";)x+=1;for(;f[y-1].type==="separator";)y-=1;if(f[0].type==="separator"){const D=f[1].type==="separator"?"0.15em double":f[0].separator==="|"?"0.06em solid ":"0.06em dashed ";for(const E of u.children)E.children[0].style.borderLeft=D}let _=e.autoTag?0:-1;for(let D=x;D0?m:"center ")+"right "),m&&u.setAttribute("columnalign",m.trim()),e.envClasses.includes("small")&&(u=new p.MathNode("mstyle",[u]),u.setAttribute("scriptlevel","1")),u},nr=function(e,t){e.envName.indexOf("ed")===-1&&xe(e);const r=e.envName==="split",o=[],s=ee(e.parser,{cols:o,emptySingleRow:!0,autoTag:r?void 0:tt(e.envName),envClasses:["abut","jot"],maxNumCols:e.envName==="split"?2:void 0,leqno:e.parser.settings.leqno},"display");let i,l=0;const u=e.envName.indexOf("at")>-1;if(t[0]&&u){let m="";for(let f=0;f0?new Array(s.body[0].length).fill({type:"align",align:r}):[];const[i,l]=tr(e.parser.gullet.macros);return s.arraystretch=i,l&&!(l===6&&l==="pt")&&(s.arraycolsep=l),t?{type:"leftright",mode:e.mode,body:[s],left:t[0],right:t[1],rightColor:void 0}:s},mathmlBuilder:K});Y({type:"array",names:["bordermatrix"],props:{numArgs:0},handler(e){const t={cols:[],envClasses:["bordermatrix"]},r=ee(e.parser,t,"text");return r.cols=r.body.length>0?new Array(r.body[0].length).fill({type:"align",align:"c"}):[],r.envClasses=[],r.arraystretch=1,e.envName==="matrix"?r:un(r,e.delimiters)},mathmlBuilder:K});Y({type:"array",names:["smallmatrix"],props:{numArgs:0},handler(e){const t={type:"small"},r=ee(e.parser,t,"script");return r.envClasses=["small"],r},mathmlBuilder:K});Y({type:"array",names:["subarray"],props:{numArgs:1},handler(e,t){const s=(Be(t[0])?[t[0]]:C(t[0],"ordgroup").body).map(function(l){const m=Ke(l).text;if("lc".indexOf(m)!==-1)return{type:"align",align:m};throw new v("Unknown column alignment: "+m,l)});if(s.length>1)throw new v("{subarray} can contain only one column");let i={cols:s,envClasses:["small"]};if(i=ee(e.parser,i,"script"),i.body.length>0&&i.body[0].length>1)throw new v("{subarray} can contain only one column");return i},mathmlBuilder:K});Y({type:"array",names:["cases","dcases","rcases","drcases"],props:{numArgs:0},handler(e){const t={cols:[],envClasses:["cases"]},r=ee(e.parser,t,rr(e.envName));return{type:"leftright",mode:e.mode,body:[r],left:e.envName.indexOf("r")>-1?".":"\\{",right:e.envName.indexOf("r")>-1?"\\}":".",rightColor:void 0}},mathmlBuilder:K});Y({type:"array",names:["align","align*","aligned","split"],props:{numArgs:0},handler:nr,mathmlBuilder:K});Y({type:"array",names:["alignat","alignat*","alignedat"],props:{numArgs:1},handler:nr,mathmlBuilder:K});Y({type:"array",names:["gathered","gather","gather*"],props:{numArgs:0},handler(e){e.envName!=="gathered"&&xe(e);const t={cols:[],envClasses:["abut","jot"],autoTag:tt(e.envName),emptySingleRow:!0,leqno:e.parser.settings.leqno};return ee(e.parser,t,"display")},mathmlBuilder:K});Y({type:"array",names:["equation","equation*"],props:{numArgs:0},handler(e){xe(e);const t={autoTag:tt(e.envName),emptySingleRow:!0,singleRow:!0,maxNumCols:1,envClasses:["align"],leqno:e.parser.settings.leqno};return ee(e.parser,t,"display")},mathmlBuilder:K});Y({type:"array",names:["multline","multline*"],props:{numArgs:0},handler(e){xe(e);const t={autoTag:e.envName==="multline",maxNumCols:1,envClasses:["jot","multline"],leqno:e.parser.settings.leqno};return ee(e.parser,t,"display")},mathmlBuilder:K});Y({type:"array",names:["CD"],props:{numArgs:0},handler(e){return xe(e),ln(e.parser)},mathmlBuilder:K});S({type:"text",names:["\\hline","\\hdashline"],props:{numArgs:0,allowedInText:!0,allowedInMath:!0},handler(e,t){throw new v(`${e.funcName} valid only within array environment`)}});const je=Xt;S({type:"bordermatrix",names:["\\bordermatrix","\\matrix"],props:{numArgs:0,numOptionalArgs:1},handler:({parser:e,funcName:t},r,o)=>{let s=["(",")"];if(t==="\\bordermatrix"&&o[0]&&o[0].body){const m=o[0].body;m.length===2&&m[0].type==="atom"&&m[1].type==="atom"&&m[0].family==="open"&&m[1].family==="close"&&(s=[m[0].text,m[1].text])}e.consumeSpaces(),e.consume();const i=je.bordermatrix,l={mode:e.mode,envName:t.slice(1),delimiters:s,parser:e},u=i.handler(l);return e.expect("}",!0),u}});S({type:"textord",names:["\\@char"],props:{numArgs:1,allowedInText:!0},handler({parser:e,token:t},r){const s=C(r[0],"ordgroup").body;let i="";for(let u=0;u{let t=e.toString(16);return t.length===1&&(t="0"+t),t},kt=JSON.parse(`{ "Apricot": "#ffb484", "Aquamarine": "#08b4bc", "Bittersweet": "#c84c14", "blue": "#0000FF", "Blue": "#303494", "BlueGreen": "#08b4bc", "BlueViolet": "#503c94", "BrickRed": "#b8341c", "brown": "#BF8040", "Brown": "#802404", "BurntOrange": "#f8941c", "CadetBlue": "#78749c", "CarnationPink": "#f884b4", "Cerulean": "#08a4e4", "CornflowerBlue": "#40ace4", "cyan": "#00FFFF", "Cyan": "#08acec", "Dandelion": "#ffbc44", "darkgray": "#404040", "DarkOrchid": "#a8548c", "Emerald": "#08ac9c", "ForestGreen": "#089c54", "Fuchsia": "#90348c", "Goldenrod": "#ffdc44", "gray": "#808080", "Gray": "#98949c", "green": "#00FF00", "Green": "#08a44c", "GreenYellow": "#e0e474", "JungleGreen": "#08ac9c", "Lavender": "#f89cc4", "lightgray": "#c0c0c0", "lime": "#BFFF00", "LimeGreen": "#90c43c", "magenta": "#FF00FF", "Magenta": "#f0048c", "Mahogany": "#b0341c", "Maroon": "#b03434", "Melon": "#f89c7c", "MidnightBlue": "#086494", "Mulberry": "#b03c94", "NavyBlue": "#086cbc", "olive": "#7F7F00", "OliveGreen": "#407c34", "orange": "#FF8000", "Orange": "#f8843c", "OrangeRed": "#f0145c", "Orchid": "#b074ac", "Peach": "#f8945c", "Periwinkle": "#8074bc", "PineGreen": "#088c74", "pink": "#ff7f7f", "Plum": "#98248c", "ProcessBlue": "#08b4ec", "purple": "#BF0040", "Purple": "#a0449c", "RawSienna": "#983c04", "red": "#ff0000", "Red": "#f01c24", "RedOrange": "#f86434", "RedViolet": "#a0246c", "Rhodamine": "#f0549c", "Royallue": "#0874bc", "RoyalPurple": "#683c9c", "RubineRed": "#f0047c", "Salmon": "#f8948c", "SeaGreen": "#30bc9c", "Sepia": "#701404", "SkyBlue": "#48c4dc", "SpringGreen": "#c8dc64", "Tan": "#e09c74", "teal": "#007F7F", "TealBlue": "#08acb4", "Thistle": "#d884b4", "Turquoise": "#08b4cc", "violet": "#800080", "Violet": "#60449c", "VioletRed": "#f054a4", "WildStrawberry": "#f0246c", "yellow": "#FFFF00", "Yellow": "#fff404", "YellowGreen": "#98cc6c", "YellowOrange": "#ffa41c" }`),ce=(e,t)=>{let r="";if(e==="HTML"){if(!mn.test(t))throw new v("Invalid HTML input.");r=t}else if(e==="RGB"){if(!fn.test(t))throw new v("Invalid RGB input.");t.split(",").map(o=>{r+=At(Number(o.trim()))})}else{if(!gn.test(t))throw new v("Invalid rbg input.");t.split(",").map(o=>{const s=Number(o.trim());if(s>1)throw new v("Color rgb input must be < 1.");r+=At(Number((s*255).toFixed(0)))})}return r.charAt(0)!=="#"&&(r="#"+r),r},fe=(e,t,r)=>{const o=`\\\\color@${e}`;if(!pn.exec(e))throw new v("Invalid color: '"+e+"'",r);return bn.test(e)?"#"+e:(e.charAt(0)==="#"||(t.has(o)?e=t.get(o).tokens[0].text:kt[e]&&(e=kt[e])),e)},or=(e,t)=>{let r=U(e.body,t.withColor(e.color));return r.length===0&&r.push(new p.MathNode("mrow")),r=r.map(o=>(o.style.color=e.color,o)),p.newDocumentFragment(r)};S({type:"color",names:["\\textcolor"],props:{numArgs:2,numOptionalArgs:1,allowedInText:!0,argTypes:["raw","raw","original"]},handler({parser:e,token:t},r,o){const s=o[0]&&C(o[0],"raw").string;let i="";if(s){const u=C(r[0],"raw").string;i=ce(s,u)}else i=fe(C(r[0],"raw").string,e.gullet.macros,t);const l=r[1];return{type:"color",mode:e.mode,color:i,isTextColor:!0,body:j(l)}},mathmlBuilder:or});S({type:"color",names:["\\color"],props:{numArgs:1,numOptionalArgs:1,allowedInText:!0,argTypes:["raw","raw"]},handler({parser:e,breakOnTokenText:t,token:r},o,s){const i=s[0]&&C(s[0],"raw").string;let l="";if(i){const m=C(o[0],"raw").string;l=ce(i,m)}else l=fe(C(o[0],"raw").string,e.gullet.macros,r);const u=e.parseExpression(!0,t,!0);return{type:"color",mode:e.mode,color:l,isTextColor:!1,body:u}},mathmlBuilder:or});S({type:"color",names:["\\definecolor"],props:{numArgs:3,allowedInText:!0,argTypes:["raw","raw","raw"]},handler({parser:e,funcName:t,token:r},o){const s=C(o[0],"raw").string;if(!/^[A-Za-z]+$/.test(s))throw new v("Color name must be latin letters.",r);const i=C(o[1],"raw").string;if(!["HTML","RGB","rgb"].includes(i))throw new v("Color model must be HTML, RGB, or rgb.",r);const l=C(o[2],"raw").string,u=ce(i,l);return e.gullet.macros.set(`\\\\color@${s}`,{tokens:[{text:u}],numArgs:0}),{type:"internal",mode:e.mode}}});S({type:"cr",names:["\\\\"],props:{numArgs:0,numOptionalArgs:0,allowedInText:!0},handler({parser:e},t,r){const o=e.gullet.future().text==="["?e.parseSizeGroup(!0):null,s=!e.settings.displayMode;return{type:"cr",mode:e.mode,newLine:s,size:o&&C(o,"size").value}},mathmlBuilder(e,t){const r=new p.MathNode("mo");if(e.newLine&&(r.setAttribute("linebreak","newline"),e.size)){const o=Q(e.size,t);r.setAttribute("height",o.number+o.unit)}return r}});const Ue={"\\global":"\\global","\\long":"\\\\globallong","\\\\globallong":"\\\\globallong","\\def":"\\gdef","\\gdef":"\\gdef","\\edef":"\\xdef","\\xdef":"\\xdef","\\let":"\\\\globallet","\\futurelet":"\\\\globalfuture"},De=e=>{const t=e.text;if(/^(?:[\\{}$&#^_]|EOF)$/.test(t))throw new v("Expected a control sequence",e);return t},xn=e=>{let t=e.gullet.popToken();return t.text==="="&&(t=e.gullet.popToken(),t.text===" "&&(t=e.gullet.popToken())),t},ar=(e,t,r,o)=>{let s=e.gullet.macros.get(r.text);s==null&&(r.noexpand=!0,s={tokens:[r],numArgs:0,unexpandable:!e.gullet.isExpandable(r.text)}),e.gullet.macros.set(t,s,o)};S({type:"internal",names:["\\global","\\long","\\\\globallong"],props:{numArgs:0,allowedInText:!0},handler({parser:e,funcName:t}){e.consumeSpaces();const r=e.fetch();if(Ue[r.text])return(t==="\\global"||t==="\\\\globallong")&&(r.text=Ue[r.text]),C(e.parseFunction(),"internal");throw new v("Invalid token after macro prefix",r)}});S({type:"internal",names:["\\def","\\gdef","\\edef","\\xdef"],props:{numArgs:0,allowedInText:!0,primitive:!0},handler({parser:e,funcName:t}){let r=e.gullet.popToken();const o=r.text;if(/^(?:[\\{}$&#^_]|EOF)$/.test(o))throw new v("Expected a control sequence",r);let s=0,i;const l=[[]];for(;e.gullet.future().text!=="{";)if(r=e.gullet.popToken(),r.text==="#"){if(e.gullet.future().text==="{"){i=e.gullet.future(),l[s].push("{");break}if(r=e.gullet.popToken(),!/^[1-9]$/.test(r.text))throw new v(`Invalid argument number "${r.text}"`);if(parseInt(r.text)!==s+1)throw new v(`Argument number "${r.text}" out of order`);s++,l.push([])}else{if(r.text==="EOF")throw new v("Expected a macro definition");l[s].push(r.text)}let{tokens:u}=e.gullet.consumeArg();if(i&&u.unshift(i),t==="\\edef"||t==="\\xdef"){if(u=e.gullet.expandTokens(u),u.length>e.gullet.settings.maxExpand)throw new v("Too many expansions in an "+t);u.reverse()}return e.gullet.macros.set(o,{tokens:u,numArgs:s,delimiters:l},t===Ue[t]),{type:"internal",mode:e.mode}}});S({type:"internal",names:["\\let","\\\\globallet"],props:{numArgs:0,allowedInText:!0,primitive:!0},handler({parser:e,funcName:t}){const r=De(e.gullet.popToken());e.gullet.consumeSpaces();const o=xn(e);return ar(e,r,o,t==="\\\\globallet"),{type:"internal",mode:e.mode}}});S({type:"internal",names:["\\futurelet","\\\\globalfuture"],props:{numArgs:0,allowedInText:!0,primitive:!0},handler({parser:e,funcName:t}){const r=De(e.gullet.popToken()),o=e.gullet.popToken(),s=e.gullet.popToken();return ar(e,r,s,t==="\\\\globalfuture"),e.gullet.pushToken(s),e.gullet.pushToken(o),{type:"internal",mode:e.mode}}});S({type:"internal",names:["\\newcommand","\\renewcommand","\\providecommand"],props:{numArgs:0,allowedInText:!0,primitive:!0},handler({parser:e,funcName:t}){let r="";const o=e.gullet.popToken();o.text==="{"?(r=De(e.gullet.popToken()),e.gullet.popToken()):r=De(o);const s=e.gullet.isDefined(r);if(s&&t==="\\newcommand")throw new v(`\\newcommand{${r}} attempting to redefine ${r}; use \\renewcommand`);if(!s&&t==="\\renewcommand")throw new v(`\\renewcommand{${r}} when command ${r} does not yet exist; use \\newcommand`);let i=0;if(e.gullet.future().text==="["){let u=e.gullet.popToken();if(u=e.gullet.popToken(),!/^[0-9]$/.test(u.text))throw new v(`Invalid number of arguments: "${u.text}"`);if(i=parseInt(u.text),u=e.gullet.popToken(),u.text!=="]")throw new v(`Invalid argument "${u.text}"`)}const{tokens:l}=e.gullet.consumeArg();return t==="\\providecommand"&&e.gullet.macros.has(r)||e.gullet.macros.set(r,{tokens:l,numArgs:i}),{type:"internal",mode:e.mode}}});const Ve={"\\bigl":{mclass:"mopen",size:1},"\\Bigl":{mclass:"mopen",size:2},"\\biggl":{mclass:"mopen",size:3},"\\Biggl":{mclass:"mopen",size:4},"\\bigr":{mclass:"mclose",size:1},"\\Bigr":{mclass:"mclose",size:2},"\\biggr":{mclass:"mclose",size:3},"\\Biggr":{mclass:"mclose",size:4},"\\bigm":{mclass:"mrel",size:1},"\\Bigm":{mclass:"mrel",size:2},"\\biggm":{mclass:"mrel",size:3},"\\Biggm":{mclass:"mrel",size:4},"\\big":{mclass:"mord",size:1},"\\Big":{mclass:"mord",size:2},"\\bigg":{mclass:"mord",size:3},"\\Bigg":{mclass:"mord",size:4}},sr=["(","\\lparen",")","\\rparen","[","\\lbrack","]","\\rbrack","\\{","\\lbrace","\\}","\\rbrace","⦇","\\llparenthesis","⦈","\\rrparenthesis","\\lfloor","\\rfloor","⌊","⌋","\\lceil","\\rceil","⌈","⌉","<",">","\\langle","⟨","\\rangle","⟩","\\lAngle","⟪","\\rAngle","⟫","\\llangle","⦉","\\rrangle","⦊","\\lt","\\gt","\\lvert","\\rvert","\\lVert","\\rVert","\\lgroup","\\rgroup","⟮","⟯","\\lmoustache","\\rmoustache","⎰","⎱","\\llbracket","\\rrbracket","⟦","⟦","\\lBrace","\\rBrace","⦃","⦄","/","\\backslash","|","\\vert","\\|","\\Vert","‖","\\uparrow","\\Uparrow","\\downarrow","\\Downarrow","\\updownarrow","\\Updownarrow","."],yn=["}","\\left","\\middle","\\right"],$e=e=>e.length>0&&(sr.includes(e)||Ve[e]||yn.includes(e)),St=[0,1.2,1.8,2.4,3];function ge(e,t){const r=Be(e);if(r&&sr.includes(r.text))return["<","\\lt"].includes(r.text)&&(r.text="⟨"),[">","\\gt"].includes(r.text)&&(r.text="⟩"),r;throw r?new v(`Invalid delimiter '${r.text}' after '${t.funcName}'`,e):new v(`Invalid delimiter type '${e.type}'`,e)}const wn=["/","\\","\\backslash","\\vert","|"];S({type:"delimsizing",names:["\\bigl","\\Bigl","\\biggl","\\Biggl","\\bigr","\\Bigr","\\biggr","\\Biggr","\\bigm","\\Bigm","\\biggm","\\Biggm","\\big","\\Big","\\bigg","\\Bigg"],props:{numArgs:1,argTypes:["primitive"]},handler:(e,t)=>{const r=ge(t[0],e),o={type:"delimsizing",mode:e.parser.mode,size:Ve[e.funcName].size,mclass:Ve[e.funcName].mclass,delim:r.text},s=e.parser.fetch().text;return s!=="^"&&s!=="_"?o:{type:"ordgroup",mode:"math",body:[o,{type:"ordgroup",mode:"math",body:[]}]}},mathmlBuilder:e=>{const t=[];e.delim==="."&&(e.delim=""),t.push(W(e.delim,e.mode));const r=new p.MathNode("mo",t);return e.mclass==="mopen"||e.mclass==="mclose"?r.setAttribute("fence","true"):r.setAttribute("fence","false"),(wn.includes(e.delim)||e.delim.indexOf("arrow")>-1)&&r.setAttribute("stretchy","true"),r.setAttribute("symmetric","true"),r.setAttribute("minsize",St[e.size]+"em"),r.setAttribute("maxsize",St[e.size]+"em"),r}});function vn(e){if(!e.body)throw new Error("Bug: The leftright ParseNode wasn't fully parsed.")}S({type:"leftright-right",names:["\\right"],props:{numArgs:1,argTypes:["primitive"]},handler:(e,t)=>({type:"leftright-right",mode:e.parser.mode,delim:ge(t[0],e).text})});S({type:"leftright",names:["\\left"],props:{numArgs:1,argTypes:["primitive"]},handler:(e,t)=>{const r=ge(t[0],e),o=e.parser;++o.leftrightDepth;let s=o.parseExpression(!1,null,!0),i=o.fetch();for(;i.text==="\\middle";){o.consume();const u=o.fetch().text;if(!G.math[u])throw new v(`Invalid delimiter '${u}' after '\\middle'`);ge({type:"atom",mode:"math",text:u},{funcName:"\\middle"}),s.push({type:"middle",mode:"math",delim:u}),o.consume(),s=s.concat(o.parseExpression(!1,null,!0)),i=o.fetch()}--o.leftrightDepth,o.expect("\\right",!1);const l=C(o.parseFunction(),"leftright-right");return{type:"leftright",mode:o.mode,body:s,left:r.text,right:l.delim}},mathmlBuilder:(e,t)=>{vn(e);const r=U(e.body,t);e.left==="."&&(e.left="");const o=new p.MathNode("mo",[W(e.left,e.mode)]);o.setAttribute("fence","true"),o.setAttribute("form","prefix"),(e.left==="/"||e.left==="\\"||e.left.indexOf("arrow")>-1)&&o.setAttribute("stretchy","true"),r.unshift(o),e.right==="."&&(e.right="");const s=new p.MathNode("mo",[W(e.right,e.mode)]);if(s.setAttribute("fence","true"),s.setAttribute("form","postfix"),(e.right==="∖"||e.right.indexOf("arrow")>-1)&&s.setAttribute("stretchy","true"),e.body.length>0){const i=e.body[e.body.length-1];i.type==="color"&&!i.isTextColor&&s.setAttribute("mathcolor",i.color)}return r.push(s),Ye(r)}});S({type:"middle",names:["\\middle"],props:{numArgs:1,argTypes:["primitive"]},handler:(e,t)=>{const r=ge(t[0],e);if(!e.parser.leftrightDepth)throw new v("\\middle without preceding \\left",r);return{type:"middle",mode:e.parser.mode,delim:r.text}},mathmlBuilder:(e,t)=>{const r=W(e.delim,e.mode),o=new p.MathNode("mo",[r]);return o.setAttribute("fence","true"),e.delim.indexOf("arrow")>-1&&o.setAttribute("stretchy","true"),o.setAttribute("form","prefix"),o.setAttribute("lspace","0.05em"),o.setAttribute("rspace","0.05em"),o}});const qt=e=>{const t=new p.MathNode("mspace");return t.setAttribute("width","3pt"),t},ye=(e,t)=>{let r;switch(e.label.indexOf("colorbox")>-1||e.label==="\\boxed"?r=new p.MathNode("mrow",[qt(),M(e.body,t),qt()]):r=new p.MathNode("menclose",[M(e.body,t)]),e.label){case"\\overline":r.setAttribute("notation","top"),r.classes.push("tml-overline");break;case"\\underline":r.setAttribute("notation","bottom"),r.classes.push("tml-underline");break;case"\\cancel":r.setAttribute("notation","updiagonalstrike"),r.children.push(new p.MathNode("mrow",[],["tml-cancel","upstrike"]));break;case"\\bcancel":r.setAttribute("notation","downdiagonalstrike"),r.children.push(new p.MathNode("mrow",[],["tml-cancel","downstrike"]));break;case"\\sout":r.setAttribute("notation","horizontalstrike"),r.children.push(new p.MathNode("mrow",[],["tml-cancel","sout"]));break;case"\\xcancel":r.setAttribute("notation","updiagonalstrike downdiagonalstrike"),r.classes.push("tml-xcancel");break;case"\\longdiv":r.setAttribute("notation","longdiv"),r.classes.push("longdiv-top"),r.children.push(new p.MathNode("mrow",[],["longdiv-arc"]));break;case"\\phase":r.setAttribute("notation","phasorangle"),r.classes.push("phasor-bottom"),r.children.push(new p.MathNode("mrow",[],["phasor-angle"]));break;case"\\textcircled":r.setAttribute("notation","circle"),r.classes.push("circle-pad"),r.children.push(new p.MathNode("mrow",[],["textcircle"]));break;case"\\angl":r.setAttribute("notation","actuarial"),r.classes.push("actuarial");break;case"\\boxed":r.setAttribute("notation","box"),r.style.padding="padding: 3pt 0 3pt 0",r.style.border="1px solid",r.setAttribute("scriptlevel","0"),r.setAttribute("displaystyle","true");break;case"\\fbox":r.setAttribute("notation","box"),r.classes.push("tml-fbox");break;case"\\fcolorbox":case"\\colorbox":{const o={padding:"3pt 0 3pt 0"};e.label==="\\fcolorbox"&&(o.border="0.0667em solid "+String(e.borderColor)),r.style=o;break}}return e.backgroundColor&&r.setAttribute("mathbackground",e.backgroundColor),r};S({type:"enclose",names:["\\colorbox"],props:{numArgs:2,numOptionalArgs:1,allowedInText:!0,argTypes:["raw","raw","text"]},handler({parser:e,funcName:t},r,o){const s=o[0]&&C(o[0],"raw").string;let i="";if(s){const u=C(r[0],"raw").string;i=ce(s,u)}else i=fe(C(r[0],"raw").string,e.gullet.macros);const l=r[1];return{type:"enclose",mode:e.mode,label:t,backgroundColor:i,body:l}},mathmlBuilder:ye});S({type:"enclose",names:["\\fcolorbox"],props:{numArgs:3,numOptionalArgs:1,allowedInText:!0,argTypes:["raw","raw","raw","text"]},handler({parser:e,funcName:t},r,o){const s=o[0]&&C(o[0],"raw").string;let i="",l;if(s){const m=C(r[0],"raw").string,f=C(r[0],"raw").string;i=ce(s,m),l=ce(s,f)}else i=fe(C(r[0],"raw").string,e.gullet.macros),l=fe(C(r[1],"raw").string,e.gullet.macros);const u=r[2];return{type:"enclose",mode:e.mode,label:t,backgroundColor:l,borderColor:i,body:u}},mathmlBuilder:ye});S({type:"enclose",names:["\\fbox"],props:{numArgs:1,argTypes:["hbox"],allowedInText:!0},handler({parser:e},t){return{type:"enclose",mode:e.mode,label:"\\fbox",body:t[0]}}});S({type:"enclose",names:["\\angl","\\cancel","\\bcancel","\\xcancel","\\sout","\\overline","\\boxed","\\longdiv","\\phase"],props:{numArgs:1},handler({parser:e,funcName:t},r){const o=r[0];return{type:"enclose",mode:e.mode,label:t,body:o}},mathmlBuilder:ye});S({type:"enclose",names:["\\underline"],props:{numArgs:1,allowedInText:!0},handler({parser:e,funcName:t},r){const o=r[0];return{type:"enclose",mode:e.mode,label:t,body:o}},mathmlBuilder:ye});S({type:"enclose",names:["\\textcircled"],props:{numArgs:1,argTypes:["text"],allowedInArgument:!0,allowedInText:!0},handler({parser:e,funcName:t},r){const o=r[0];return{type:"enclose",mode:e.mode,label:t,body:o}},mathmlBuilder:ye});S({type:"environment",names:["\\begin","\\end"],props:{numArgs:1,argTypes:["text"]},handler({parser:e,funcName:t},r){const o=r[0];if(o.type!=="ordgroup")throw new v("Invalid environment name",o);let s="";for(let i=0;i{if(t!=="mathrm"||e.body.type!=="ordgroup"||e.body.body.length===1||e.body.body[0].type!=="mathord")return!1;for(let r=1;r{const r=e.font,o=t.withFont(r),s=M(e.body,o);if(s.children.length===0)return s;if(r==="boldsymbol"&&["mo","mpadded","mrow"].includes(s.type))return s.style.fontWeight="bold",s;if(An(e,r)){const u=s.children[0].children[0].children?s.children[0].children[0]:s.children[0];delete u.attributes.mathvariant;for(let f=1;f{const o=pe(r[0]);let s=t;return s in _t&&(s=_t[s]),{type:"font",mode:e.mode,font:s.slice(1),body:o}},mathmlBuilder:ir});S({type:"font",names:["\\rm","\\sf","\\tt","\\bf","\\it","\\cal"],props:{numArgs:0,allowedInText:!0},handler:({parser:e,funcName:t,breakOnTokenText:r},o)=>{const{mode:s}=e,i=e.parseExpression(!0,r,!0),l=`math${t.slice(1)}`;return{type:"font",mode:s,font:l,body:{type:"ordgroup",mode:e.mode,body:i}}},mathmlBuilder:ir});const Tt=["display","text","script","scriptscript"],kn={auto:-1,display:0,text:0,script:1,scriptscript:2},rt=(e,t)=>{const r=e.scriptLevel==="auto"?t.incrementLevel():e.scriptLevel==="display"?t.withLevel(P.TEXT):e.scriptLevel==="text"?t.withLevel(P.SCRIPT):t.withLevel(P.SCRIPTSCRIPT),o=M(e.numer,r),s=M(e.denom,r);t.level===3&&(o.style.mathDepth="2",o.setAttribute("scriptlevel","2"),s.style.mathDepth="2",s.setAttribute("scriptlevel","2"));let i=new p.MathNode("mfrac",[o,s]);if(!e.hasBarLine)i.setAttribute("linethickness","0px");else if(e.barSize){const l=Q(e.barSize,t);i.setAttribute("linethickness",l.number+l.unit)}if(e.leftDelim!=null||e.rightDelim!=null){const l=[];if(e.leftDelim!=null){const u=new p.MathNode("mo",[new p.TextNode(e.leftDelim.replace("\\",""))]);u.setAttribute("fence","true"),l.push(u)}if(l.push(i),e.rightDelim!=null){const u=new p.MathNode("mo",[new p.TextNode(e.rightDelim.replace("\\",""))]);u.setAttribute("fence","true"),l.push(u)}i=Ye(l)}return e.scriptLevel!=="auto"&&(i=new p.MathNode("mstyle",[i]),i.setAttribute("displaystyle",String(e.scriptLevel==="display")),i.setAttribute("scriptlevel",kn[e.scriptLevel])),i};S({type:"genfrac",names:["\\dfrac","\\frac","\\tfrac","\\dbinom","\\binom","\\tbinom","\\\\atopfrac","\\\\bracefrac","\\\\brackfrac"],props:{numArgs:2,allowedInArgument:!0},handler:({parser:e,funcName:t},r)=>{const o=r[0],s=r[1];let i=!1,l=null,u=null,m="auto";switch(t){case"\\dfrac":case"\\frac":case"\\tfrac":i=!0;break;case"\\\\atopfrac":i=!1;break;case"\\dbinom":case"\\binom":case"\\tbinom":l="(",u=")";break;case"\\\\bracefrac":l="\\{",u="\\}";break;case"\\\\brackfrac":l="[",u="]";break;default:throw new Error("Unrecognized genfrac command")}switch(t){case"\\dfrac":case"\\dbinom":m="display";break;case"\\tfrac":case"\\tbinom":m="text";break}return{type:"genfrac",mode:e.mode,continued:!1,numer:o,denom:s,hasBarLine:i,leftDelim:l,rightDelim:u,scriptLevel:m,barSize:null}},mathmlBuilder:rt});S({type:"genfrac",names:["\\cfrac"],props:{numArgs:2},handler:({parser:e,funcName:t},r)=>{const o=r[0],s=r[1];return{type:"genfrac",mode:e.mode,continued:!0,numer:o,denom:s,hasBarLine:!0,leftDelim:null,rightDelim:null,scriptLevel:"display",barSize:null}}});S({type:"infix",names:["\\over","\\choose","\\atop","\\brace","\\brack"],props:{numArgs:0,infix:!0},handler({parser:e,funcName:t,token:r}){let o;switch(t){case"\\over":o="\\frac";break;case"\\choose":o="\\binom";break;case"\\atop":o="\\\\atopfrac";break;case"\\brace":o="\\\\bracefrac";break;case"\\brack":o="\\\\brackfrac";break;default:throw new Error("Unrecognized infix genfrac command")}return{type:"infix",mode:e.mode,replaceWith:o,token:r}}});const Dt=function(e){let t=null;return e.length>0&&(t=e,t=t==="."?null:t),t};S({type:"genfrac",names:["\\genfrac"],props:{numArgs:6,allowedInArgument:!0,argTypes:["math","math","size","text","math","math"]},handler({parser:e},t){const r=t[4],o=t[5],s=pe(t[0]),i=s.type==="atom"&&s.family==="open"?Dt(s.text):null,l=pe(t[1]),u=l.type==="atom"&&l.family==="close"?Dt(l.text):null,m=C(t[2],"size");let f,A=null;m.isBlank?f=!0:(A=m.value,f=A.number>0);let x="auto",y=t[3];if(y.type==="ordgroup"){if(y.body.length>0){const _=C(y.body[0],"textord");x=Tt[Number(_.text)]}}else y=C(y,"textord"),x=Tt[Number(y.text)];return{type:"genfrac",mode:e.mode,numer:r,denom:o,continued:!1,hasBarLine:f,barSize:A,leftDelim:i,rightDelim:u,scriptLevel:x}},mathmlBuilder:rt});S({type:"infix",names:["\\above"],props:{numArgs:1,argTypes:["size"],infix:!0},handler({parser:e,funcName:t,token:r},o){return{type:"infix",mode:e.mode,replaceWith:"\\\\abovefrac",barSize:C(o[0],"size").value,token:r}}});S({type:"genfrac",names:["\\\\abovefrac"],props:{numArgs:3,argTypes:["math","size","math"]},handler:({parser:e,funcName:t},r)=>{const o=r[0],s=Cr(C(r[1],"infix").barSize),i=r[2],l=s.number>0;return{type:"genfrac",mode:e.mode,numer:o,denom:i,continued:!1,hasBarLine:l,barSize:s,leftDelim:null,rightDelim:null,scriptLevel:"auto"}},mathmlBuilder:rt});S({type:"hbox",names:["\\hbox"],props:{numArgs:1,argTypes:["hbox"],allowedInArgument:!0,allowedInText:!1},handler({parser:e},t){return{type:"hbox",mode:e.mode,body:j(t[0])}},mathmlBuilder(e,t){const r=t.withLevel(P.TEXT),o=re(e.body,r);return Ne(o)}});const Sn=(e,t)=>{const r=Ce.mathMLnode(e.label);return r.style["math-depth"]=0,new p.MathNode(e.isOver?"mover":"munder",[M(e.base,t),r])};S({type:"horizBrace",names:["\\overbrace","\\underbrace"],props:{numArgs:1},handler({parser:e,funcName:t},r){return{type:"horizBrace",mode:e.mode,label:t,isOver:/^\\over/.test(t),base:r[0]}},mathmlBuilder:Sn});S({type:"html",names:["\\class","\\id","\\style","\\data"],props:{numArgs:2,argTypes:["raw","original"],allowedInText:!0},handler:({parser:e,funcName:t,token:r},o)=>{const s=C(o[0],"raw").string,i=o[1];if(e.settings.strict)throw new v(`Function "${t}" is disabled in strict mode`,r);let l;const u={};switch(t){case"\\class":u.class=s,l={command:"\\class",class:s};break;case"\\id":u.id=s,l={command:"\\id",id:s};break;case"\\style":u.style=s,l={command:"\\style",style:s};break;case"\\data":{const m=s.split(",");for(let f=0;f{const r=re(e.body,t),o=[];e.attributes.class&&o.push(...e.attributes.class.trim().split(/\s+/)),r.classes=o;for(const s in e.attributes)s!=="class"&&Object.prototype.hasOwnProperty.call(e.attributes,s)&&r.setAttribute(s,e.attributes[s]);return r}});const ze=function(e){if(/^[-+]? *(\d+(\.\d*)?|\.\d+)$/.test(e))return{number:+e,unit:"bp"};{const t=/([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(e);if(!t)throw new v("Invalid size: '"+e+"' in \\includegraphics");const r={number:+(t[1]+t[2]),unit:t[3]};if(!Wt(r))throw new v("Invalid unit: '"+r.unit+"' in \\includegraphics.");return r}};S({type:"includegraphics",names:["\\includegraphics"],props:{numArgs:1,numOptionalArgs:1,argTypes:["raw","url"],allowedInText:!1},handler:({parser:e,token:t},r,o)=>{let s={number:0,unit:"em"},i={number:.9,unit:"em"},l={number:0,unit:"em"},u="";if(o[0]){const A=C(o[0],"raw").string.split(",");for(let x=0;x{const r=Q(e.height,t),o={number:0,unit:"em"};e.totalheight.number>0&&e.totalheight.unit===r.unit&&e.totalheight.number>r.number&&(o.number=e.totalheight.number-r.number,o.unit=r.unit);let s=0;e.width.number>0&&(s=Q(e.width,t));const i={height:r.number+o.number+"em"};s.number>0&&(i.width=s.number+s.unit),o.number>0&&(i.verticalAlign=-o.number+o.unit);const l=new Lr(e.src,e.alt,i);return l.height=r,l.depth=o,new p.MathNode("mtext",[l])}});S({type:"kern",names:["\\kern","\\mkern","\\hskip","\\mskip"],props:{numArgs:1,argTypes:["size"],primitive:!0,allowedInText:!0},handler({parser:e,funcName:t,token:r},o){const s=C(o[0],"size");if(e.settings.strict){const i=t[1]==="m",l=s.value.unit==="mu";if(i){if(!l)throw new v(`LaTeX's ${t} supports only mu units, not ${s.value.unit} units`,r);if(e.mode!=="math")throw new v(`LaTeX's ${t} works only in math mode`,r)}else if(l)throw new v(`LaTeX's ${t} doesn't support mu units`,r)}return{type:"kern",mode:e.mode,dimension:s.value}},mathmlBuilder(e,t){const r=Q(e.dimension,t),o=r.number>0&&r.unit==="em"?lr(r.number):"";if(e.mode==="text"&&o.length>0){const s=new p.TextNode(o);return new p.MathNode("mtext",[s])}else if(r.number>=0){const s=new p.MathNode("mspace");return s.setAttribute("width",r.number+r.unit),s}else{const s=new p.MathNode("mrow");return s.style.marginLeft=r.number+r.unit,s}}});const lr=function(e){return e>=.05555&&e<=.05556?" ":e>=.1666&&e<=.1667?" ":e>=.2222&&e<=.2223?" ":e>=.2777&&e<=.2778?"  ":""},ur=/[^A-Za-z_0-9-]/g;S({type:"label",names:["\\label"],props:{numArgs:1,argTypes:["raw"]},handler({parser:e},t){return{type:"label",mode:e.mode,string:t[0].string.replace(ur,"")}},mathmlBuilder(e,t){const r=new p.MathNode("mrow",[],["tml-label"]);return e.string.length>0&&r.setLabel(e.string),r}});const qn=["\\clap","\\llap","\\rlap"];S({type:"lap",names:["\\mathllap","\\mathrlap","\\mathclap","\\clap","\\llap","\\rlap"],props:{numArgs:1,allowedInText:!0},handler:({parser:e,funcName:t,token:r},o)=>{if(qn.includes(t)){if(e.settings.strict&&e.mode!=="text")throw new v(`{${t}} can be used only in text mode. Try \\math${t.slice(1)}`,r);t=t.slice(1)}else t=t.slice(5);const s=o[0];return{type:"lap",mode:e.mode,alignment:t,body:s}},mathmlBuilder:(e,t)=>{let r;if(e.alignment==="llap"){const i=U(j(e.body),t),l=new p.MathNode("mphantom",i);r=new p.MathNode("mpadded",[l]),r.setAttribute("width","0px")}const o=M(e.body,t);let s;if(e.alignment==="llap"?(o.style.position="absolute",o.style.right="0",o.style.bottom="0",s=new p.MathNode("mpadded",[r,o])):s=new p.MathNode("mpadded",[o]),e.alignment==="rlap")e.body.body.length>0&&e.body.body[0].type==="genfrac"&&s.setAttribute("lspace","0.16667em");else{const i=e.alignment==="llap"?"-1":"-0.5";s.setAttribute("lspace",i+"width"),e.alignment==="llap"?s.style.position="relative":(s.style.display="flex",s.style.justifyContent="center")}return s.setAttribute("width","0px"),s}});S({type:"ordgroup",names:["\\(","$"],props:{numArgs:0,allowedInText:!0,allowedInMath:!1},handler({funcName:e,parser:t},r){const o=t.mode;t.switchMode("math");const s=e==="\\("?"\\)":"$",i=t.parseExpression(!1,s);return t.expect(s),t.switchMode(o),{type:"ordgroup",mode:t.mode,body:i}}});S({type:"text",names:["\\)","\\]"],props:{numArgs:0,allowedInText:!0,allowedInMath:!1},handler(e,t){throw new v(`Mismatched ${e.funcName}`,t)}});const _n=(e,t)=>{switch(t.level){case P.DISPLAY:return e.display;case P.TEXT:return e.text;case P.SCRIPT:return e.script;case P.SCRIPTSCRIPT:return e.scriptscript;default:return e.text}};S({type:"mathchoice",names:["\\mathchoice"],props:{numArgs:4,primitive:!0},handler:({parser:e},t)=>({type:"mathchoice",mode:e.mode,display:j(t[0]),text:j(t[1]),script:j(t[2]),scriptscript:j(t[3])}),mathmlBuilder:(e,t)=>{const r=_n(e,t);return re(r,t)}});const Tn=["text","textord","mathord","atom"];function cr(e,t){let r;const o=U(e.body,t);if(e.mclass==="minner")r=new p.MathNode("mpadded",o);else if(e.mclass==="mord")e.isCharacterBox||o[0].type==="mathord"?(r=o[0],r.type="mi",r.children.length===1&&r.children[0].text&&r.children[0].text==="∇"&&r.setAttribute("mathvariant","normal")):r=new p.MathNode("mi",o);else{r=new p.MathNode("mrow",o),e.mustPromote?(r=o[0],r.type="mo",e.isCharacterBox&&e.body[0].text&&/[A-Za-z]/.test(e.body[0].text)&&r.setAttribute("mathvariant","italic")):r=new p.MathNode("mrow",o);const s=t.level<2;r.type==="mrow"?s&&(e.mclass==="mbin"?(r.children.unshift(I(.2222)),r.children.push(I(.2222))):e.mclass==="mrel"?(r.children.unshift(I(.2778)),r.children.push(I(.2778))):e.mclass==="mpunct"?r.children.push(I(.1667)):e.mclass==="minner"&&(r.children.unshift(I(.0556)),r.children.push(I(.0556)))):e.mclass==="mbin"?(r.attributes.lspace=s?"0.2222em":"0",r.attributes.rspace=s?"0.2222em":"0"):e.mclass==="mrel"?(r.attributes.lspace=s?"0.2778em":"0",r.attributes.rspace=s?"0.2778em":"0"):e.mclass==="mpunct"?(r.attributes.lspace="0em",r.attributes.rspace=s?"0.1667em":"0"):e.mclass==="mopen"||e.mclass==="mclose"?(r.attributes.lspace="0em",r.attributes.rspace="0em"):e.mclass==="minner"&&s&&(r.attributes.lspace="0.0556em",r.attributes.width="+0.1111em"),e.mclass==="mopen"||e.mclass==="mclose"||(delete r.attributes.stretchy,delete r.attributes.form)}return r}S({type:"mclass",names:["\\mathord","\\mathbin","\\mathrel","\\mathopen","\\mathclose","\\mathpunct","\\mathinner"],props:{numArgs:1,primitive:!0},handler({parser:e,funcName:t},r){const o=r[0],s=O.isCharacterBox(o);let i=!0;const l={type:"mathord",text:"",mode:e.mode},u=o.body?o.body:[o];for(const m of u)if(Tn.includes(m.type))G[e.mode][m.text]?l.text+=G[e.mode][m.text].replace:m.text?l.text+=m.text:m.body&&m.body.map(f=>{l.text+=f.text});else{i=!1;break}return i&&t==="\\mathord"&&l.type==="mathord"&&l.text.length>1?l:{type:"mclass",mode:e.mode,mclass:"m"+t.slice(5),body:j(i?l:o),isCharacterBox:s,mustPromote:i}},mathmlBuilder:cr});const dr=e=>{const t=e.type==="ordgroup"&&e.body.length&&e.body.length===1?e.body[0]:e;return t.type==="atom"&&(t.family==="bin"||t.family==="rel")?"m"+t.family:"mord"};S({type:"mclass",names:["\\@binrel"],props:{numArgs:2},handler({parser:e},t){return{type:"mclass",mode:e.mode,mclass:dr(t[0]),body:j(t[1]),isCharacterBox:O.isCharacterBox(t[1])}}});S({type:"mclass",names:["\\stackrel","\\overset","\\underset"],props:{numArgs:2},handler({parser:e,funcName:t},r){const o=r[1],s=r[0];let i;t!=="\\stackrel"?i=dr(o):i="mrel";const u={type:i==="mrel"||i==="mbin"?"op":"ordgroup",mode:o.mode,limits:!0,alwaysHandleSupSub:!0,parentIsSupSub:!1,symbol:!1,suppressBaseShift:t!=="\\stackrel",body:j(o)};return{type:"supsub",mode:s.mode,stack:!0,base:u,sup:t==="\\underset"?null:s,sub:t==="\\underset"?s:null}},mathmlBuilder:cr});const ke=(e,t,r)=>{if(!e)return r;const o=M(e,t);return o.type==="mrow"&&o.children.length===0?r:o};S({type:"multiscript",names:["\\sideset","\\pres@cript"],props:{numArgs:3},handler({parser:e,funcName:t,token:r},o){if(o[2].body.length===0)throw new v(t+"cannot parse an empty base.");const s=o[2].body[0];if(e.settings.strict&&t==="\\sideset"&&!s.symbol)throw new v("The base of \\sideset must be a big operator. Try \\prescript.");if(o[0].body.length>0&&o[0].body[0].type!=="supsub"||o[1].body.length>0&&o[1].body[0].type!=="supsub")throw new v("\\sideset can parse only subscripts and superscripts in its first two arguments",r);const i=o[0].body.length>0?o[0].body[0]:null,l=o[1].body.length>0?o[1].body[0]:null;return!i&&!l?s:i?{type:"multiscript",mode:e.mode,isSideset:t==="\\sideset",prescripts:i,postscripts:l,base:s}:{type:"styling",mode:e.mode,scriptLevel:"text",body:[{type:"supsub",mode:e.mode,base:s,sup:l.sup,sub:l.sub}]}},mathmlBuilder(e,t){const r=M(e.base,t),o=new p.MathNode("mprescripts"),s=new p.MathNode("none");let i=[];const l=ke(e.prescripts.sub,t,s),u=ke(e.prescripts.sup,t,s);if(e.isSideset&&(l.setAttribute("style","text-align: left;"),u.setAttribute("style","text-align: left;")),e.postscripts){const m=ke(e.postscripts.sub,t,s),f=ke(e.postscripts.sup,t,s);i=[r,m,f,o,l,u]}else i=[r,o,l,u];return new p.MathNode("mmultiscripts",i)}});S({type:"not",names:["\\not"],props:{numArgs:1,primitive:!0,allowedInText:!1},handler({parser:e},t){const r=O.isCharacterBox(t[0]);let o;return r?(o=j(t[0]),o[0].text.charAt(0)==="\\"&&(o[0].text=G.math[o[0].text].replace),o[0].text=o[0].text.slice(0,1)+"̸"+o[0].text.slice(1)):o=[{type:"textord",mode:"math",text:"̸"},{type:"kern",mode:"math",dimension:{number:-.6,unit:"em"}},t[0]],{type:"not",mode:e.mode,body:o,isCharacterBox:r}},mathmlBuilder(e,t){return e.isCharacterBox?U(e.body,t,!0)[0]:re(e.body,t)}});const Dn=["textord","mathord","atom"],Cn=["\\smallint"],nt=["textord","mathord","ordgroup","close","leftright","font"],Ct=e=>{e.attributes.lspace="0.1667em",e.attributes.rspace="0.1667em"},we=(e,t)=>{let r;if(e.symbol)r=new V("mo",[W(e.name,e.mode)]),Cn.includes(e.name)?r.setAttribute("largeop","false"):r.setAttribute("movablelimits","false"),e.fromMathOp&&Ct(r);else if(e.body)r=new V("mo",U(e.body,t)),e.fromMathOp&&Ct(r);else if(r=new V("mi",[new he(e.name.slice(1))]),!e.parentIsSupSub){const o=new V("mo",[W("⁡","text")]),s=[r,o];if(e.needsLeadingSpace){const i=new V("mspace");i.setAttribute("width","0.1667em"),s.unshift(i)}if(!e.isFollowedByDelimiter){const i=new V("mspace");i.setAttribute("width","0.1667em"),s.push(i)}r=new V("mrow",s)}return r},Nn={"∏":"\\prod","∐":"\\coprod","∑":"\\sum","⋀":"\\bigwedge","⋁":"\\bigvee","⋂":"\\bigcap","⋃":"\\bigcup","⨀":"\\bigodot","⨁":"\\bigoplus","⨂":"\\bigotimes","⨄":"\\biguplus","⨅":"\\bigsqcap","⨆":"\\bigsqcup","⨃":"\\bigcupdot","⨇":"\\bigdoublevee","⨈":"\\bigdoublewedge","⨉":"\\bigtimes"};S({type:"op",names:["\\coprod","\\bigvee","\\bigwedge","\\biguplus","\\bigcupplus","\\bigcupdot","\\bigcap","\\bigcup","\\bigdoublevee","\\bigdoublewedge","\\intop","\\prod","\\sum","\\bigotimes","\\bigoplus","\\bigodot","\\bigsqcap","\\bigsqcup","\\bigtimes","\\smallint","∏","∐","∑","⋀","⋁","⋂","⋃","⨀","⨁","⨂","⨃","⨄","⨅","⨆","⨇","⨈","⨉"],props:{numArgs:0},handler:({parser:e,funcName:t},r)=>{let o=t;return o.length===1&&(o=Nn[o]),{type:"op",mode:e.mode,limits:!0,parentIsSupSub:!1,symbol:!0,stack:!1,name:o}},mathmlBuilder:we});S({type:"op",names:["\\mathop"],props:{numArgs:1,primitive:!0},handler:({parser:e},t)=>{const r=t[0],o=r.body?r.body:[r],s=o.length===1&&Dn.includes(o[0].type);return{type:"op",mode:e.mode,limits:!0,parentIsSupSub:!1,symbol:s,fromMathOp:!0,stack:!1,name:s?o[0].text:null,body:s?null:j(r)}},mathmlBuilder:we});const Bn={"∫":"\\int","∬":"\\iint","∭":"\\iiint","∮":"\\oint","∯":"\\oiint","∰":"\\oiiint","∱":"\\intclockwise","∲":"\\varointclockwise","⨌":"\\iiiint","⨍":"\\intbar","⨎":"\\intBar","⨏":"\\fint","⨒":"\\rppolint","⨓":"\\scpolint","⨕":"\\pointint","⨖":"\\sqint","⨗":"\\intlarhk","⨘":"\\intx","⨙":"\\intcap","⨚":"\\intcup"};S({type:"op",names:["\\arcsin","\\arccos","\\arctan","\\arctg","\\arcctg","\\arg","\\ch","\\cos","\\cosec","\\cosh","\\cot","\\cotg","\\coth","\\csc","\\ctg","\\cth","\\deg","\\dim","\\exp","\\hom","\\ker","\\lg","\\ln","\\log","\\sec","\\sin","\\sinh","\\sh","\\sgn","\\tan","\\tanh","\\tg","\\th"],props:{numArgs:0},handler({parser:e,funcName:t}){const r=e.prevAtomType,o=e.gullet.future().text;return{type:"op",mode:e.mode,limits:!1,parentIsSupSub:!1,symbol:!1,stack:!1,isFollowedByDelimiter:$e(o),needsLeadingSpace:r.length>0&&nt.includes(r),name:t}},mathmlBuilder:we});S({type:"op",names:["\\det","\\gcd","\\inf","\\lim","\\max","\\min","\\Pr","\\sup"],props:{numArgs:0},handler({parser:e,funcName:t}){const r=e.prevAtomType,o=e.gullet.future().text;return{type:"op",mode:e.mode,limits:!0,parentIsSupSub:!1,symbol:!1,stack:!1,isFollowedByDelimiter:$e(o),needsLeadingSpace:r.length>0&&nt.includes(r),name:t}},mathmlBuilder:we});S({type:"op",names:["\\int","\\iint","\\iiint","\\iiiint","\\oint","\\oiint","\\oiiint","\\intclockwise","\\varointclockwise","\\intbar","\\intBar","\\fint","\\rppolint","\\scpolint","\\pointint","\\sqint","\\intlarhk","\\intx","\\intcap","\\intcup","∫","∬","∭","∮","∯","∰","∱","∲","⨌","⨍","⨎","⨏","⨒","⨓","⨕","⨖","⨗","⨘","⨙","⨚"],props:{numArgs:0},handler({parser:e,funcName:t}){let r=t;return r.length===1&&(r=Bn[r]),{type:"op",mode:e.mode,limits:!1,parentIsSupSub:!1,symbol:!0,stack:!1,name:r}},mathmlBuilder:we});const $n=(e,t)=>{let r=U(e.body,t.withFont("mathrm")),o=!0;for(let i=0;il.toText()).join("");r=[new p.TextNode(i)]}else if(r.length===1&&["mover","munder"].includes(r[0].type)&&(r[0].children[0].type==="mi"||r[0].children[0].type==="mtext")){if(r[0].children[0].type="mi",e.parentIsSupSub)return new p.MathNode("mrow",r);{const i=new p.MathNode("mo",[W("⁡","text")]);return p.newDocumentFragment([r[0],i])}}let s;if(o?(s=new p.MathNode("mi",r),r[0].text.length===1&&s.setAttribute("mathvariant","normal")):s=new p.MathNode("mrow",r),!e.parentIsSupSub){const i=new p.MathNode("mo",[W("⁡","text")]),l=[s,i];if(e.needsLeadingSpace){const u=new p.MathNode("mspace");u.setAttribute("width","0.1667em"),l.unshift(u)}if(!e.isFollowedByDelimiter){const u=new p.MathNode("mspace");u.setAttribute("width","0.1667em"),l.push(u)}return p.newDocumentFragment(l)}return s};S({type:"operatorname",names:["\\operatorname@","\\operatornamewithlimits"],props:{numArgs:1,allowedInArgument:!0},handler:({parser:e,funcName:t},r)=>{const o=r[0],s=e.prevAtomType,i=e.gullet.future().text;return{type:"operatorname",mode:e.mode,body:j(o),alwaysHandleSupSub:t==="\\operatornamewithlimits",limits:!1,parentIsSupSub:!1,isFollowedByDelimiter:$e(i),needsLeadingSpace:s.length>0&&nt.includes(s)}},mathmlBuilder:$n});c("\\operatorname","\\@ifstar\\operatornamewithlimits\\operatorname@");oe({type:"ordgroup",mathmlBuilder(e,t){return re(e.body,t,e.semisimple)}});S({type:"phantom",names:["\\phantom"],props:{numArgs:1,allowedInText:!0},handler:({parser:e},t)=>{const r=t[0];return{type:"phantom",mode:e.mode,body:j(r)}},mathmlBuilder:(e,t)=>{const r=U(e.body,t);return new p.MathNode("mphantom",r)}});S({type:"hphantom",names:["\\hphantom"],props:{numArgs:1,allowedInText:!0},handler:({parser:e},t)=>{const r=t[0];return{type:"hphantom",mode:e.mode,body:r}},mathmlBuilder:(e,t)=>{const r=U(j(e.body),t),o=new p.MathNode("mphantom",r),s=new p.MathNode("mpadded",[o]);return s.setAttribute("height","0px"),s.setAttribute("depth","0px"),s}});S({type:"vphantom",names:["\\vphantom"],props:{numArgs:1,allowedInText:!0},handler:({parser:e},t)=>{const r=t[0];return{type:"vphantom",mode:e.mode,body:r}},mathmlBuilder:(e,t)=>{const r=U(j(e.body),t),o=new p.MathNode("mphantom",r),s=new p.MathNode("mpadded",[o]);return s.setAttribute("width","0px"),s}});S({type:"pmb",names:["\\pmb"],props:{numArgs:1,allowedInText:!0},handler({parser:e},t){return{type:"pmb",mode:e.mode,body:j(t[0])}},mathmlBuilder(e,t){const r=U(e.body,t),o=Xe(r);return o.setAttribute("style","font-weight:bold"),o}});const hr=(e,t)=>{const r=t.withLevel(P.TEXT),o=new p.MathNode("mpadded",[M(e.body,r)]),s=Q(e.dy,t);return o.setAttribute("voffset",s.number+s.unit),s.number>0?o.style.padding=s.number+s.unit+" 0 0 0":o.style.padding="0 0 "+Math.abs(s.number)+s.unit+" 0",o};S({type:"raise",names:["\\raise","\\lower"],props:{numArgs:2,argTypes:["size","primitive"],primitive:!0},handler({parser:e,funcName:t},r){const o=C(r[0],"size").value;t==="\\lower"&&(o.number*=-1);const s=r[1];return{type:"raise",mode:e.mode,dy:o,body:s}},mathmlBuilder:hr});S({type:"raise",names:["\\raisebox"],props:{numArgs:2,argTypes:["size","hbox"],allowedInText:!0},handler({parser:e,funcName:t},r){const o=C(r[0],"size").value,s=r[1];return{type:"raise",mode:e.mode,dy:o,body:s}},mathmlBuilder:hr});S({type:"ref",names:["\\ref","\\eqref"],props:{numArgs:1,argTypes:["raw"]},handler({parser:e,funcName:t},r){return{type:"ref",mode:e.mode,funcName:t,string:r[0].string.replace(ur,"")}},mathmlBuilder(e,t){const r=e.funcName==="\\ref"?["tml-ref"]:["tml-ref","tml-eqref"];return new Ut("#"+e.string,r,null)}});S({type:"reflect",names:["\\reflectbox"],props:{numArgs:1,argTypes:["hbox"],allowedInText:!0},handler({parser:e},t){return{type:"reflect",mode:e.mode,body:t[0]}},mathmlBuilder(e,t){const r=M(e.body,t);return r.style.transform="scaleX(-1)",r}});S({type:"internal",names:["\\relax"],props:{numArgs:0,allowedInText:!0,allowedInArgument:!0},handler({parser:e}){return{type:"internal",mode:e.mode}}});S({type:"rule",names:["\\rule"],props:{numArgs:2,numOptionalArgs:1,allowedInText:!0,allowedInMath:!0,argTypes:["size","size","size"]},handler({parser:e},t,r){const o=r[0],s=C(t[0],"size"),i=C(t[1],"size");return{type:"rule",mode:e.mode,shift:o&&C(o,"size").value,width:s.value,height:i.value}},mathmlBuilder(e,t){const r=Q(e.width,t),o=Q(e.height,t),s=e.shift?Q(e.shift,t):{number:0,unit:"em"},i=t.color&&t.getColor()||"black",l=new p.MathNode("mspace");if(r.number>0&&o.number>0&&l.setAttribute("mathbackground",i),l.setAttribute("width",r.number+r.unit),l.setAttribute("height",o.number+o.unit),s.number===0)return l;const u=new p.MathNode("mpadded",[l]);return s.number>=0?u.setAttribute("height","+"+s.number+s.unit):(u.setAttribute("height",s.number+s.unit),u.setAttribute("depth","+"+-s.number+s.unit)),u.setAttribute("voffset",s.number+s.unit),u}});const Nt=/^[0-9]$/,On={0:"₀",1:"₁",2:"₂",3:"₃",4:"₄",5:"₅",6:"₆",7:"₇",8:"₈",9:"₉"},Mn={0:"⁰",1:"¹",2:"²",3:"³",4:"⁴",5:"⁵",6:"⁶",7:"⁷",8:"⁸",9:"⁹"};S({type:"sfrac",names:["\\sfrac"],props:{numArgs:2,allowedInText:!0,allowedInMath:!0},handler({parser:e},t){let r="";for(const s of t[0].body){if(s.type!=="textord"||!Nt.test(s.text))throw new v("Numerator must be an integer.",s);r+=s.text}let o="";for(const s of t[1].body){if(s.type!=="textord"||!Nt.test(s.text))throw new v("Denominator must be an integer.",s);o+=s.text}return{type:"sfrac",mode:e.mode,numerator:r,denominator:o}},mathmlBuilder(e,t){const r=e.numerator.split("").map(i=>Mn[i]).join(""),o=e.denominator.split("").map(i=>On[i]).join(""),s=new p.TextNode(r+"⁄"+o,e.mode,t);return new p.MathNode("mn",[s],["special-fraction"])}});const Bt={"\\tiny":.5,"\\sixptsize":.6,"\\Tiny":.6,"\\scriptsize":.7,"\\footnotesize":.8,"\\small":.9,"\\normalsize":1,"\\large":1.2,"\\Large":1.44,"\\LARGE":1.728,"\\huge":2.074,"\\Huge":2.488};S({type:"sizing",names:["\\tiny","\\sixptsize","\\Tiny","\\scriptsize","\\footnotesize","\\small","\\normalsize","\\large","\\Large","\\LARGE","\\huge","\\Huge"],props:{numArgs:0,allowedInText:!0},handler:({breakOnTokenText:e,funcName:t,parser:r},o)=>{r.settings.strict&&r.mode==="math"&&console.log(`Temml strict-mode warning: Command ${t} is invalid in math mode.`);const s=r.parseExpression(!1,e,!0);return{type:"sizing",mode:r.mode,funcName:t,body:s}},mathmlBuilder:(e,t)=>{const r=t.withFontSize(Bt[e.funcName]),o=U(e.body,r),s=Xe(o),i=(Bt[e.funcName]/t.fontSize).toFixed(4);return s.setAttribute("mathsize",i+"em"),s}});S({type:"smash",names:["\\smash"],props:{numArgs:1,numOptionalArgs:1,allowedInText:!0},handler:({parser:e},t,r)=>{let o=!1,s=!1;const i=r[0]&&C(r[0],"ordgroup");if(i){let u="";for(let m=0;m{const r=new p.MathNode("mpadded",[M(e.body,t)]);return e.smashHeight&&r.setAttribute("height","0px"),e.smashDepth&&r.setAttribute("depth","0px"),r}});S({type:"sqrt",names:["\\sqrt"],props:{numArgs:1,numOptionalArgs:1},handler({parser:e},t,r){const o=r[0],s=t[0];return{type:"sqrt",mode:e.mode,body:s,index:o}},mathmlBuilder(e,t){const{body:r,index:o}=e;return o?new p.MathNode("mroot",[M(r,t),M(o,t.incrementLevel())]):new p.MathNode("msqrt",[M(r,t)])}});const En={display:0,text:1,script:2,scriptscript:3},Ln={display:["0","true"],text:["0","false"],script:["1","false"],scriptscript:["2","false"]};S({type:"styling",names:["\\displaystyle","\\textstyle","\\scriptstyle","\\scriptscriptstyle"],props:{numArgs:0,allowedInText:!0,primitive:!0},handler({breakOnTokenText:e,funcName:t,parser:r},o){const s=r.parseExpression(!0,e,!0),i=t.slice(1,t.length-5);return{type:"styling",mode:r.mode,scriptLevel:i,body:s}},mathmlBuilder(e,t){const r=t.withLevel(En[e.scriptLevel]),o=U(e.body,r),s=Xe(o),i=Ln[e.scriptLevel];return s.setAttribute("scriptlevel",i[0]),s.setAttribute("displaystyle",i[1]),s}});const zn=/^m(over|under|underover)$/,Fn="DHKLUcegorsuvxyzΠΥΨαδηιμνοτυχϵ",In="BCEFGIMNOPQRSTXZlpqtwΓΘΞΣΦΩβεζθξρςφψϑϕϱ",Pn="AJdfΔΛ";oe({type:"supsub",mathmlBuilder(e,t){let r=!1,o,s,i=!1,l=!1,u=!1;e.base&&e.base.type==="horizBrace"&&(s=!!e.sup,s===e.base.isOver&&(r=!0,o=e.base.isOver)),e.base&&!e.stack&&(e.base.type==="op"||e.base.type==="operatorname")&&(e.base.parentIsSupSub=!0,i=!e.base.symbol,l=i&&!e.isFollowedByDelimiter,u=e.base.needsLeadingSpace);const m=e.stack&&e.base.body.length===1?[M(e.base.body[0],t)]:[M(e.base,t)],f=t.inSubOrSup();if(e.sub){const y=M(e.sub,f);t.level===3&&y.setAttribute("scriptlevel","2"),m.push(y)}if(e.sup){const y=M(e.sup,f);if(t.level===3&&y.setAttribute("scriptlevel","2"),e.base&&e.base.text&&e.base.text.length===1){const _=e.base.text;Fn.indexOf(_)>-1?y.classes.push("tml-sml-pad"):In.indexOf(_)>-1?y.classes.push("tml-med-pad"):Pn.indexOf(_)>-1&&y.classes.push("tml-lrg-pad")}m.push(y)}let A;if(r)A=o?"mover":"munder";else if(e.sub)if(e.sup){const y=e.base;y&&(y.type==="op"&&y.limits||y.type==="multiscript")&&(t.level===P.DISPLAY||y.alwaysHandleSupSub)||y&&y.type==="operatorname"&&y.alwaysHandleSupSub&&(t.level===P.DISPLAY||y.limits)?A="munderover":A="msubsup"}else{const y=e.base;e.stack||y&&y.type==="op"&&y.limits&&(t.level===P.DISPLAY||y.alwaysHandleSupSub)||y&&y.type==="operatorname"&&y.alwaysHandleSupSub&&(y.limits||t.level===P.DISPLAY)?A="munder":A="msub"}else{const y=e.base;y&&y.type==="op"&&y.limits&&(t.level===P.DISPLAY||y.alwaysHandleSupSub)||y&&y.type==="operatorname"&&y.alwaysHandleSupSub&&(y.limits||t.level===P.DISPLAY)?A="mover":A="msup"}let x=new p.MathNode(A,m);if(i){const y=new p.MathNode("mo",[W("⁡","text")]);if(u){const _=new p.MathNode("mspace");_.setAttribute("width","0.1667em"),x=p.newDocumentFragment([_,x,y])}else x=p.newDocumentFragment([x,y]);if(l){const _=new p.MathNode("mspace");_.setAttribute("width","0.1667em"),x.children.push(_)}}else zn.test(A)&&(x=new p.MathNode("mrow",[x]));return x}});const Gn=["\\shortmid","\\nshortmid","\\shortparallel","\\nshortparallel","\\smallsetminus"],Rn=["\\Rsh","\\Lsh","\\restriction"],jn=e=>{if(e.length===1){const t=e.codePointAt(0);return 8591-1||e.indexOf("harpoon")>-1||Rn.includes(e)};oe({type:"atom",mathmlBuilder(e,t){const r=new p.MathNode("mo",[W(e.text,e.mode)]);if(e.family==="punct")r.setAttribute("separator","true");else if(e.family==="open"||e.family==="close")e.family==="open"?(r.setAttribute("form","prefix"),r.setAttribute("stretchy","false")):e.family==="close"&&(r.setAttribute("form","postfix"),r.setAttribute("stretchy","false"));else if(e.text==="\\mid")r.setAttribute("lspace","0.22em"),r.setAttribute("rspace","0.22em"),r.setAttribute("stretchy","false");else if(e.family==="rel"&&jn(e.text))r.setAttribute("stretchy","false");else if(Gn.includes(e.text))r.setAttribute("mathsize","70%");else if(e.text===":")r.attributes.lspace="0.2222em",r.attributes.rspace="0.2222em";else if(e.needsSpacing)return e.family==="bin"?new p.MathNode("mrow",[I(.222),r,I(.222)]):new p.MathNode("mrow",[I(.2778),r,I(.2778)]);return r}});const $t={mathbf:"bold",mathrm:"normal",textit:"italic",mathit:"italic",mathnormal:"italic",mathbb:"double-struck",mathcal:"script",mathfrak:"fraktur",mathscr:"script",mathsf:"sans-serif",mathtt:"monospace"},mr=function(e,t){if(t.fontFamily==="texttt")return"monospace";if(t.fontFamily==="textsc")return"normal";if(t.fontFamily==="textsf")return t.fontShape==="textit"&&t.fontWeight==="textbf"?"sans-serif-bold-italic":t.fontShape==="textit"?"sans-serif-italic":t.fontWeight==="textbf"?"sans-serif-bold":"sans-serif";if(t.fontShape==="textit"&&t.fontWeight==="textbf")return"bold-italic";if(t.fontShape==="textit")return"italic";if(t.fontWeight==="textbf")return"bold";const r=t.font;if(!r||r==="mathnormal")return null;const o=e.mode;switch(r){case"mathit":return"italic";case"mathrm":{const i=e.text.codePointAt(0);return 9390,bold:e=>119743,italic:e=>119795,"bold-italic":e=>119847,script:e=>Ot[e]||119899,"script-bold":e=>119951,fraktur:e=>Un[e]||120003,"fraktur-bold":e=>120107,"double-struck":e=>Vn[e]||120055,"sans-serif":e=>120159,"sans-serif-bold":e=>120211,"sans-serif-italic":e=>120263,"sans-serif-bold-italic":e=>120380,monospace:e=>120367},lowerCaseLatin:{normal:e=>0,bold:e=>119737,italic:e=>e==="h"?8358:119789,"bold-italic":e=>119841,script:e=>Ot[e]||119893,"script-bold":e=>119945,fraktur:e=>119997,"fraktur-bold":e=>120101,"double-struck":e=>120049,"sans-serif":e=>120153,"sans-serif-bold":e=>120205,"sans-serif-italic":e=>120257,"sans-serif-bold-italic":e=>120309,monospace:e=>120361},upperCaseGreek:{normal:e=>0,bold:e=>119575,italic:e=>119633,"bold-italic":e=>119575,script:e=>0,"script-bold":e=>0,fraktur:e=>0,"fraktur-bold":e=>0,"double-struck":e=>0,"sans-serif":e=>119749,"sans-serif-bold":e=>119749,"sans-serif-italic":e=>0,"sans-serif-bold-italic":e=>119807,monospace:e=>0},lowerCaseGreek:{normal:e=>0,bold:e=>119569,italic:e=>119627,"bold-italic":e=>e==="ϕ"?119678:119685,script:e=>0,"script-bold":e=>0,fraktur:e=>0,"fraktur-bold":e=>0,"double-struck":e=>0,"sans-serif":e=>119743,"sans-serif-bold":e=>119743,"sans-serif-italic":e=>0,"sans-serif-bold-italic":e=>119801,monospace:e=>0},varGreek:{normal:e=>0,bold:e=>pr[e]||-51,italic:e=>0,"bold-italic":e=>Hn[e]||58,script:e=>0,"script-bold":e=>0,fraktur:e=>0,"fraktur-bold":e=>0,"double-struck":e=>0,"sans-serif":e=>Mt[e]||116,"sans-serif-bold":e=>Mt[e]||116,"sans-serif-italic":e=>0,"sans-serif-bold-italic":e=>Wn[e]||174,monospace:e=>0},numeral:{normal:e=>0,bold:e=>120734,italic:e=>0,"bold-italic":e=>0,script:e=>0,"script-bold":e=>0,fraktur:e=>0,"fraktur-bold":e=>0,"double-struck":e=>120744,"sans-serif":e=>120754,"sans-serif-bold":e=>120764,"sans-serif-italic":e=>0,"sans-serif-bold-italic":e=>0,monospace:e=>120774}}),me=(e,t)=>{const r=e.codePointAt(0),o=64{const o=new p.MathNode(r,[e]),s=new p.MathNode("mstyle",[o]);return s.style["font-style"]="italic",s.style["font-family"]="Cambria, 'Times New Roman', serif",t==="bold-italic"&&(s.style["font-weight"]="bold"),s};oe({type:"mathord",mathmlBuilder(e,t){const r=W(e.text,e.mode,t),o=r.text.codePointAt(0),s=912me(m,i)).join("")),l=new p.MathNode(u,[s])}else if(e.mode==="text")i!=="normal"&&(s.text=me(s.text,i)),l=new p.MathNode("mtext",[s]);else if(Jn.has(e.text))l=new p.MathNode("mo",[s]),l.classes.push("tml-prime");else{const u=s.text;i!=="italic"&&(s.text=me(s.text,i)),l=new p.MathNode("mi",[s]),s.text===u&&Kn.test(u)&&l.setAttribute("mathvariant","italic")}return l}});const eo={"\\nobreak":"nobreak","\\allowbreak":"allowbreak"},to={" ":{},"\\ ":{},"~":{className:"nobreak"},"\\space":{},"\\nobreakspace":{className:"nobreak"}};oe({type:"spacing",mathmlBuilder(e,t){let r;if(Object.prototype.hasOwnProperty.call(to,e.text))r=new p.MathNode("mtext",[new p.TextNode(" ")]);else if(Object.prototype.hasOwnProperty.call(eo,e.text))r=new p.MathNode("mo"),e.text==="\\nobreak"&&r.setAttribute("linebreak","nobreak");else throw new v(`Unknown type of space "${e.text}"`);return r}});oe({type:"tag"});const Et={"\\text":void 0,"\\textrm":"textrm","\\textsf":"textsf","\\texttt":"texttt","\\textnormal":"textrm","\\textsc":"textsc"},Lt={"\\textbf":"textbf","\\textmd":"textmd"},ro={"\\textit":"textit","\\textup":"textup"},no=(e,t)=>{const r=e.font;if(r){if(Et[r])return t.withTextFontFamily(Et[r]);if(Lt[r])return t.withTextFontWeight(Lt[r]);if(r==="\\emph")return t.fontShape==="textit"?t.withTextFontShape("textup"):t.withTextFontShape("textit")}else return t;return t.withTextFontShape(ro[r])};S({type:"text",names:["\\text","\\textrm","\\textsf","\\texttt","\\textnormal","\\textsc","\\textbf","\\textmd","\\textit","\\textup","\\emph"],props:{numArgs:1,argTypes:["text"],allowedInArgument:!0,allowedInText:!0},handler({parser:e,funcName:t},r){const o=r[0];return{type:"text",mode:e.mode,body:j(o),font:t}},mathmlBuilder(e,t){const r=no(e,t),o=re(e.body,r);return Ne(o)}});S({type:"vcenter",names:["\\vcenter"],props:{numArgs:1,argTypes:["original"],allowedInText:!1},handler({parser:e},t){return{type:"vcenter",mode:e.mode,body:t[0]}},mathmlBuilder(e,t){const r=new p.MathNode("mtd",[M(e.body,t)]);r.style.padding="0";const o=new p.MathNode("mtr",[r]);return new p.MathNode("mtable",[o])}});S({type:"verb",names:["\\verb"],props:{numArgs:0,allowedInText:!0},handler(e,t,r){throw new v("\\verb ended by end of line instead of matching delimiter")},mathmlBuilder(e,t){const r=new p.TextNode(oo(e)),o=new p.MathNode("mtext",[r]);return o.setAttribute("mathvariant","monospace"),o}});const oo=e=>e.body.replace(/ /g,e.star?"␣":" "),ne=Rt,fr=`[ \r ]`,ao="\\\\[a-zA-Z@]+",so="\\\\[^\uD800-\uDFFF]",io=`(${ao})${fr}*`,lo=`\\\\( |[ \r ]+ ?)[ \r ]*`,He="[̀-ͯ]",zt=new RegExp(`${He}+$`),uo=`(${fr}+)|${lo}|([!-\\[\\]-‧‪-퟿豈-￿]${He}*|[\uD800-\uDBFF][\uDC00-\uDFFF]${He}*|\\\\verb\\*([^]).*?\\4|\\\\verb([^*a-zA-Z]).*?\\5|${io}|${so})`;class Ft{constructor(t,r){this.input=t,this.settings=r,this.tokenRegex=new RegExp(uo,"g"),this.catcodes={"%":14,"~":13}}setCatcode(t,r){this.catcodes[t]=r}lex(){const t=this.input,r=this.tokenRegex.lastIndex;if(r===t.length)return new J("EOF",new H(this,r,r));const o=this.tokenRegex.exec(t);if(o===null||o.index!==r)throw new v(`Unexpected character: '${t[r]}'`,new J(t[r],new H(this,r,r+1)));const s=o[6]||o[3]||(o[2]?"\\ ":" ");if(this.catcodes[s]===14){const i=t.indexOf(` `,this.tokenRegex.lastIndex);if(i===-1){if(this.tokenRegex.lastIndex=t.length,this.settings.strict)throw new v("% comment has no terminating newline; LaTeX would fail because of commenting the end of math mode")}else this.tokenRegex.lastIndex=i+1;return this.lex()}return new J(s,new H(this,r,this.tokenRegex.lastIndex))}}class co{constructor(t={},r={}){this.current=r,this.builtins=t,this.undefStack=[]}beginGroup(){this.undefStack.push({})}endGroup(){if(this.undefStack.length===0)throw new v("Unbalanced namespace destruction: attempt to pop global namespace; please report this as a bug");const t=this.undefStack.pop();for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&(t[r]===void 0?delete this.current[r]:this.current[r]=t[r])}has(t){return Object.prototype.hasOwnProperty.call(this.current,t)||Object.prototype.hasOwnProperty.call(this.builtins,t)}get(t){return Object.prototype.hasOwnProperty.call(this.current,t)?this.current[t]:this.builtins[t]}set(t,r,o=!1){if(o){for(let s=0;s0&&(this.undefStack[this.undefStack.length-1][t]=r)}else{const s=this.undefStack[this.undefStack.length-1];s&&!Object.prototype.hasOwnProperty.call(s,t)&&(s[t]=this.current[t])}this.current[t]=r}}const gr={"^":!0,_:!0,"\\limits":!0,"\\nolimits":!0};class ho{constructor(t,r,o){this.settings=r,this.expansionCount=0,this.feed(t),this.macros=new co(cn,r.macros),this.mode=o,this.stack=[]}feed(t){this.lexer=new Ft(t,this.settings)}switchMode(t){this.mode=t}beginGroup(){this.macros.beginGroup()}endGroup(){this.macros.endGroup()}future(){return this.stack.length===0&&this.pushToken(this.lexer.lex()),this.stack[this.stack.length-1]}popToken(){return this.future(),this.stack.pop()}pushToken(t){this.stack.push(t)}pushTokens(t){this.stack.push(...t)}scanArgument(t){let r,o,s;if(t){if(this.consumeSpaces(),this.future().text!=="[")return null;r=this.popToken(),{tokens:s,end:o}=this.consumeArg(["]"])}else({tokens:s,start:r,end:o}=this.consumeArg());return this.pushToken(new J("EOF",o.loc)),this.pushTokens(s),r.range(o,"")}consumeSpaces(){for(;this.future().text===" ";)this.stack.pop()}consumeArg(t){const r=[],o=t&&t.length>0;o||this.consumeSpaces();const s=this.future();let i,l=0,u=0;do{if(i=this.popToken(),r.push(i),i.text==="{")++l;else if(i.text==="}"){if(--l,l===-1)throw new v("Extra }",i)}else if(i.text==="EOF")throw new v("Unexpected end of input in a macro argument, expected '"+(t&&o?t[u]:"}")+"'",i);if(t&&o)if((l===0||l===1&&t[u]==="{")&&i.text===t[u]){if(++u,u===t.length){r.splice(-u,u);break}}else u=0}while(l!==0||o);return s.text==="{"&&r[r.length-1].text==="}"&&(r.pop(),r.shift()),r.reverse(),{tokens:r,start:s,end:i}}consumeArgs(t,r){if(r){if(r.length!==t+1)throw new v("The length of delimiters doesn't match the number of args!");const s=r[0];for(let i=0;ithis.settings.maxExpand)throw new v("Too many expansions: infinite loop or need to increase maxExpand setting");let i=s.tokens;const l=this.consumeArgs(s.numArgs,s.delimiters);if(s.numArgs){i=i.slice();for(let u=i.length-1;u>=0;--u){let m=i[u];if(m.text==="#"){if(u===0)throw new v("Incomplete placeholder at end of macro body",m);if(m=i[--u],m.text==="#")i.splice(u+1,1);else if(/^[1-9]$/.test(m.text))i.splice(u,2,...l[+m.text-1]);else throw new v("Not a valid argument number",m)}}}return this.pushTokens(i),i.length}expandAfterFuture(){return this.expandOnce(),this.future()}expandNextToken(){for(;;)if(this.expandOnce()===!1){const t=this.stack.pop();return t.treatAsRelax&&(t.text="\\relax"),t}throw new Error}expandMacro(t){return this.macros.has(t)?this.expandTokens([new J(t)]):void 0}expandTokens(t){const r=[],o=this.stack.length;for(this.pushTokens(t);this.stack.length>o;)if(this.expandOnce(!0)===!1){const s=this.stack.pop();s.treatAsRelax&&(s.noexpand=!1,s.treatAsRelax=!1),r.push(s)}return r}expandMacroAsText(t){const r=this.expandMacro(t);return r&&r.map(o=>o.text).join("")}_getExpansion(t){const r=this.macros.get(t);if(r==null)return r;if(t.length===1){const s=this.lexer.catcodes[t];if(s!=null&&s!==13)return}const o=typeof r=="function"?r(this):r;if(typeof o=="string"){let s=0;if(o.indexOf("#")!==-1){const f=o.replace(/##/g,"");for(;f.indexOf("#"+(s+1))!==-1;)++s}const i=new Ft(o,this.settings),l=[];let u=i.lex();for(;u.text!=="EOF";)l.push(u),u=i.lex();return l.reverse(),{tokens:l,numArgs:s}}return o}isDefined(t){return this.macros.has(t)||Object.prototype.hasOwnProperty.call(ne,t)||Object.prototype.hasOwnProperty.call(G.math,t)||Object.prototype.hasOwnProperty.call(G.text,t)||Object.prototype.hasOwnProperty.call(gr,t)}isExpandable(t){const r=this.macros.get(t);return r!=null?typeof r=="string"||typeof r=="function"||!r.unexpandable:Object.prototype.hasOwnProperty.call(ne,t)&&!ne[t].primitive}}const It=/^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/,Se=Object.freeze({"₊":"+","₋":"-","₌":"=","₍":"(","₎":")","₀":"0","₁":"1","₂":"2","₃":"3","₄":"4","₅":"5","₆":"6","₇":"7","₈":"8","₉":"9","ₐ":"a","ₑ":"e","ₕ":"h","ᵢ":"i","ⱼ":"j","ₖ":"k","ₗ":"l","ₘ":"m","ₙ":"n","ₒ":"o","ₚ":"p","ᵣ":"r","ₛ":"s","ₜ":"t","ᵤ":"u","ᵥ":"v","ₓ":"x","ᵦ":"β","ᵧ":"γ","ᵨ":"ρ","ᵩ":"ϕ","ᵪ":"χ","⁺":"+","⁻":"-","⁼":"=","⁽":"(","⁾":")","⁰":"0","¹":"1","²":"2","³":"3","⁴":"4","⁵":"5","⁶":"6","⁷":"7","⁸":"8","⁹":"9","ᴬ":"A","ᴮ":"B","ᴰ":"D","ᴱ":"E","ᴳ":"G","ᴴ":"H","ᴵ":"I","ᴶ":"J","ᴷ":"K","ᴸ":"L","ᴹ":"M","ᴺ":"N","ᴼ":"O","ᴾ":"P","ᴿ":"R","ᵀ":"T","ᵁ":"U","ⱽ":"V","ᵂ":"W","ᵃ":"a","ᵇ":"b","ᶜ":"c","ᵈ":"d","ᵉ":"e","ᶠ":"f","ᵍ":"g",ʰ:"h","ⁱ":"i",ʲ:"j","ᵏ":"k",ˡ:"l","ᵐ":"m",ⁿ:"n","ᵒ":"o","ᵖ":"p",ʳ:"r",ˢ:"s","ᵗ":"t","ᵘ":"u","ᵛ":"v",ʷ:"w",ˣ:"x",ʸ:"y","ᶻ":"z","ᵝ":"β","ᵞ":"γ","ᵟ":"δ","ᵠ":"ϕ","ᵡ":"χ","ᶿ":"θ"}),Pt=Object.freeze({"𝒜":"A",ℬ:"B","𝒞":"C","𝒟":"D",ℰ:"E",ℱ:"F","𝒢":"G",ℋ:"H",ℐ:"I","𝒥":"J","𝒦":"K",ℒ:"L",ℳ:"M","𝒩":"N","𝒪":"O","𝒫":"P","𝒬":"Q",ℛ:"R","𝒮":"S","𝒯":"T","𝒰":"U","𝒱":"V","𝒲":"W","𝒳":"X","𝒴":"Y","𝒵":"Z"});var Fe={"́":{text:"\\'",math:"\\acute"},"̀":{text:"\\`",math:"\\grave"},"̈":{text:'\\"',math:"\\ddot"},"̃":{text:"\\~",math:"\\tilde"},"̄":{text:"\\=",math:"\\bar"},"̆":{text:"\\u",math:"\\breve"},"̌":{text:"\\v",math:"\\check"},"̂":{text:"\\^",math:"\\hat"},"̇":{text:"\\.",math:"\\dot"},"̊":{text:"\\r",math:"\\mathring"},"̋":{text:"\\H"},"̧":{text:"\\c"}},Gt={á:"á",à:"à",ä:"ä",ǟ:"ǟ",ã:"ã",ā:"ā",ă:"ă",ắ:"ắ",ằ:"ằ",ẵ:"ẵ",ǎ:"ǎ",â:"â",ấ:"ấ",ầ:"ầ",ẫ:"ẫ",ȧ:"ȧ",ǡ:"ǡ",å:"å",ǻ:"ǻ",ḃ:"ḃ",ć:"ć",č:"č",ĉ:"ĉ",ċ:"ċ",ď:"ď",ḋ:"ḋ",é:"é",è:"è",ë:"ë",ẽ:"ẽ",ē:"ē",ḗ:"ḗ",ḕ:"ḕ",ĕ:"ĕ",ě:"ě",ê:"ê",ế:"ế",ề:"ề",ễ:"ễ",ė:"ė",ḟ:"ḟ",ǵ:"ǵ",ḡ:"ḡ",ğ:"ğ",ǧ:"ǧ",ĝ:"ĝ",ġ:"ġ",ḧ:"ḧ",ȟ:"ȟ",ĥ:"ĥ",ḣ:"ḣ",í:"í",ì:"ì",ï:"ï",ḯ:"ḯ",ĩ:"ĩ",ī:"ī",ĭ:"ĭ",ǐ:"ǐ",î:"î",ǰ:"ǰ",ĵ:"ĵ",ḱ:"ḱ",ǩ:"ǩ",ĺ:"ĺ",ľ:"ľ",ḿ:"ḿ",ṁ:"ṁ",ń:"ń",ǹ:"ǹ",ñ:"ñ",ň:"ň",ṅ:"ṅ",ó:"ó",ò:"ò",ö:"ö",ȫ:"ȫ",õ:"õ",ṍ:"ṍ",ṏ:"ṏ",ȭ:"ȭ",ō:"ō",ṓ:"ṓ",ṑ:"ṑ",ŏ:"ŏ",ǒ:"ǒ",ô:"ô",ố:"ố",ồ:"ồ",ỗ:"ỗ",ȯ:"ȯ",ȱ:"ȱ",ő:"ő",ṕ:"ṕ",ṗ:"ṗ",ŕ:"ŕ",ř:"ř",ṙ:"ṙ",ś:"ś",ṥ:"ṥ",š:"š",ṧ:"ṧ",ŝ:"ŝ",ṡ:"ṡ",ẗ:"ẗ",ť:"ť",ṫ:"ṫ",ú:"ú",ù:"ù",ü:"ü",ǘ:"ǘ",ǜ:"ǜ",ǖ:"ǖ",ǚ:"ǚ",ũ:"ũ",ṹ:"ṹ",ū:"ū",ṻ:"ṻ",ŭ:"ŭ",ǔ:"ǔ",û:"û",ů:"ů",ű:"ű",ṽ:"ṽ",ẃ:"ẃ",ẁ:"ẁ",ẅ:"ẅ",ŵ:"ŵ",ẇ:"ẇ",ẘ:"ẘ",ẍ:"ẍ",ẋ:"ẋ",ý:"ý",ỳ:"ỳ",ÿ:"ÿ",ỹ:"ỹ",ȳ:"ȳ",ŷ:"ŷ",ẏ:"ẏ",ẙ:"ẙ",ź:"ź",ž:"ž",ẑ:"ẑ",ż:"ż",Á:"Á",À:"À",Ä:"Ä",Ǟ:"Ǟ",Ã:"Ã",Ā:"Ā",Ă:"Ă",Ắ:"Ắ",Ằ:"Ằ",Ẵ:"Ẵ",Ǎ:"Ǎ",Â:"Â",Ấ:"Ấ",Ầ:"Ầ",Ẫ:"Ẫ",Ȧ:"Ȧ",Ǡ:"Ǡ",Å:"Å",Ǻ:"Ǻ",Ḃ:"Ḃ",Ć:"Ć",Č:"Č",Ĉ:"Ĉ",Ċ:"Ċ",Ď:"Ď",Ḋ:"Ḋ",É:"É",È:"È",Ë:"Ë",Ẽ:"Ẽ",Ē:"Ē",Ḗ:"Ḗ",Ḕ:"Ḕ",Ĕ:"Ĕ",Ě:"Ě",Ê:"Ê",Ế:"Ế",Ề:"Ề",Ễ:"Ễ",Ė:"Ė",Ḟ:"Ḟ",Ǵ:"Ǵ",Ḡ:"Ḡ",Ğ:"Ğ",Ǧ:"Ǧ",Ĝ:"Ĝ",Ġ:"Ġ",Ḧ:"Ḧ",Ȟ:"Ȟ",Ĥ:"Ĥ",Ḣ:"Ḣ",Í:"Í",Ì:"Ì",Ï:"Ï",Ḯ:"Ḯ",Ĩ:"Ĩ",Ī:"Ī",Ĭ:"Ĭ",Ǐ:"Ǐ",Î:"Î",İ:"İ",Ĵ:"Ĵ",Ḱ:"Ḱ",Ǩ:"Ǩ",Ĺ:"Ĺ",Ľ:"Ľ",Ḿ:"Ḿ",Ṁ:"Ṁ",Ń:"Ń",Ǹ:"Ǹ",Ñ:"Ñ",Ň:"Ň",Ṅ:"Ṅ",Ó:"Ó",Ò:"Ò",Ö:"Ö",Ȫ:"Ȫ",Õ:"Õ",Ṍ:"Ṍ",Ṏ:"Ṏ",Ȭ:"Ȭ",Ō:"Ō",Ṓ:"Ṓ",Ṑ:"Ṑ",Ŏ:"Ŏ",Ǒ:"Ǒ",Ô:"Ô",Ố:"Ố",Ồ:"Ồ",Ỗ:"Ỗ",Ȯ:"Ȯ",Ȱ:"Ȱ",Ő:"Ő",Ṕ:"Ṕ",Ṗ:"Ṗ",Ŕ:"Ŕ",Ř:"Ř",Ṙ:"Ṙ",Ś:"Ś",Ṥ:"Ṥ",Š:"Š",Ṧ:"Ṧ",Ŝ:"Ŝ",Ṡ:"Ṡ",Ť:"Ť",Ṫ:"Ṫ",Ú:"Ú",Ù:"Ù",Ü:"Ü",Ǘ:"Ǘ",Ǜ:"Ǜ",Ǖ:"Ǖ",Ǚ:"Ǚ",Ũ:"Ũ",Ṹ:"Ṹ",Ū:"Ū",Ṻ:"Ṻ",Ŭ:"Ŭ",Ǔ:"Ǔ",Û:"Û",Ů:"Ů",Ű:"Ű",Ṽ:"Ṽ",Ẃ:"Ẃ",Ẁ:"Ẁ",Ẅ:"Ẅ",Ŵ:"Ŵ",Ẇ:"Ẇ",Ẍ:"Ẍ",Ẋ:"Ẋ",Ý:"Ý",Ỳ:"Ỳ",Ÿ:"Ÿ",Ỹ:"Ỹ",Ȳ:"Ȳ",Ŷ:"Ŷ",Ẏ:"Ẏ",Ź:"Ź",Ž:"Ž",Ẑ:"Ẑ",Ż:"Ż",ά:"ά",ὰ:"ὰ",ᾱ:"ᾱ",ᾰ:"ᾰ",έ:"έ",ὲ:"ὲ",ή:"ή",ὴ:"ὴ",ί:"ί",ὶ:"ὶ",ϊ:"ϊ",ΐ:"ΐ",ῒ:"ῒ",ῑ:"ῑ",ῐ:"ῐ",ό:"ό",ὸ:"ὸ",ύ:"ύ",ὺ:"ὺ",ϋ:"ϋ",ΰ:"ΰ",ῢ:"ῢ",ῡ:"ῡ",ῠ:"ῠ",ώ:"ώ",ὼ:"ὼ",Ύ:"Ύ",Ὺ:"Ὺ",Ϋ:"Ϋ",Ῡ:"Ῡ",Ῠ:"Ῠ",Ώ:"Ώ",Ὼ:"Ὼ"};const mo=["bin","op","open","punct","rel"],po=/([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/,fo=/^ *\\text/;class Oe{constructor(t,r,o=!1){this.mode="math",this.gullet=new ho(t,r,this.mode),this.settings=r,this.isPreamble=o,this.leftrightDepth=0,this.prevAtomType=""}expect(t,r=!0){if(this.fetch().text!==t)throw new v(`Expected '${t}', got '${this.fetch().text}'`,this.fetch());r&&this.consume()}consume(){this.nextToken=null}fetch(){return this.nextToken==null&&(this.nextToken=this.gullet.expandNextToken()),this.nextToken}switchMode(t){this.mode=t,this.gullet.switchMode(t)}parse(){this.gullet.beginGroup(),this.settings.colorIsTextColor&&this.gullet.macros.set("\\color","\\textcolor");const t=this.parseExpression(!1);if(this.expect("EOF"),this.isPreamble){const o=Object.create(null);return Object.entries(this.gullet.macros.current).forEach(([s,i])=>{o[s]=i}),this.gullet.endGroup(),o}const r=this.gullet.macros.get("\\df@tag");return this.gullet.endGroup(),r&&(this.gullet.macros.current["\\df@tag"]=r),t}static get endOfExpression(){return["}","\\endgroup","\\end","\\right","\\endtoggle","&"]}subparse(t){const r=this.nextToken;this.consume(),this.gullet.pushToken(new J("}")),this.gullet.pushTokens(t);const o=this.parseExpression(!1);return this.expect("}"),this.nextToken=r,o}parseExpression(t,r,o){const s=[];for(this.prevAtomType="";;){this.mode==="math"&&this.consumeSpaces();const i=this.fetch();if(Oe.endOfExpression.indexOf(i.text)!==-1||r&&i.text===r||o&&i.text==="\\middle"||t&&ne[i.text]&&ne[i.text].infix)break;const l=this.parseAtom(r);if(l){if(l.type==="internal")continue}else break;s.push(l),this.prevAtomType=l.type==="atom"?l.family:l.type}return this.mode==="text"&&this.formLigatures(s),this.handleInfixNodes(s)}handleInfixNodes(t){let r=-1,o;for(let s=0;s=128||zt.exec(r)){if(this.settings.strict&&this.mode==="math")throw new v(`Unicode text character "${r[0]}" used in math mode`,t);s={type:"textord",mode:"text",loc:H.range(t),text:r}}else return null;if(this.consume(),o)for(let i=0;i0&&o[0].type&&o[0].type==="array"&&o[0].addEqnNum)&&r.gullet.macros.get("\\df@tag")){if(!t.displayMode)throw new v("\\tag works only in display mode");r.gullet.feed("\\df@tag"),o=[{type:"tag",mode:"text",body:o,tag:r.parse()}]}return o},go=[2,2,3,3];class ot{constructor(t){this.level=t.level,this.color=t.color,this.font=t.font||"",this.fontFamily=t.fontFamily||"",this.fontSize=t.fontSize||1,this.fontWeight=t.fontWeight||"",this.fontShape=t.fontShape||"",this.maxSize=t.maxSize}extend(t){const r={level:this.level,color:this.color,font:this.font,fontFamily:this.fontFamily,fontSize:this.fontSize,fontWeight:this.fontWeight,fontShape:this.fontShape,maxSize:this.maxSize};for(const o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o]);return new ot(r)}withLevel(t){return this.extend({level:t})}incrementLevel(){return this.extend({level:Math.min(this.level+1,3)})}inSubOrSup(){return this.extend({level:go[this.level]})}withColor(t){return this.extend({color:t})}withFont(t){return this.extend({font:t})}withTextFontFamily(t){return this.extend({fontFamily:t,font:""})}withFontSize(t){return this.extend({fontSize:t})}withTextFontWeight(t){return this.extend({fontWeight:t,font:""})}withTextFontShape(t){return this.extend({fontShape:t,font:""})}getColor(){return this.color}}const bo="0.11.09";function xr(e){const t={};let r=0;const o=document.getElementsByClassName("tml-eqn");for(let l of o)for(r+=1,l.setAttribute("id","tml-eqn-"+String(r));l.tagName!=="mtable";)if(l.getElementsByClassName("tml-label").length>0){const m=l.attributes.id.value;t[m]=String(r);break}else l=l.parentElement;const s=document.getElementsByClassName("tml-tageqn");for(const l of s)if(l.getElementsByClassName("tml-label").length>0){const m=l.getElementsByClassName("tml-tag");if(m.length>0){const f=l.attributes.id.value;t[f]=m[0].textContent}}[...e.getElementsByClassName("tml-ref")].forEach(l=>{const u=l.getAttribute("href");let m=t[u.slice(1)];l.className.indexOf("tml-eqref")===-1?(m=m.replace(/^\(/,""),m=m.replace(/\)$/,"")):(m.charAt(0)!=="("&&(m="("+m),m.slice(-1)!==")"&&(m=m+")"));const f=document.createElementNS("http://www.w3.org/1998/Math/MathML","mtext");f.appendChild(document.createTextNode(m));const A=document.createElementNS("http://www.w3.org/1998/Math/MathML","math");A.appendChild(f),l.textContent="",l.appendChild(A)})}const xo=function(e,t,r){let o=r,s=0;const i=e.length;for(;oyo(i.left)).join("|")+")");for(;r=e.search(s),r!==-1;){r>0&&(o.push({type:"text",data:e.slice(0,r)}),e=e.slice(r));const i=t.findIndex(m=>e.startsWith(m.left));if(r=xo(t[i].right,e,t[i].left.length),r===-1)break;const l=e.slice(0,r+t[i].right.length),u=wo.test(l)?l:e.slice(t[i].left.length,r);o.push({type:"math",data:u,rawData:l,display:t[i].display}),e=e.slice(r+t[i].right.length)}return e!==""&&o.push({type:"text",data:e}),o},yr=[{left:"$$",right:"$$",display:!0},{left:"\\(",right:"\\)",display:!1},{left:"\\begin{equation}",right:"\\end{equation}",display:!0},{left:"\\begin{equation*}",right:"\\end{equation*}",display:!0},{left:"\\begin{align}",right:"\\end{align}",display:!0},{left:"\\begin{align*}",right:"\\end{align*}",display:!0},{left:"\\begin{alignat}",right:"\\end{alignat}",display:!0},{left:"\\begin{alignat*}",right:"\\end{alignat*}",display:!0},{left:"\\begin{gather}",right:"\\end{gather}",display:!0},{left:"\\begin{gather*}",right:"\\end{gather*}",display:!0},{left:"\\begin{CD}",right:"\\end{CD}",display:!0},{left:"\\ref{",right:"}",display:!1},{left:"\\eqref{",right:"}",display:!1},{left:"\\[",right:"\\]",display:!0}],qe={$:[{left:"$$",right:"$$",display:!0},{left:"$`",right:"`$",display:!1},{left:"$",right:"$",display:!1}],"(":[{left:"\\[",right:"\\]",display:!0},{left:"\\(",right:"\\)",display:!1}]},Ie=[{left:"\\begin{equation}",right:"\\end{equation}",display:!0},{left:"\\begin{equation*}",right:"\\end{equation*}",display:!0},{left:"\\begin{align}",right:"\\end{align}",display:!0},{left:"\\begin{align*}",right:"\\end{align*}",display:!0},{left:"\\begin{alignat}",right:"\\end{alignat}",display:!0},{left:"\\begin{alignat*}",right:"\\end{alignat*}",display:!0},{left:"\\begin{gather}",right:"\\end{gather}",display:!0},{left:"\\begin{gather*}",right:"\\end{gather*}",display:!0},{left:"\\begin{CD}",right:"\\end{CD}",display:!0},{left:"\\ref{",right:"}",display:!1},{left:"\\eqref{",right:"}",display:!1}],Ao=e=>e==="$"||e==="("?qe[e]:e==="$+"||e==="(+"?qe[e.slice(0,1)].concat(Ie):e==="ams"?Ie:e==="all"?qe["("].concat(qe.$).concat(Ie):yr,ko=function(e,t){const r=vo(e,t.delimiters);if(r.length===1&&r[0].type==="text")return null;const o=document.createDocumentFragment();for(let s=0;ss.indexOf(" "+l+" ")===-1)&&wr(o,t)}}},So=function(e,t){if(!e)throw new Error("No element provided to render");const r={};for(const o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o]);r.fences?r.delimiters=Ao(r.fences):r.delimiters=r.delimiters||yr,r.ignoredTags=r.ignoredTags||["script","noscript","style","textarea","pre","code","option"],r.ignoredClasses=r.ignoredClasses||[],r.errorCallback=r.errorCallback||console.error,r.macros=r.macros||{},wr(e,r),xr(e)};let vr=function(e,t,r={}){t.textContent="";const o=t.tagName.toLowerCase()==="math";o&&(r.wrap="none");const s=at(e,r);o?(t.textContent="",s.children.forEach(i=>{t.appendChild(i.toNode())})):s.children.length>1?(t.textContent="",s.children.forEach(i=>{t.appendChild(i.toNode())})):t.appendChild(s.toNode())};typeof document<"u"&&document.compatMode!=="CSS1Compat"&&(typeof console<"u"&&console.warn("Warning: Temml doesn't work in quirks mode. Make sure your website has a suitable doctype."),vr=function(){throw new v("Temml doesn't work in quirks mode.")});const qo=function(e,t){return at(e,t).toMarkup()},_o=function(e,t){const r=new We(t);return br(e,r)},To=function(e,t){const r=new We(t);if(r.macros={},!(typeof e=="string"||e instanceof String))throw new TypeError("Temml can only parse string typed expression");const o=new Oe(e,r,!0);return delete o.gullet.macros.current["\\df@tag"],o.parse()},Do=function(e,t,r){if(r.throwOnError||!(e instanceof v))throw e;const o=new jt(["temml-error"],[new Er(t+` `+e.toString())]);return o.style.color=r.errorColor,o.style.whiteSpace="pre-line",o},at=function(e,t){const r=new We(t);try{const o=br(e,r),s=new ot({level:r.displayMode?P.DISPLAY:P.TEXT,maxSize:r.maxSize});return Yr(o,e,s,r)}catch(o){return Do(o,e,r)}};var No={version:bo,render:vr,renderToString:qo,renderMathInElement:So,postProcess:xr,ParseError:v,definePreamble:To,__parse:_o,__renderToMathMLTree:at,__defineSymbol:n,__defineMacro:c};export{No as default}; //# sourceMappingURL=temml-BWesIjnj.js.map