95 lines
191 KiB
JavaScript
95 lines
191 KiB
JavaScript
|
|
var w=class e{constructor(t,r){let o=" "+t,s,i=r&&r.loc;if(i&&i.start<=i.end){let u=i.lexer.input;s=i.start;let h=i.end;s===u.length?o+=" at end of input: ":o+=" at position "+(s+1)+": ";let x=u.slice(s,h).replace(/[^]/g,"$&̲"),A;s>15?A="…"+u.slice(s-15,s):A=u.slice(0,s);let q;h+15<u.length?q=u.slice(h,h+15)+"…":q=u.slice(h),o+=A+x+q}let l=new Error(o);return l.name="ParseError",l.__proto__=e.prototype,l.position=s,l}};w.prototype.__proto__=Error.prototype;var yr=function(e,t){return e===void 0?t:e},wr=/([A-Z])/g,vr=function(e){return e.replace(wr,"-$1").toLowerCase()},kr={"&":"&",">":">","<":"<",'"':""","'":"'"},Ar=/[&><"']/g;function Sr(e){return String(e).replace(Ar,t=>kr[t])}var me=function(e){return e.type==="ordgroup"||e.type==="color"?e.body.length===1?me(e.body[0]):e:e.type==="font"?me(e.body):e},qr=function(e){let t=me(e);return t.type==="mathord"||t.type==="textord"||t.type==="atom"},_r=function(e){if(!e)throw new Error("Expected non-null, but got "+String(e));return e},Tr=function(e){let 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"},Cr=function(e){return+e.toFixed(4)},N={deflt:yr,escape:Sr,hyphenate:vr,getBaseElem:me,isCharacterBox:qr,protocolFromUrl:Tr,round:Cr},pe=class{constructor(t){t=t||{},this.displayMode=N.deflt(t.displayMode,!1),this.annotate=N.deflt(t.annotate,!1),this.leqno=N.deflt(t.leqno,!1),this.throwOnError=N.deflt(t.throwOnError,!1),this.errorColor=N.deflt(t.errorColor,"#b22222"),this.macros=t.macros||{},this.wrap=N.deflt(t.wrap,"tex"),this.xml=N.deflt(t.xml,!1),this.colorIsTextColor=N.deflt(t.colorIsTextColor,!1),this.strict=N.deflt(t.strict,!1),this.trust=N.deflt(t.trust,!1),this.maxSize=t.maxSize===void 0?[1/0,1/0]:Array.isArray(t.maxSize)?t.maxSize:[1/0,1/0],this.maxExpand=Math.max(0,N.deflt(t.maxExpand,1e3))}isTrusted(t){if(t.url&&!t.protocol){let o=N.protocolFromUrl(t.url);if(o==null)return!1;t.protocol=o}return!!(typeof this.trust=="function"?this.trust(t):this.trust)}},Ut={},Ce={};function S({type:e,names:t,props:r,handler:o,mathmlBuilder:s}){let 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;l<t.length;++l)Ut[t[l]]=i;e&&s&&(Ce[e]=s)}function se({type:e,mathmlBuilder:t}){S({type:e,names:[],props:{numArgs:0},handler(){throw new Error("Should never be called.")},mathmlBuilder:t})}var fe=function(e){return e.type==="ordgroup"&&e.body.length===1?e.body[0]:e},z=function(e){return e.type==="ordgroup"?e.body:[e]},ge=class{constructor(t){this.children=t,this.classes=[],this.style={}}hasClass(t){return this.classes.includes(t)}toNode(){let t=document.createDocumentFragment();for(let r=0;r<this.children.length;r++)t.appendChild(this.children[r].toNode());return t}toMarkup(){let t="";for(let r=0;r<this.children.length;r++)t+=this.children[r].toMarkup();return t}toText(){let t=r=>r.toText();return this.children.map(t).join("")}},ue=function(e){return e.filter(t=>t).join(" ")},Dr=function(e,t){this.classes=e||[],this.attributes={},this.style=t||{}},Br=function(e){let t=document.createElement(e);t.className=ue(this.classes);for(let r in this.style)Object.prototype.hasOwnProperty.call(this.style,r)&&(t.style[r]=this.style[r]);for(let r in this.attributes)Object.prototype.hasOwnProperty.call(this.attributes,r)&&t.setAttribute(r,this.attributes[r]);for(let r=0;r<this.children.length;r++)t.appendChild(this.children[r].toNode());return t},Nr=function(e){let t=`<${e}`;this.classes.length&&(t+=` class="${N.escape(ue(this.classes))}"`);let r="";for(let o in this.style)Object.prototype.hasOwnProperty.call(this.style,o)&&(r+=`${N.hyphenate(o)}:${this.style[o]};`);r&&(t+=` style="${r}"`);for(let o in this.attributes)Object.prototype.hasOwnProperty.call(this.attributes,o)&&(t+=` ${o}="${N.escape(this.attributes[o])}"`);t+=">";for(let o=0;o<this.c
|
|||
|
|
"Apricot": "#ffb484",
|
|||
|
|
"Aquamarine": "#08b4bc",
|
|||
|
|
"Bittersweet": "#c84c14",
|
|||
|
|
"blue": "#0000FF",
|
|||
|
|
"Blue": "#303494",
|
|||
|
|
"BlueGreen": "#08b4bc",
|
|||
|
|
"BlueViolet": "#503c94",
|
|||
|
|
"BrickRed": "#b8341c",
|
|||
|
|
"brown": "#BF8040",
|
|||
|
|
"Brown": "#802404",
|
|||
|
|
"BurntOrange": "#f8941c",
|
|||
|
|
"CadetBlue": "#78749c",
|
|||
|
|
"CarnationPink": "#f884b4",
|
|||
|
|
"Cerulean": "#08a4e4",
|
|||
|
|
"CornflowerBlue": "#40ace4",
|
|||
|
|
"cyan": "#00FFFF",
|
|||
|
|
"Cyan": "#08acec",
|
|||
|
|
"Dandelion": "#ffbc44",
|
|||
|
|
"darkgray": "#404040",
|
|||
|
|
"DarkOrchid": "#a8548c",
|
|||
|
|
"Emerald": "#08ac9c",
|
|||
|
|
"ForestGreen": "#089c54",
|
|||
|
|
"Fuchsia": "#90348c",
|
|||
|
|
"Goldenrod": "#ffdc44",
|
|||
|
|
"gray": "#808080",
|
|||
|
|
"Gray": "#98949c",
|
|||
|
|
"green": "#00FF00",
|
|||
|
|
"Green": "#08a44c",
|
|||
|
|
"GreenYellow": "#e0e474",
|
|||
|
|
"JungleGreen": "#08ac9c",
|
|||
|
|
"Lavender": "#f89cc4",
|
|||
|
|
"lightgray": "#c0c0c0",
|
|||
|
|
"lime": "#BFFF00",
|
|||
|
|
"LimeGreen": "#90c43c",
|
|||
|
|
"magenta": "#FF00FF",
|
|||
|
|
"Magenta": "#f0048c",
|
|||
|
|
"Mahogany": "#b0341c",
|
|||
|
|
"Maroon": "#b03434",
|
|||
|
|
"Melon": "#f89c7c",
|
|||
|
|
"MidnightBlue": "#086494",
|
|||
|
|
"Mulberry": "#b03c94",
|
|||
|
|
"NavyBlue": "#086cbc",
|
|||
|
|
"olive": "#7F7F00",
|
|||
|
|
"OliveGreen": "#407c34",
|
|||
|
|
"orange": "#FF8000",
|
|||
|
|
"Orange": "#f8843c",
|
|||
|
|
"OrangeRed": "#f0145c",
|
|||
|
|
"Orchid": "#b074ac",
|
|||
|
|
"Peach": "#f8945c",
|
|||
|
|
"Periwinkle": "#8074bc",
|
|||
|
|
"PineGreen": "#088c74",
|
|||
|
|
"pink": "#ff7f7f",
|
|||
|
|
"Plum": "#98248c",
|
|||
|
|
"ProcessBlue": "#08b4ec",
|
|||
|
|
"purple": "#BF0040",
|
|||
|
|
"Purple": "#a0449c",
|
|||
|
|
"RawSienna": "#983c04",
|
|||
|
|
"red": "#ff0000",
|
|||
|
|
"Red": "#f01c24",
|
|||
|
|
"RedOrange": "#f86434",
|
|||
|
|
"RedViolet": "#a0246c",
|
|||
|
|
"Rhodamine": "#f0549c",
|
|||
|
|
"Royallue": "#0874bc",
|
|||
|
|
"RoyalPurple": "#683c9c",
|
|||
|
|
"RubineRed": "#f0047c",
|
|||
|
|
"Salmon": "#f8948c",
|
|||
|
|
"SeaGreen": "#30bc9c",
|
|||
|
|
"Sepia": "#701404",
|
|||
|
|
"SkyBlue": "#48c4dc",
|
|||
|
|
"SpringGreen": "#c8dc64",
|
|||
|
|
"Tan": "#e09c74",
|
|||
|
|
"teal": "#007F7F",
|
|||
|
|
"TealBlue": "#08acb4",
|
|||
|
|
"Thistle": "#d884b4",
|
|||
|
|
"Turquoise": "#08b4cc",
|
|||
|
|
"violet": "#800080",
|
|||
|
|
"Violet": "#60449c",
|
|||
|
|
"VioletRed": "#f054a4",
|
|||
|
|
"WildStrawberry": "#f0246c",
|
|||
|
|
"yellow": "#FFFF00",
|
|||
|
|
"Yellow": "#fff404",
|
|||
|
|
"YellowGreen": "#98cc6c",
|
|||
|
|
"YellowOrange": "#ffa41c"
|
|||
|
|
}`),ce=(e,t)=>{let r="";if(e==="HTML"){if(!nn.test(t))throw new w("Invalid HTML input.");r=t}else if(e==="RGB"){if(!an.test(t))throw new w("Invalid RGB input.");t.split(",").map(o=>{r+=yt(Number(o.trim()))})}else{if(!sn.test(t))throw new w("Invalid rbg input.");t.split(",").map(o=>{let s=Number(o.trim());if(s>1)throw new w("Color rgb input must be < 1.");r+=yt(Number((s*255).toFixed(0)))})}return r.charAt(0)!=="#"&&(r="#"+r),r},xe=(e,t,r)=>{let o=`\\\\color@${e}`;if(!on.exec(e))throw new w("Invalid color: '"+e+"'",r);return ln.test(e)?"#"+e:(e.charAt(0)==="#"||(t.has(o)?e=t.get(o).tokens[0].text:wt[e]&&(e=wt[e])),e)},Yt=(e,t)=>{let r=U(e.body,t.withColor(e.color));return r=r.map(o=>(o.style.color=e.color,o)),p.newDocumentFragment(r)};S({type:"color",names:["\\textcolor"],props:{numArgs:2,numOptionalArgs:1,allowedInText:!0,argTypes:["raw","raw","original"]},handler({parser:e,token:t},r,o){let s=o[0]&&C(o[0],"raw").string,i="";if(s){let u=C(r[0],"raw").string;i=ce(s,u)}else i=xe(C(r[0],"raw").string,e.gullet.macros,t);let l=r[1];return{type:"color",mode:e.mode,color:i,isTextColor:!0,body:z(l)}},mathmlBuilder:Yt});S({type:"color",names:["\\color"],props:{numArgs:1,numOptionalArgs:1,allowedInText:!0,argTypes:["raw","raw"]},handler({parser:e,breakOnTokenText:t,token:r},o,s){let i=s[0]&&C(s[0],"raw").string,l="";if(i){let h=C(o[0],"raw").string;l=ce(i,h)}else l=xe(C(o[0],"raw").string,e.gullet.macros,r);let u=e.parseExpression(!0,t,!0);return{type:"color",mode:e.mode,color:l,isTextColor:!1,body:u}},mathmlBuilder:Yt});S({type:"color",names:["\\definecolor"],props:{numArgs:3,allowedInText:!0,argTypes:["raw","raw","raw"]},handler({parser:e,funcName:t,token:r},o){let s=C(o[0],"raw").string;if(!/^[A-Za-z]+$/.test(s))throw new w("Color name must be latin letters.",r);let i=C(o[1],"raw").string;if(!["HTML","RGB","rgb"].includes(i))throw new w("Color model must be HTML, RGB, or rgb.",r);let l=C(o[2],"raw").string,u=ce(i,l);return e.gullet.macros.set(`\\\\color@${s}`,{tokens:[{text:u}],numArgs:0}),{type:"internal",mode:e.mode}}});S({type:"cr",names:["\\\\"],props:{numArgs:0,numOptionalArgs:0,allowedInText:!0},handler({parser:e},t,r){let o=e.gullet.future().text==="["?e.parseSizeGroup(!0):null,s=!e.settings.displayMode;return{type:"cr",mode:e.mode,newLine:s,size:o&&C(o,"size").value}},mathmlBuilder(e,t){let r=new p.MathNode("mo");if(e.newLine&&(r.setAttribute("linebreak","newline"),e.size)){let o=K(e.size,t);r.setAttribute("height",o.number+o.unit)}return r}});var Ve={"\\global":"\\global","\\long":"\\\\globallong","\\\\globallong":"\\\\globallong","\\def":"\\gdef","\\gdef":"\\gdef","\\edef":"\\xdef","\\xdef":"\\xdef","\\let":"\\\\globallet","\\futurelet":"\\\\globalfuture"},Ne=e=>{let t=e.text;if(/^(?:[\\{}$&#^_]|EOF)$/.test(t))throw new w("Expected a control sequence",e);return t},un=e=>{let t=e.gullet.popToken();return t.text==="="&&(t=e.gullet.popToken(),t.text===" "&&(t=e.gullet.popToken())),t},Kt=(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();let r=e.fetch();if(Ve[r.text])return(t==="\\global"||t==="\\\\globallong")&&(r.text=Ve[r.text]),C(e.parseFunction(),"internal");throw new w("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(),o=r.text;if(/^(?:[\\{}$&#^_]|EOF)$/.test(o))throw new w("Expected a control sequence",r);let s=0,i,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 w(`Invalid argument number "${r.text}"`);if(parseInt(r.text)!==s+1)throw new w(`Argument number "${r.text}" out of order`);s++,l.push([])}else{if(r.text==="EOF")throw new w("Expe
|
|||
|
|
{\\smash{\\lower4mu{\\char"2323}}}\\mkern5mu}`);c("\\incoh",`{\\mkern5mu\\rule{}{0.7em}\\mathrlap{\\smash{\\raise2mu{\\char"2323}}}
|
|||
|
|
{\\smash{\\lower4mu{\\char"2322}}}\\mkern5mu}`);c("\\standardstate","\\text{\\tiny\\char`⦵}");c("\\ce",function(e){return nr(e.consumeArgs(1)[0],"ce")});c("\\pu",function(e){return nr(e.consumeArgs(1)[0],"pu")});c("\\uniDash","{\\rule{0.672em}{0.06em}}");c("\\triDash","{\\rule{0.15em}{0.06em}\\kern2mu\\rule{0.15em}{0.06em}\\kern2mu\\rule{0.15em}{0.06em}}");c("\\tripleDash","\\kern0.075em\\raise0.25em{\\triDash}\\kern0.075em");c("\\tripleDashOverLine","\\kern0.075em\\mathrlap{\\raise0.125em{\\uniDash}}\\raise0.34em{\\triDash}\\kern0.075em");c("\\tripleDashOverDoubleLine","\\kern0.075em\\mathrlap{\\mathrlap{\\raise0.48em{\\triDash}}\\raise0.27em{\\uniDash}}{\\raise0.05em{\\uniDash}}\\kern0.075em");c("\\tripleDashBetweenDoubleLine","\\kern0.075em\\mathrlap{\\mathrlap{\\raise0.48em{\\uniDash}}\\raise0.27em{\\triDash}}{\\raise0.05em{\\uniDash}}\\kern0.075em");var nr=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=M.go(y.go(r,t));return i},y={go:function(e,t){if(!e)return[];t===void 0&&(t="ce");var r="0",o={};o.parenthesisLevel=0,e=e.replace(/\n/g," "),e=e.replace(/[\u2212\u2013\u2014\u2010]/g,"-"),e=e.replace(/[\u2026]/g,"...");for(var s,i=10,l=[];;){s!==e?(i=10,s=e):i--;var u=y.stateMachines[t],h=u.transitions[r]||u.transitions["*"];e:for(var x=0;x<h.length;x++){var A=y.patterns.match_(h[x].pattern,e);if(A){for(var q=h[x].task,b=0;b<q.action_.length;b++){var k;if(u.actions[q.action_[b].type_])k=u.actions[q.action_[b].type_](o,A.match_,q.action_[b].option);else if(y.actions[q.action_[b].type_])k=y.actions[q.action_[b].type_](o,A.match_,q.action_[b].option);else throw["MhchemBugA","mhchem bug A. Please report. ("+q.action_[b].type_+")"];y.concatArray(l,k)}if(r=q.nextState||r,e.length>0){if(q.revisit||(e=A.remainder),!q.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<t.length;r++)e.push(t[r]);else e.push(t)},patterns:{patterns:{empty:/^$/,else:/^./,else2:/^./,space:/^\s/,"space A":/^\s(?=[A-Z\\$])/,space$:/^\s$/,"a-z":/^[a-z]/,x:/^x/,x$:/^x$/,i$:/^i$/,letters:/^(?:[a-zA-Z\u03B1-\u03C9\u0391-\u03A9?@]|(?:\\(?:alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega|Gamma|Delta|Theta|Lambda|Xi|Pi|Sigma|Upsilon|Phi|Psi|Omega)(?:\s+|\{\}|(?![a-zA-Z]))))+/,"\\greek":/^\\(?:alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega|Gamma|Delta|Theta|Lambda|Xi|Pi|Sigma|Upsilon|Phi|Psi|Omega)(?:\s+|\{\}|(?![a-zA-Z]))/,"one lowercase latin letter $":/^(?:([a-z])(?:$|[^a-zA-Z]))$/,"$one lowercase latin letter$ $":/^\$(?:([a-z])(?:$|[^a-zA-Z]))\$$/,"one lowercase greek letter $":/^(?:\$?[\u03B1-\u03C9]\$?|\$?\\(?:alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega)\s*\$?)(?:\s+|\{\}|(?![a-zA-Z]))$/,digits:/^[0-9]+/,"-9.,9":/^[+\-]?(?:[0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+))/,"-9.,9 no missing 0":/^[+\-]?[0-9]+(?:[.,][0-9]+)?/,"(-)(9.,9)(e)(99)":function(e){var t=e.match(/^(\+\-|\+\/\-|\+|\-|\\pm\s?)?([0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+))?(\((?:[0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+))\))?(?:([eE]|\s*(\*|x|\\times|\u00D7)\s*10\^)([+\-]?[0-9]+|\{[+\-]?[0-9]+\}))?/);return t&&t[0]?{match_:t.splice(1),remainder:e.substr(t[0].length)}:null},"(-)(9)^(-9)":function(e){var t=e.match(/^(\+\-|\+\/\-|\+|\-|\\pm\s?)?([0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+)?)\^([+\-]?[0-9]+|\{[+\-]?[0-9]+\})/);return t&&t[0]?{match_:t.splice(1),remainder:e.substr(t[0].length)}:null},"state of aggregation $":function(e){var t=y.patterns.findObserveGroups(e,"",/^\([a-z]{1,3}(?=[\),])/,")","");if(t&&t.remainder.match(/^($|[\s,;\)\]\}])/))return t;var r=e.match(/^(?:\((?:\\ca\s?)?\$[amothc]\$\))/);return r?{match_:r[0],remainder:e.substr(r[0].length)}:null},"_{(state of aggregation)}$":/^_\{(\([a-z]{1,3}\))\}/,"{[(":/^(?:\\\{|\[|\()/,"
|
|||
|
|
Try \\math${t.slice(1)}`,r);t=t.slice(1)}else t=t.slice(5);let s=o[0];return{type:"lap",mode:e.mode,alignment:t,body:s}},mathmlBuilder:(e,t)=>{let r;if(e.alignment==="llap"){let i=U(z(e.body),t),l=new p.MathNode("mphantom",i);r=new p.MathNode("mpadded",[l]),r.setAttribute("width","0px")}let o=O(e.body,t),s;if(e.alignment==="llap"?(o.style.position="absolute",o.style.right="0",o.style.bottom="0",s=new p.MathNode("mpadded",[r,o])):s=new p.MathNode("mpadded",[o]),e.alignment==="rlap")e.body.body.length>0&&e.body.body[0].type==="genfrac"&&s.setAttribute("lspace","0.16667em");else{let i=e.alignment==="llap"?"-1":"-0.5";s.setAttribute("lspace",i+"width"),e.alignment==="llap"?s.style.position="relative":(s.style.display="flex",s.style.justifyContent="center")}return s.setAttribute("width","0px"),s}});S({type:"ordgroup",names:["\\(","$"],props:{numArgs:0,allowedInText:!0,allowedInMath:!1},handler({funcName:e,parser:t},r){let o=t.mode;t.switchMode("math");let 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 w(`Mismatched ${e.funcName}`,t)}});var wn=(e,t)=>{switch(t.level){case F.DISPLAY:return e.display;case F.TEXT:return e.text;case F.SCRIPT:return e.script;case F.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:z(t[0]),text:z(t[1]),script:z(t[2]),scriptscript:z(t[3])}),mathmlBuilder:(e,t)=>{let r=wn(e,t);return te(r,t)}});var vn=["text","textord","mathord","atom"],ne=e=>{let t=new p.MathNode("mspace");return t.setAttribute("width",e+"em"),t};function cr(e,t){let r,o=U(e.body,t);if(e.mclass==="minner")r=new p.MathNode("mpadded",o);else if(e.mclass==="mord")e.isCharacterBox||o[0].type==="mathord"?(r=o[0],r.type="mi",r.children.length===1&&r.children[0].text&&r.children[0].text==="∇"&&r.setAttribute("mathvariant","normal")):r=new p.MathNode("mi",o);else{r=new p.MathNode("mrow",o),e.mustPromote?(r=o[0],r.type="mo",e.isCharacterBox&&e.body[0].text&&/[A-Za-z]/.test(e.body[0].text)&&r.setAttribute("mathvariant","italic")):r=new p.MathNode("mrow",o);let s=t.level<2;r.type==="mrow"?s&&(e.mclass==="mbin"?(r.children.unshift(ne(.2222)),r.children.push(ne(.2222))):e.mclass==="mrel"?(r.children.unshift(ne(.2778)),r.children.push(ne(.2778))):e.mclass==="mpunct"?r.children.push(ne(.1667)):e.mclass==="minner"&&(r.children.unshift(ne(.0556)),r.children.push(ne(.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){let o=r[0],s=N.isCharacterBox(o),i=!0,l={type:"mathord",text:"",mode:e.mode},u=o.body?o.body:[o];for(let h of u)if(vn.includes(h.type))I[e.mode][h.text]?l.text+=I[e.mode][h.text].replace:h.text?l.text+=h.text:h.body&&h.body.map(x=>{l.text+=x.text});else{i=!1;break}return{type:"mclass",mode:e.mode,mclass:"m"+t.slice(5),body:z(i?l:o),isCharacterBox:s,mustPromote:i}},mathmlBuilder:cr});var kn=e=>{let t=e.type==="ordgroup"&&e.body.length?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:kn(t[0]),body:z(t[1]),isCharacterBox:N.isCharacterBox(t[1])}}});S({type:"mclass",n
|
|||
|
|
]`,Xn="\\\\[a-zA-Z@]+",Yn="\\\\[^\uD800-\uDFFF]",Kn=`(${Xn})${pr}*`,Jn=`\\\\(
|
|||
|
|
|[ \r ]+
|
|||
|
|
?)[ \r ]*`,Ze="[̀-ͯ]",Pt=new RegExp(`${Ze}+$`),Qn=`(${pr}+)|${Jn}|([!-\\[\\]-‧-豈-]${Ze}*|[\uD800-\uDBFF][\uDC00-\uDFFF]${Ze}*|\\\\verb\\*([^]).*?\\4|\\\\verb([^*a-zA-Z]).*?\\5|${Kn}|${Yn})`,Oe=class{constructor(t,r){this.input=t,this.settings=r,this.tokenRegex=new RegExp(Qn,"g"),this.catcodes={"%":14,"~":13}}setCatcode(t,r){this.catcodes[t]=r}lex(){let t=this.input,r=this.tokenRegex.lastIndex;if(r===t.length)return new Z("EOF",new V(this,r,r));let o=this.tokenRegex.exec(t);if(o===null||o.index!==r)throw new w(`Unexpected character: '${t[r]}'`,new Z(t[r],new V(this,r,r+1)));let s=o[6]||o[3]||(o[2]?"\\ ":" ");if(this.catcodes[s]===14){let i=t.indexOf(`
|
|||
|
|
`,this.tokenRegex.lastIndex);if(i===-1){if(this.tokenRegex.lastIndex=t.length,this.settings.strict)throw new w("% 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 Z(s,new V(this,r,this.tokenRegex.lastIndex))}},Xe=class{constructor(t={},r={}){this.current=r,this.builtins=t,this.undefStack=[]}beginGroup(){this.undefStack.push({})}endGroup(){if(this.undefStack.length===0)throw new w("Unbalanced namespace destruction: attempt to pop global namespace; please report this as a bug");let t=this.undefStack.pop();for(let 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;s<this.undefStack.length;s++)delete this.undefStack[s][t];this.undefStack.length>0&&(this.undefStack[this.undefStack.length-1][t]=r)}else{let s=this.undefStack[this.undefStack.length-1];s&&!Object.prototype.hasOwnProperty.call(s,t)&&(s[t]=this.current[t])}this.current[t]=r}},fr={"^":!0,_:!0,"\\limits":!0,"\\nolimits":!0},Ye=class{constructor(t,r,o){this.settings=r,this.expansionCount=0,this.feed(t),this.macros=new Xe(hn,r.macros),this.mode=o,this.stack=[]}feed(t){this.lexer=new Oe(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 Z("EOF",o.loc)),this.pushTokens(s),r.range(o,"")}consumeSpaces(){for(;this.future().text===" ";)this.stack.pop()}consumeArg(t){let r=[],o=t&&t.length>0;o||this.consumeSpaces();let s=this.future(),i,l=0,u=0;do{if(i=this.popToken(),r.push(i),i.text==="{")++l;else if(i.text==="}"){if(--l,l===-1)throw new w("Extra }",i)}else if(i.text==="EOF")throw new w("Unexpected end of input in a macro argument, expected '"+(t&&o?t[u]:"}")+"'",i);if(t&&o)if((l===0||l===1&&t[u]==="{")&&i.text===t[u]){if(++u,u===t.length){r.splice(-u,u);break}}else u=0}while(l!==0||o);return s.text==="{"&&r[r.length-1].text==="}"&&(r.pop(),r.shift()),r.reverse(),{tokens:r,start:s,end:i}}consumeArgs(t,r){if(r){if(r.length!==t+1)throw new w("The length of delimiters doesn't match the number of args!");let s=r[0];for(let i=0;i<s.length;i++){let l=this.popToken();if(s[i]!==l.text)throw new w("Use of the macro doesn't match its definition",l)}}let o=[];for(let s=0;s<t;s++)o.push(this.consumeArg(r&&r[s+1]).tokens);return o}expandOnce(t){let r=this.popToken(),o=r.text,s=r.noexpand?null:this._getExpansion(o);if(s==null||t&&s.unexpandable){if(t&&s==null&&o[0]==="\\"&&!this.isDefined(o))throw new w("Undefined control sequence: "+o);return this.pushToken(r),!1}if(this.expansionCount++,this.expansionCount>this.settings.maxExpand)throw new w("Too many expansions: infinite loop or need to increase maxExpand setting");let i=s.tokens,l=this.consumeArgs(s.numArgs,s.delimiters);if(s.numArgs){i=i.slice();for(let u=i.length-1;u>=0;--u){let h=i[u];if(h.text==="#"){if(u===0)throw new w("Incomplete placeholder at end of macro body",h);if(h=i[--u],h.text==="#")i.splice(u+1,1);else if(/^[1-9]$/.test(h.text))i.splice(u,2,...l[+h.text-1]);else throw new w("Not a valid argument number",h)}}}return this.pushTokens(i),i.length}expandAfterFuture(){return this.expandOnce(),this.future()}expandNextToken(){for(;;)if(this.expandOnce()===!1){let t=this.stack.pop();return t.treatAsRelax&&(t.text="\\relax"),t}throw new Error}expandMacro(t){return this.macros.has(t)?this.expandTokens([new Z(
|
|||
|
|
please report what input caused this bug`);return i=i.slice(1,-1),{type:"verb",mode:"text",body:i,star:l}}if(Object.prototype.hasOwnProperty.call(jt,r[0])&&this.mode==="math"&&!I[this.mode][r[0]]){if(this.settings.strict&&this.mode==="math")throw new w(`Accented Unicode text character "${r[0]}" used in math mode`,t);r=jt[r[0]]+r.slice(1)}let o=this.mode==="math"?Pt.exec(r):null;o&&(r=r.substring(0,o.index),r==="i"?r="ı":r==="j"&&(r="ȷ"));let s;if(I[this.mode][r]){let i=I[this.mode][r].group;i==="bin"&&eo.includes(this.prevAtomType)&&(i="open");let l=V.range(t),u;if(Object.prototype.hasOwnProperty.call(Lr,i)){let h=i;u={type:"atom",mode:this.mode,family:h,loc:l,text:r}}else{if(Rt[r]){this.consume();let h=this.fetch().text.charCodeAt(0),x=h===65025?"mathscr":"mathcal";return(h===65024||h===65025)&&this.consume(),{type:"font",mode:"math",font:x,body:{type:"mathord",mode:"math",loc:l,text:Rt[r]}}}u={type:i,mode:this.mode,loc:l,text:r}}s=u}else if(r.charCodeAt(0)>=128||Pt.exec(r)){if(this.settings.strict&&this.mode==="math")throw new w(`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;i<o[0].length;i++){let l=o[0][i];if(!Ge[l])throw new w(`Unknown accent ' ${l}'`,t);let u=Ge[l][this.mode]||Ge[l].text;if(!u)throw new w(`Accent ${l} unsupported in ${this.mode} mode`,t);s={type:"accent",mode:this.mode,loc:V.range(t),label:u,isStretchy:!1,base:s}}return s}},gr=function(e,t){if(!(typeof e=="string"||e instanceof String))throw new TypeError("Temml can only parse string typed expression");let r=new $e(e,t);delete r.gullet.macros.current["\\df@tag"];let o=r.parse();if(!(o.length>0&&o[0].type&&o[0].type==="array"&&o[0].addEqnNum)&&r.gullet.macros.get("\\df@tag")){if(!t.displayMode)throw new w("\\tag works only in display mode");r.gullet.feed("\\df@tag"),o=[{type:"tag",mode:"text",body:o,tag:r.parse()}]}return o},ro=[2,2,3,3],Ke=class e{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){let 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(let o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o]);return new e(r)}withLevel(t){return this.extend({level:t})}incrementLevel(){return this.extend({level:Math.min(this.level+1,3)})}inSubOrSup(){return this.extend({level:ro[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}},no="0.10.34";function oo(e){let t={},r=0,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){let h=l.attributes.id.value;t[h]=String(r);break}else l=l.parentElement;let s=document.getElementsByClassName("tml-tageqn");for(let l of s)if(l.getElementsByClassName("tml-label").length>0){let h=l.getElementsByClassName("tml-tag");if(h.length>0){let x=l.attributes.id.value;t[x]=h[0].textContent}}[...e.getElementsByClassName("tml-ref")].forEach(l=>{let u=l.getAttribute("href"),h=t[u.slice(1)];l.className.indexOf("tml-eqref")===-1?(h=h.replace(/^\(/,""),h=h.replace(/\)$/,"")):(h.charAt(0)!=="("&&(h="("+h),h.slice(-1)!==")"&&(h=h+")"));let x=document.createElementNS("http://www.w3.org/1998/Math/MathML","mtext");x.appendChild(document.createTextNode(h));let A=document.createElementNS("http://www.w3.org/1998/Math/MathML","math");A.appendChild(x),l.appendChild(A)})}var br=function(e,t,r={}){t.textContent="";let o=t.tagName.toLowerCase()==="math";o&&(r.wra
|
|||
|
|
`+e.toString())]);return o.style.color=r.errorColor,o.style.whiteSpace="pre-line",o},it=function(e,t){let r=new pe(t);try{let o=gr(e,r),s=new Ke({level:r.displayMode?F.DISPLAY:F.TEXT,maxSize:r.maxSize});return Wr(o,e,s,r)}catch(o){return lo(o,e,r)}},xr={version:no,render:br,renderToString:ao,postProcess:oo,ParseError:w,definePreamble:io,__parse:so,__renderToMathMLTree:it,__defineSymbol:n,__defineMacro:c};function ho(e,{displayMode:t=!0}={}){let r=xr.renderToString(e,{displayMode:t,annotate:!0,throwOnError:!0}),o=document.implementation.createHTMLDocument("");return o.body.innerHTML=r,o.body.querySelector("math")?.innerHTML??""}export{ho as default};
|