class v{constructor(t,r){let o=" "+t,s;const i=r&&r.loc;if(i&&i.start<=i.end){const c=i.lexer.input;s=i.start;const h=i.end;s===c.length?o+=" at end of input: ":o+=" at position "+(s+1)+`: `;const f=c.slice(s,h).replace(/[^]/g,"$&̲");let k;s>15?k="…"+c.slice(s-15,s):k=c.slice(0,s);let x;h+15":">","<":"<",'"':""","'":"'"},Cr=/[&><"']/g;function te(e){return String(e).replace(Cr,t=>Tr[t])}const _e=function(e){return e.type==="ordgroup"||e.type==="color"?e.body.length===1?_e(e.body[0]):e:e.type==="font"?_e(e.body):e},Be=function(e){const t=_e(e);return t.type==="mathord"||t.type==="textord"||t.type==="atom"},Dr=function(e){if(!e)throw new Error("Expected non-null, but got "+String(e));return e},Br=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"},Fe=function(e){return+e.toFixed(4)},Vt="acegıȷmnopqrsuvwxyzαγεηικμνοπρςστυχωϕ𝐚𝐜𝐞𝐠𝐦𝐧𝐨𝐩𝐪𝐫𝐬𝐮𝐯𝐰𝐱𝐲𝐳";class Ke{constructor(t){t=t||{},this.displayMode=K(t.displayMode,!1),this.annotate=K(t.annotate,!1),this.leqno=K(t.leqno,!1),this.throwOnError=K(t.throwOnError,!1),this.errorColor=K(t.errorColor,"#b22222"),this.macros=t.macros||{},this.wrap=K(t.wrap,"none"),this.xml=K(t.xml,!1),this.colorIsTextColor=K(t.colorIsTextColor,!1),this.strict=K(t.strict,!1),this.trust=K(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,K(t.maxExpand,1e3))}isTrusted(t){if(t.url&&!t.protocol){const o=Br(t.url);if(o==null)return!1;t.protocol=o}return!!(typeof this.trust=="function"?this.trust(t):this.trust)}}const Wt={},Te={};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 de=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=de(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 Ht{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 Er.call(this,"span")}}let zr=class{constructor(t){this.text=t}toNode(){return document.createTextNode(this.text)}toMarkup(){return te(this.text)}};class Zt{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=de(this.classes));for(let r=0;r0&&(t+=` class="${te(de(this.classes))}"`),t+=">";for(let r=0;r0&&(t.className=de(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="${te(de(this.classes))}"`);let r="";for(const o in this.style)Object.prototype.hasOwnProperty.call(this.style,o)&&(r+=`${Ye(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 j{constructor(t){this.text=t}toNode(){return document.createTextNode(this.text)}toMarkup(){return te(this.toText())}toText(){return this.text}}const Qe=e=>{let t;return e.length===1&&e[0].type==="mrow"?(t=e.pop(),t.type="mstyle"):t=new p("mstyle",e),t},ce=e=>{let t=0;if(e.body&&Array.isArray(e.body))for(const r of e.body)t+=ce(r);else if(e.body)t+=ce(e.body);else if(e.type==="supsub")t+=ce(e.base),e.sub&&(t+=.7*ce(e.sub)),e.sup&&(t+=.7*ce(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=et(e.label);if(Ir.includes(e.label)){const r=ce(e.base);1","\\gt",!0);n(a,m,"∈","\\in",!0);n(a,m,"∉","\\notin",!0);n(a,m,"","\\@not");n(a,m,"⊂","\\subset",!0);n(a,m,"⊃","\\supset",!0);n(a,m,"⊆","\\subseteq",!0);n(a,m,"⊇","\\supseteq",!0);n(a,m,"⊈","\\nsubseteq",!0);n(a,m,"⊈","\\nsubseteqq");n(a,m,"⊉","\\nsupseteq",!0);n(a,m,"⊉","\\nsupseteqq");n(a,m,"⊨","\\models");n(a,m,"←","\\leftarrow",!0);n(a,m,"≤","\\le");n(a,m,"≤","\\leq",!0);n(a,m,"<","\\lt",!0);n(a,m,"→","\\rightarrow",!0);n(a,m,"→","\\to");n(a,m,"≱","\\ngeq",!0);n(a,m,"≱","\\ngeqq");n(a,m,"≱","\\ngeqslant");n(a,m,"≰","\\nleq",!0);n(a,m,"≰","\\nleqq");n(a,m,"≰","\\nleqslant");n(a,m,"⫫","\\Perp",!0);n(a,re," ","\\ ");n(a,re," ","\\space");n(a,re," ","\\nobreakspace");n(g,re," ","\\ ");n(g,re," "," ");n(g,re," ","\\space");n(g,re," ","\\nobreakspace");n(a,re,null,"\\nobreak");n(a,re,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,G,"{","\\{");n(g,d,"{","\\{");n(g,d,"{","\\textbraceleft");n(a,I,"}","\\}");n(g,d,"}","\\}");n(g,d,"}","\\textbraceright");n(a,G,"{","\\lbrace");n(a,I,"}","\\rbrace");n(a,G,"[","\\lbrack",!0);n(g,d,"[","\\lbrack",!0);n(a,I,"]","\\rbrack",!0);n(g,d,"]","\\rbrack",!0);n(a,G,"(","\\lparen",!0);n(a,I,")","\\rparen",!0);n(a,G,"⦇","\\llparenthesis",!0);n(a,I,"⦈","\\rrparenthesis",!0);n(g,d,"<","\\textless",!0);n(g,d,">","\\textgreater",!0);n(a,G,"⌊","\\lfloor",!0);n(a,I,"⌋","\\rfloor",!0);n(a,G,"⌈","\\lceil",!0);n(a,I,"⌉","\\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,m,"↑","\\uparrow",!0);n(a,m,"⇑","\\Uparrow",!0);n(a,m,"↓","\\downarrow",!0);n(a,m,"⇓","\\Downarrow",!0);n(a,m,"↕","\\updownarrow",!0);n(a,m,"⇕","\\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,ie,"…","\\textellipsis");n(a,ie,"…","\\mathellipsis");n(g,ie,"…","\\ldots",!0);n(a,ie,"…","\\ldots",!0);n(a,ie,"⋰","\\iddots",!0);n(a,ie,"⋯","\\@cdots",!0);n(a,ie,"⋱","\\ddots",!0);n(a,d,"⋮","\\varvdots");n(g,d,"⋮","\\varvdots");n(a,O,"´","\\acute");n(a,O,"`","\\grave");n(a,O,"¨","\\ddot");n(a,O,"…","\\dddot");n(a,O,"….","\\ddddot");n(a,O,"~","\\tilde");n(a,O,"‾","\\bar");n(a,O,"˘","\\breve");n(a,O,"ˇ","\\check");n(a,O,"^","\\hat");n(a,O,"→","\\vec");n(a,O,"˙","\\dot");n(a,O,"˚","\\mathring");n(a,A,"ı","\\imath",!0);n(a,A,"ȷ","\\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,A,"ø","\\o",!0);n(g,d,"Ø","\\O",!0);n(a,A,"Ø","\\O",!0);n(g,O,"ˊ","\\'");n(g,O,"ˋ","\\`");n(g,O,"ˆ","\\^");n(g,O,"~","\\~");n(g,O,"ˉ","\\=");n(g,O,"˘","\\u");n(g,O,"˙","\\.");n(g,O,"¸","\\c");n(g,O,"˚","\\r");n(g,O,"ˇ","\\v");n(g,O,"¨",'\\"');n(g,O,"˝","\\H");n(a,O,"ˊ","\\'");n(a,O,"ˋ","\\`");n(a,O,"ˆ","\\^");n(a,O,"~","\\~");n(a,O,"ˉ","\\=");n(a,O,"˘","\\u");n(a,O,"˙","\\.");n(a,O,"¸","\\c");n(a,O,"˚","\\r");n(a,O,"ˇ","\\v");n(a,O,"¨",'\\"');n(a,O,"˝","\\H");const Pr={"--":!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 ct='0123456789/@."';for(let e=0;e0&&s.push(new p("mrow",i)),s.push(f),i=[];const k=new p("mtd",s);k.style.textAlign="left",o.push(new p("mtr",[k])),s=[],c+=1;continue}if(i.push(f),f.type&&f.type==="mo"&&f.children.length===1&&!Object.prototype.hasOwnProperty.call(f.attributes,"movablelimits")){const k=f.children[0].text;if(Gr.indexOf(k)>-1)h+=1;else if(Rr.indexOf(k)>-1)h-=1;else if(h===0&&t==="="&&k==="="){if(l+=1,l>1){i.pop();const x=new p("mrow",i);s.push(x),i=[f]}}else if(h===0&&t==="tex"&&k!=="∇"){const x=c0){const f=new p("mrow",i);s.push(f)}if(o.length>0){const f=new p("mtd",s);f.style.textAlign="left";const k=new p("mtr",[f]);o.push(k);const x=new p("mtable",o);return r||(x.setAttribute("columnalign","left"),x.setAttribute("rowspacing","0em")),x}return ae(s)}const W=function(e,t,r){return P[t][e]&&P[t][e].replace&&e.charCodeAt(0)!==55349&&!(Object.prototype.hasOwnProperty.call(Pr,e)&&r&&(r.fontFamily&&r.fontFamily.slice(4,6)==="tt"||r.font&&r.font.slice(4,6)==="tt"))&&(e=P[t][e].replace),new j(e)},ht=(e,t)=>{if(e.children.length===0||e.children[e.children.length-1].type!=="mtext"){const r=new p("mtext",[new j(t.children[0].text)]);e.children.push(r)}else e.children[e.children.length-1].children[0].text+=t.children[0].text},$e=e=>{if(e.type!=="mrow"&&e.type!=="mstyle"||e.children.length===0)return e;const t=new p("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},Oe=function(e,t=!1){if(e.length===1&&!(e[0]instanceof Je))return e[0];if(!t){e[0]instanceof p&&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 p&&e[r].type==="mo"&&!e[r].attributes.fence&&(e[r].attributes.lspace="0em",e[r].attributes.rspace="0em")}return new p("mrow",e)};function Ie(e){if(!e)return!1;if(e.type==="mi"&&e.children.length===1){const t=e.children[0];return t instanceof j&&t.text==="."}else if(e.type==="mtext"&&e.children.length===1){const t=e.children[0];return t instanceof j&&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 j&&t.text===","}else return!1}const Ur=(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=E(e[0],t);return l instanceof p&&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])&&c.setAttribute("lspace","0em"),c.type==="mn"&&i&&i.type==="mn"){i.children.push(...c.children);continue}else if(Ie(c)&&i&&i.type==="mn"){i.children.push(...c.children);continue}else if(i&&i.type==="mn"&&l=1&&i&&(i.type==="mn"||Ie(i))){const h=c.children[0];h instanceof p&&h.type==="mn"&&i&&(h.children=[...i.children,...h.children],o.pop())}o.push(c),i=c}return o},ne=function(e,t,r=!1){return Oe(U(e,t,r),r)},E=function(e,t){if(!e)return new p("mrow");if(Te[e.type])return Te[e.type](e,t);throw new v("Got group of unknown type: '"+e.type+"'")},pt=e=>new p("mtd",[],[],{padding:"0",width:"50%"}),Vr=["mrow","mtd","mtable","mtr"],je=e=>{for(const t of e.children)if(t.type&&Vr.includes(t.type)){if(t.classes&&t.classes[0]==="tml-label")return t.label;{const r=je(t);if(r)return r}}else if(!t.type){const r=je(t);if(r)return r}},Wr=(e,t,r,o)=>{t=ne(t[0].body,r),t=$e(t),t.classes.push("tml-tag");const s=je(e);e=new p("mtd",[e]);const i=[pt(),e,pt()];i[o?0:2].children.push(t);const l=new p("mtr",i,["tml-tageqn"]);s&&l.setAttribute("id",s);const c=new p("mtable",[l]);return c.style.width="100%",c.setAttribute("displaystyle","true"),c};function Hr(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 Zt)return i[0];const l=o.displayMode||o.annotate?"none":o.wrap,c=i.length===0?null:i[0];let h=i.length===1&&s===null&&c instanceof p?i[0]:jr(i,l,o.displayMode);if(s&&(h=Wr(h,s,r,o.leqno)),o.annotate){const k=new p("annotation",[new j(t)]);k.setAttribute("encoding","application/x-tex"),h=new p("semantics",[h,k])}const f=new p("math",[h]);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 Zr="DHKLUcegorsuvxyzΠΥΨαδηιμνοτυχϵ",Xr="BCEGIMNOPQRSTXZlpqtwΓΘΞΣΦΩβεζθξρςφψϑϕϱ",Yr="AFJdfΔΛ",Yt=(e,t)=>{const r=e.isStretchy?Xt(e):new p("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=Jr.has(e.label);if(o==="mover"&&e.mode==="math"&&!e.isStretchy&&e.base.text&&e.base.text.length===1){const l=e.base.text,c=e.label==="\\vec",h=c==="\\vec"?"-vec":"";c&&r.classes.push("tml-vec");const f=c?"-vec":s?"-acc":"";Zr.indexOf(l)>-1?(r.classes.push(`chr-sml${h}`),r.classes.push(`wbk-sml${f}`)):Xr.indexOf(l)>-1?(r.classes.push(`chr-med${h}`),r.classes.push(`wbk-med${f}`)):Yr.indexOf(l)>-1?(r.classes.push(`chr-lrg${h}`),r.classes.push(`wbk-lrg${f}`)):c?r.classes.push("wbk-vec"):s&&r.classes.push("wbk-acc")}else s&&r.classes.push("wbk-acc");return new p(o,[E(e.base,t),r])},Kr=new Set(["\\acute","\\check","\\grave","\\ddot","\\dddot","\\ddddot","\\tilde","\\bar","\\breve","\\check","\\hat","\\vec","\\dot","\\mathring"]),Jr=new Set(["\\acute","\\bar","\\breve","\\check","\\dot","\\ddot","\\grave","\\hat","\\mathring","\\`","\\'","\\^","\\=","\\u","\\.",'\\"',"\\r","\\H","\\v"]),ft={"\\`":"̀","\\'":"́","\\^":"̂","\\~":"̃","\\=":"̄","\\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=!Kr.has(e.funcName);return{type:"accent",mode:e.parser.mode,label:e.funcName,isStretchy:o,base:r}},mathmlBuilder:Yt});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 ft&&Vt.indexOf(r.text)>-1?{type:"textord",mode:"text",text:r.text+ft[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:Yt});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=Xt(e);return r.style["math-depth"]=0,new p("munder",[E(e.base,t),r])}});const gt={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},Qr=["em","ex","mu","pt","mm","cm","in","px","bp","pc","dd","cc","nd","nc","sp"],Kt=function(e){return typeof e!="string"&&(e=e.unit),Qr.indexOf(e)>-1},Jt=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*gt[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/Jt(t.level),t.maxSize[0]),{number:Fe(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*gt[o],t.maxSize[1]),{number:Fe(r),unit:"pt"};case"mu":return r=Math.min(r/18,t.maxSize[0]),{number:Fe(r),unit:"em"};default:throw new v("Invalid unit: '"+o+"'")}},N=e=>{const t=new p("mspace");return t.setAttribute("width",e+"em"),t},ke=(e,t=.3,r=0,o=!1)=>{if(e==null&&r===0)return N(t);const s=e?[e]:[];if(t!==0&&s.unshift(N(t)),r>0&&s.push(N(r)),o){const i=new p("mpadded",s);return i.setAttribute("height","0.1px"),i}else return new p("mrow",s)},Ne=(e,t)=>Number(e)/Jt(t),Ue=(e,t,r,o)=>{const s=et(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 c=o.withLevel(o.level<2?2:3),h=Ne(l,c.level),f=Ne(l,3),k=ke(null,h.toFixed(4),0),x=ke(null,f.toFixed(4),0),y=Ne(i?0:.3,c.level).toFixed(4);let _,C;const z=t&&t.body&&(t.body.body||t.body.length>0);if(z){let $=E(t,c);$=ke($,y,y,e==="\\\\cdrightarrow"||e==="\\\\cdleftarrow"),_=new p("mover",[$,x])}const F=r&&r.body&&(r.body.body||r.body.length>0);if(F){let $=E(r,c);$=ke($,y,y),C=new p("munder",[$,x])}let T;return!z&&!F?T=new p("mover",[s,k]):z&&F?T=new p("munderover",[s,C,_]):z?T=new p("mover",[s,_]):T=new p("munder",[s,C]),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=[Ue(e.name,e.body,e.below,t)];return o.unshift(N(.2778)),o.push(N(.2778)),new p("mrow",o)}});const bt={"\\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=bt[e.name][0],o=bt[e.name][1],s=Ue(r,e.body,e.upperArrowBelow,t),i=Ue(o,e.lowerArrowBody,e.below,t);let l;const c=new p("mpadded",[s]);if(c.setAttribute("voffset","0.3em"),c.setAttribute("height","+0.3em"),c.setAttribute("depth","-0.3em"),e.name==="\\equilibriumLeft"){const h=new p("mpadded",[i]);h.setAttribute("width","0.5em"),l=new p("mpadded",[N(.2778),h,c,N(.2778)])}else c.setAttribute("width",e.name==="\\equilibriumRight"?"0.5em":"0"),l=new p("mpadded",[N(.2778),c,i,N(.2778)]);return l.setAttribute("voffset","-0.18em"),l.setAttribute("height","-0.18em"),l.setAttribute("depth","+0.18em"),l}});const Qt={};function Z({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"},xt=()=>({type:"styling",body:[],mode:"math",scriptLevel:"display"}),yt=e=>e.type==="textord"&&e.text==="@",tn=(e,t)=>(e.type==="mathord"||e.type==="atom")&&e.text===t;function rn(e,t,r){const o=en[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],[]),c=r.callFunction("\\\\cdright",[t[1]],[]),h={type:"ordgroup",mode:"math",body:[s,l,c],semisimple:!0};return r.callFunction("\\\\cdparent",[h],[])}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 nn(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(h)>-1)for(let x=0;x<2;x++){let y=!0;for(let _=c+1;_AV=|." after @.');const k=rn(h,f,e);r.push(k),l=xt()}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("mrow",t);const r=E(e.label,t);e.side==="left"&&r.classes.push("tml-shift-left");const o=new p("mtd",[r]);o.style.padding="0";const s=new p("mtr",[o]),i=new p("mtable",[s]),l=new p("mpadded",[i]);return l.setAttribute("width","0.1px"),l.setAttribute("displaystyle","false"),l.setAttribute("scriptlevel","1"),l}});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("mrow",[E(e.fragment,t)])}});const er=e=>({type:"ordgroup",mode:"math",body:e,semisimple:!0}),Me=(e,t)=>({type:t,mode:"math",body:er(e)}),on=(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"}},c={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}]},k={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:c,sub:null};return er([i,k])};class V{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 V(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,V.range(this,t))}}const M={DISPLAY:0,TEXT:1,SCRIPT:2,SCRIPTSCRIPT:3},tr={};function u(e,t){tr[e]=t}const an=tr;u("\\noexpand",function(e){const t=e.popToken();return e.isExpandable(t.text)&&(t.noexpand=!0,t.treatAsRelax=!0),{tokens:[t],numArgs:0}});u("\\expandafter",function(e){const t=e.popToken();return e.expandOnce(!0),{tokens:[t],numArgs:0}});u("\\@firstoftwo",function(e){return{tokens:e.consumeArgs(2)[0],numArgs:0}});u("\\@secondoftwo",function(e){return{tokens:e.consumeArgs(2)[1],numArgs:0}});u("\\@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}});u("\\@ifstar","\\@ifnextchar *{\\@firstoftwo{#1}}");u("\\TextOrMath",function(e){const t=e.consumeArgs(2);return e.mode==="text"?{tokens:t[0],numArgs:0}:{tokens:t[1],numArgs:0}});const Ve=e=>{let t="";for(let r=e.length-1;r>-1;r--)t+=e[r].text;return t},rt={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},wt=e=>{const t=e.future().text;return t==="EOF"?[null,""]:[rt[t.charAt(0)],t]},vt=(e,t,r)=>{for(let o=1;o=r)throw new v(`Invalid base-${r} digit ${t.text}`);o=vt(o,s,r);let i;for([i,s]=wt(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}u("\\surd","\\sqrt{\\vphantom{|}}");u("⊕","\\oplus");u("\\long","");u("\\bgroup","{");u("\\egroup","}");u("~","\\nobreakspace");u("\\lq","`");u("\\rq","'");u("\\aa","\\r a");u("\\Bbbk","\\Bbb{k}");u("\\mathstrut","\\vphantom{(}");u("\\underbar","\\underline{\\text{#1}}");u("\\vdots","{\\varvdots\\rule{0pt}{15pt}}");u("⋮","\\vdots");u("\\arraystretch","1");u("\\arraycolsep","6pt");u("\\substack","\\begin{subarray}{c}#1\\end{subarray}");u("\\iff","\\DOTSB\\;\\Longleftrightarrow\\;");u("\\implies","\\DOTSB\\;\\Longrightarrow\\;");u("\\impliedby","\\DOTSB\\;\\Longleftarrow\\;");const kt={",":"\\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","\\DOTSX":"\\dotsx"};u("\\dots",function(e){let t="\\dotso";const r=e.expandAfterFuture().text;return r in kt?t=kt[r]:(r.slice(0,4)==="\\not"||r in P.math&&["bin","rel"].includes(P.math[r].group))&&(t="\\dotsb"),t});const ot={")":!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};u("\\dotso",function(e){return e.future().text in ot?"\\ldots\\,":"\\ldots"});u("\\dotsc",function(e){const t=e.future().text;return t in ot&&t!==","?"\\ldots\\,":"\\ldots"});u("\\cdots",function(e){return e.future().text in ot?"\\@cdots\\,":"\\@cdots"});u("\\dotsb","\\cdots");u("\\dotsm","\\cdots");u("\\dotsi","\\!\\cdots");u("\\idotsint","\\int\\!\\cdots\\!\\int");u("\\dotsx","\\ldots\\,");u("\\DOTSI","\\relax");u("\\DOTSB","\\relax");u("\\DOTSX","\\relax");u("\\tmspace","\\TextOrMath{\\kern#1#3}{\\mskip#1#2}\\relax");u("\\,","{\\tmspace+{3mu}{.1667em}}");u("\\thinspace","\\,");u("\\>","\\mskip{4mu}");u("\\:","{\\tmspace+{4mu}{.2222em}}");u("\\medspace","\\:");u("\\;","{\\tmspace+{5mu}{.2777em}}");u("\\thickspace","\\;");u("\\!","{\\tmspace-{3mu}{.1667em}}");u("\\negthinspace","\\!");u("\\negmedspace","{\\tmspace-{4mu}{.2222em}}");u("\\negthickspace","{\\tmspace-{5mu}{.277em}}");u("\\enspace","\\kern.5em ");u("\\enskip","\\hskip.5em\\relax");u("\\quad","\\hskip1em\\relax");u("\\qquad","\\hskip2em\\relax");u("\\AA","\\TextOrMath{\\Angstrom}{\\mathring{A}}\\relax");u("\\tag","\\@ifstar\\tag@literal\\tag@paren");u("\\tag@paren","\\tag@literal{({#1})}");u("\\tag@literal",e=>{if(e.macros.get("\\df@tag"))throw new v("Multiple \\tag");return"\\gdef\\df@tag{\\text{#1}}"});u("\\notag","\\nonumber");u("\\nonumber","\\gdef\\@eqnsw{0}");u("\\bmod","\\mathbin{\\text{mod}}");u("\\pod","\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern8mu}{\\mkern8mu}{\\mkern8mu}(#1)");u("\\pmod","\\pod{{\\rm mod}\\mkern6mu#1}");u("\\mod","\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern12mu}{\\mkern12mu}{\\mkern12mu}{\\rm mod}\\,\\,#1");u("\\newline","\\\\\\relax");u("\\TeX","\\textrm{T}\\kern-.1667em\\raisebox{-.5ex}{E}\\kern-.125em\\textrm{X}");u("\\LaTeX","\\textrm{L}\\kern-.35em\\raisebox{0.2em}{\\scriptstyle A}\\kern-.15em\\TeX");u("\\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}}");u("\\hspace","\\@ifstar\\@hspacer\\@hspace");u("\\@hspace","\\hskip #1\\relax");u("\\@hspacer","\\rule{0pt}{0pt}\\hskip #1\\relax");u("\\colon",'\\mathpunct{\\char"3a}');u("\\prescript","\\pres@cript{_{#1}^{#2}}{}{#3}");u("\\ordinarycolon",'\\char"3a');u("\\vcentcolon","\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}}");u("\\coloneq",'\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}\\char"2212}');u("\\Coloneq",'\\mathrel{\\char"2237\\char"2212}');u("\\Eqqcolon",'\\mathrel{\\char"3d\\char"2237}');u("\\Eqcolon",'\\mathrel{\\char"2212\\char"2237}');u("\\colonapprox",'\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}\\char"2248}');u("\\Colonapprox",'\\mathrel{\\char"2237\\char"2248}');u("\\colonsim",'\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}\\char"223c}');u("\\Colonsim",'\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}\\char"223c}');u("\\ratio","\\vcentcolon");u("\\coloncolon","\\dblcolon");u("\\colonequals","\\coloneqq");u("\\coloncolonequals","\\Coloneqq");u("\\equalscolon","\\eqqcolon");u("\\equalscoloncolon","\\Eqqcolon");u("\\colonminus","\\coloneq");u("\\coloncolonminus","\\Coloneq");u("\\minuscolon","\\eqcolon");u("\\minuscoloncolon","\\Eqcolon");u("\\coloncolonapprox","\\Colonapprox");u("\\coloncolonsim","\\Colonsim");u("\\notni","\\mathrel{\\char`∌}");u("\\limsup","\\DOTSB\\operatorname*{lim\\,sup}");u("\\liminf","\\DOTSB\\operatorname*{lim\\,inf}");u("\\injlim","\\DOTSB\\operatorname*{inj\\,lim}");u("\\projlim","\\DOTSB\\operatorname*{proj\\,lim}");u("\\varlimsup","\\DOTSB\\operatorname*{\\overline{\\text{lim}}}");u("\\varliminf","\\DOTSB\\operatorname*{\\underline{\\text{lim}}}");u("\\varinjlim","\\DOTSB\\operatorname*{\\underrightarrow{\\text{lim}}}");u("\\varprojlim","\\DOTSB\\operatorname*{\\underleftarrow{\\text{lim}}}");u("\\centerdot","{\\medspace\\rule{0.167em}{0.189em}\\medspace}");u("\\argmin","\\DOTSB\\operatorname*{arg\\,min}");u("\\argmax","\\DOTSB\\operatorname*{arg\\,max}");u("\\plim","\\DOTSB\\operatorname*{plim}");u("\\leftmodels","\\mathop{\\reflectbox{$\\models$}}");u("\\bra","\\mathinner{\\langle{#1}|}");u("\\ket","\\mathinner{|{#1}\\rangle}");u("\\braket","\\mathinner{\\langle{#1}\\rangle}");u("\\Bra","\\left\\langle#1\\right|");u("\\Ket","\\left|#1\\right\\rangle");const rr=(e,t)=>{const o=`}\\,\\middle${t[0]==="|"?"\\vert":"\\Vert"}\\,{`;return e.slice(0,t.index)+o+e.slice(t.index+t[0].length)};u("\\Braket",function(e){let t=nt(e);const r=/\|\||\||\\\|/g;let o;for(;(o=r.exec(t))!==null;)t=rr(t,o);return"\\left\\langle{"+t+"}\\right\\rangle"});u("\\Set",function(e){let t=nt(e);const r=/\|\||\||\\\|/.exec(t);return r&&(t=rr(t,r)),"\\left\\{\\:{"+t+"}\\:\\right\\}"});u("\\set",function(e){return"\\{{"+nt(e).replace(/\|/,"}\\mid{")+"}\\}"});u("\\angln","{\\angl n}");u("\\odv","\\@ifstar\\odv@next\\odv@numerator");u("\\odv@numerator","\\frac{\\mathrm{d}#1}{\\mathrm{d}#2}");u("\\odv@next","\\frac{\\mathrm{d}}{\\mathrm{d}#2}#1");u("\\pdv","\\@ifstar\\pdv@next\\pdv@numerator");const nr=e=>{const t=e[0][0].text,r=Ve(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(/\\,$/,"")]};u("\\pdv@numerator",function(e){const[t,r,o]=nr(e.consumeArgs(2));return`\\frac{${r} ${t}}{${o}}`});u("\\pdv@next",function(e){const[t,r,o]=nr(e.consumeArgs(2));return`\\frac{${r}}{${o}} ${t}`});u("\\upalpha","\\up@greek{\\alpha}");u("\\upbeta","\\up@greek{\\beta}");u("\\upgamma","\\up@greek{\\gamma}");u("\\updelta","\\up@greek{\\delta}");u("\\upepsilon","\\up@greek{\\epsilon}");u("\\upzeta","\\up@greek{\\zeta}");u("\\upeta","\\up@greek{\\eta}");u("\\uptheta","\\up@greek{\\theta}");u("\\upiota","\\up@greek{\\iota}");u("\\upkappa","\\up@greek{\\kappa}");u("\\uplambda","\\up@greek{\\lambda}");u("\\upmu","\\up@greek{\\mu}");u("\\upnu","\\up@greek{\\nu}");u("\\upxi","\\up@greek{\\xi}");u("\\upomicron","\\up@greek{\\omicron}");u("\\uppi","\\up@greek{\\pi}");u("\\upalpha","\\up@greek{\\alpha}");u("\\uprho","\\up@greek{\\rho}");u("\\upsigma","\\up@greek{\\sigma}");u("\\uptau","\\up@greek{\\tau}");u("\\upupsilon","\\up@greek{\\upsilon}");u("\\upphi","\\up@greek{\\phi}");u("\\upchi","\\up@greek{\\chi}");u("\\uppsi","\\up@greek{\\psi}");u("\\upomega","\\up@greek{\\omega}");u("\\invamp",'\\mathbin{\\char"214b}');u("\\parr",'\\mathbin{\\char"214b}');u("\\with",'\\mathbin{\\char"26}');u("\\multimapinv",'\\mathrel{\\char"27dc}');u("\\multimapboth",'\\mathrel{\\char"29df}');u("\\scoh",'{\\mkern5mu\\char"2322\\mkern5mu}');u("\\sincoh",'{\\mkern5mu\\char"2323\\mkern5mu}');u("\\coh",`{\\mkern5mu\\rule{}{0.7em}\\mathrlap{\\smash{\\raise2mu{\\char"2322}}} {\\smash{\\lower4mu{\\char"2323}}}\\mkern5mu}`);u("\\incoh",`{\\mkern5mu\\rule{}{0.7em}\\mathrlap{\\smash{\\raise2mu{\\char"2323}}} {\\smash{\\lower4mu{\\char"2322}}}\\mkern5mu}`);u("\\standardstate","\\text{\\tiny\\char`⦵}");u("\\ce",function(e){return or(e.consumeArgs(1)[0],"ce")});u("\\pu",function(e){return or(e.consumeArgs(1)[0],"pu")});u("\\uniDash","{\\rule{0.672em}{0.06em}}");u("\\triDash","{\\rule{0.15em}{0.06em}\\kern2mu\\rule{0.15em}{0.06em}\\kern2mu\\rule{0.15em}{0.06em}}");u("\\tripleDash","\\kern0.075em\\raise0.25em{\\triDash}\\kern0.075em");u("\\tripleDashOverLine","\\kern0.075em\\mathrlap{\\raise0.125em{\\uniDash}}\\raise0.34em{\\triDash}\\kern0.075em");u("\\tripleDashOverDoubleLine","\\kern0.075em\\mathrlap{\\mathrlap{\\raise0.48em{\\triDash}}\\raise0.27em{\\uniDash}}{\\raise0.05em{\\uniDash}}\\kern0.075em");u("\\tripleDashBetweenDoubleLine","\\kern0.075em\\mathrlap{\\mathrlap{\\raise0.48em{\\uniDash}}\\raise0.27em{\\triDash}}{\\raise0.05em{\\uniDash}}\\kern0.075em");var or=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 c=w.stateMachines[t],h=c.transitions[r]||c.transitions["*"];e:for(var f=0;f0){if(x.revisit||(e=k.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,c,h,f){var k=function(T,$){if(typeof $=="string")return T.indexOf($)!==0?null:$;var Y=T.match($);return Y?Y[0]:null},x=function(T,$,Y){for(var H=0;$0,null},y=k(e,t);if(y===null||(e=e.substr(y.length),y=k(e,r),y===null))return null;var _=x(e,y.length,o||s);if(_===null)return null;var C=e.substring(0,o?_.endMatchEnd:_.endMatchBegin);if(i||l){var z=this.findObserveGroups(e.substr(_.endMatchEnd),i,l,c,h);if(z===null)return null;var F=[C,z.match_];return{match_:f?F.join(""):F,remainder:z.remainder}}else return{match_:C,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||""),c=t==="-"&&(o&&o.remainder===""||s||i||l);c&&!e.a&&!e.b&&!e.p&&!e.d&&!e.q&&!o&&i&&(e.o="$"+e.o+"$");var h=[];return c?(w.concatArray(h,this.output(e)),h.push({type_:"hyphen"})):(o=w.patterns.match_("digits",e.d||""),r&&o&&o.remainder===""?(w.concatArray(h,w.actions["d="](e,t)),w.concatArray(h,this.output(e))):(w.concatArray(h,this.output(e)),w.concatArray(h,w.actions.bond(e,t,"-")))),h},"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."]}}};u("\\darr","\\downarrow");u("\\dArr","\\Downarrow");u("\\Darr","\\Downarrow");u("\\lang","\\langle");u("\\rang","\\rangle");u("\\uarr","\\uparrow");u("\\uArr","\\Uparrow");u("\\Uarr","\\Uparrow");u("\\N","\\mathbb{N}");u("\\R","\\mathbb{R}");u("\\Z","\\mathbb{Z}");u("\\alef","\\aleph");u("\\alefsym","\\aleph");u("\\bull","\\bullet");u("\\clubs","\\clubsuit");u("\\cnums","\\mathbb{C}");u("\\Complex","\\mathbb{C}");u("\\Dagger","\\ddagger");u("\\diamonds","\\diamondsuit");u("\\empty","\\emptyset");u("\\exist","\\exists");u("\\harr","\\leftrightarrow");u("\\hArr","\\Leftrightarrow");u("\\Harr","\\Leftrightarrow");u("\\hearts","\\heartsuit");u("\\image","\\Im");u("\\infin","\\infty");u("\\isin","\\in");u("\\larr","\\leftarrow");u("\\lArr","\\Leftarrow");u("\\Larr","\\Leftarrow");u("\\lrarr","\\leftrightarrow");u("\\lrArr","\\Leftrightarrow");u("\\Lrarr","\\Leftrightarrow");u("\\natnums","\\mathbb{N}");u("\\plusmn","\\pm");u("\\rarr","\\rightarrow");u("\\rArr","\\Rightarrow");u("\\Rarr","\\Rightarrow");u("\\real","\\Re");u("\\reals","\\mathbb{R}");u("\\Reals","\\mathbb{R}");u("\\sdot","\\cdot");u("\\sect","\\S");u("\\spades","\\spadesuit");u("\\sub","\\subset");u("\\sube","\\subseteq");u("\\supe","\\supseteq");u("\\thetasym","\\vartheta");u("\\weierp","\\wp");u("\\quantity","{\\left\\{ #1 \\right\\}}");u("\\qty","{\\left\\{ #1 \\right\\}}");u("\\pqty","{\\left( #1 \\right)}");u("\\bqty","{\\left[ #1 \\right]}");u("\\vqty","{\\left\\vert #1 \\right\\vert}");u("\\Bqty","{\\left\\{ #1 \\right\\}}");u("\\absolutevalue","{\\left\\vert #1 \\right\\vert}");u("\\abs","{\\left\\vert #1 \\right\\vert}");u("\\norm","{\\left\\Vert #1 \\right\\Vert}");u("\\evaluated","{\\left.#1 \\right\\vert}");u("\\eval","{\\left.#1 \\right\\vert}");u("\\order","{\\mathcal{O} \\left( #1 \\right)}");u("\\commutator","{\\left[ #1 , #2 \\right]}");u("\\comm","{\\left[ #1 , #2 \\right]}");u("\\anticommutator","{\\left\\{ #1 , #2 \\right\\}}");u("\\acomm","{\\left\\{ #1 , #2 \\right\\}}");u("\\poissonbracket","{\\left\\{ #1 , #2 \\right\\}}");u("\\pb","{\\left\\{ #1 , #2 \\right\\}}");u("\\vectorbold","{\\boldsymbol{ #1 }}");u("\\vb","{\\boldsymbol{ #1 }}");u("\\vectorarrow","{\\vec{\\boldsymbol{ #1 }}}");u("\\va","{\\vec{\\boldsymbol{ #1 }}}");u("\\vectorunit","{{\\boldsymbol{\\hat{ #1 }}}}");u("\\vu","{{\\boldsymbol{\\hat{ #1 }}}}");u("\\dotproduct","\\mathbin{\\boldsymbol\\cdot}");u("\\vdot","{\\boldsymbol\\cdot}");u("\\crossproduct","\\mathbin{\\boldsymbol\\times}");u("\\cross","\\mathbin{\\boldsymbol\\times}");u("\\cp","\\mathbin{\\boldsymbol\\times}");u("\\gradient","{\\boldsymbol\\nabla}");u("\\grad","{\\boldsymbol\\nabla}");u("\\divergence","{\\grad\\vdot}");u("\\curl","{\\grad\\cross}");u("\\laplacian","\\nabla^2");u("\\tr","{\\operatorname{tr}}");u("\\Tr","{\\operatorname{Tr}}");u("\\rank","{\\operatorname{rank}}");u("\\erf","{\\operatorname{erf}}");u("\\Res","{\\operatorname{Res}}");u("\\principalvalue","{\\mathcal{P}}");u("\\pv","{\\mathcal{P}}");u("\\PV","{\\operatorname{P.V.}}");u("\\qqtext","{\\quad\\text{ #1 }\\quad}");u("\\qq","{\\quad\\text{ #1 }\\quad}");u("\\qcomma","{\\text{,}\\quad}");u("\\qc","{\\text{,}\\quad}");u("\\qcc","{\\quad\\text{c.c.}\\quad}");u("\\qif","{\\quad\\text{if}\\quad}");u("\\qthen","{\\quad\\text{then}\\quad}");u("\\qelse","{\\quad\\text{else}\\quad}");u("\\qotherwise","{\\quad\\text{otherwise}\\quad}");u("\\qunless","{\\quad\\text{unless}\\quad}");u("\\qgiven","{\\quad\\text{given}\\quad}");u("\\qusing","{\\quad\\text{using}\\quad}");u("\\qassume","{\\quad\\text{assume}\\quad}");u("\\qsince","{\\quad\\text{since}\\quad}");u("\\qlet","{\\quad\\text{let}\\quad}");u("\\qfor","{\\quad\\text{for}\\quad}");u("\\qall","{\\quad\\text{all}\\quad}");u("\\qeven","{\\quad\\text{even}\\quad}");u("\\qodd","{\\quad\\text{odd}\\quad}");u("\\qinteger","{\\quad\\text{integer}\\quad}");u("\\qand","{\\quad\\text{and}\\quad}");u("\\qor","{\\quad\\text{or}\\quad}");u("\\qas","{\\quad\\text{as}\\quad}");u("\\qin","{\\quad\\text{in}\\quad}");u("\\differential","{\\text{d}}");u("\\dd","{\\text{d}}");u("\\derivative","{\\frac{\\text{d}{ #1 }}{\\text{d}{ #2 }}}");u("\\dv","{\\frac{\\text{d}{ #1 }}{\\text{d}{ #2 }}}");u("\\partialderivative","{\\frac{\\partial{ #1 }}{\\partial{ #2 }}}");u("\\variation","{\\delta}");u("\\var","{\\delta}");u("\\functionalderivative","{\\frac{\\delta{ #1 }}{\\delta{ #2 }}}");u("\\fdv","{\\frac{\\delta{ #1 }}{\\delta{ #2 }}}");u("\\innerproduct","{\\left\\langle {#1} \\mid { #2} \\right\\rangle}");u("\\outerproduct","{\\left\\vert { #1 } \\right\\rangle\\left\\langle { #2} \\right\\vert}");u("\\dyad","{\\left\\vert { #1 } \\right\\rangle\\left\\langle { #2} \\right\\vert}");u("\\ketbra","{\\left\\vert { #1 } \\right\\rangle\\left\\langle { #2} \\right\\vert}");u("\\op","{\\left\\vert { #1 } \\right\\rangle\\left\\langle { #2} \\right\\vert}");u("\\expectationvalue","{\\left\\langle {#1 } \\right\\rangle}");u("\\expval","{\\left\\langle {#1 } \\right\\rangle}");u("\\ev","{\\left\\langle {#1 } \\right\\rangle}");u("\\matrixelement","{\\left\\langle{ #1 }\\right\\vert{ #2 }\\left\\vert{#3}\\right\\rangle}");u("\\matrixel","{\\left\\langle{ #1 }\\right\\vert{ #2 }\\left\\vert{#3}\\right\\rangle}");u("\\mel","{\\left\\langle{ #1 }\\right\\vert{ #2 }\\left\\vert{#3}\\right\\rangle}");function At(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.`)},sn=/([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/,ar=e=>{let t=e.get("\\arraystretch");typeof t!="string"&&(t=Ve(t.tokens)),t=isNaN(t)?null:Number(t);let r=e.get("\\arraycolsep");typeof r!="string"&&(r=Ve(r.tokens));const o=sn.exec(r),s=o?{number:+(o[1]+o[2]),unit:o[3]}:null;return[t,s]},St=e=>{let t="";for(let r=0;r1||!i)&&_.pop(),z.push(St(H.body)),F.length<_.length+1&&F.push([]);break}else if(le==="\\\\"){e.consume();let ue;e.gullet.future().text!==" "&&(ue=e.parseSizeGroup(!0)),C.push(ue?ue.value:null),Y(),z.push(St(H.body)),F.push(At(e)),y=[],_.push(y),$()}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:C,hLinesBeforeRow:F,envClasses:r,autoTag:o,scriptLevel:k,tags:T,labels:z,leqno:c,arraystretch:h,arraycolsep:f}}function sr(e){return e.slice(0,1)==="d"?"display":"text"}const ln={c:"center ",l:"left ",r:"right "},qt=e=>{const t=new p("mtd",[]);return t.style={padding:"0",width:"50%"},e.envClasses.includes("multline")&&(t.style.width="7.5%"),t},X=function(e,t){const r=[],o=e.body.length,s=e.hLinesBeforeRow,i=e.tags&&e.tags.some(f=>f);for(let f=0;f0&&(s[0].length===2?C.children.forEach(T=>{T.style.borderTop="0.15em double"}):C.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?C.children.forEach(T=>{T.style.borderBottom="0.15em double"}):C.children.forEach(T=>{T.style.borderBottom=s[f+1][0]?"0.06em dashed":"0.06em solid"}));let F=!0;for(let T=0;T0&&(l=e.envClasses.includes("abut")||e.envClasses.includes("cases")?"0":e.envClasses.includes("small")?"0.1389":e.envClasses.includes("cd")?"0.25":"0.4",c="em"),e.arraycolsep){const f=Q(e.arraycolsep,t);l=f.number.toFixed(4),c=f.unit}if(l){const f=r.length===0?0:r[0].children.length,k=(x,y)=>x===0&&y===0||x===f-1&&y===1?"0":e.envClasses[0]!=="align"?l:y===1?"0":i?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 k=0;k1&&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 h=new p("mtable",r);if(e.envClasses.length>0&&(e.envClasses.includes("jot")?h.classes.push("tml-jot"):e.envClasses.includes("small")&&h.classes.push("tml-small")),e.scriptLevel==="display"&&h.setAttribute("displaystyle","true"),(e.autoTag||e.envClasses.includes("multline"))&&(h.style.width="100%"),e.cols&&e.cols.length>0){const f=e.cols;let k=!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 C=f[1].type==="separator"?"0.15em double":f[0].separator==="|"?"0.06em solid ":"0.06em dashed ";for(const z of h.children)z.children[0].style.borderLeft=C}let _=i?0:-1;for(let C=x;C-1;if(t[0]&&c){let h="";for(let f=0;f0?new Array(s.body[0].length).fill({type:"align",align:r}):[];const[i,l]=ar(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:X});Z({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:on(r,e.delimiters)},mathmlBuilder:X});Z({type:"array",names:["smallmatrix"],props:{numArgs:0},handler(e){const t={envClasses:["small"]};return ee(e.parser,t,"script")},mathmlBuilder:X});Z({type:"array",names:["subarray"],props:{numArgs:1},handler(e,t){const s=(Ee(t[0])?[t[0]]:D(t[0],"ordgroup").body).map(function(l){const h=tt(l).text;if("lc".indexOf(h)!==-1)return{type:"align",align:h};throw new v("Unknown column alignment: "+h,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:X});Z({type:"array",names:["cases","dcases","rcases","drcases"],props:{numArgs:0},handler(e){const t={cols:[],envClasses:["cases"]},r=ee(e.parser,t,sr(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:X});Z({type:"array",names:["align","align*","aligned","split"],props:{numArgs:0},handler:ir,mathmlBuilder:X});Z({type:"array",names:["alignat","alignat*","alignedat"],props:{numArgs:1},handler:ir,mathmlBuilder:X});Z({type:"array",names:["gathered","gather","gather*"],props:{numArgs:0},handler(e){e.envName!=="gathered"&&xe(e);const t={cols:[],envClasses:["abut","jot"],autoTag:at(e.envName),emptySingleRow:!0,leqno:e.parser.settings.leqno};return ee(e.parser,t,"display")},mathmlBuilder:X});Z({type:"array",names:["equation","equation*"],props:{numArgs:0},handler(e){xe(e);const t={autoTag:at(e.envName),emptySingleRow:!0,singleRow:!0,maxNumCols:1,envClasses:["align"],leqno:e.parser.settings.leqno};return ee(e.parser,t,"display")},mathmlBuilder:X});Z({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:X});Z({type:"array",names:["CD"],props:{numArgs:0},handler(e){return xe(e),nn(e.parser)},mathmlBuilder:X});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 We=Qt;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 h=o[0].body;h.length===2&&h[0].type==="atom"&&h[1].type==="atom"&&h[0].family==="open"&&h[1].family==="close"&&(s=[h[0].text,h[1].text])}e.consumeSpaces(),e.consume();const i=We.bordermatrix,l={mode:e.mode,envName:t.slice(1),delimiters:s,parser:e},c=i.handler(l);return e.expect("}",!0),c}});S({type:"cancelto",names:["\\cancelto"],props:{numArgs:2},handler({parser:e},t){const r=t[0],o=t[1];return{type:"cancelto",mode:e.mode,body:o,to:r,isCharacterBox:Be(o)}},mathmlBuilder(e,t){const r=new p("mrow",[E(e.body,t)],["ff-narrow"]),o=new p("mphantom",[E(e.body,t)]),s=new p("mrow",[o],["tml-cancelto"]);e.isCharacterBox&&Vt.indexOf(e.body.body[0].text)>-1&&(s.style.left="0.1em",s.style.width="90%");const i=new p("mrow",[r,s],["menclose"]);if(!e.isCharacterBox||/[f∫∑]/.test(e.body.body[0].text))o.style.paddingRight="0.2em";else{o.style.padding="0.5ex 0.1em 0 0";const x=new p("mspace",[]);x.setAttribute("height","0.85em"),r.children.push(x)}let l;if(e.isCharacterBox)l=new p("mspace",[]),l.setAttribute("height","1em");else{const x=E(e.body,t),y=new p("mpadded",[x]);y.setAttribute("width","0.1px"),l=new p("mphantom",[y])}const c=E(e.to,t),h=new p("mpadded",[c]);if(!e.isCharacterBox||/[f∫∑]/.test(e.body.body[0].text)){const x=new p("mspace",[]);x.setAttribute("width","0.2em"),h.children.unshift(x)}h.setAttribute("width","0.1px");const f=new p("mover",[l,h]),k=new p("mrow",[],["ff-nudge-left"]);return ae([Oe([i,f]),k])}});S({type:"textord",names:["\\@char"],props:{numArgs:1,allowedInText:!0},handler({parser:e,token:t},r){const s=D(r[0],"ordgroup").body;let i="";for(let c=0;c{let t=e.toString(16);return t.length===1&&(t="0"+t),t},Tt=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" }`),me=(e,t)=>{let r="";if(e==="HTML"){if(!un.test(t))throw new v("Invalid HTML input.");r=t}else if(e==="RGB"){if(!dn.test(t))throw new v("Invalid RGB input.");t.split(",").map(o=>{r+=_t(Number(o.trim()))})}else{if(!mn.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+=_t(Number((s*255).toFixed(0)))})}return r.charAt(0)!=="#"&&(r="#"+r),r},fe=(e,t,r)=>{const o=`\\\\color@${e}`;if(!cn.exec(e))throw new v("Invalid color: '"+e+"'",r);return hn.test(e)?"#"+e:(e.charAt(0)==="#"||(t.has(o)?e=t.get(o).tokens[0].text:Tt[e]&&(e=Tt[e])),e)},lr=(e,t)=>{let r=U(e.body,t.withColor(e.color));return r.length===0&&r.push(new p("mrow")),r=r.map(o=>(o.style.color=e.color,o)),ae(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]&&D(o[0],"raw").string;let i="";if(s){const c=D(r[0],"raw").string;i=me(s,c)}else i=fe(D(r[0],"raw").string,e.gullet.macros,t);const l=r[1];return{type:"color",mode:e.mode,color:i,isTextColor:!0,body:R(l)}},mathmlBuilder:lr});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]&&D(s[0],"raw").string;let l="";if(i){const h=D(o[0],"raw").string;l=me(i,h)}else l=fe(D(o[0],"raw").string,e.gullet.macros,r);const c=e.parseExpression(!0,t,!0);return{type:"color",mode:e.mode,color:l,isTextColor:!1,body:c}},mathmlBuilder:lr});S({type:"color",names:["\\definecolor"],props:{numArgs:3,allowedInText:!0,argTypes:["raw","raw","raw"]},handler({parser:e,funcName:t,token:r},o){const s=D(o[0],"raw").string;if(!/^[A-Za-z]+$/.test(s))throw new v("Color name must be latin letters.",r);const i=D(o[1],"raw").string;if(!["HTML","RGB","rgb"].includes(i))throw new v("Color model must be HTML, RGB, or rgb.",r);const l=D(o[2],"raw").string,c=me(i,l);return e.gullet.macros.set(`\\\\color@${s}`,{tokens:[{text:c}],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&&D(o,"size").value}},mathmlBuilder(e,t){const r=new p("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 He={"\\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},pn=e=>{let t=e.gullet.popToken();return t.text==="="&&(t=e.gullet.popToken(),t.text===" "&&(t=e.gullet.popToken())),t},ur=(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(He[r.text])return(t==="\\global"||t==="\\\\globallong")&&(r.text=He[r.text]),D(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:c}=e.gullet.consumeArg();if(i&&c.unshift(i),t==="\\edef"||t==="\\xdef"){if(c=e.gullet.expandTokens(c),c.length>e.gullet.settings.maxExpand)throw new v("Too many expansions in an "+t);c.reverse()}return e.gullet.macros.set(o,{tokens:c,numArgs:s,delimiters:l},t===He[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=pn(e);return ur(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 ur(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 c=e.gullet.popToken();if(c=e.gullet.popToken(),!/^[0-9]$/.test(c.text))throw new v(`Invalid number of arguments: "${c.text}"`);if(i=parseInt(c.text),c=e.gullet.popToken(),c.text!=="]")throw new v(`Invalid argument "${c.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 Ze={"\\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}},cr=["(","\\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","."],fn=["}","\\left","\\middle","\\right"],ze=e=>e.length>0&&(cr.includes(e)||Ze[e]||fn.includes(e)),Ct=[0,1.2,1.8,2.4,3];function ge(e,t){e.type==="ordgroup"&&e.body.length===1&&(e=e.body[0]);const r=Ee(e);if(r&&cr.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 gn=["/","\\","\\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:Ze[e.funcName].size,mclass:Ze[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("mo",t);return e.mclass==="mopen"||e.mclass==="mclose"?r.setAttribute("fence","true"):r.setAttribute("fence","false"),(gn.includes(e.delim)||e.delim.indexOf("arrow")>-1)&&r.setAttribute("stretchy","true"),r.setAttribute("symmetric","true"),r.setAttribute("minsize",Ct[e.size]+"em"),r.setAttribute("maxsize",Ct[e.size]+"em"),r}});function bn(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 c=o.fetch().text;if(!P.math[c])throw new v(`Invalid delimiter '${c}' after '\\middle'`);ge({type:"atom",mode:"math",text:c},{funcName:"\\middle"}),s.push({type:"middle",mode:"math",delim:c}),o.consume(),s=s.concat(o.parseExpression(!1,null,!0)),i=o.fetch()}--o.leftrightDepth,o.expect("\\right",!1);const l=D(o.parseFunction(),"leftright-right");return{type:"leftright",mode:o.mode,body:s,left:r.text,right:l.delim}},mathmlBuilder:(e,t)=>{bn(e);const r=U(e.body,t);e.left==="."&&(e.left="");const o=new p("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("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),Oe(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("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 xn=["\\boxed","\\fcolorbox","\\colorbox"],ye=(e,t)=>{const r=xn.includes(e.label)?"mrow":"menclose",o=new p(r,[E(e.body,t)]);switch(e.label){case"\\overline":o.setAttribute("notation","top"),o.classes.push("tml-overline");break;case"\\underline":o.setAttribute("notation","bottom"),o.classes.push("tml-underline");break;case"\\cancel":o.setAttribute("notation","updiagonalstrike"),o.children.push(new p("mrow",[],["tml-cancel","upstrike"]));break;case"\\bcancel":o.setAttribute("notation","downdiagonalstrike"),o.children.push(new p("mrow",[],["tml-cancel","downstrike"]));break;case"\\sout":o.setAttribute("notation","horizontalstrike"),o.children.push(new p("mrow",[],["tml-cancel","sout"]));break;case"\\xcancel":o.setAttribute("notation","updiagonalstrike downdiagonalstrike"),o.classes.push("tml-xcancel");break;case"\\longdiv":o.setAttribute("notation","longdiv"),o.classes.push("longdiv-top"),o.children.push(new p("mrow",[],["longdiv-arc"]));break;case"\\phase":o.setAttribute("notation","phasorangle"),o.classes.push("phasor-bottom"),o.children.push(new p("mrow",[],["phasor-angle"]));break;case"\\textcircled":o.setAttribute("notation","circle"),o.classes.push("circle-pad"),o.children.push(new p("mrow",[],["textcircle"]));break;case"\\angl":o.setAttribute("notation","actuarial"),o.classes.push("actuarial");break;case"\\boxed":o.style.padding="3pt",o.style.border="1px solid",o.setAttribute("scriptlevel","0"),o.setAttribute("displaystyle","true");break;case"\\fbox":o.setAttribute("notation","box"),o.classes.push("tml-fbox");break;case"\\fcolorbox":case"\\colorbox":{o.style.padding="0.3em",e.label==="\\fcolorbox"&&(o.style.border="0.0667em solid "+String(e.borderColor));break}}return e.backgroundColor&&o.setAttribute("mathbackground",e.backgroundColor),o};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]&&D(o[0],"raw").string;let i="";if(s){const c=D(r[0],"raw").string;i=me(s,c)}else i=fe(D(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]&&D(o[0],"raw").string;let i="",l;if(s){const h=D(r[0],"raw").string,f=D(r[0],"raw").string;i=me(s,h),l=me(s,f)}else i=fe(D(r[0],"raw").string,e.gullet.macros),l=fe(D(r[1],"raw").string,e.gullet.macros);const c=r[2];return{type:"enclose",mode:e.mode,label:t,backgroundColor:l,borderColor:i,body:c}},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=E(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(yn(e,r)){const c=s.children[0].children[0].children?s.children[0].children[0]:s.children[0];delete c.attributes.mathvariant;for(let f=1;f{const o=pe(r[0]);let s=t;return s in Dt&&(s=Dt[s]),{type:"font",mode:e.mode,font:s.slice(1),body:o}},mathmlBuilder:dr});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:dr});const Bt=["display","text","script","scriptscript"],wn={auto:-1,display:0,text:0,script:1,scriptscript:2},st=(e,t)=>{const r=e.scriptLevel==="auto"?t.incrementLevel():e.scriptLevel==="display"?t.withLevel(M.TEXT):e.scriptLevel==="text"?t.withLevel(M.SCRIPT):t.withLevel(M.SCRIPTSCRIPT),o=E(e.numer,r),s=E(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("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 c=new p("mo",[new j(e.leftDelim.replace("\\",""))]);c.setAttribute("fence","true"),l.push(c)}if(l.push(i),e.rightDelim!=null){const c=new p("mo",[new j(e.rightDelim.replace("\\",""))]);c.setAttribute("fence","true"),l.push(c)}i=Oe(l)}return e.scriptLevel!=="auto"&&(i=new p("mstyle",[i]),i.setAttribute("displaystyle",String(e.scriptLevel==="display")),i.setAttribute("scriptlevel",wn[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,c=null,h="auto";switch(t){case"\\dfrac":case"\\frac":case"\\tfrac":i=!0;break;case"\\\\atopfrac":i=!1;break;case"\\dbinom":case"\\binom":case"\\tbinom":l="(",c=")";break;case"\\\\bracefrac":l="\\{",c="\\}";break;case"\\\\brackfrac":l="[",c="]";break;default:throw new Error("Unrecognized genfrac command")}switch(t){case"\\dfrac":case"\\dbinom":h="display";break;case"\\tfrac":case"\\tbinom":h="text";break}return{type:"genfrac",mode:e.mode,continued:!1,numer:o,denom:s,hasBarLine:i,leftDelim:l,rightDelim:c,scriptLevel:h,barSize:null}},mathmlBuilder:st});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 $t=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"?$t(s.text):null,l=pe(t[1]),c=l.type==="atom"&&l.family==="close"?$t(l.text):null,h=D(t[2],"size");let f,k=null;h.isBlank?f=!0:(k=h.value,f=k.number>0);let x="auto",y=t[3];if(y.type==="ordgroup"){if(y.body.length>0){const _=D(y.body[0],"textord");x=Bt[Number(_.text)]}}else y=D(y,"textord"),x=Bt[Number(y.text)];return{type:"genfrac",mode:e.mode,numer:r,denom:o,continued:!1,hasBarLine:f,barSize:k,leftDelim:i,rightDelim:c,scriptLevel:x}},mathmlBuilder:st});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:D(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=Dr(D(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:st});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:R(t[0])}},mathmlBuilder(e,t){const r=t.withLevel(M.TEXT),o=ne(e.body,r);return $e(o)}});const vn=(e,t)=>{const r=et(e.label);return r.style["math-depth"]=0,new p(e.isOver?"mover":"munder",[E(e.base,t),r])};S({type:"horizBracket",names:["\\overbrace","\\underbrace","\\overbracket","\\underbracket"],props:{numArgs:1},handler({parser:e,funcName:t},r){return{type:"horizBracket",mode:e.mode,label:t,isOver:/^\\over/.test(t),base:r[0]}},mathmlBuilder:vn});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=D(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 c={};switch(t){case"\\class":c.class=s,l={command:"\\class",class:s};break;case"\\id":c.id=s,l={command:"\\id",id:s};break;case"\\style":c.style=s,l={command:"\\style",style:s};break;case"\\data":{const h=s.split(",");for(let f=0;f{const r=ne(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 Pe=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(!Kt(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"},c="";if(o[0]){const k=D(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("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=D(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"?mr(r.number):"";if(e.mode==="text"&&o.length>0){const s=new j(o);return new p("mtext",[s])}else if(r.number>=0){const s=new p("mspace");return s.setAttribute("width",r.number+r.unit),s}else{const s=new p("mrow");return s.style.marginLeft=r.number+r.unit,s}}});const mr=function(e){return e>=.05555&&e<=.05556?" ":e>=.1666&&e<=.1667?" ":e>=.2222&&e<=.2223?" ":e>=.2777&&e<=.2778?"  ":""},hr=/[^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(hr,"")}},mathmlBuilder(e,t){const r=new p("mrow",[],["tml-label"]);return e.string.length>0&&r.setLabel(e.string),r}});const kn=["\\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(kn.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(R(e.body),t),l=new p("mphantom",i);r=new p("mpadded",[l]),r.setAttribute("width","0.1px")}const o=E(e.body,t);let s;if(e.alignment==="llap"?(o.style.position="absolute",o.style.right="0",o.style.bottom="0",s=new p("mpadded",[r,o])):s=new p("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","0.1px"),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 An=(e,t)=>{switch(t.level){case M.DISPLAY:return e.display;case M.TEXT:return e.text;case M.SCRIPT:return e.script;case M.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:R(t[0]),text:R(t[1]),script:R(t[2]),scriptscript:R(t[3])}),mathmlBuilder:(e,t)=>{const r=An(e,t);return ne(r,t)}});const Sn=["text","textord","mathord","atom"];function pr(e,t){let r;const o=U(e.body,t);if(e.mclass==="minner")r=new p("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("mi",o);else{r=new p("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("mrow",o);const s=t.level<2;r.type==="mrow"?s&&(e.mclass==="mbin"?(r.children.unshift(N(.2222)),r.children.push(N(.2222))):e.mclass==="mrel"?(r.children.unshift(N(.2778)),r.children.push(N(.2778))):e.mclass==="mpunct"?r.children.push(N(.1667)):e.mclass==="minner"&&(r.children.unshift(N(.0556)),r.children.push(N(.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=Be(o);let i=!0;const l={type:"mathord",text:"",mode:e.mode},c=o.body?o.body:[o];for(const h of c)if(Sn.includes(h.type))P[e.mode][h.text]?l.text+=P[e.mode][h.text].replace:h.text?l.text+=h.text:h.body&&h.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:R(i?l:o),isCharacterBox:s,mustPromote:i}},mathmlBuilder:pr});const fr=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:fr(t[0]),body:R(t[1]),isCharacterBox:Be(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=fr(o):i="mrel";const c={type:i==="mrel"||i==="mbin"?"op":"ordgroup",mode:o.mode,limits:!0,alwaysHandleSupSub:!0,parentIsSupSub:!1,symbol:!1,suppressBaseShift:t!=="\\stackrel",body:R(o)};return{type:"supsub",mode:s.mode,stack:!0,base:c,sup:t==="\\underset"?null:s,sub:t==="\\underset"?s:null}},mathmlBuilder:pr});const Ae=(e,t,r)=>{if(!e)return r;const o=E(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=E(e.base,t),o=new p("mprescripts"),s=new p("none");let i=[];const l=Ae(e.prescripts.sub,t,s),c=Ae(e.prescripts.sup,t,s);if(e.isSideset&&(l.setAttribute("style","text-align: left;"),c.setAttribute("style","text-align: left;")),e.postscripts){const h=Ae(e.postscripts.sub,t,s),f=Ae(e.postscripts.sup,t,s);i=[r,h,f,o,l,c]}else i=[r,o,l,c];return new p("mmultiscripts",i)}});S({type:"not",names:["\\not"],props:{numArgs:1,primitive:!0,allowedInText:!1},handler({parser:e},t){const r=Be(t[0]);let o;return r?(o=R(t[0]),o[0].text.charAt(0)==="\\"&&(o[0].text=P.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]:ne(e.body,t)}});const qn=["textord","mathord","atom"],_n=["\\smallint"],it=["textord","mathord","ordgroup","close","leftright","font"],Ot=e=>{e.attributes.lspace="0.1667em",e.attributes.rspace="0.1667em"},we=(e,t)=>{let r;if(e.symbol)r=new p("mo",[W(e.name,e.mode)]),_n.includes(e.name)?r.setAttribute("largeop","false"):r.setAttribute("movablelimits","false"),e.fromMathOp&&Ot(r);else if(e.body)r=new p("mo",U(e.body,t)),e.fromMathOp&&Ot(r);else if(r=new p("mi",[new j(e.name.slice(1))]),!e.parentIsSupSub){const o=new p("mo",[W("⁡","text")]),s=[r,o];if(e.needsLeadingSpace){const i=new p("mspace");i.setAttribute("width","0.1667em"),s.unshift(i)}if(!e.isFollowedByDelimiter){const i=new p("mspace");i.setAttribute("width","0.1667em"),s.push(i)}r=new p("mrow",s)}return r},Tn={"∏":"\\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=Tn[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&&qn.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:R(r)}},mathmlBuilder:we});const Cn={"∫":"\\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:ze(o),needsLeadingSpace:r.length>0&&it.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:ze(o),needsLeadingSpace:r.length>0&&it.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,allowedInArgument:!0},handler({parser:e,funcName:t}){let r=t;return r.length===1&&(r=Cn[r]),{type:"op",mode:e.mode,limits:!1,parentIsSupSub:!1,symbol:!0,stack:!1,name:r}},mathmlBuilder:we});const Dn=(e,t)=>{let r=U(e.body,t.withFont("mathrm")),o=!0;for(let i=0;il.toText()).join("");r=[new j(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("mrow",r);{const i=new p("mo",[W("⁡","text")]);return ae([r[0],i])}}let s;if(o?(s=new p("mi",r),r[0].text.length===1&&s.setAttribute("mathvariant","normal")):s=new p("mrow",r),!e.parentIsSupSub){const i=new p("mo",[W("⁡","text")]),l=[s,i];if(e.needsLeadingSpace){const c=new p("mspace");c.setAttribute("width","0.1667em"),l.unshift(c)}if(!e.isFollowedByDelimiter){const c=new p("mspace");c.setAttribute("width","0.1667em"),l.push(c)}return ae(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:R(o),alwaysHandleSupSub:t==="\\operatornamewithlimits",limits:!1,parentIsSupSub:!1,isFollowedByDelimiter:ze(i),needsLeadingSpace:s.length>0&&it.includes(s)}},mathmlBuilder:Dn});u("\\operatorname","\\@ifstar\\operatornamewithlimits\\operatorname@");se({type:"ordgroup",mathmlBuilder(e,t){return ne(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:R(r)}},mathmlBuilder:(e,t)=>{const r=U(e.body,t);return new p("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(R(e.body),t),o=new p("mphantom",r),s=new p("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(R(e.body),t),o=new p("mphantom",r),s=new p("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:R(t[0])}},mathmlBuilder(e,t){const r=U(e.body,t),o=Qe(r);return o.setAttribute("style","font-weight:bold"),o}});const gr=(e,t)=>{const r=t.withLevel(M.TEXT),o=new p("mpadded",[E(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=D(r[0],"size").value;t==="\\lower"&&(o.number*=-1);const s=r[1];return{type:"raise",mode:e.mode,dy:o,body:s}},mathmlBuilder:gr});S({type:"raise",names:["\\raisebox"],props:{numArgs:2,argTypes:["size","hbox"],allowedInText:!0},handler({parser:e,funcName:t},r){const o=D(r[0],"size").value,s=r[1];return{type:"raise",mode:e.mode,dy:o,body:s}},mathmlBuilder:gr});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(hr,"")}},mathmlBuilder(e,t){const r=e.funcName==="\\ref"?["tml-ref"]:["tml-ref","tml-eqref"];return new Zt("#"+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=E(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=D(t[0],"size"),i=D(t[1],"size");return{type:"rule",mode:e.mode,shift:o&&D(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("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 c=new p("mpadded",[l]);return s.number>=0?c.setAttribute("height","+"+s.number+s.unit):(c.setAttribute("height",s.number+s.unit),c.setAttribute("depth","+"+-s.number+s.unit)),c.setAttribute("voffset",s.number+s.unit),c}});const Et=/^[0-9]$/,Bn={0:"₀",1:"₁",2:"₂",3:"₃",4:"₄",5:"₅",6:"₆",7:"₇",8:"₈",9:"₉"},$n={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"||!Et.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"||!Et.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=>$n[i]).join(""),o=e.denominator.split("").map(i=>Bn[i]).join(""),s=new j(r+"⁄"+o,e.mode,t);return new p("mn",[s],["special-fraction"])}});const zt={"\\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(zt[e.funcName]),o=U(e.body,r),s=Qe(o),i=(zt[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]&&D(r[0],"ordgroup");if(i){let c="";for(let h=0;h{const r=new p("mpadded",[E(e.body,t)]);return e.smashHeight&&r.setAttribute("height","0px"),e.smashDepth&&r.setAttribute("depth","0px"),r}});const On=["a","c","e","ı","m","n","o","r","s","u","v","w","x","z","α","ε","ι","κ","ν","ο","π","σ","τ","υ","ω","\\alpha","\\epsilon","\\iota","\\kappa","\\nu","\\omega","\\pi","\\tau","\\omega"];S({type:"sqrt",names:["\\sqrt"],props:{numArgs:1,numOptionalArgs:1},handler({parser:e},t,r){const o=r[0],s=t[0];return s.body&&s.body.length===1&&s.body[0].text&&On.includes(s.body[0].text)&&s.body.push({type:"rule",mode:"math",shift:null,width:{number:0,unit:"pt"},height:{number:.5,unit:"em"}}),{type:"sqrt",mode:e.mode,body:s,index:o}},mathmlBuilder(e,t){const{body:r,index:o}=e;return o?new p("mroot",[E(r,t),E(o,t.incrementLevel())]):new p("msqrt",[E(r,t)])}});const En={display:0,text:1,script:2,scriptscript:3},zn={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=Qe(o),i=zn[e.scriptLevel];return s.setAttribute("scriptlevel",i[0]),s.setAttribute("displaystyle",i[1]),s}});const Ln=/^m(over|under|underover)$/,Fn="DHKLUcegorsuvxyzΠΥΨαδηιμνοτυχϵ",In="BCEFGIMNOPQRSTXZlpqtwΓΘΞΣΦΩβεζθξρςφψϑϕϱ",Nn="AJdfΔΛ";se({type:"supsub",mathmlBuilder(e,t){let r=!1,o,s,i=!1,l=!1,c=!1;e.base&&e.base.type==="horizBracket"&&(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,c=e.base.needsLeadingSpace);const h=e.stack&&e.base.body.length===1?[E(e.base.body[0],t)]:[E(e.base,t)],f=t.inSubOrSup();if(e.sub){const y=E(e.sub,f);t.level===3&&y.setAttribute("scriptlevel","2"),h.push(y)}if(e.sup){const y=E(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"):Nn.indexOf(_)>-1&&y.classes.push("tml-lrg-pad")}h.push(y)}let k;if(r)k=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===M.DISPLAY||y.alwaysHandleSupSub)||y&&y.type==="operatorname"&&y.alwaysHandleSupSub&&(t.level===M.DISPLAY||y.limits)?k="munderover":k="msubsup"}else{const y=e.base;e.stack||y&&y.type==="op"&&y.limits&&(t.level===M.DISPLAY||y.alwaysHandleSupSub)||y&&y.type==="operatorname"&&y.alwaysHandleSupSub&&(y.limits||t.level===M.DISPLAY)?k="munder":k="msub"}else{const y=e.base;y&&y.type==="op"&&y.limits&&(t.level===M.DISPLAY||y.alwaysHandleSupSub)||y&&y.type==="operatorname"&&y.alwaysHandleSupSub&&(y.limits||t.level===M.DISPLAY)?k="mover":k="msup"}let x=new p(k,h);if(i){const y=new p("mo",[W("⁡","text")]);if(c){const _=new p("mspace");_.setAttribute("width","0.1667em"),x=ae([_,x,y])}else x=ae([x,y]);if(l){const _=new p("mspace");_.setAttribute("width","0.1667em"),x.children.push(_)}}else Ln.test(k)&&(x=new p("mrow",[x]));return x}});const Mn=["\\shortmid","\\nshortmid","\\shortparallel","\\nshortparallel","\\smallsetminus"],Pn=["\\Rsh","\\Lsh","\\restriction"],Gn=e=>{if(e.length===1){const t=e.codePointAt(0);return 8591-1||e.indexOf("harpoon")>-1||Pn.includes(e)};se({type:"atom",mathmlBuilder(e,t){const r=new p("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"&&Gn(e.text))r.setAttribute("stretchy","false");else if(Mn.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("mrow",[N(.222),r,N(.222)]):new p("mrow",[N(.2778),r,N(.2778)]);return r}});const Lt={mathbf:"bold",mathrm:"normal",textit:"italic",mathit:"italic",mathnormal:"italic",mathbb:"double-struck",mathcal:"script",mathfrak:"fraktur",mathscr:"script",mathsf:"sans-serif",mathtt:"monospace"},br=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=>Ft[e]||119899,"script-bold":e=>119951,fraktur:e=>Rn[e]||120003,"fraktur-bold":e=>120107,"double-struck":e=>jn[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=>Ft[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=>xr[e]||-51,italic:e=>0,"bold-italic":e=>Un[e]||58,script:e=>0,"script-bold":e=>0,fraktur:e=>0,"fraktur-bold":e=>0,"double-struck":e=>0,"sans-serif":e=>It[e]||116,"sans-serif-bold":e=>It[e]||116,"sans-serif-italic":e=>0,"sans-serif-bold-italic":e=>Vn[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}}),he=(e,t)=>{const r=e.codePointAt(0),o=64{const o=new p(r,[e]),s=new p("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};se({type:"mathord",mathmlBuilder(e,t){const r=W(e.text,e.mode,t),o=r.text.codePointAt(0),s=912he(h,i)).join("")),l=new p(c,[s])}else if(e.mode==="text")i!=="normal"&&(s.text=he(s.text,i)),l=new p("mtext",[s]);else if(Yn.has(e.text))l=new p("mo",[s]),l.classes.push("tml-prime");else{const c=s.text;i!=="italic"&&(s.text=he(s.text,i)),l=new p("mi",[s]),s.text===c&&Xn.test(c)&&l.setAttribute("mathvariant","italic")}return l}});const Jn={"\\nobreak":"nobreak","\\allowbreak":"allowbreak"},Qn={" ":{},"\\ ":{},"~":{className:"nobreak"},"\\space":{},"\\nobreakspace":{className:"nobreak"}};se({type:"spacing",mathmlBuilder(e,t){let r;if(Object.prototype.hasOwnProperty.call(Qn,e.text))r=new p("mtext",[new j(" ")]);else if(Object.prototype.hasOwnProperty.call(Jn,e.text))r=new p("mo"),e.text==="\\nobreak"&&r.setAttribute("linebreak","nobreak");else throw new v(`Unknown type of space "${e.text}"`);return r}});se({type:"tag"});const Nt={"\\text":void 0,"\\textrm":"textrm","\\textsf":"textsf","\\texttt":"texttt","\\textnormal":"textrm","\\textsc":"textsc"},Mt={"\\textbf":"textbf","\\textmd":"textmd"},eo={"\\textit":"textit","\\textup":"textup"},to=(e,t)=>{const r=e.font;if(r){if(Nt[r])return t.withTextFontFamily(Nt[r]);if(Mt[r])return t.withTextFontWeight(Mt[r]);if(r==="\\emph")return t.fontShape==="textit"?t.withTextFontShape("textup"):t.withTextFontShape("textit")}else return t;return t.withTextFontShape(eo[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:R(o),font:t}},mathmlBuilder(e,t){const r=to(e,t),o=ne(e.body,r);return $e(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("mtd",[E(e.body,t)]);r.style.padding="0";const o=new p("mtr",[r]);return new p("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 j(ro(e)),o=new p("mtext",[r]);return o.setAttribute("mathvariant","monospace"),o}});const ro=e=>e.body.replace(/ /g,e.star?"␣":" "),oe=Wt,yr=`[ \r ]`,no="\\\\[a-zA-Z@]+",oo="\\\\[^\uD800-\uDFFF]",ao=`(${no})${yr}*`,so=`\\\\( |[ \r ]+ ?)[ \r ]*`,Xe="[̀-ͯ]",Pt=new RegExp(`${Xe}+$`),io=`(${yr}+)|${so}|([!-\\[\\]-‧‪-퟿豈-￿]${Xe}*|[\uD800-\uDBFF][\uDC00-\uDFFF]${Xe}*|\\\\verb\\*([^]).*?\\4|\\\\verb([^*a-zA-Z]).*?\\5|${ao}|${oo})`;class Gt{constructor(t,r){this.input=t,this.settings=r,this.tokenRegex=new RegExp(io,"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 V(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 V(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 V(this,r,this.tokenRegex.lastIndex))}}class lo{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 wr={"^":!0,_:!0,"\\limits":!0,"\\nolimits":!0};class uo{constructor(t,r,o){this.settings=r,this.expansionCount=0,this.feed(t),this.macros=new lo(an,r.macros),this.mode=o,this.stack=[]}feed(t){this.lexer=new Gt(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,c=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[c]:"}")+"'",i);if(t&&o)if((l===0||l===1&&t[c]==="{")&&i.text===t[c]){if(++c,c===t.length){r.splice(-c,c);break}}else c=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 c=i.length-1;c>=0;--c){let h=i[c];if(h.text==="#"){if(c===0)throw new v("Incomplete placeholder at end of macro body",h);if(h=i[--c],h.text==="#")i.splice(c+1,1);else if(/^[1-9]$/.test(h.text))i.splice(c,2,...l[+h.text-1]);else throw new v("Not a valid argument number",h)}}}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 Gt(o,this.settings),l=[];let c=i.lex();for(;c.text!=="EOF";)l.push(c),c=i.lex();return l.reverse(),{tokens:l,numArgs:s}}return o}isDefined(t){return this.macros.has(t)||Object.prototype.hasOwnProperty.call(oe,t)||Object.prototype.hasOwnProperty.call(P.math,t)||Object.prototype.hasOwnProperty.call(P.text,t)||Object.prototype.hasOwnProperty.call(wr,t)}isExpandable(t){const r=this.macros.get(t);return r!=null?typeof r=="string"||typeof r=="function"||!r.unexpandable:Object.prototype.hasOwnProperty.call(oe,t)&&!oe[t].primitive}}const Rt=/^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/,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","ᵝ":"β","ᵞ":"γ","ᵟ":"δ","ᵠ":"ϕ","ᵡ":"χ","ᶿ":"θ"}),jt=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 Ge={"́":{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"}},Ut={á:"á",à:"à",ä:"ä",ǟ:"ǟ",ã:"ã",ā:"ā",ă:"ă",ắ:"ắ",ằ:"ằ",ẵ:"ẵ",ǎ:"ǎ",â:"â",ấ:"ấ",ầ:"ầ",ẫ:"ẫ",ȧ:"ȧ",ǡ:"ǡ",å:"å",ǻ:"ǻ",ḃ:"ḃ",ć:"ć",č:"č",ĉ:"ĉ",ċ:"ċ",ď:"ď",ḋ:"ḋ",é:"é",è:"è",ë:"ë",ẽ:"ẽ",ē:"ē",ḗ:"ḗ",ḕ:"ḕ",ĕ:"ĕ",ě:"ě",ê:"ê",ế:"ế",ề:"ề",ễ:"ễ",ė:"ė",ḟ:"ḟ",ǵ:"ǵ",ḡ:"ḡ",ğ:"ğ",ǧ:"ǧ",ĝ:"ĝ",ġ:"ġ",ḧ:"ḧ",ȟ:"ȟ",ĥ:"ĥ",ḣ:"ḣ",í:"í",ì:"ì",ï:"ï",ḯ:"ḯ",ĩ:"ĩ",ī:"ī",ĭ:"ĭ",ǐ:"ǐ",î:"î",ǰ:"ǰ",ĵ:"ĵ",ḱ:"ḱ",ǩ:"ǩ",ĺ:"ĺ",ľ:"ľ",ḿ:"ḿ",ṁ:"ṁ",ń:"ń",ǹ:"ǹ",ñ:"ñ",ň:"ň",ṅ:"ṅ",ó:"ó",ò:"ò",ö:"ö",ȫ:"ȫ",õ:"õ",ṍ:"ṍ",ṏ:"ṏ",ȭ:"ȭ",ō:"ō",ṓ:"ṓ",ṑ:"ṑ",ŏ:"ŏ",ǒ:"ǒ",ô:"ô",ố:"ố",ồ:"ồ",ỗ:"ỗ",ȯ:"ȯ",ȱ:"ȱ",ő:"ő",ṕ:"ṕ",ṗ:"ṗ",ŕ:"ŕ",ř:"ř",ṙ:"ṙ",ś:"ś",ṥ:"ṥ",š:"š",ṧ:"ṧ",ŝ:"ŝ",ṡ:"ṡ",ẗ:"ẗ",ť:"ť",ṫ:"ṫ",ú:"ú",ù:"ù",ü:"ü",ǘ:"ǘ",ǜ:"ǜ",ǖ:"ǖ",ǚ:"ǚ",ũ:"ũ",ṹ:"ṹ",ū:"ū",ṻ:"ṻ",ŭ:"ŭ",ǔ:"ǔ",û:"û",ů:"ů",ű:"ű",ṽ:"ṽ",ẃ:"ẃ",ẁ:"ẁ",ẅ:"ẅ",ŵ:"ŵ",ẇ:"ẇ",ẘ:"ẘ",ẍ:"ẍ",ẋ:"ẋ",ý:"ý",ỳ:"ỳ",ÿ:"ÿ",ỹ:"ỹ",ȳ:"ȳ",ŷ:"ŷ",ẏ:"ẏ",ẙ:"ẙ",ź:"ź",ž:"ž",ẑ:"ẑ",ż:"ż",Á:"Á",À:"À",Ä:"Ä",Ǟ:"Ǟ",Ã:"Ã",Ā:"Ā",Ă:"Ă",Ắ:"Ắ",Ằ:"Ằ",Ẵ:"Ẵ",Ǎ:"Ǎ",Â:"Â",Ấ:"Ấ",Ầ:"Ầ",Ẫ:"Ẫ",Ȧ:"Ȧ",Ǡ:"Ǡ",Å:"Å",Ǻ:"Ǻ",Ḃ:"Ḃ",Ć:"Ć",Č:"Č",Ĉ:"Ĉ",Ċ:"Ċ",Ď:"Ď",Ḋ:"Ḋ",É:"É",È:"È",Ë:"Ë",Ẽ:"Ẽ",Ē:"Ē",Ḗ:"Ḗ",Ḕ:"Ḕ",Ĕ:"Ĕ",Ě:"Ě",Ê:"Ê",Ế:"Ế",Ề:"Ề",Ễ:"Ễ",Ė:"Ė",Ḟ:"Ḟ",Ǵ:"Ǵ",Ḡ:"Ḡ",Ğ:"Ğ",Ǧ:"Ǧ",Ĝ:"Ĝ",Ġ:"Ġ",Ḧ:"Ḧ",Ȟ:"Ȟ",Ĥ:"Ĥ",Ḣ:"Ḣ",Í:"Í",Ì:"Ì",Ï:"Ï",Ḯ:"Ḯ",Ĩ:"Ĩ",Ī:"Ī",Ĭ:"Ĭ",Ǐ:"Ǐ",Î:"Î",İ:"İ",Ĵ:"Ĵ",Ḱ:"Ḱ",Ǩ:"Ǩ",Ĺ:"Ĺ",Ľ:"Ľ",Ḿ:"Ḿ",Ṁ:"Ṁ",Ń:"Ń",Ǹ:"Ǹ",Ñ:"Ñ",Ň:"Ň",Ṅ:"Ṅ",Ó:"Ó",Ò:"Ò",Ö:"Ö",Ȫ:"Ȫ",Õ:"Õ",Ṍ:"Ṍ",Ṏ:"Ṏ",Ȭ:"Ȭ",Ō:"Ō",Ṓ:"Ṓ",Ṑ:"Ṑ",Ŏ:"Ŏ",Ǒ:"Ǒ",Ô:"Ô",Ố:"Ố",Ồ:"Ồ",Ỗ:"Ỗ",Ȯ:"Ȯ",Ȱ:"Ȱ",Ő:"Ő",Ṕ:"Ṕ",Ṗ:"Ṗ",Ŕ:"Ŕ",Ř:"Ř",Ṙ:"Ṙ",Ś:"Ś",Ṥ:"Ṥ",Š:"Š",Ṧ:"Ṧ",Ŝ:"Ŝ",Ṡ:"Ṡ",Ť:"Ť",Ṫ:"Ṫ",Ú:"Ú",Ù:"Ù",Ü:"Ü",Ǘ:"Ǘ",Ǜ:"Ǜ",Ǖ:"Ǖ",Ǚ:"Ǚ",Ũ:"Ũ",Ṹ:"Ṹ",Ū:"Ū",Ṻ:"Ṻ",Ŭ:"Ŭ",Ǔ:"Ǔ",Û:"Û",Ů:"Ů",Ű:"Ű",Ṽ:"Ṽ",Ẃ:"Ẃ",Ẁ:"Ẁ",Ẅ:"Ẅ",Ŵ:"Ŵ",Ẇ:"Ẇ",Ẍ:"Ẍ",Ẋ:"Ẋ",Ý:"Ý",Ỳ:"Ỳ",Ÿ:"Ÿ",Ỹ:"Ỹ",Ȳ:"Ȳ",Ŷ:"Ŷ",Ẏ:"Ẏ",Ź:"Ź",Ž:"Ž",Ẑ:"Ẑ",Ż:"Ż",ά:"ά",ὰ:"ὰ",ᾱ:"ᾱ",ᾰ:"ᾰ",έ:"έ",ὲ:"ὲ",ή:"ή",ὴ:"ὴ",ί:"ί",ὶ:"ὶ",ϊ:"ϊ",ΐ:"ΐ",ῒ:"ῒ",ῑ:"ῑ",ῐ:"ῐ",ό:"ό",ὸ:"ὸ",ύ:"ύ",ὺ:"ὺ",ϋ:"ϋ",ΰ:"ΰ",ῢ:"ῢ",ῡ:"ῡ",ῠ:"ῠ",ώ:"ώ",ὼ:"ὼ",Ύ:"Ύ",Ὺ:"Ὺ",Ϋ:"Ϋ",Ῡ:"Ῡ",Ῠ:"Ῠ",Ώ:"Ώ",Ὼ:"Ὼ"};const co=["bin","op","open","punct","rel"],mo=/([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/,ho=/^ *\\text/;class Le{constructor(t,r,o=!1){this.mode="math",this.gullet=new uo(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(Le.endOfExpression.indexOf(i.text)!==-1||r&&i.text===r||o&&i.text==="\\middle"||t&&oe[i.text]&&oe[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||Pt.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:V.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},po=[2,2,3,3];class lt{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 lt(r)}withLevel(t){return this.extend({level:t})}incrementLevel(){return this.extend({level:Math.min(this.level+1,3)})}inSubOrSup(){return this.extend({level:po[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 fo="0.13.01";function kr(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 h=l.attributes.id.value;t[h]=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 h=l.getElementsByClassName("tml-tag");if(h.length>0){const f=l.attributes.id.value;t[f]=h[0].textContent}}[...e.getElementsByClassName("tml-ref")].forEach(l=>{const c=l.getAttribute("href");let h=t[c.slice(1)];l.className.indexOf("tml-eqref")===-1?(h=h.replace(/^\(/,""),h=h.replace(/\)$/,"")):(h.charAt(0)!=="("&&(h="("+h),h.slice(-1)!==")"&&(h=h+")"));const f=document.createElementNS("http://www.w3.org/1998/Math/MathML","mtext");f.appendChild(document.createTextNode(h));const k=document.createElementNS("http://www.w3.org/1998/Math/MathML","math");k.appendChild(f),l.textContent="",l.appendChild(k)})}const go=function(e,t,r){let o=r,s=0;const i=e.length;for(;obo(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(h=>e.startsWith(h.left));if(r=go(t[i].right,e,t[i].left.length),r===-1)break;const l=e.slice(0,r+t[i].right.length),c=xo.test(l)?l:e.slice(t[i].left.length,r);o.push({type:"math",data:c,rawData:l,display:t[i].display}),e=e.slice(r+t[i].right.length)}return e!==""&&o.push({type:"text",data:e}),o},Ar=[{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}]},Re=[{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}],wo=e=>e==="$"||e==="("?qe[e]:e==="$+"||e==="(+"?qe[e.slice(0,1)].concat(Re):e==="ams"?Re:e==="all"?qe["("].concat(qe.$).concat(Re):Ar,vo=function(e,t){const r=yo(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)&&Sr(o,t)}}},ko=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=wo(r.fences):r.delimiters=r.delimiters||Ar,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||{},Sr(e,r),kr(e)};let qr=function(e,t,r={}){t.textContent="";const o=t.tagName.toLowerCase()==="math";o&&(r.wrap="none");const s=ut(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."),qr=function(){throw new v("Temml doesn't work in quirks mode.")});const Ao=function(e,t){return ut(e,t).toMarkup()},So=function(e,t){const r=new Ke(t);return vr(e,r)},qo=function(e,t){const r=new Ke(t);if(r.macros={},!(typeof e=="string"||e instanceof String))throw new TypeError("Temml can only parse string typed expression");const o=new Le(e,r,!0);return delete o.gullet.macros.current["\\df@tag"],o.parse()},_o=function(e,t,r){if(r.throwOnError||!(e instanceof v))throw e;const o=new Ht(["temml-error"],[new zr(t+` `+e.toString())]);return o.style.color=r.errorColor,o.style.whiteSpace="pre-line",o},ut=function(e,t){const r=new Ke(t);try{const o=vr(e,r),s=new lt({level:r.displayMode?M.DISPLAY:M.TEXT,maxSize:r.maxSize});return Hr(o,e,s,r)}catch(o){return _o(o,e,r)}};var Co={version:fo,render:qr,renderToString:Ao,renderMathInElement:ko,postProcess:kr,ParseError:v,definePreamble:qo,__parse:So,__renderToMathMLTree:ut,__defineSymbol:n,__defineMacro:u};export{Co as default}; //# sourceMappingURL=temml-BQUKR1fw.js.map