From 572ec8a7337b949106f8ab670c70cddd1f3b5c9e Mon Sep 17 00:00:00 2001 From: Ron Kok Date: Mon, 25 Mar 2024 09:09:33 -0700 Subject: [PATCH] Version 0.10.24 --- CHANGELOG.md | 12 + README.md | 2 +- dist/Temml-Asana.css | 2 + dist/Temml-Fira.css | 2 + dist/Temml-Latin-Modern.css | 2 + dist/Temml-Libertinus.css | 2 + dist/Temml-Local.css | 2 + dist/Temml-STIX2.css | 2 + dist/temml.cjs | 107 ++- dist/temml.js | 107 ++- dist/temml.min.js | 2 +- dist/temml.mjs | 107 ++- dist/temmlPostProcess.js | 2 +- docs/administration.md | 2 +- docs/comparison.html | 2 +- docs/support_table.md | 2 +- docs/supported.md | 2 +- package.json | 2 +- site/assets/temml.min.js | 2 +- site/docs/en/administration.html | 2 +- site/docs/en/comparison.html | 506 +++++++++++++- site/docs/en/support_table.html | 67 +- site/docs/en/supported.html | 133 ++-- src/postProcess.js | 2 +- test/temml.js | 74 ++- test/temmlPostProcess.js | 2 +- utils/hurmet.cjs | 1067 ++++++++++++++++++++---------- utils/temml.cjs | 74 ++- utils/temml.mjs | 74 ++- 29 files changed, 1887 insertions(+), 477 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae81f60..c60f3e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. This CHANGELOG roughly follows the guidelines from [keepachangelog.com](https://keepachangelog.com/en/1.0.0/). +## [0.10.24] = 2024-03-25 + +### Fixed + +- Prevent Firefox from omitting the dot on i or j +- Prevent infinite loop in an `\edef` macro +- Convert protocol in a URL to lower case, to enable a URL whitelist + +### Added + +- Support 60 binary operators from the `stix` package + ## [0.10.23] = 2024-03-11 ### Fixed diff --git a/README.md b/README.md index 3f093bc..99bd568 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Library | Minified JavaScript + CSS | |:--------------|:-------------------------:| -| Temml | 151 KB | +| Temml | 153 KB | | MathJax 2.7.5 | 338 KB | | KaTeX | 280 KB | | TeXZilla | 168 KB | diff --git a/dist/Temml-Asana.css b/dist/Temml-Asana.css index 725f9dc..4d54269 100644 --- a/dist/Temml-Asana.css +++ b/dist/Temml-Asana.css @@ -24,6 +24,8 @@ math { letter-spacing: normal; word-wrap: normal; direction: ltr; + /* Prevent Firefox from omitting the dot on i or j. */ + font-feature-settings: "dtls" off; } math * { diff --git a/dist/Temml-Fira.css b/dist/Temml-Fira.css index 03e844b..7596f1e 100644 --- a/dist/Temml-Fira.css +++ b/dist/Temml-Fira.css @@ -31,6 +31,8 @@ math { letter-spacing: normal; word-wrap: normal; direction: ltr; + /* Prevent Firefox from omitting the dot on i or j. */ + font-feature-settings: "dtls" off; } math * { diff --git a/dist/Temml-Latin-Modern.css b/dist/Temml-Latin-Modern.css index 2cf2776..bd2fd0a 100644 --- a/dist/Temml-Latin-Modern.css +++ b/dist/Temml-Latin-Modern.css @@ -34,6 +34,8 @@ math { letter-spacing: normal; word-wrap: normal; direction: ltr; + /* Prevent Firefox from omitting the dot on i or j. */ + font-feature-settings: "dtls" off; } math * { diff --git a/dist/Temml-Libertinus.css b/dist/Temml-Libertinus.css index c80f24b..647b646 100644 --- a/dist/Temml-Libertinus.css +++ b/dist/Temml-Libertinus.css @@ -32,6 +32,8 @@ math { letter-spacing: normal; word-wrap: normal; direction: ltr; + /* Prevent Firefox from omitting the dot on i or j. */ + font-feature-settings: "dtls" off; } math * { diff --git a/dist/Temml-Local.css b/dist/Temml-Local.css index 9390132..0b58a6d 100644 --- a/dist/Temml-Local.css +++ b/dist/Temml-Local.css @@ -22,6 +22,8 @@ math { letter-spacing: normal; word-wrap: normal; direction: ltr; + /* Prevent Firefox from omitting the dot on i or j. */ + font-feature-settings: "dtls" off; } math * { diff --git a/dist/Temml-STIX2.css b/dist/Temml-STIX2.css index 4b8b2b7..6536ba5 100644 --- a/dist/Temml-STIX2.css +++ b/dist/Temml-STIX2.css @@ -22,6 +22,8 @@ math { letter-spacing: normal; word-wrap: normal; direction: ltr; + /* Prevent Firefox from omitting the dot on i or j. */ + font-feature-settings: "dtls" off; } math * { diff --git a/dist/temml.cjs b/dist/temml.cjs index fbfebad..747e0fe 100644 --- a/dist/temml.cjs +++ b/dist/temml.cjs @@ -146,11 +146,29 @@ const assert = function(value) { /** * Return the protocol of a URL, or "_relative" if the URL does not specify a - * protocol (and thus is relative). + * protocol (and thus is relative), or `null` if URL has invalid protocol + * (so should be outright rejected). */ const protocolFromUrl = function(url) { - const protocol = /^\s*([^\\/#]*?)(?::|�*58|�*3a)/i.exec(url); - return protocol != null ? protocol[1] : "_relative"; + // Check for possible leading protocol. + // https://url.spec.whatwg.org/#url-parsing strips leading whitespace + // (\x00) or C0 control (\x00-\x1F) characters. + // eslint-disable-next-line no-control-regex + const protocol = /^[\x00-\x20]*([^\\/#?]*?)(:|�*58|�*3a|&colon)/i.exec(url); + if (!protocol) { + return "_relative"; + } + // Reject weird colons + if (protocol[2] !== ":") { + return null; + } + // Reject invalid characters in scheme according to + // https://datatracker.ietf.org/doc/html/rfc3986#section-3.1 + if (!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(protocol[1])) { + return null; + } + // Lowercase the protocol + return protocol[1].toLowerCase(); }; /** @@ -215,7 +233,11 @@ class Settings { */ isTrusted(context) { if (context.url && !context.protocol) { - context.protocol = utils.protocolFromUrl(context.url); + const protocol = utils.protocolFromUrl(context.url); + if (protocol == null) { + return false + } + context.protocol = protocol; } const trust = typeof this.trust === "function" ? this.trust(context) : this.trust; return Boolean(trust); @@ -1254,7 +1276,72 @@ defineSymbol(math, bin, "\u27d5", "\\leftouterjoin", true); defineSymbol(math, bin, "\u27d6", "\\rightouterjoin", true); defineSymbol(math, bin, "\u27d7", "\\fullouterjoin", true); -defineSymbol(math, bin, "\u2238", "\\dotminus", true); // stix +// stix Binary Operators +defineSymbol(math, bin, "\u2238", "\\dotminus", true); +defineSymbol(math, bin, "\u27D1", "\\wedgedot", true); +defineSymbol(math, bin, "\u27C7", "\\veedot", true); +defineSymbol(math, bin, "\u2A62", "\\doublebarvee", true); +defineSymbol(math, bin, "\u2A63", "\\veedoublebar", true); +defineSymbol(math, bin, "\u2A5F", "\\wedgebar", true); +defineSymbol(math, bin, "\u2A60", "\\wedgedoublebar", true); +defineSymbol(math, bin, "\u2A54", "\\Vee", true); +defineSymbol(math, bin, "\u2A53", "\\Wedge", true); +defineSymbol(math, bin, "\u2A43", "\\barcap", true); +defineSymbol(math, bin, "\u2A42", "\\barcup", true); +defineSymbol(math, bin, "\u2A48", "\\capbarcup", true); +defineSymbol(math, bin, "\u2A40", "\\capdot", true); +defineSymbol(math, bin, "\u2A47", "\\capovercup", true); +defineSymbol(math, bin, "\u2A46", "\\cupovercap", true); +defineSymbol(math, bin, "\u2A4D", "\\closedvarcap", true); +defineSymbol(math, bin, "\u2A4C", "\\closedvarcup", true); +defineSymbol(math, bin, "\u2A2A", "\\minusdot", true); +defineSymbol(math, bin, "\u2A2B", "\\minusfdots", true); +defineSymbol(math, bin, "\u2A2C", "\\minusrdots", true); +defineSymbol(math, bin, "\u22BB", "\\Xor", true); +defineSymbol(math, bin, "\u22BC", "\\Nand", true); +defineSymbol(math, bin, "\u22BD", "\\Nor", true); +defineSymbol(math, bin, "\u22BD", "\\barvee"); +defineSymbol(math, bin, "\u2AF4", "\\interleave", true); +defineSymbol(math, bin, "\u29E2", "\\shuffle", true); +defineSymbol(math, bin, "\u2AF6", "\\threedotcolon", true); +defineSymbol(math, bin, "\u2982", "\\typecolon", true); +defineSymbol(math, bin, "\u223E", "\\invlazys", true); +defineSymbol(math, bin, "\u2A4B", "\\twocaps", true); +defineSymbol(math, bin, "\u2A4A", "\\twocups", true); +defineSymbol(math, bin, "\u2A4E", "\\Sqcap", true); +defineSymbol(math, bin, "\u2A4F", "\\Sqcup", true); +defineSymbol(math, bin, "\u2A56", "\\veeonvee", true); +defineSymbol(math, bin, "\u2A55", "\\wedgeonwedge", true); +defineSymbol(math, bin, "\u29D7", "\\blackhourglass", true); +defineSymbol(math, bin, "\u29C6", "\\boxast", true); +defineSymbol(math, bin, "\u29C8", "\\boxbox", true); +defineSymbol(math, bin, "\u29C7", "\\boxcircle", true); +defineSymbol(math, bin, "\u229C", "\\circledequal", true); +defineSymbol(math, bin, "\u29B7", "\\circledparallel", true); +defineSymbol(math, bin, "\u29B6", "\\circledvert", true); +defineSymbol(math, bin, "\u29B5", "\\circlehbar", true); +defineSymbol(math, bin, "\u27E1", "\\concavediamond", true); +defineSymbol(math, bin, "\u27E2", "\\concavediamondtickleft", true); +defineSymbol(math, bin, "\u27E3", "\\concavediamondtickright", true); +defineSymbol(math, bin, "\u22C4", "\\diamond", true); +defineSymbol(math, bin, "\u29D6", "\\hourglass", true); +defineSymbol(math, bin, "\u27E0", "\\lozengeminus", true); +defineSymbol(math, bin, "\u233D", "\\obar", true); +defineSymbol(math, bin, "\u29B8", "\\obslash", true); +defineSymbol(math, bin, "\u2A38", "\\odiv", true); +defineSymbol(math, bin, "\u29C1", "\\ogreaterthan", true); +defineSymbol(math, bin, "\u29C0", "\\olessthan", true); +defineSymbol(math, bin, "\u29B9", "\\operp", true); +defineSymbol(math, bin, "\u2A37", "\\Otimes", true); +defineSymbol(math, bin, "\u2A36", "\\otimeshat", true); +defineSymbol(math, bin, "\u22C6", "\\star", true); +defineSymbol(math, bin, "\u25B3", "\\triangle", true); +defineSymbol(math, bin, "\u2A3A", "\\triangleminus", true); +defineSymbol(math, bin, "\u2A39", "\\triangleplus", true); +defineSymbol(math, bin, "\u2A3B", "\\triangletimes", true); +defineSymbol(math, bin, "\u27E4", "\\whitesquaretickleft", true); +defineSymbol(math, bin, "\u27E5", "\\whitesquaretickright", true); +defineSymbol(math, bin, "\u2A33", "\\smashtimes", true); // AMS Arrows // Note: unicode-math maps \u21e2 to their own function \rightdasharrow. @@ -1496,8 +1583,8 @@ defineSymbol(math, spacing, null, "\\allowbreak"); defineSymbol(math, punct, ",", ","); defineSymbol(text, punct, ":", ":"); defineSymbol(math, punct, ";", ";"); -defineSymbol(math, bin, "\u22bc", "\\barwedge", true); -defineSymbol(math, bin, "\u22bb", "\\veebar", true); +defineSymbol(math, bin, "\u22bc", "\\barwedge"); +defineSymbol(math, bin, "\u22bb", "\\veebar"); defineSymbol(math, bin, "\u2299", "\\odot", true); // Firefox turns ⊕ into an emoji. So append \uFE0E. Define Unicode character in macros, not here. defineSymbol(math, bin, "\u2295\uFE0E", "\\oplus"); @@ -1510,7 +1597,6 @@ defineSymbol(math, bin, "\u25b3", "\\bigtriangleup"); defineSymbol(math, bin, "\u25bd", "\\bigtriangledown"); defineSymbol(math, bin, "\u2020", "\\dagger"); defineSymbol(math, bin, "\u22c4", "\\diamond"); -defineSymbol(math, bin, "\u22c6", "\\star"); defineSymbol(math, bin, "\u25c3", "\\triangleleft"); defineSymbol(math, bin, "\u25b9", "\\triangleright"); defineSymbol(math, open, "{", "\\{"); @@ -3485,6 +3571,9 @@ defineFunction({ if (funcName === "\\edef" || funcName === "\\xdef") { tokens = parser.gullet.expandTokens(tokens); + if (tokens.length > parser.gullet.settings.maxExpand) { + throw new ParseError("Too many expansions in an " + funcName); + } tokens.reverse(); // to fit in with stack order } // Final arg is the expansion of the macro @@ -13223,7 +13312,7 @@ class Style { * https://mit-license.org/ */ -const version = "0.10.23"; +const version = "0.10.24"; function postProcess(block) { const labelMap = {}; diff --git a/dist/temml.js b/dist/temml.js index 0b91c62..2adf8d2 100644 --- a/dist/temml.js +++ b/dist/temml.js @@ -147,11 +147,29 @@ var temml = (function () { /** * Return the protocol of a URL, or "_relative" if the URL does not specify a - * protocol (and thus is relative). + * protocol (and thus is relative), or `null` if URL has invalid protocol + * (so should be outright rejected). */ const protocolFromUrl = function(url) { - const protocol = /^\s*([^\\/#]*?)(?::|�*58|�*3a)/i.exec(url); - return protocol != null ? protocol[1] : "_relative"; + // Check for possible leading protocol. + // https://url.spec.whatwg.org/#url-parsing strips leading whitespace + // (\x00) or C0 control (\x00-\x1F) characters. + // eslint-disable-next-line no-control-regex + const protocol = /^[\x00-\x20]*([^\\/#?]*?)(:|�*58|�*3a|&colon)/i.exec(url); + if (!protocol) { + return "_relative"; + } + // Reject weird colons + if (protocol[2] !== ":") { + return null; + } + // Reject invalid characters in scheme according to + // https://datatracker.ietf.org/doc/html/rfc3986#section-3.1 + if (!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(protocol[1])) { + return null; + } + // Lowercase the protocol + return protocol[1].toLowerCase(); }; /** @@ -216,7 +234,11 @@ var temml = (function () { */ isTrusted(context) { if (context.url && !context.protocol) { - context.protocol = utils.protocolFromUrl(context.url); + const protocol = utils.protocolFromUrl(context.url); + if (protocol == null) { + return false + } + context.protocol = protocol; } const trust = typeof this.trust === "function" ? this.trust(context) : this.trust; return Boolean(trust); @@ -1255,7 +1277,72 @@ var temml = (function () { defineSymbol(math, bin, "\u27d6", "\\rightouterjoin", true); defineSymbol(math, bin, "\u27d7", "\\fullouterjoin", true); - defineSymbol(math, bin, "\u2238", "\\dotminus", true); // stix + // stix Binary Operators + defineSymbol(math, bin, "\u2238", "\\dotminus", true); + defineSymbol(math, bin, "\u27D1", "\\wedgedot", true); + defineSymbol(math, bin, "\u27C7", "\\veedot", true); + defineSymbol(math, bin, "\u2A62", "\\doublebarvee", true); + defineSymbol(math, bin, "\u2A63", "\\veedoublebar", true); + defineSymbol(math, bin, "\u2A5F", "\\wedgebar", true); + defineSymbol(math, bin, "\u2A60", "\\wedgedoublebar", true); + defineSymbol(math, bin, "\u2A54", "\\Vee", true); + defineSymbol(math, bin, "\u2A53", "\\Wedge", true); + defineSymbol(math, bin, "\u2A43", "\\barcap", true); + defineSymbol(math, bin, "\u2A42", "\\barcup", true); + defineSymbol(math, bin, "\u2A48", "\\capbarcup", true); + defineSymbol(math, bin, "\u2A40", "\\capdot", true); + defineSymbol(math, bin, "\u2A47", "\\capovercup", true); + defineSymbol(math, bin, "\u2A46", "\\cupovercap", true); + defineSymbol(math, bin, "\u2A4D", "\\closedvarcap", true); + defineSymbol(math, bin, "\u2A4C", "\\closedvarcup", true); + defineSymbol(math, bin, "\u2A2A", "\\minusdot", true); + defineSymbol(math, bin, "\u2A2B", "\\minusfdots", true); + defineSymbol(math, bin, "\u2A2C", "\\minusrdots", true); + defineSymbol(math, bin, "\u22BB", "\\Xor", true); + defineSymbol(math, bin, "\u22BC", "\\Nand", true); + defineSymbol(math, bin, "\u22BD", "\\Nor", true); + defineSymbol(math, bin, "\u22BD", "\\barvee"); + defineSymbol(math, bin, "\u2AF4", "\\interleave", true); + defineSymbol(math, bin, "\u29E2", "\\shuffle", true); + defineSymbol(math, bin, "\u2AF6", "\\threedotcolon", true); + defineSymbol(math, bin, "\u2982", "\\typecolon", true); + defineSymbol(math, bin, "\u223E", "\\invlazys", true); + defineSymbol(math, bin, "\u2A4B", "\\twocaps", true); + defineSymbol(math, bin, "\u2A4A", "\\twocups", true); + defineSymbol(math, bin, "\u2A4E", "\\Sqcap", true); + defineSymbol(math, bin, "\u2A4F", "\\Sqcup", true); + defineSymbol(math, bin, "\u2A56", "\\veeonvee", true); + defineSymbol(math, bin, "\u2A55", "\\wedgeonwedge", true); + defineSymbol(math, bin, "\u29D7", "\\blackhourglass", true); + defineSymbol(math, bin, "\u29C6", "\\boxast", true); + defineSymbol(math, bin, "\u29C8", "\\boxbox", true); + defineSymbol(math, bin, "\u29C7", "\\boxcircle", true); + defineSymbol(math, bin, "\u229C", "\\circledequal", true); + defineSymbol(math, bin, "\u29B7", "\\circledparallel", true); + defineSymbol(math, bin, "\u29B6", "\\circledvert", true); + defineSymbol(math, bin, "\u29B5", "\\circlehbar", true); + defineSymbol(math, bin, "\u27E1", "\\concavediamond", true); + defineSymbol(math, bin, "\u27E2", "\\concavediamondtickleft", true); + defineSymbol(math, bin, "\u27E3", "\\concavediamondtickright", true); + defineSymbol(math, bin, "\u22C4", "\\diamond", true); + defineSymbol(math, bin, "\u29D6", "\\hourglass", true); + defineSymbol(math, bin, "\u27E0", "\\lozengeminus", true); + defineSymbol(math, bin, "\u233D", "\\obar", true); + defineSymbol(math, bin, "\u29B8", "\\obslash", true); + defineSymbol(math, bin, "\u2A38", "\\odiv", true); + defineSymbol(math, bin, "\u29C1", "\\ogreaterthan", true); + defineSymbol(math, bin, "\u29C0", "\\olessthan", true); + defineSymbol(math, bin, "\u29B9", "\\operp", true); + defineSymbol(math, bin, "\u2A37", "\\Otimes", true); + defineSymbol(math, bin, "\u2A36", "\\otimeshat", true); + defineSymbol(math, bin, "\u22C6", "\\star", true); + defineSymbol(math, bin, "\u25B3", "\\triangle", true); + defineSymbol(math, bin, "\u2A3A", "\\triangleminus", true); + defineSymbol(math, bin, "\u2A39", "\\triangleplus", true); + defineSymbol(math, bin, "\u2A3B", "\\triangletimes", true); + defineSymbol(math, bin, "\u27E4", "\\whitesquaretickleft", true); + defineSymbol(math, bin, "\u27E5", "\\whitesquaretickright", true); + defineSymbol(math, bin, "\u2A33", "\\smashtimes", true); // AMS Arrows // Note: unicode-math maps \u21e2 to their own function \rightdasharrow. @@ -1497,8 +1584,8 @@ var temml = (function () { defineSymbol(math, punct, ",", ","); defineSymbol(text, punct, ":", ":"); defineSymbol(math, punct, ";", ";"); - defineSymbol(math, bin, "\u22bc", "\\barwedge", true); - defineSymbol(math, bin, "\u22bb", "\\veebar", true); + defineSymbol(math, bin, "\u22bc", "\\barwedge"); + defineSymbol(math, bin, "\u22bb", "\\veebar"); defineSymbol(math, bin, "\u2299", "\\odot", true); // Firefox turns ⊕ into an emoji. So append \uFE0E. Define Unicode character in macros, not here. defineSymbol(math, bin, "\u2295\uFE0E", "\\oplus"); @@ -1511,7 +1598,6 @@ var temml = (function () { defineSymbol(math, bin, "\u25bd", "\\bigtriangledown"); defineSymbol(math, bin, "\u2020", "\\dagger"); defineSymbol(math, bin, "\u22c4", "\\diamond"); - defineSymbol(math, bin, "\u22c6", "\\star"); defineSymbol(math, bin, "\u25c3", "\\triangleleft"); defineSymbol(math, bin, "\u25b9", "\\triangleright"); defineSymbol(math, open, "{", "\\{"); @@ -3486,6 +3572,9 @@ var temml = (function () { if (funcName === "\\edef" || funcName === "\\xdef") { tokens = parser.gullet.expandTokens(tokens); + if (tokens.length > parser.gullet.settings.maxExpand) { + throw new ParseError("Too many expansions in an " + funcName); + } tokens.reverse(); // to fit in with stack order } // Final arg is the expansion of the macro @@ -11324,7 +11413,7 @@ var temml = (function () { * https://mit-license.org/ */ - const version = "0.10.23"; + const version = "0.10.24"; function postProcess(block) { const labelMap = {}; diff --git a/dist/temml.min.js b/dist/temml.min.js index 19e5e6e..ffdb9ec 100644 --- a/dist/temml.min.js +++ b/dist/temml.min.js @@ -1 +1 @@ -var temml=function(){"use strict";class e{constructor(t,r){let n,s=" "+t;const o=r&&r.loc;if(o&&o.start<=o.end){const e=o.lexer.input;n=o.start;const t=o.end;n===e.length?s+=" at end of input: ":s+=" at position "+(n+1)+": ";const r=e.slice(n,t).replace(/[^]/g,"$&̲");let a,i;a=n>15?"…"+e.slice(n-15,n):e.slice(0,n),i=t+15":">","<":"<",'"':""","'":"'"},n=/[&><"']/g;const s=function(e){return"ordgroup"===e.type||"color"===e.type?1===e.body.length?s(e.body[0]):e:"font"===e.type?s(e.body):e};var o={deflt:function(e,t){return void 0===e?t:e},escape:function(e){return String(e).replace(n,(e=>r[e]))},hyphenate:function(e){return e.replace(t,"-$1").toLowerCase()},getBaseElem:s,isCharacterBox:function(e){const t=s(e);return"mathord"===t.type||"textord"===t.type||"atom"===t.type},protocolFromUrl:function(e){const t=/^\s*([^\\/#]*?)(?::|�*58|�*3a)/i.exec(e);return null!=t?t[1]:"_relative"},round:function(e){return+e.toFixed(4)}};class a{constructor(e){e=e||{},this.displayMode=o.deflt(e.displayMode,!1),this.annotate=o.deflt(e.annotate,!1),this.leqno=o.deflt(e.leqno,!1),this.throwOnError=o.deflt(e.throwOnError,!1),this.errorColor=o.deflt(e.errorColor,"#b22222"),this.macros=e.macros||{},this.wrap=o.deflt(e.wrap,"tex"),this.xml=o.deflt(e.xml,!1),this.colorIsTextColor=o.deflt(e.colorIsTextColor,!1),this.strict=o.deflt(e.strict,!1),this.trust=o.deflt(e.trust,!1),this.maxSize=void 0===e.maxSize?[1/0,1/0]:Array.isArray(e.maxSize)?e.maxSize:[1/0,1/0],this.maxExpand=Math.max(0,o.deflt(e.maxExpand,1e3))}isTrusted(e){e.url&&!e.protocol&&(e.protocol=o.protocolFromUrl(e.url));const t="function"==typeof this.trust?this.trust(e):this.trust;return Boolean(t)}}const i={},l={};function c({type:e,names:t,props:r,handler:n,mathmlBuilder:s}){const o={type:e,numArgs:r.numArgs,argTypes:r.argTypes,allowedInArgument:!!r.allowedInArgument,allowedInText:!!r.allowedInText,allowedInMath:void 0===r.allowedInMath||r.allowedInMath,numOptionalArgs:r.numOptionalArgs||0,infix:!!r.infix,primitive:!!r.primitive,handler:n};for(let e=0;ee.toText())).join("")}}const h=function(e){return e.filter((e=>e)).join(" ")},g=function(e,t){this.classes=e||[],this.attributes={},this.style=t||{}},f=function(e){const t=document.createElement(e);t.className=h(this.classes);for(const e in this.style)Object.prototype.hasOwnProperty.call(this.style,e)&&(t.style[e]=this.style[e]);for(const e in this.attributes)Object.prototype.hasOwnProperty.call(this.attributes,e)&&t.setAttribute(e,this.attributes[e]);for(let e=0;e`,t};class y{constructor(e,t,r){g.call(this,e,r),this.children=t||[]}setAttribute(e,t){this.attributes[e]=t}toNode(){return f.call(this,"span")}toMarkup(){return b.call(this,"span")}}class x{constructor(e){this.text=e}toNode(){return document.createTextNode(this.text)}toMarkup(){return o.escape(this.text)}}class w{constructor(e,t,r){this.alt=t,this.src=e,this.classes=["mord"],this.style=r}hasClass(e){return this.classes.includes(e)}toNode(){const e=document.createElement("img");e.src=this.src,e.alt=this.alt,e.className="mord";for(const t in this.style)Object.prototype.hasOwnProperty.call(this.style,t)&&(e.style[t]=this.style[t]);return e}toMarkup(){let e=`${this.alt}0&&(e.className=h(this.classes));for(const t in this.style)Object.prototype.hasOwnProperty.call(this.style,t)&&(e.style[t]=this.style[t]);for(let t=0;t0&&(e+=` class="${o.escape(h(this.classes))}"`);let t="";for(const e in this.style)Object.prototype.hasOwnProperty.call(this.style,e)&&(t+=`${o.hyphenate(e)}:${this.style[e]};`);t&&(e+=` style="${t}"`),e+=">";for(let t=0;t",e}toText(){return this.children.map((e=>e.toText())).join("")}}class v{constructor(e){this.text=e}toNode(){return document.createTextNode(this.text)}toMarkup(){return o.escape(this.toText())}toText(){return this.text}}const A=e=>{let t;return 1===e.length&&"mrow"===e[0].type?(t=e.pop(),t.type="mstyle"):t=new k("mstyle",e),t};var N={MathNode:k,TextNode:v,newDocumentFragment:function(e){return new d(e)}};const T=e=>{let t=0;if(e.body)for(const r of e.body)t+=T(r);else if("supsub"===e.type)t+=T(e.base),e.sub&&(t+=.7*T(e.sub)),e.sup&&(t+=.7*T(e.sup));else if("mathord"===e.type||"textord"===e.type)for(const r of e.text.split("")){const e=r.codePointAt(0);t+=96{const t=S(e.label);if(O.includes(e.label)){const r=T(e.base);1","\\gt",!0),I($,V,"∈","\\in",!0),I($,V,"∉","\\notin",!0),I($,V,"","\\@not"),I($,V,"⊂","\\subset",!0),I($,V,"⊃","\\supset",!0),I($,V,"⊆","\\subseteq",!0),I($,V,"⊇","\\supseteq",!0),I($,V,"⊈","\\nsubseteq",!0),I($,V,"⊈","\\nsubseteqq"),I($,V,"⊉","\\nsupseteq",!0),I($,V,"⊉","\\nsupseteqq"),I($,V,"⊨","\\models"),I($,V,"←","\\leftarrow",!0),I($,V,"≤","\\le"),I($,V,"≤","\\leq",!0),I($,V,"<","\\lt",!0),I($,V,"→","\\rightarrow",!0),I($,V,"→","\\to"),I($,V,"≱","\\ngeq",!0),I($,V,"≱","\\ngeqq"),I($,V,"≱","\\ngeqslant"),I($,V,"≰","\\nleq",!0),I($,V,"≰","\\nleqq"),I($,V,"≰","\\nleqslant"),I($,V,"⫫","\\Perp",!0),I($,_," ","\\ "),I($,_," ","\\space"),I($,_," ","\\nobreakspace"),I(L,_," ","\\ "),I(L,_," "," "),I(L,_," ","\\space"),I(L,_," ","\\nobreakspace"),I($,_,null,"\\nobreak"),I($,_,null,"\\allowbreak"),I($,H,",",","),I(L,H,":",":"),I($,H,";",";"),I($,G,"⊼","\\barwedge",!0),I($,G,"⊻","\\veebar",!0),I($,G,"⊙","\\odot",!0),I($,G,"⊕︎","\\oplus"),I($,G,"⊗","\\otimes",!0),I($,W,"∂","\\partial",!0),I($,G,"⊘","\\oslash",!0),I($,G,"⊚","\\circledcirc",!0),I($,G,"⊡","\\boxdot",!0),I($,G,"△","\\bigtriangleup"),I($,G,"▽","\\bigtriangledown"),I($,G,"†","\\dagger"),I($,G,"⋄","\\diamond"),I($,G,"⋆","\\star"),I($,G,"◃","\\triangleleft"),I($,G,"▹","\\triangleright"),I($,U,"{","\\{"),I(L,W,"{","\\{"),I(L,W,"{","\\textbraceleft"),I($,D,"}","\\}"),I(L,W,"}","\\}"),I(L,W,"}","\\textbraceright"),I($,U,"{","\\lbrace"),I($,D,"}","\\rbrace"),I($,U,"[","\\lbrack",!0),I(L,W,"[","\\lbrack",!0),I($,D,"]","\\rbrack",!0),I(L,W,"]","\\rbrack",!0),I($,U,"(","\\lparen",!0),I($,D,")","\\rparen",!0),I($,U,"⦇","\\llparenthesis",!0),I($,D,"⦈","\\rrparenthesis",!0),I(L,W,"<","\\textless",!0),I(L,W,">","\\textgreater",!0),I($,U,"⌊","\\lfloor",!0),I($,D,"⌋","\\rfloor",!0),I($,U,"⌈","\\lceil",!0),I($,D,"⌉","\\rceil",!0),I($,W,"\\","\\backslash"),I($,W,"|","|"),I($,W,"|","\\vert"),I(L,W,"|","\\textbar",!0),I($,W,"‖","\\|"),I($,W,"‖","\\Vert"),I(L,W,"‖","\\textbardbl"),I(L,W,"~","\\textasciitilde"),I(L,W,"\\","\\textbackslash"),I(L,W,"^","\\textasciicircum"),I($,V,"↑","\\uparrow",!0),I($,V,"⇑","\\Uparrow",!0),I($,V,"↓","\\downarrow",!0),I($,V,"⇓","\\Downarrow",!0),I($,V,"↕","\\updownarrow",!0),I($,V,"⇕","\\Updownarrow",!0),I($,j,"∐","\\coprod"),I($,j,"⋁","\\bigvee"),I($,j,"⋀","\\bigwedge"),I($,j,"⨄","\\biguplus"),I($,j,"⋂","\\bigcap"),I($,j,"⋃","\\bigcup"),I($,j,"∫","\\int"),I($,j,"∫","\\intop"),I($,j,"∬","\\iint"),I($,j,"∭","\\iiint"),I($,j,"∏","\\prod"),I($,j,"∑","\\sum"),I($,j,"⨂","\\bigotimes"),I($,j,"⨁","\\bigoplus"),I($,j,"⨀","\\bigodot"),I($,j,"⨉","\\bigtimes"),I($,j,"∮","\\oint"),I($,j,"∯","\\oiint"),I($,j,"∰","\\oiiint"),I($,j,"∱","\\intclockwise"),I($,j,"∲","\\varointclockwise"),I($,j,"⨌","\\iiiint"),I($,j,"⨍","\\intbar"),I($,j,"⨎","\\intBar"),I($,j,"⨏","\\fint"),I($,j,"⨒","\\rppolint"),I($,j,"⨓","\\scpolint"),I($,j,"⨕","\\pointint"),I($,j,"⨖","\\sqint"),I($,j,"⨗","\\intlarhk"),I($,j,"⨘","\\intx"),I($,j,"⨙","\\intcap"),I($,j,"⨚","\\intcup"),I($,j,"⨅","\\bigsqcap"),I($,j,"⨆","\\bigsqcup"),I($,j,"∫","\\smallint"),I(L,P,"…","\\textellipsis"),I($,P,"…","\\mathellipsis"),I(L,P,"…","\\ldots",!0),I($,P,"…","\\ldots",!0),I($,P,"⋰","\\iddots",!0),I($,P,"⋯","\\@cdots",!0),I($,P,"⋱","\\ddots",!0),I($,W,"⋮","\\varvdots"),I($,F,"ˊ","\\acute"),I($,F,"`","\\grave"),I($,F,"¨","\\ddot"),I($,F,"…","\\dddot"),I($,F,"….","\\ddddot"),I($,F,"~","\\tilde"),I($,F,"‾","\\bar"),I($,F,"˘","\\breve"),I($,F,"ˇ","\\check"),I($,F,"^","\\hat"),I($,F,"→","\\vec"),I($,F,"˙","\\dot"),I($,F,"˚","\\mathring"),I($,R,"ı","\\imath",!0),I($,R,"ȷ","\\jmath",!0),I($,W,"ı","ı"),I($,W,"ȷ","ȷ"),I(L,W,"ı","\\i",!0),I(L,W,"ȷ","\\j",!0),I(L,W,"ß","\\ss",!0),I(L,W,"æ","\\ae",!0),I(L,W,"œ","\\oe",!0),I(L,W,"ø","\\o",!0),I($,R,"ø","\\o",!0),I(L,W,"Æ","\\AE",!0),I(L,W,"Œ","\\OE",!0),I(L,W,"Ø","\\O",!0),I($,R,"Ø","\\O",!0),I(L,F,"ˊ","\\'"),I(L,F,"ˋ","\\`"),I(L,F,"ˆ","\\^"),I(L,F,"˜","\\~"),I(L,F,"ˉ","\\="),I(L,F,"˘","\\u"),I(L,F,"˙","\\."),I(L,F,"¸","\\c"),I(L,F,"˚","\\r"),I(L,F,"ˇ","\\v"),I(L,F,"¨",'\\"'),I(L,F,"˝","\\H"),I($,F,"ˊ","\\'"),I($,F,"ˋ","\\`"),I($,F,"ˆ","\\^"),I($,F,"˜","\\~"),I($,F,"ˉ","\\="),I($,F,"˘","\\u"),I($,F,"˙","\\."),I($,F,"¸","\\c"),I($,F,"˚","\\r"),I($,F,"ˇ","\\v"),I($,F,"¨",'\\"'),I($,F,"˝","\\H");const X={"--":!0,"---":!0,"``":!0,"''":!0};I(L,W,"–","--",!0),I(L,W,"–","\\textendash"),I(L,W,"—","---",!0),I(L,W,"—","\\textemdash"),I(L,W,"‘","`",!0),I(L,W,"‘","\\textquoteleft"),I(L,W,"’","'",!0),I(L,W,"’","\\textquoteright"),I(L,W,"“","``",!0),I(L,W,"“","\\textquotedblleft"),I(L,W,"”","''",!0),I(L,W,"”","\\textquotedblright"),I($,W,"°","\\degree",!0),I(L,W,"°","\\degree"),I(L,W,"°","\\textdegree",!0),I($,W,"£","\\pounds"),I($,W,"£","\\mathsterling",!0),I(L,W,"£","\\pounds"),I(L,W,"£","\\textsterling",!0),I($,W,"✠","\\maltese"),I(L,W,"✠","\\maltese"),I($,W,"€","\\euro",!0),I(L,W,"€","\\euro",!0),I(L,W,"€","\\texteuro"),I($,W,"©","\\copyright",!0),I(L,W,"©","\\textcopyright"),I($,W,"⌀","\\diameter",!0),I(L,W,"⌀","\\diameter"),I($,W,"𝛤","\\varGamma"),I($,W,"𝛥","\\varDelta"),I($,W,"𝛩","\\varTheta"),I($,W,"𝛬","\\varLambda"),I($,W,"𝛯","\\varXi"),I($,W,"𝛱","\\varPi"),I($,W,"𝛴","\\varSigma"),I($,W,"𝛶","\\varUpsilon"),I($,W,"𝛷","\\varPhi"),I($,W,"𝛹","\\varPsi"),I($,W,"𝛺","\\varOmega"),I(L,W,"𝛤","\\varGamma"),I(L,W,"𝛥","\\varDelta"),I(L,W,"𝛩","\\varTheta"),I(L,W,"𝛬","\\varLambda"),I(L,W,"𝛯","\\varXi"),I(L,W,"𝛱","\\varPi"),I(L,W,"𝛴","\\varSigma"),I(L,W,"𝛶","\\varUpsilon"),I(L,W,"𝛷","\\varPhi"),I(L,W,"𝛹","\\varPsi"),I(L,W,"𝛺","\\varOmega");const Z='0123456789/@."';for(let e=0;e<14;e++){const t=Z.charAt(e);I($,W,t,t)}const Y='0123456789!@*()-=+";:?/.,';for(let e=0;e<25;e++){const t=Y.charAt(e);I(L,W,t,t)}const K="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";for(let e=0;e<52;e++){const t=K.charAt(e);I($,R,t,t),I(L,W,t,t)}const J="ÇÐÞçþℂℍℕℙℚℝℤℎℏℊℋℌℐℑℒℓ℘ℛℜℬℰℱℳℭℨ";for(let e=0;e<30;e++){const t=J.charAt(e);I($,R,t,t),I(L,W,t,t)}let Q="";for(let e=0;e<52;e++){Q=String.fromCharCode(55349,56320+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,56372+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,56424+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,56580+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,56736+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,56788+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,56840+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,56944+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,56632+e),I($,R,Q,Q),I(L,W,Q,Q);const t=K.charAt(e);Q=String.fromCharCode(55349,56476+e),I($,R,t,Q),I(L,W,t,Q)}for(let e=0;e<10;e++)Q=String.fromCharCode(55349,57294+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,57314+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,57324+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,57334+e),I($,R,Q,Q),I(L,W,Q,Q);const ee="([{⌊⌈⟨⟮⎰⟦⦃",te=")]}⌋⌉⟩⟯⎱⟦⦄";const re=function(e,t,r){return!E[t][e]||!E[t][e].replace||55349===e.charCodeAt(0)||Object.prototype.hasOwnProperty.call(X,e)&&r&&(r.fontFamily&&"tt"===r.fontFamily.slice(4,6)||r.font&&"tt"===r.font.slice(4,6))||(e=E[t][e].replace),new N.TextNode(e)},ne=e=>{if("mrow"!==e.type&&"mstyle"!==e.type)return e;if(0===e.children.length)return e;if(!e.children[0].attributes||"mtext"!==e.children[0].type)return e;const t=e.children[0].attributes.mathvariant||"",r=new N.MathNode("mtext",[new N.TextNode(e.children[0].children[0].text)]);for(let n=1;n0&&" "===r.children[0].text.charAt(n-1)&&(r.children[0].text=r.children[0].text.slice(0,-1)+" ");for(const[t,n]of Object.entries(e.attributes))r.attributes[t]=n;return r},se=/^[0-9]$/,oe=function(e,t=!1){if(!(1!==e.length||e[0]instanceof d))return e[0];if(!t){e[0]instanceof k&&"mo"===e[0].type&&!e[0].attributes.fence&&(e[0].attributes.lspace="0em",e[0].attributes.rspace="0em");const t=e.length-1;e[t]instanceof k&&"mo"===e[t].type&&!e[t].attributes.fence&&(e[t].attributes.lspace="0em",e[t].attributes.rspace="0em")}return new N.MathNode("mrow",e)},ae=e=>"atom"===e.type&&"rel"===e.family||"mclass"===e.type&&"mrel"===e.mclass,ie=function(e,t,r=!1){if(!r&&1===e.length){const r=ce(e[0],t);return r instanceof k&&"mo"===r.type&&(r.setAttribute("lspace","0em"),r.setAttribute("rspace","0em")),[r]}(e=>{if(e.length<2)return;const t=[];let r=!1;for(let n=0;n0;r--)t[r-1].end===t[r].start-2&&(n=e[t[r].start-1],s=e[t[r].start],("textord"===n.type&&"."===n.text||"atom"===n.type&&","===n.text)&&n.loc&&s.loc&&n.loc.end===s.loc.start)&&(t[r-1].end=t[r].end,t.splice(r,1));var n,s;for(let r=t.length-1;r>=0;r--){for(let n=t[r].start+1;n<=t[r].end;n++)e[t[r].start].text+=e[n].text;if(e.splice(t[r].start+1,t[r].end-t[r].start),e.length>t[r].start+1){const n=e[t[r].start+1];"supsub"===n.type&&n.base&&"textord"===n.base.type&&se.test(n.base.text)&&(n.base.text=e[t[r].start].text+n.base.text,e.splice(t[r].start,1))}}})(e);const n=[];for(let r=0;r0&&ae(e[r])&&ae(e[r-1])&&s.setAttribute("lspace","0em"),n.push(s)}return n},le=function(e,t,r=!1){return oe(ie(e,t,r),r)},ce=function(t,r){if(!t)return new N.MathNode("mrow");if(l[t.type]){return l[t.type](t,r)}throw new e("Got group of unknown type: '"+t.type+"'")},me=e=>new N.MathNode("mtd",[],[],{padding:"0",width:"50%"});function ue(e,t,r,n){let s=null;1===e.length&&"tag"===e[0].type&&(s=e[0].tag,e=e[0].body);const o=ie(e,r),a=n.displayMode||n.annotate?"none":n.wrap,i=0===o.length?null:o[0];let l=1===o.length&&null===s&&i instanceof k?o[0]:function(e,t,r){const n=[];let s=[],o=[],a=0,i=0,l=0;for(;i0&&s.push(new N.MathNode("mrow",o)),s.push(r),o=[];const e=new N.MathNode("mtd",s);e.style.textAlign="left",n.push(new N.MathNode("mtr",[e])),s=[],i+=1}else{if(o.push(r),r.type&&"mo"===r.type&&1===r.children.length&&!Object.hasOwn(r.attributes,"movablelimits")){const n=r.children[0].text;if(ee.indexOf(n)>-1)l+=1;else if(te.indexOf(n)>-1)l-=1;else if(0===l&&"="===t&&"="===n){if(a+=1,a>1){o.pop();const e=new N.MathNode("mrow",o);s.push(e),o=[r]}}else if(0===l&&"tex"===t&&"∇"!==n){const t=i0){const e=new N.MathNode("mrow",o);s.push(e)}if(n.length>0){const e=new N.MathNode("mtd",s);e.style.textAlign="left";const t=new N.MathNode("mtr",[e]);n.push(t);const o=new N.MathNode("mtable",n);return r||(o.setAttribute("columnalign","left"),o.setAttribute("rowspacing","0em")),o}return N.newDocumentFragment(s)}(o,a,n.displayMode);if(s&&(l=((e,t,r,n)=>{t=le(t[0].body,r),(t=ne(t)).classes.push("tml-tag"),e=new N.MathNode("mtd",[e]);const s=[me(),e,me()];s[n?0:2].classes.push(n?"tml-left":"tml-right"),s[n?0:2].children.push(t);const o=new N.MathNode("mtr",s,["tml-tageqn"]),a=new N.MathNode("mtable",[o]);return a.style.width="100%",a.setAttribute("displaystyle","true"),a})(l,s,r,n.leqno)),n.annotate){const e=new N.MathNode("annotation",[new N.TextNode(t)]);e.setAttribute("encoding","application/x-tex"),l=new N.MathNode("semantics",[l,e])}const c=new N.MathNode("math",[l]);return n.xml&&c.setAttribute("xmlns","http://www.w3.org/1998/Math/MathML"),n.displayMode&&(c.setAttribute("display","block"),c.style.display="block math",c.classes=["tml-display"]),c}const pe="ABCDEFGHIJKLMNOPQRSTUVWXYZbdfhkltΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩβδλζφθψ𝐀𝐁𝐂𝐃𝐄𝐅𝐆𝐇𝐈𝐉𝐊𝐋𝐌𝐍𝐎𝐏𝐐𝐑𝐒𝐓𝐔𝐕𝐖𝐗𝐘𝐙𝐛𝐝𝐟𝐡𝐤𝐥𝐭",de=new Set(["\\alpha","\\gamma","\\delta","\\epsilon","\\eta","\\iota","\\kappa","\\mu","\\nu","\\pi","\\rho","\\sigma","\\tau","\\upsilon","\\chi","\\psi","\\omega","\\imath","\\jmath"]),he=new Set(["\\Gamma","\\Delta","\\Sigma","\\Omega","\\beta","\\delta","\\lambda","\\theta","\\psi"]),ge=(e,t)=>{const r=e.isStretchy?M(e):new N.MathNode("mo",[re(e.label,e.mode)]);if("\\vec"===e.label)r.style.transform="scale(0.75) translate(10%, 30%)";else if(r.style.mathStyle="normal",r.style.mathDepth="0",be.has(e.label)&&o.isCharacterBox(e.base)){let t="";const n=e.base.text;("acegıȷmnopqrsuvwxyzαγεηικμνοπρςστυχωϕ𝐚𝐜𝐞𝐠𝐦𝐧𝐨𝐩𝐪𝐫𝐬𝐮𝐯𝐰𝐱𝐲𝐳".indexOf(n)>-1||de.has(n))&&(t="tml-xshift"),(pe.indexOf(n)>-1||he.has(n))&&(t="tml-capshift"),t&&r.classes.push(t)}e.isStretchy||r.setAttribute("stretchy","false");return new N.MathNode("\\c"===e.label?"munder":"mover",[ce(e.base,t),r])},fe=new Set(["\\acute","\\grave","\\ddot","\\dddot","\\ddddot","\\tilde","\\bar","\\breve","\\check","\\hat","\\vec","\\dot","\\mathring"]),be=new Set(["\\acute","\\bar","\\breve","\\check","\\dot","\\ddot","\\grave","\\hat","\\mathring","\\'","\\^","\\~","\\=","\\u","\\.",'\\"',"\\r","\\H","\\v"]);c({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=u(t[0]),n=!fe.has(e.funcName);return{type:"accent",mode:e.parser.mode,label:e.funcName,isStretchy:n,base:r}},mathmlBuilder:ge}),c({type:"accent",names:["\\'","\\`","\\^","\\~","\\=","\\c","\\u","\\.",'\\"',"\\r","\\H","\\v"],props:{numArgs:1,allowedInText:!0,allowedInMath:!0,argTypes:["primitive"]},handler:(e,t)=>{const r=u(t[0]),n=e.parser.mode;return"math"===n&&e.parser.settings.strict&&console.log(`Temml parse error: Command ${e.funcName} is invalid in math mode.`),{type:"accent",mode:n,label:e.funcName,isStretchy:!1,base:r}},mathmlBuilder:ge}),c({type:"accentUnder",names:["\\underleftarrow","\\underrightarrow","\\underleftrightarrow","\\undergroup","\\underparen","\\utilde"],props:{numArgs:1},handler:({parser:e,funcName:t},r)=>{const n=r[0];return{type:"accentUnder",mode:e.mode,label:t,base:n}},mathmlBuilder:(e,t)=>{const r=M(e);r.style["math-depth"]=0;return new N.MathNode("munder",[ce(e.base,t),r])}});const ye={pt:800/803,pc:9600/803,dd:1238/1157*800/803,cc:12.792133216944668,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},xe=["em","ex","mu","pt","mm","cm","in","px","bp","pc","dd","cc","nd","nc","sp"],we=function(e){return"string"!=typeof e&&(e=e.unit),xe.indexOf(e)>-1},ke=e=>[1,.7,.5][Math.max(e-1,0)],ve=function(t,r){let n=t.number;if(r.maxSize[0]<0&&n>0)return{number:0,unit:"em"};const s=t.unit;switch(s){case"mm":case"cm":case"in":case"px":return n*ye[s]>r.maxSize[1]?{number:r.maxSize[1],unit:"pt"}:{number:n,unit:s};case"em":case"ex":return"ex"===s&&(n*=.431),n=Math.min(n/ke(r.level),r.maxSize[0]),{number:o.round(n),unit:"em"};case"bp":return n>r.maxSize[1]&&(n=r.maxSize[1]),{number:n,unit:"pt"};case"pt":case"pc":case"dd":case"cc":case"nd":case"nc":case"sp":return n=Math.min(n*ye[s],r.maxSize[1]),{number:o.round(n),unit:"pt"};case"mu":return n=Math.min(n/18,r.maxSize[0]),{number:o.round(n),unit:"em"};default:throw new e("Invalid unit: '"+s+"'")}},Ae=e=>{const t=new N.MathNode("mspace");return t.setAttribute("width",e+"em"),t},Ne=(e,t=.3,r=0)=>{if(null==e&&0===r)return Ae(t);const n=e?[e]:[];return 0!==t&&n.unshift(Ae(t)),r>0&&n.push(Ae(r)),new N.MathNode("mrow",n)},Te=(e,t)=>Number(e)/ke(t),qe=(e,t,r,n)=>{const s=B(e),o="eq"===e.slice(1,3),a="x"===e.charAt(1)?"1.75":"cd"===e.slice(2,4)?"3.0":o?"1.0":"2.0";s.setAttribute("lspace","0"),s.setAttribute("rspace",o?"0.5em":"0");const i=n.withLevel(n.level<2?2:3),l=Te(a,i.level),c=Te(a,3),m=Ne(null,l.toFixed(4),0),u=Ne(null,c.toFixed(4),0),p=Te(o?0:.3,i.level).toFixed(4);let d,h;const g=t&&t.body&&(t.body.body||t.body.length>0);if(g){let e=ce(t,i);e=Ne(e,p,p),d=new N.MathNode("mover",[e,u])}const f=r&&r.body&&(r.body.body||r.body.length>0);if(f){let e=ce(r,i);e=Ne(e,p,p),h=new N.MathNode("munder",[e,u])}let b;return b=g||f?g&&f?new N.MathNode("munderover",[s,h,d]):g?new N.MathNode("mover",[s,d]):new N.MathNode("munder",[s,h]):new N.MathNode("mover",[s,m]),"3.0"===a&&(b.style.height="1em"),b.setAttribute("accent","false"),b};c({type:"xArrow",names:["\\xleftarrow","\\xrightarrow","\\xLeftarrow","\\xRightarrow","\\xleftrightarrow","\\xLeftrightarrow","\\xhookleftarrow","\\xhookrightarrow","\\xmapsto","\\xrightharpoondown","\\xrightharpoonup","\\xleftharpoondown","\\xleftharpoonup","\\xlongequal","\\xtwoheadrightarrow","\\xtwoheadleftarrow","\\yields","\\yieldsLeft","\\mesomerism","\\longrightharpoonup","\\longleftharpoondown","\\\\cdrightarrow","\\\\cdleftarrow","\\\\cdlongequal"],props:{numArgs:1,numOptionalArgs:1},handler:({parser:e,funcName:t},r,n)=>({type:"xArrow",mode:e.mode,name:t,body:r[0],below:n[0]}),mathmlBuilder(e,t){const r=[qe(e.name,e.body,e.below,t)];return r.unshift(Ae(.2778)),r.push(Ae(.2778)),new N.MathNode("mrow",r)}});const Se={"\\xtofrom":["\\xrightarrow","\\xleftarrow"],"\\xleftrightharpoons":["\\xleftharpoonup","\\xrightharpoondown"],"\\xrightleftharpoons":["\\xrightharpoonup","\\xleftharpoondown"],"\\yieldsLeftRight":["\\yields","\\yieldsLeft"],"\\equilibrium":["\\longrightharpoonup","\\longleftharpoondown"],"\\equilibriumRight":["\\longrightharpoonup","\\eqleftharpoondown"],"\\equilibriumLeft":["\\eqrightharpoonup","\\longleftharpoondown"]};function Oe(e,t){if(!e||e.type!==t)throw new Error(`Expected node of type ${t}, but got `+(e?`node of type ${e.type}`:String(e)));return e}function Be(e){const t=Me(e);if(!t)throw new Error("Expected node of symbol group type, but got "+(e?`node of type ${e.type}`:String(e)));return t}function Me(e){return e&&("atom"===e.type||Object.prototype.hasOwnProperty.call(z,e.type))?e:null}c({type:"stackedArrow",names:["\\xtofrom","\\xleftrightharpoons","\\xrightleftharpoons","\\yieldsLeftRight","\\equilibrium","\\equilibriumRight","\\equilibriumLeft"],props:{numArgs:1,numOptionalArgs:1},handler({parser:e,funcName:t},r,n){const s=r[0]?{type:"hphantom",mode:e.mode,body:r[0]}:null,o=n[0]?{type:"hphantom",mode:e.mode,body:n[0]}:null;return{type:"stackedArrow",mode:e.mode,name:t,body:r[0],upperArrowBelow:o,lowerArrowBody:s,below:n[0]}},mathmlBuilder(e,t){const r=Se[e.name][0],n=Se[e.name][1],s=qe(r,e.body,e.upperArrowBelow,t),o=qe(n,e.lowerArrowBody,e.below,t);let a;const i=new N.MathNode("mpadded",[s]);if(i.setAttribute("voffset","0.3em"),i.setAttribute("height","+0.3em"),i.setAttribute("depth","-0.3em"),"\\equilibriumLeft"===e.name){const e=new N.MathNode("mpadded",[o]);e.setAttribute("width","0.5em"),a=new N.MathNode("mpadded",[Ae(.2778),e,i,Ae(.2778)])}else i.setAttribute("width","\\equilibriumRight"===e.name?"0.5em":"0"),a=new N.MathNode("mpadded",[Ae(.2778),i,o,Ae(.2778)]);return a.setAttribute("voffset","-0.18em"),a.setAttribute("height","-0.18em"),a.setAttribute("depth","+0.18em"),a}});const Ce={">":"\\\\cdrightarrow","<":"\\\\cdleftarrow","=":"\\\\cdlongequal",A:"\\uparrow",V:"\\downarrow","|":"\\Vert",".":"no arrow"},ze=e=>"textord"===e.type&&"@"===e.text;function Ee(e,t,r){const n=Ce[e];switch(n){case"\\\\cdrightarrow":case"\\\\cdleftarrow":return r.callFunction(n,[t[0]],[t[1]]);case"\\uparrow":case"\\downarrow":{const e={type:"atom",text:n,mode:"math",family:"rel"},s={type:"ordgroup",mode:"math",body:[r.callFunction("\\\\cdleft",[t[0]],[]),r.callFunction("\\Big",[e],[]),r.callFunction("\\\\cdright",[t[1]],[])],semisimple:!0};return r.callFunction("\\\\cdparent",[s],[])}case"\\\\cdlongequal":return r.callFunction("\\\\cdlongequal",[],[]);case"\\Vert":{const e={type:"textord",text:"\\Vert",mode:"math"};return r.callFunction("\\Big",[e],[])}default:return{type:"textord",text:" ",mode:"math"}}}c({type:"cdlabel",names:["\\\\cdleft","\\\\cdright"],props:{numArgs:1},handler:({parser:e,funcName:t},r)=>({type:"cdlabel",mode:e.mode,side:t.slice(4),label:r[0]}),mathmlBuilder(e,t){let r=new N.MathNode("mrow",[ce(e.label,t)]);return r=new N.MathNode("mpadded",[r]),r.setAttribute("width","0"),"left"===e.side&&r.setAttribute("lspace","-1width"),r.setAttribute("voffset","0.7em"),r=new N.MathNode("mstyle",[r]),r.setAttribute("displaystyle","false"),r.setAttribute("scriptlevel","1"),r}}),c({type:"cdlabelparent",names:["\\\\cdparent"],props:{numArgs:1},handler:({parser:e},t)=>({type:"cdlabelparent",mode:e.mode,fragment:t[0]}),mathmlBuilder:(e,t)=>new N.MathNode("mrow",[ce(e.fragment,t)])}),c({type:"textord",names:["\\@char"],props:{numArgs:1,allowedInText:!0},handler({parser:t,token:r},n){const s=Oe(n[0],"ordgroup").body;let o="";for(let e=0;e{let t=e.toString(16);return 1===t.length&&(t="0"+t),t},Pe=JSON.parse('{\n "Apricot": "#ffb484",\n "Aquamarine": "#08b4bc",\n "Bittersweet": "#c84c14",\n "blue": "#0000FF",\n "Blue": "#303494",\n "BlueGreen": "#08b4bc",\n "BlueViolet": "#503c94",\n "BrickRed": "#b8341c",\n "brown": "#BF8040",\n "Brown": "#802404",\n "BurntOrange": "#f8941c",\n "CadetBlue": "#78749c",\n "CarnationPink": "#f884b4",\n "Cerulean": "#08a4e4",\n "CornflowerBlue": "#40ace4",\n "cyan": "#00FFFF",\n "Cyan": "#08acec",\n "Dandelion": "#ffbc44",\n "darkgray": "#404040",\n "DarkOrchid": "#a8548c",\n "Emerald": "#08ac9c",\n "ForestGreen": "#089c54",\n "Fuchsia": "#90348c",\n "Goldenrod": "#ffdc44",\n "gray": "#808080",\n "Gray": "#98949c",\n "green": "#00FF00",\n "Green": "#08a44c",\n "GreenYellow": "#e0e474",\n "JungleGreen": "#08ac9c",\n "Lavender": "#f89cc4",\n "lightgray": "#c0c0c0",\n "lime": "#BFFF00",\n "LimeGreen": "#90c43c",\n "magenta": "#FF00FF",\n "Magenta": "#f0048c",\n "Mahogany": "#b0341c",\n "Maroon": "#b03434",\n "Melon": "#f89c7c",\n "MidnightBlue": "#086494",\n "Mulberry": "#b03c94",\n "NavyBlue": "#086cbc",\n "olive": "#7F7F00",\n "OliveGreen": "#407c34",\n "orange": "#FF8000",\n "Orange": "#f8843c",\n "OrangeRed": "#f0145c",\n "Orchid": "#b074ac",\n "Peach": "#f8945c",\n "Periwinkle": "#8074bc",\n "PineGreen": "#088c74",\n "pink": "#ff7f7f",\n "Plum": "#98248c",\n "ProcessBlue": "#08b4ec",\n "purple": "#BF0040",\n "Purple": "#a0449c",\n "RawSienna": "#983c04",\n "red": "#ff0000",\n "Red": "#f01c24",\n "RedOrange": "#f86434",\n "RedViolet": "#a0246c",\n "Rhodamine": "#f0549c",\n "Royallue": "#0874bc",\n "RoyalPurple": "#683c9c",\n "RubineRed": "#f0047c",\n "Salmon": "#f8948c",\n "SeaGreen": "#30bc9c",\n "Sepia": "#701404",\n "SkyBlue": "#48c4dc",\n "SpringGreen": "#c8dc64",\n "Tan": "#e09c74",\n "teal": "#007F7F",\n "TealBlue": "#08acb4",\n "Thistle": "#d884b4",\n "Turquoise": "#08b4cc",\n "violet": "#800080",\n "Violet": "#60449c",\n "VioletRed": "#f054a4",\n "WildStrawberry": "#f0246c",\n "yellow": "#FFFF00",\n "Yellow": "#fff404",\n "YellowGreen": "#98cc6c",\n "YellowOrange": "#ffa41c"\n}'),Re=(t,r)=>{let n="";if("HTML"===t){if(!Ie.test(r))throw new e("Invalid HTML input.");n=r}else if("RGB"===t){if(!Le.test(r))throw new e("Invalid RGB input.");r.split(",").map((e=>{n+=De(Number(e.trim()))}))}else{if(!Fe.test(r))throw new e("Invalid rbg input.");r.split(",").map((t=>{const r=Number(t.trim());if(r>1)throw new e("Color rgb input must be < 1.");n+=De(Number((255*r).toFixed(0)))}))}return"#"!==n.charAt(0)&&(n="#"+n),n},je=(t,r,n)=>{const s=`\\\\color@${t}`;if(!$e.exec(t))throw new e("Invalid color: '"+t+"'",n);return Ge.test(t)?"#"+t:("#"===t.charAt(0)||(r.has(s)?t=r.get(s).tokens[0].text:Pe[t]&&(t=Pe[t])),t)},Ue=(e,t)=>{let r=ie(e.body,t.withColor(e.color));return r=r.map((t=>(t.style.color=e.color,t))),N.newDocumentFragment(r)};c({type:"color",names:["\\textcolor"],props:{numArgs:2,numOptionalArgs:1,allowedInText:!0,argTypes:["raw","raw","original"]},handler({parser:e,token:t},r,n){const s=n[0]&&Oe(n[0],"raw").string;let o="";if(s){const e=Oe(r[0],"raw").string;o=Re(s,e)}else o=je(Oe(r[0],"raw").string,e.gullet.macros,t);const a=r[1];return{type:"color",mode:e.mode,color:o,body:p(a)}},mathmlBuilder:Ue}),c({type:"color",names:["\\color"],props:{numArgs:1,numOptionalArgs:1,allowedInText:!0,argTypes:["raw","raw"]},handler({parser:e,breakOnTokenText:t,token:r},n,s){const o=s[0]&&Oe(s[0],"raw").string;let a="";if(o){const e=Oe(n[0],"raw").string;a=Re(o,e)}else a=je(Oe(n[0],"raw").string,e.gullet.macros,r);const i=e.parseExpression(!0,t,!0);return{type:"color",mode:e.mode,color:a,body:i}},mathmlBuilder:Ue}),c({type:"color",names:["\\definecolor"],props:{numArgs:3,allowedInText:!0,argTypes:["raw","raw","raw"]},handler({parser:t,funcName:r,token:n},s){const o=Oe(s[0],"raw").string;if(!/^[A-Za-z]+$/.test(o))throw new e("Color name must be latin letters.",n);const a=Oe(s[1],"raw").string;if(!["HTML","RGB","rgb"].includes(a))throw new e("Color model must be HTML, RGB, or rgb.",n);const i=Oe(s[2],"raw").string,l=Re(a,i);return t.gullet.macros.set(`\\\\color@${o}`,{tokens:[{text:l}],numArgs:0}),{type:"internal",mode:t.mode}}}),c({type:"cr",names:["\\\\"],props:{numArgs:0,numOptionalArgs:0,allowedInText:!0},handler({parser:e},t,r){const n="["===e.gullet.future().text?e.parseSizeGroup(!0):null,s=!e.settings.displayMode;return{type:"cr",mode:e.mode,newLine:s,size:n&&Oe(n,"size").value}},mathmlBuilder(e,t){const r=new N.MathNode("mo");if(e.newLine&&(r.setAttribute("linebreak","newline"),e.size)){const n=ve(e.size,t);r.setAttribute("height",n.number+n.unit)}return r}});const He={"\\global":"\\global","\\long":"\\\\globallong","\\\\globallong":"\\\\globallong","\\def":"\\gdef","\\gdef":"\\gdef","\\edef":"\\xdef","\\xdef":"\\xdef","\\let":"\\\\globallet","\\futurelet":"\\\\globalfuture"},Ve=t=>{const r=t.text;if(/^(?:[\\{}$&#^_]|EOF)$/.test(r))throw new e("Expected a control sequence",t);return r},_e=(e,t,r,n)=>{let s=e.gullet.macros.get(r.text);null==s&&(r.noexpand=!0,s={tokens:[r],numArgs:0,unexpandable:!e.gullet.isExpandable(r.text)}),e.gullet.macros.set(t,s,n)};c({type:"internal",names:["\\global","\\long","\\\\globallong"],props:{numArgs:0,allowedInText:!0},handler({parser:t,funcName:r}){t.consumeSpaces();const n=t.fetch();if(He[n.text])return"\\global"!==r&&"\\\\globallong"!==r||(n.text=He[n.text]),Oe(t.parseFunction(),"internal");throw new e("Invalid token after macro prefix",n)}}),c({type:"internal",names:["\\def","\\gdef","\\edef","\\xdef"],props:{numArgs:0,allowedInText:!0,primitive:!0},handler({parser:t,funcName:r}){let n=t.gullet.popToken();const s=n.text;if(/^(?:[\\{}$&#^_]|EOF)$/.test(s))throw new e("Expected a control sequence",n);let o,a=0;const i=[[]];for(;"{"!==t.gullet.future().text;)if(n=t.gullet.popToken(),"#"===n.text){if("{"===t.gullet.future().text){o=t.gullet.future(),i[a].push("{");break}if(n=t.gullet.popToken(),!/^[1-9]$/.test(n.text))throw new e(`Invalid argument number "${n.text}"`);if(parseInt(n.text)!==a+1)throw new e(`Argument number "${n.text}" out of order`);a++,i.push([])}else{if("EOF"===n.text)throw new e("Expected a macro definition");i[a].push(n.text)}let{tokens:l}=t.gullet.consumeArg();return o&&l.unshift(o),"\\edef"!==r&&"\\xdef"!==r||(l=t.gullet.expandTokens(l),l.reverse()),t.gullet.macros.set(s,{tokens:l,numArgs:a,delimiters:i},r===He[r]),{type:"internal",mode:t.mode}}}),c({type:"internal",names:["\\let","\\\\globallet"],props:{numArgs:0,allowedInText:!0,primitive:!0},handler({parser:e,funcName:t}){const r=Ve(e.gullet.popToken());e.gullet.consumeSpaces();const n=(e=>{let t=e.gullet.popToken();return"="===t.text&&(t=e.gullet.popToken()," "===t.text&&(t=e.gullet.popToken())),t})(e);return _e(e,r,n,"\\\\globallet"===t),{type:"internal",mode:e.mode}}}),c({type:"internal",names:["\\futurelet","\\\\globalfuture"],props:{numArgs:0,allowedInText:!0,primitive:!0},handler({parser:e,funcName:t}){const r=Ve(e.gullet.popToken()),n=e.gullet.popToken(),s=e.gullet.popToken();return _e(e,r,s,"\\\\globalfuture"===t),e.gullet.pushToken(s),e.gullet.pushToken(n),{type:"internal",mode:e.mode}}}),c({type:"internal",names:["\\newcommand","\\renewcommand","\\providecommand"],props:{numArgs:0,allowedInText:!0,primitive:!0},handler({parser:t,funcName:r}){let n="";const s=t.gullet.popToken();"{"===s.text?(n=Ve(t.gullet.popToken()),t.gullet.popToken()):n=Ve(s);const o=t.gullet.isDefined(n);if(o&&"\\newcommand"===r)throw new e(`\\newcommand{${n}} attempting to redefine ${n}; use \\renewcommand`);if(!o&&"\\renewcommand"===r)throw new e(`\\renewcommand{${n}} when command ${n} does not yet exist; use \\newcommand`);let a=0;if("["===t.gullet.future().text){let r=t.gullet.popToken();if(r=t.gullet.popToken(),!/^[0-9]$/.test(r.text))throw new e(`Invalid number of arguments: "${r.text}"`);if(a=parseInt(r.text),r=t.gullet.popToken(),"]"!==r.text)throw new e(`Invalid argument "${r.text}"`)}const{tokens:i}=t.gullet.consumeArg();return t.gullet.macros.set(n,{tokens:i,numArgs:a},!t.settings.strict),{type:"internal",mode:t.mode}}});const We={"\\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}},Xe=["(","\\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","."],Ze=["}","\\left","\\middle","\\right"],Ye=e=>e.length>0&&(Xe.includes(e)||We[e]||Ze.includes(e)),Ke=[0,1.2,1.8,2.4,3];function Je(t,r){const n=Me(t);if(n&&Xe.includes(n.text))return["/","⁄"].includes(n.text)&&(n.text="∕"),["<","\\lt"].includes(n.text)&&(n.text="⟨"),[">","\\gt"].includes(n.text)&&(n.text="⟩"),"\\backslash"===n.text&&(n.text="∖"),n;throw new e(n?`Invalid delimiter '${n.text}' after '${r.funcName}'`:`Invalid delimiter type '${t.type}'`,t)}c({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=Je(t[0],e);return{type:"delimsizing",mode:e.parser.mode,size:We[e.funcName].size,mclass:We[e.funcName].mclass,delim:r.text}},mathmlBuilder:e=>{const t=[];"."===e.delim&&(e.delim=""),t.push(re(e.delim,e.mode));const r=new N.MathNode("mo",t);return"mopen"===e.mclass||"mclose"===e.mclass?r.setAttribute("fence","true"):r.setAttribute("fence","false"),("∖"===e.delim||"\\vert"===e.delim||"|"===e.delim||e.delim.indexOf("arrow")>-1)&&r.setAttribute("stretchy","true"),r.setAttribute("symmetric","true"),r.setAttribute("minsize",Ke[e.size]+"em"),r.setAttribute("maxsize",Ke[e.size]+"em"),r}}),c({type:"leftright-right",names:["\\right"],props:{numArgs:1,argTypes:["primitive"]},handler:(e,t)=>({type:"leftright-right",mode:e.parser.mode,delim:Je(t[0],e).text})}),c({type:"leftright",names:["\\left"],props:{numArgs:1,argTypes:["primitive"]},handler:(t,r)=>{const n=Je(r[0],t),s=t.parser;++s.leftrightDepth;let o=s.parseExpression(!1,null,!0),a=s.fetch();for(;"\\middle"===a.text;){s.consume();const t=s.fetch().text;if(!E.math[t])throw new e(`Invalid delimiter '${t}' after '\\middle'`);Je({type:"atom",mode:"math",text:t},{funcName:"\\middle"}),o.push({type:"middle",mode:"math",delim:t}),s.consume(),o=o.concat(s.parseExpression(!1,null,!0)),a=s.fetch()}--s.leftrightDepth,s.expect("\\right",!1);const i=Oe(s.parseFunction(),"leftright-right");return{type:"leftright",mode:s.mode,body:o,left:n.text,right:i.delim}},mathmlBuilder:(e,t)=>{!function(e){if(!e.body)throw new Error("Bug: The leftright ParseNode wasn't fully parsed.")}(e);const r=ie(e.body,t);"."===e.left&&(e.left="");const n=new N.MathNode("mo",[re(e.left,e.mode)]);n.setAttribute("fence","true"),n.setAttribute("form","prefix"),("∖"===e.left||e.left.indexOf("arrow")>-1)&&n.setAttribute("stretchy","true"),r.unshift(n),"."===e.right&&(e.right="");const s=new N.MathNode("mo",[re(e.right,e.mode)]);return s.setAttribute("fence","true"),s.setAttribute("form","postfix"),("∖"===e.right||e.right.indexOf("arrow")>-1)&&s.setAttribute("stretchy","true"),r.push(s),oe(r)}}),c({type:"middle",names:["\\middle"],props:{numArgs:1,argTypes:["primitive"]},handler:(t,r)=>{const n=Je(r[0],t);if(!t.parser.leftrightDepth)throw new e("\\middle without preceding \\left",n);return{type:"middle",mode:t.parser.mode,delim:n.text}},mathmlBuilder:(e,t)=>{const r=re(e.delim,e.mode),n=new N.MathNode("mo",[r]);return n.setAttribute("fence","true"),e.delim.indexOf("arrow")>-1&&n.setAttribute("stretchy","true"),n.setAttribute("form","prefix"),n.setAttribute("lspace","0.05em"),n.setAttribute("rspace","0.05em"),n}});const Qe=e=>{const t=new N.MathNode("mspace");return t.setAttribute("width","3pt"),t},et=(e,t)=>{let r;switch(r=e.label.indexOf("colorbox")>-1||"\\boxed"===e.label?new N.MathNode("mrow",[Qe(),ce(e.body,t),Qe()]):new N.MathNode("mrow",[ce(e.body,t)]),e.label){case"\\overline":r.style.padding="0.1em 0 0 0",r.style.borderTop="0.065em solid";break;case"\\underline":r.style.padding="0 0 0.1em 0",r.style.borderBottom="0.065em solid";break;case"\\cancel":r.classes.push("tml-cancel");break;case"\\bcancel":r.classes.push("tml-bcancel");break;case"\\angl":r.style.padding="0.03889em 0.03889em 0 0.03889em",r.style.borderTop="0.049em solid",r.style.borderRight="0.049em solid",r.style.marginRight="0.03889em";break;case"\\sout":r.style.backgroundImage="linear-gradient(black, black)",r.style.backgroundRepeat="no-repeat",r.style.backgroundSize="100% 1.5px",r.style.backgroundPosition="0 center";break;case"\\boxed":r.style={padding:"3pt 0 3pt 0",border:"1px solid"},r.setAttribute("scriptlevel","0"),r.setAttribute("displaystyle","true");break;case"\\fbox":r.style={padding:"3pt",border:"1px solid"};break;case"\\fcolorbox":case"\\colorbox":{const t={padding:"3pt 0 3pt 0"};"\\fcolorbox"===e.label&&(t.border="0.06em solid "+String(e.borderColor)),r.style=t;break}case"\\xcancel":r.classes.push("tml-xcancel")}return e.backgroundColor&&r.setAttribute("mathbackground",e.backgroundColor),r};c({type:"enclose",names:["\\colorbox"],props:{numArgs:2,numOptionalArgs:1,allowedInText:!0,argTypes:["raw","raw","text"]},handler({parser:e,funcName:t},r,n){const s=n[0]&&Oe(n[0],"raw").string;let o="";if(s){const e=Oe(r[0],"raw").string;o=Re(s,e)}else o=je(Oe(r[0],"raw").string,e.gullet.macros);const a=r[1];return{type:"enclose",mode:e.mode,label:t,backgroundColor:o,body:a}},mathmlBuilder:et}),c({type:"enclose",names:["\\fcolorbox"],props:{numArgs:3,numOptionalArgs:1,allowedInText:!0,argTypes:["raw","raw","raw","text"]},handler({parser:e,funcName:t},r,n){const s=n[0]&&Oe(n[0],"raw").string;let o,a="";if(s){const e=Oe(r[0],"raw").string,t=Oe(r[0],"raw").string;a=Re(s,e),o=Re(s,t)}else a=je(Oe(r[0],"raw").string,e.gullet.macros),o=je(Oe(r[1],"raw").string,e.gullet.macros);const i=r[2];return{type:"enclose",mode:e.mode,label:t,backgroundColor:o,borderColor:a,body:i}},mathmlBuilder:et}),c({type:"enclose",names:["\\fbox"],props:{numArgs:1,argTypes:["hbox"],allowedInText:!0},handler:({parser:e},t)=>({type:"enclose",mode:e.mode,label:"\\fbox",body:t[0]})}),c({type:"enclose",names:["\\angl","\\cancel","\\bcancel","\\xcancel","\\sout","\\overline","\\boxed"],props:{numArgs:1},handler({parser:e,funcName:t},r){const n=r[0];return{type:"enclose",mode:e.mode,label:t,body:n}},mathmlBuilder:et}),c({type:"enclose",names:["\\underline"],props:{numArgs:1,allowedInText:!0},handler({parser:e,funcName:t},r){const n=r[0];return{type:"enclose",mode:e.mode,label:t,body:n}},mathmlBuilder:et});const tt={};function rt({type:e,names:t,props:r,handler:n,mathmlBuilder:s}){const o={type:e,numArgs:r.numArgs||0,allowedInText:!1,numOptionalArgs:0,handler:n};for(let e=0;e{if(!t.parser.settings.displayMode)throw new e(`{${t.envName}} can be used only in display mode.`)},ct=(e,t,r)=>{let n;const s=e.tags.shift();if(s){if(!s.body)return n=new N.MathNode("mtext",[],[]),n;n=le(s.body,t,!0),n.classes=["tml-tag"]}else{if(e.envClasses.includes("multline")&&(e.leqno&&0!==r||!e.leqno&&r!==e.body.length-1))return n=new N.MathNode("mtext",[],[]),n;n=new N.MathNode("mtext",[new y(["tml-eqn"])])}return n};function mt(t,{cols:r,envClasses:n,addEqnNum:s,singleRow:o,emptySingleRow:a,maxNumCols:i,leqno:l},c){t.gullet.beginGroup(),o||t.gullet.macros.set("\\cr","\\\\\\relax"),s&&(t.gullet.macros.set("\\tag","\\@ifstar\\envtag@literal\\envtag@paren"),t.gullet.macros.set("\\envtag@paren","\\env@tag{{(\\text{#1})}}"),t.gullet.macros.set("\\envtag@literal","\\env@tag{\\text{#1}}"),t.gullet.macros.set("\\notag","\\env@notag"),t.gullet.macros.set("\\nonumber","\\env@notag")),t.gullet.beginGroup();let m=[];const u=[m],p=[],d=[];let h;const g=[];for(g.push(it(t));;){let r=t.parseExpression(!1,o?"\\end":"\\\\");if(s&&!h)for(let e=0;e1||!a)&&u.pop(),g.length{const t=new N.MathNode("mtd",[]);return t.style={padding:"0",width:"50%"},e.envClasses.includes("multline")&&(t.style.width="7.5%"),t},ht=function(e,t){const r=[],n=e.body.length,s=e.hLinesBeforeRow;for(let o=0;o0&&(2===s[0].length?c.children.forEach((e=>{e.style.borderTop="0.15em double"})):c.children.forEach((e=>{e.style.borderTop=s[0][0]?"0.06em dashed":"0.06em solid"}))),s[o+1].length>0&&(2===s[o+1].length?c.children.forEach((e=>{e.style.borderBottom="0.15em double"})):c.children.forEach((e=>{e.style.borderBottom=s[o+1][0]?"0.06em dashed":"0.06em solid"}))),r.push(c)}if(e.envClasses.length>0){const t=e.envClasses.includes("jot")?"0.7":e.envClasses.includes("small")?"0.35":"0.5",n=e.envClasses.includes("abut")||e.envClasses.includes("cases")?"0":e.envClasses.includes("small")?"0.1389":e.envClasses.includes("cd")?"0.25":"0.4",s=0===r.length?0:r[0].children.length,o=(t,r)=>0===t&&0===r||t===s-1&&1===r?"0":"align"!==e.envClasses[0]?n:1===r?"0":e.addEqnNum?t%2?"1":"0":t%2?"0":"1";for(let e=0;e1&&e.envClasses.includes("cases")&&(n.children[1].style.padding=n.children[1].style.padding.replace(/0em$/,"1em")),e.envClasses.includes("cases")||e.envClasses.includes("subarray"))for(const e of n.children)e.classes.push("tml-left")}}else for(let e=0;e0){const t=e.cols;let r=!1,n=0,s=t.length;for(;"separator"===t[n].type;)n+=1;for(;"separator"===t[s-1].type;)s-=1;if("separator"===t[0].type){const e="separator"===t[1].type?"0.15em double":"|"===t[0].separator?"0.06em solid ":"0.06em dashed ";for(const t of o.children)t.children[0].style.borderLeft=e}let i=e.addEqnNum?0:-1;for(let e=n;e0?a:"center ")+"right "),a&&o.setAttribute("columnalign",a.trim()),e.envClasses.includes("small")&&(o=new N.MathNode("mstyle",[o]),o.setAttribute("scriptlevel","1")),o},gt=function(t,r){-1===t.envName.indexOf("ed")&<(t);const n=[],s=mt(t.parser,{cols:n,addEqnNum:"align"===t.envName||"alignat"===t.envName,emptySingleRow:!0,envClasses:["abut","jot"],maxNumCols:"split"===t.envName?2:void 0,leqno:t.parser.settings.leqno},"display");let o,a=0;const i=t.envName.indexOf("at")>-1;if(r[0]&&i){let t="";for(let e=0;e1)throw new e("{subarray} can contain only one column");let s={cols:n,envClasses:["small"]};if(s=mt(t.parser,s,"script"),s.body.length>0&&s.body[0].length>1)throw new e("{subarray} can contain only one column");return s},mathmlBuilder:ht}),rt({type:"array",names:["cases","dcases","rcases","drcases"],props:{numArgs:0},handler(e){const t=mt(e.parser,{cols:[],envClasses:["cases"]},ut(e.envName));return{type:"leftright",mode:e.mode,body:[t],left:e.envName.indexOf("r")>-1?".":"\\{",right:e.envName.indexOf("r")>-1?"\\}":".",rightColor:void 0}},mathmlBuilder:ht}),rt({type:"array",names:["align","align*","aligned","split"],props:{numArgs:0},handler:gt,mathmlBuilder:ht}),rt({type:"array",names:["alignat","alignat*","alignedat"],props:{numArgs:1},handler:gt,mathmlBuilder:ht}),rt({type:"array",names:["gathered","gather","gather*"],props:{numArgs:0},handler(e){"gathered"!==e.envName&<(e);const t={cols:[],envClasses:["abut","jot"],addEqnNum:"gather"===e.envName,emptySingleRow:!0,leqno:e.parser.settings.leqno};return mt(e.parser,t,"display")},mathmlBuilder:ht}),rt({type:"array",names:["equation","equation*"],props:{numArgs:0},handler(e){lt(e);const t={addEqnNum:"equation"===e.envName,emptySingleRow:!0,singleRow:!0,maxNumCols:1,envClasses:["align"],leqno:e.parser.settings.leqno};return mt(e.parser,t,"display")},mathmlBuilder:ht}),rt({type:"array",names:["multline","multline*"],props:{numArgs:0},handler(e){lt(e);const t={addEqnNum:"multline"===e.envName,maxNumCols:1,envClasses:["jot","multline"],leqno:e.parser.settings.leqno};return mt(e.parser,t,"display")},mathmlBuilder:ht}),rt({type:"array",names:["CD"],props:{numArgs:0},handler:t=>(lt(t),function(t){const r=[];for(t.gullet.beginGroup(),t.gullet.macros.set("\\cr","\\\\\\relax"),t.gullet.beginGroup();;){r.push(t.parseExpression(!1,"\\\\")),t.gullet.endGroup(),t.gullet.beginGroup();const n=t.fetch().text;if("&"!==n&&"\\\\"!==n){if("\\end"===n){0===r[r.length-1].length&&r.pop();break}throw new e("Expected \\\\ or \\cr or \\end",t.nextToken)}t.consume()}let n=[];const s=[n];for(let i=0;i-1);else{if(!("<>AV".indexOf(s)>-1))throw new e('Expected one of "<>AV=|." after @.');for(let t=0;t<2;t++){let n=!0;for(let c=r+1;c({type:"envTag",mode:e.mode,body:t[0]}),mathmlBuilder:(e,t)=>new N.MathNode("mrow")}),c({type:"noTag",names:["\\env@notag"],props:{numArgs:0},handler:({parser:e})=>({type:"noTag",mode:e.mode}),mathmlBuilder:(e,t)=>new N.MathNode("mrow")});const bt=(e,t)=>{const r=e.font,n=t.withFont(r),s=ce(e.body,n);if(0===s.children.length)return s;if("boldsymbol"===r&&["mo","mpadded","mrow"].includes(s.type))return s.style.fontWeight="bold",s;if(((e,t)=>{if("mathrm"!==t||"ordgroup"!==e.body.type||1===e.body.body.length)return!1;if("mathord"!==e.body.body[0].type)return!1;for(let t=1;t{const n=u(r[0]);let s=t;return s in yt&&(s=yt[s]),{type:"font",mode:e.mode,font:s.slice(1),body:n}},mathmlBuilder:bt}),c({type:"font",names:["\\rm","\\sf","\\tt","\\bf","\\it","\\cal"],props:{numArgs:0,allowedInText:!0},handler:({parser:e,funcName:t,breakOnTokenText:r},n)=>{const{mode:s}=e,o=e.parseExpression(!0,r,!0);return{type:"font",mode:s,font:`math${t.slice(1)}`,body:{type:"ordgroup",mode:e.mode,body:o}}},mathmlBuilder:bt});const xt=["display","text","script","scriptscript"],wt={auto:-1,display:0,text:0,script:1,scriptscript:2},kt=(e,t)=>{const r="auto"===e.scriptLevel?t.incrementLevel():"display"===e.scriptLevel?t.withLevel(st):"text"===e.scriptLevel?t.withLevel(ot):t.withLevel(at);let n=new N.MathNode("mfrac",[ce(e.numer,r),ce(e.denom,r)]);if(e.hasBarLine){if(e.barSize){const r=ve(e.barSize,t);n.setAttribute("linethickness",r.number+r.unit)}}else n.setAttribute("linethickness","0px");if(null!=e.leftDelim||null!=e.rightDelim){const t=[];if(null!=e.leftDelim){const r=new N.MathNode("mo",[new N.TextNode(e.leftDelim.replace("\\",""))]);r.setAttribute("fence","true"),t.push(r)}if(t.push(n),null!=e.rightDelim){const r=new N.MathNode("mo",[new N.TextNode(e.rightDelim.replace("\\",""))]);r.setAttribute("fence","true"),t.push(r)}n=oe(t)}return"auto"!==e.scriptLevel&&(n=new N.MathNode("mstyle",[n]),n.setAttribute("displaystyle",String("display"===e.scriptLevel)),n.setAttribute("scriptlevel",wt[e.scriptLevel])),n};c({type:"genfrac",names:["\\dfrac","\\frac","\\tfrac","\\dbinom","\\binom","\\tbinom","\\\\atopfrac","\\\\bracefrac","\\\\brackfrac"],props:{numArgs:2,allowedInArgument:!0},handler:({parser:e,funcName:t},r)=>{const n=r[0],s=r[1];let o=!1,a=null,i=null,l="auto";switch(t){case"\\dfrac":case"\\frac":case"\\tfrac":o=!0;break;case"\\\\atopfrac":o=!1;break;case"\\dbinom":case"\\binom":case"\\tbinom":a="(",i=")";break;case"\\\\bracefrac":a="\\{",i="\\}";break;case"\\\\brackfrac":a="[",i="]";break;default:throw new Error("Unrecognized genfrac command")}switch(t){case"\\dfrac":case"\\dbinom":l="display";break;case"\\tfrac":case"\\tbinom":l="text"}return{type:"genfrac",mode:e.mode,continued:!1,numer:n,denom:s,hasBarLine:o,leftDelim:a,rightDelim:i,scriptLevel:l,barSize:null}},mathmlBuilder:kt}),c({type:"genfrac",names:["\\cfrac"],props:{numArgs:2},handler:({parser:e,funcName:t},r)=>{const n=r[0],s=r[1];return{type:"genfrac",mode:e.mode,continued:!0,numer:n,denom:s,hasBarLine:!0,leftDelim:null,rightDelim:null,scriptLevel:"display",barSize:null}}}),c({type:"infix",names:["\\over","\\choose","\\atop","\\brace","\\brack"],props:{numArgs:0,infix:!0},handler({parser:e,funcName:t,token:r}){let n;switch(t){case"\\over":n="\\frac";break;case"\\choose":n="\\binom";break;case"\\atop":n="\\\\atopfrac";break;case"\\brace":n="\\\\bracefrac";break;case"\\brack":n="\\\\brackfrac";break;default:throw new Error("Unrecognized infix genfrac command")}return{type:"infix",mode:e.mode,replaceWith:n,token:r}}});const vt=function(e){let t=null;return e.length>0&&(t=e,t="."===t?null:t),t};c({type:"genfrac",names:["\\genfrac"],props:{numArgs:6,allowedInArgument:!0,argTypes:["math","math","size","text","math","math"]},handler({parser:e},t){const r=t[4],n=t[5],s=u(t[0]),o="atom"===s.type&&"open"===s.family?vt(s.text):null,a=u(t[1]),i="atom"===a.type&&"close"===a.family?vt(a.text):null,l=Oe(t[2],"size");let c,m=null;l.isBlank?c=!0:(m=l.value,c=m.number>0);let p="auto",d=t[3];if("ordgroup"===d.type){if(d.body.length>0){const e=Oe(d.body[0],"textord");p=xt[Number(e.text)]}}else d=Oe(d,"textord"),p=xt[Number(d.text)];return{type:"genfrac",mode:e.mode,numer:r,denom:n,continued:!1,hasBarLine:c,barSize:m,leftDelim:o,rightDelim:i,scriptLevel:p}},mathmlBuilder:kt}),c({type:"infix",names:["\\above"],props:{numArgs:1,argTypes:["size"],infix:!0},handler:({parser:e,funcName:t,token:r},n)=>({type:"infix",mode:e.mode,replaceWith:"\\\\abovefrac",barSize:Oe(n[0],"size").value,token:r})}),c({type:"genfrac",names:["\\\\abovefrac"],props:{numArgs:3,argTypes:["math","size","math"]},handler:({parser:e,funcName:t},r)=>{const n=r[0],s=function(e){if(!e)throw new Error("Expected non-null, but got "+String(e));return e}(Oe(r[1],"infix").barSize),o=r[2],a=s.number>0;return{type:"genfrac",mode:e.mode,numer:n,denom:o,continued:!1,hasBarLine:a,barSize:s,leftDelim:null,rightDelim:null,scriptLevel:"auto"}},mathmlBuilder:kt}),c({type:"hbox",names:["\\hbox"],props:{numArgs:1,argTypes:["hbox"],allowedInArgument:!0,allowedInText:!1},handler:({parser:e},t)=>({type:"hbox",mode:e.mode,body:p(t[0])}),mathmlBuilder(e,t){const r=t.withLevel(st),n=le(e.body,r);return ne(n)}});c({type:"horizBrace",names:["\\overbrace","\\underbrace"],props:{numArgs:1},handler:({parser:e,funcName:t},r)=>({type:"horizBrace",mode:e.mode,label:t,isOver:/^\\over/.test(t),base:r[0]}),mathmlBuilder:(e,t)=>{const r=B(e.label);return r.style["math-depth"]=0,new N.MathNode(e.isOver?"mover":"munder",[ce(e.base,t),r])}}),c({type:"href",names:["\\href"],props:{numArgs:2,argTypes:["url","original"],allowedInText:!0},handler:({parser:t,token:r},n)=>{const s=n[1],o=Oe(n[0],"url").url;if(!t.settings.isTrusted({command:"\\href",url:o}))throw new e('Function "\\href" is not trusted',r);return{type:"href",mode:t.mode,href:o,body:p(s)}},mathmlBuilder:(e,t)=>{let r=le(e.body,t);return r instanceof k||(r=new k("mrow",[r])),r.setAttribute("href",e.href),r}}),c({type:"href",names:["\\url"],props:{numArgs:1,argTypes:["url"],allowedInText:!0},handler:({parser:t,token:r},n)=>{const s=Oe(n[0],"url").url;if(!t.settings.isTrusted({command:"\\url",url:s}))throw new e('Function "\\url" is not trusted',r);const o=[];for(let e=0;e{const o=Oe(s[0],"raw").string,a=s[1];if(t.settings.strict)throw new e(`Function "${r}" is disabled in strict mode`,n);let i;const l={};switch(r){case"\\class":l.class=o,i={command:"\\class",class:o};break;case"\\id":l.id=o,i={command:"\\id",id:o};break;case"\\style":l.style=o,i={command:"\\style",style:o};break;case"\\data":{const t=o.split(",");for(let r=0;r{const r=le(e.body,t),n=[];e.attributes.class&&n.push(...e.attributes.class.trim().split(/\s+/)),r.classes=n;for(const t in e.attributes)"class"!==t&&Object.prototype.hasOwnProperty.call(e.attributes,t)&&r.setAttribute(t,e.attributes[t]);return r}});const At=function(t){if(/^[-+]? *(\d+(\.\d*)?|\.\d+)$/.test(t))return{number:+t,unit:"bp"};{const r=/([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(t);if(!r)throw new e("Invalid size: '"+t+"' in \\includegraphics");const n={number:+(r[1]+r[2]),unit:r[3]};if(!we(n))throw new e("Invalid unit: '"+n.unit+"' in \\includegraphics.");return n}};c({type:"includegraphics",names:["\\includegraphics"],props:{numArgs:1,numOptionalArgs:1,argTypes:["raw","url"],allowedInText:!1},handler:({parser:t,token:r},n,s)=>{let o={number:0,unit:"em"},a={number:.9,unit:"em"},i={number:0,unit:"em"},l="";if(s[0]){const t=Oe(s[0],"raw").string.split(",");for(let r=0;r{const r=ve(e.height,t),n={number:0,unit:"em"};e.totalheight.number>0&&e.totalheight.unit===r.unit&&e.totalheight.number>r.number&&(n.number=e.totalheight.number-r.number,n.unit=r.unit);let s=0;e.width.number>0&&(s=ve(e.width,t));const o={height:r.number+n.number+"em"};s.number>0&&(o.width=s.number+s.unit),n.number>0&&(o.verticalAlign=-n.number+n.unit);const a=new w(e.src,e.alt,o);return a.height=r,a.depth=n,new N.MathNode("mtext",[a])}}),c({type:"kern",names:["\\kern","\\mkern","\\hskip","\\mskip"],props:{numArgs:1,argTypes:["size"],primitive:!0,allowedInText:!0},handler({parser:t,funcName:r,token:n},s){const o=Oe(s[0],"size");if(t.settings.strict){const s="m"===r[1],a="mu"===o.value.unit;if(s){if(!a)throw new e(`LaTeX's ${r} supports only mu units, not ${o.value.unit} units`,n);if("math"!==t.mode)throw new e(`LaTeX's ${r} works only in math mode`,n)}else if(a)throw new e(`LaTeX's ${r} doesn't support mu units`,n)}return{type:"kern",mode:t.mode,dimension:o.value}},mathmlBuilder(e,t){const r=ve(e.dimension,t),n="em"===r.unit?Nt(r.number):"";if("text"===e.mode&&n.length>0){const e=new N.TextNode(n);return new N.MathNode("mtext",[e])}{const e=new N.MathNode("mspace");return e.setAttribute("width",r.number+r.unit),r.number<0&&(e.style.marginLeft=r.number+r.unit),e}}});const Nt=function(e){return e>=.05555&&e<=.05556?" ":e>=.1666&&e<=.1667?" ":e>=.2222&&e<=.2223?" ":e>=.2777&&e<=.2778?"  ":""},Tt=/[^A-Za-z_0-9-]/g;c({type:"label",names:["\\label"],props:{numArgs:1,argTypes:["raw"]},handler:({parser:e},t)=>({type:"label",mode:e.mode,string:t[0].string.replace(Tt,"")}),mathmlBuilder(e,t){const r=new N.MathNode("mrow",[],["tml-label"]);return e.string.length>0&&r.setAttribute("id",e.string),r}});const qt=["\\clap","\\llap","\\rlap"];c({type:"lap",names:["\\mathllap","\\mathrlap","\\mathclap","\\clap","\\llap","\\rlap"],props:{numArgs:1,allowedInText:!0},handler:({parser:t,funcName:r,token:n},s)=>{if(qt.includes(r)){if(t.settings.strict&&"text"!==t.mode)throw new e(`{${r}} can be used only in text mode.\n Try \\math${r.slice(1)}`,n);r=r.slice(1)}else r=r.slice(5);const o=s[0];return{type:"lap",mode:t.mode,alignment:r,body:o}},mathmlBuilder:(e,t)=>{let r;if("llap"===e.alignment){const n=ie(p(e.body),t),s=new N.MathNode("mphantom",n);r=new N.MathNode("mpadded",[s]),r.setAttribute("width","0px")}const n=ce(e.body,t);let s;if("llap"===e.alignment?(n.style.position="absolute",n.style.right="0",n.style.bottom="0",s=new N.MathNode("mpadded",[r,n])):s=new N.MathNode("mpadded",[n]),"rlap"===e.alignment)e.body.body.length>0&&"genfrac"===e.body.body[0].type&&s.setAttribute("lspace","0.16667em");else{const t="llap"===e.alignment?"-1":"-0.5";s.setAttribute("lspace",t+"width"),"llap"===e.alignment?s.style.position="relative":(s.style.display="flex",s.style.justifyContent="center")}return s.setAttribute("width","0px"),s}}),c({type:"ordgroup",names:["\\(","$"],props:{numArgs:0,allowedInText:!0,allowedInMath:!1},handler({funcName:e,parser:t},r){const n=t.mode;t.switchMode("math");const s="\\("===e?"\\)":"$",o=t.parseExpression(!1,s);return t.expect(s),t.switchMode(n),{type:"ordgroup",mode:t.mode,body:o}}}),c({type:"text",names:["\\)","\\]"],props:{numArgs:0,allowedInText:!0,allowedInMath:!1},handler(t,r){throw new e(`Mismatched ${t.funcName}`,r)}});c({type:"mathchoice",names:["\\mathchoice"],props:{numArgs:4,primitive:!0},handler:({parser:e},t)=>({type:"mathchoice",mode:e.mode,display:p(t[0]),text:p(t[1]),script:p(t[2]),scriptscript:p(t[3])}),mathmlBuilder:(e,t)=>{const r=((e,t)=>{switch(t.level){case nt:return e.display;case st:return e.text;case ot:return e.script;case at:return e.scriptscript;default:return e.text}})(e,t);return le(r,t)}});const St=["text","textord","mathord","atom"],Ot=e=>{const t=new N.MathNode("mspace");return t.setAttribute("width",e+"em"),t};function Bt(e,t){let r;const n=ie(e.body,t);if("minner"===e.mclass)r=new N.MathNode("mpadded",n);else if("mord"===e.mclass)e.isCharacterBox||"mathord"===n[0].type?(r=n[0],r.type="mi",1===r.children.length&&r.children[0].text&&"∇"===r.children[0].text&&r.setAttribute("mathvariant","normal")):r=new N.MathNode("mi",n);else{r=new N.MathNode("mrow",n),e.mustPromote?(r=n[0],r.type="mo",e.isCharacterBox&&e.body[0].text&&/[A-Za-z]/.test(e.body[0].text)&&r.setAttribute("mathvariant","italic")):r=new N.MathNode("mrow",n);const s=t.level<2;"mrow"===r.type?s&&("mbin"===e.mclass?(r.children.unshift(Ot(.2222)),r.children.push(Ot(.2222))):"mrel"===e.mclass?(r.children.unshift(Ot(.2778)),r.children.push(Ot(.2778))):"mpunct"===e.mclass?r.children.push(Ot(.1667)):"minner"===e.mclass&&(r.children.unshift(Ot(.0556)),r.children.push(Ot(.0556)))):"mbin"===e.mclass?(r.attributes.lspace=s?"0.2222em":"0",r.attributes.rspace=s?"0.2222em":"0"):"mrel"===e.mclass?(r.attributes.lspace=s?"0.2778em":"0",r.attributes.rspace=s?"0.2778em":"0"):"mpunct"===e.mclass?(r.attributes.lspace="0em",r.attributes.rspace=s?"0.1667em":"0"):"mopen"===e.mclass||"mclose"===e.mclass?(r.attributes.lspace="0em",r.attributes.rspace="0em"):"minner"===e.mclass&&s&&(r.attributes.lspace="0.0556em",r.attributes.width="+0.1111em"),"mopen"!==e.mclass&&"mclose"!==e.mclass&&(delete r.attributes.stretchy,delete r.attributes.form)}return r}c({type:"mclass",names:["\\mathord","\\mathbin","\\mathrel","\\mathopen","\\mathclose","\\mathpunct","\\mathinner"],props:{numArgs:1,primitive:!0},handler({parser:e,funcName:t},r){const n=r[0],s=o.isCharacterBox(n);let a=!0;const i={type:"mathord",text:"",mode:e.mode},l=n.body?n.body:[n];for(const t of l){if(!St.includes(t.type)){a=!1;break}E[e.mode][t.text]?i.text+=E[e.mode][t.text].replace:t.text?i.text+=t.text:t.body&&t.body.map((e=>{i.text+=e.text}))}return{type:"mclass",mode:e.mode,mclass:"m"+t.slice(5),body:p(a?i:n),isCharacterBox:s,mustPromote:a}},mathmlBuilder:Bt});const Mt=e=>{const t="ordgroup"===e.type&&e.body.length?e.body[0]:e;return"atom"!==t.type||"bin"!==t.family&&"rel"!==t.family?"mord":"m"+t.family};c({type:"mclass",names:["\\@binrel"],props:{numArgs:2},handler:({parser:e},t)=>({type:"mclass",mode:e.mode,mclass:Mt(t[0]),body:p(t[1]),isCharacterBox:o.isCharacterBox(t[1])})}),c({type:"mclass",names:["\\stackrel","\\overset","\\underset"],props:{numArgs:2},handler({parser:e,funcName:t},r){const n=r[1],s=r[0],o={type:"op",mode:n.mode,limits:!0,alwaysHandleSupSub:!0,parentIsSupSub:!1,symbol:!1,stack:!0,suppressBaseShift:"\\stackrel"!==t,body:p(n)};return{type:"supsub",mode:s.mode,base:o,sup:"\\underset"===t?null:s,sub:"\\underset"===t?s:null}},mathmlBuilder:Bt});const Ct=(e,t,r)=>{if(!e)return r;const n=ce(e,t);return"mrow"===n.type&&0===n.children.length?r:n};c({type:"multiscript",names:["\\sideset","\\pres@cript"],props:{numArgs:3},handler({parser:t,funcName:r,token:n},s){if(0===s[2].body.length)throw new e(r+"cannot parse an empty base.");const o=s[2].body[0];if(t.settings.strict&&"\\sideset"===r&&!o.symbol)throw new e("The base of \\sideset must be a big operator. Try \\prescript.");if(s[0].body.length>0&&"supsub"!==s[0].body[0].type||s[1].body.length>0&&"supsub"!==s[1].body[0].type)throw new e("\\sideset can parse only subscripts and superscripts in its first two arguments",n);const a=s[0].body.length>0?s[0].body[0]:null,i=s[1].body.length>0?s[1].body[0]:null;return a||i?a?{type:"multiscript",mode:t.mode,isSideset:"\\sideset"===r,prescripts:a,postscripts:i,base:o}:{type:"styling",mode:t.mode,scriptLevel:"text",body:[{type:"supsub",mode:t.mode,base:o,sup:i.sup,sub:i.sub}]}:o},mathmlBuilder(e,t){const r=ce(e.base,t),n=new N.MathNode("mprescripts"),s=new N.MathNode("none");let o=[];const a=Ct(e.prescripts.sub,t,s),i=Ct(e.prescripts.sup,t,s);if(e.isSideset&&(a.setAttribute("style","text-align: left;"),i.setAttribute("style","text-align: left;")),e.postscripts){o=[r,Ct(e.postscripts.sub,t,s),Ct(e.postscripts.sup,t,s),n,a,i]}else o=[r,n,a,i];return new N.MathNode("mmultiscripts",o)}}),c({type:"not",names:["\\not"],props:{numArgs:1,primitive:!0,allowedInText:!1},handler({parser:e},t){const r=o.isCharacterBox(t[0]);let n;if(r)n=p(t[0]),"\\"===n[0].text.charAt(0)&&(n[0].text=E.math[n[0].text].replace),n[0].text=n[0].text.slice(0,1)+"̸"+n[0].text.slice(1);else{n=[{type:"textord",mode:"math",text:"̸"},{type:"kern",mode:"math",dimension:{number:-.6,unit:"em"}},t[0]]}return{type:"not",mode:e.mode,body:n,isCharacterBox:r}},mathmlBuilder(e,t){if(e.isCharacterBox){return ie(e.body,t,!0)[0]}return le(e.body,t)}});const zt=["textord","mathord","atom"],Et=["\\smallint"],It=["textord","mathord","ordgroup","close","leftright"],$t=e=>{e.attributes.lspace="0.1667em",e.attributes.rspace="0.1667em"},Lt=(e,t)=>{let r;if(e.symbol)r=new k("mo",[re(e.name,e.mode)]),Et.includes(e.name)?r.setAttribute("largeop","false"):r.setAttribute("movablelimits","false"),e.fromMathOp&&$t(r);else if(e.body)r=new k("mo",ie(e.body,t)),e.fromMathOp&&$t(r);else if(r=new k("mi",[new v(e.name.slice(1))]),!e.parentIsSupSub){const t=[r,new k("mo",[re("⁡","text")])];if(e.needsLeadingSpace){const e=new k("mspace");e.setAttribute("width","0.1667em"),t.unshift(e)}if(!e.isFollowedByDelimiter){const e=new k("mspace");e.setAttribute("width","0.1667em"),t.push(e)}r=new k("mrow",t)}return r},Ft={"∏":"\\prod","∐":"\\coprod","∑":"\\sum","⋀":"\\bigwedge","⋁":"\\bigvee","⋂":"\\bigcap","⋃":"\\bigcup","⨀":"\\bigodot","⨁":"\\bigoplus","⨂":"\\bigotimes","⨄":"\\biguplus","⨅":"\\bigsqcap","⨆":"\\bigsqcup","⨉":"\\bigtimes"};c({type:"op",names:["\\coprod","\\bigvee","\\bigwedge","\\biguplus","\\bigcap","\\bigcup","\\intop","\\prod","\\sum","\\bigotimes","\\bigoplus","\\bigodot","\\bigsqcap","\\bigsqcup","\\bigtimes","\\smallint","∏","∐","∑","⋀","⋁","⋂","⋃","⨀","⨁","⨂","⨄","⨆"],props:{numArgs:0},handler:({parser:e,funcName:t},r)=>{let n=t;return 1===n.length&&(n=Ft[n]),{type:"op",mode:e.mode,limits:!0,parentIsSupSub:!1,symbol:!0,stack:!1,name:n}},mathmlBuilder:Lt}),c({type:"op",names:["\\mathop"],props:{numArgs:1,primitive:!0},handler:({parser:e},t)=>{const r=t[0],n=r.body?r.body:[r],s=1===n.length&&zt.includes(n[0].type);return{type:"op",mode:e.mode,limits:!0,parentIsSupSub:!1,symbol:s,fromMathOp:!0,stack:!1,name:s?n[0].text:null,body:s?null:p(r)}},mathmlBuilder:Lt});const Gt={"∫":"\\int","∬":"\\iint","∭":"\\iiint","∮":"\\oint","∯":"\\oiint","∰":"\\oiiint","∱":"\\intclockwise","∲":"\\varointclockwise","⨌":"\\iiiint","⨍":"\\intbar","⨎":"\\intBar","⨏":"\\fint","⨒":"\\rppolint","⨓":"\\scpolint","⨕":"\\pointint","⨖":"\\sqint","⨗":"\\intlarhk","⨘":"\\intx","⨙":"\\intcap","⨚":"\\intcup"};c({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,n=e.gullet.future().text;return{type:"op",mode:e.mode,limits:!1,parentIsSupSub:!1,symbol:!1,stack:!1,isFollowedByDelimiter:Ye(n),needsLeadingSpace:r.length>0&&It.includes(r),name:t}},mathmlBuilder:Lt}),c({type:"op",names:["\\det","\\gcd","\\inf","\\lim","\\max","\\min","\\Pr","\\sup"],props:{numArgs:0},handler({parser:e,funcName:t}){const r=e.prevAtomType,n=e.gullet.future().text;return{type:"op",mode:e.mode,limits:!0,parentIsSupSub:!1,symbol:!1,stack:!1,isFollowedByDelimiter:Ye(n),needsLeadingSpace:r.length>0&&It.includes(r),name:t}},mathmlBuilder:Lt}),c({type:"op",names:["\\int","\\iint","\\iiint","\\iiiint","\\oint","\\oiint","\\oiiint","\\intclockwise","\\varointclockwise","\\intbar","\\intBar","\\fint","\\rppolint","\\scpolint","\\pointint","\\sqint","\\intlarhk","\\intx","\\intcap","\\intcup","∫","∬","∭","∮","∯","∰","∱","∲","⨌","⨍","⨎","⨏","⨒","⨓","⨕","⨖","⨗","⨘","⨙","⨚"],props:{numArgs:0},handler({parser:e,funcName:t}){let r=t;return 1===r.length&&(r=Gt[r]),{type:"op",mode:e.mode,limits:!1,parentIsSupSub:!1,symbol:!0,stack:!1,name:r}},mathmlBuilder:Lt});const Dt={};function Pt(e,t){Dt[e]=t}c({type:"operatorname",names:["\\operatorname@","\\operatornamewithlimits"],props:{numArgs:1,allowedInArgument:!0},handler:({parser:e,funcName:t},r)=>{const n=r[0],s=e.prevAtomType,o=e.gullet.future().text;return{type:"operatorname",mode:e.mode,body:p(n),alwaysHandleSupSub:"\\operatornamewithlimits"===t,limits:!1,parentIsSupSub:!1,isFollowedByDelimiter:Ye(o),needsLeadingSpace:s.length>0&&It.includes(s)}},mathmlBuilder:(e,t)=>{let r,n=ie(e.body,t.withFont("mathrm")),s=!0;for(let e=0;ee.toText())).join("");n=[new N.TextNode(e)]}else if(1===n.length&&["mover","munder"].includes(n[0].type)&&("mi"===n[0].children[0].type||"mtext"===n[0].children[0].type)){if(n[0].children[0].type="mi",e.parentIsSupSub)return new N.MathNode("mrow",n);{const e=new N.MathNode("mo",[re("⁡","text")]);return N.newDocumentFragment([n[0],e])}}if(s?(r=new N.MathNode("mi",n),1===n[0].text.length&&r.setAttribute("mathvariant","normal")):r=new N.MathNode("mrow",n),!e.parentIsSupSub){const t=[r,new N.MathNode("mo",[re("⁡","text")])];if(e.needsLeadingSpace){const e=new N.MathNode("mspace");e.setAttribute("width","0.1667em"),t.unshift(e)}if(!e.isFollowedByDelimiter){const e=new N.MathNode("mspace");e.setAttribute("width","0.1667em"),t.push(e)}return N.newDocumentFragment(t)}return r}}),Pt("\\operatorname","\\@ifstar\\operatornamewithlimits\\operatorname@"),m({type:"ordgroup",mathmlBuilder:(e,t)=>le(e.body,t,e.semisimple)}),c({type:"phantom",names:["\\phantom"],props:{numArgs:1,allowedInText:!0},handler:({parser:e},t)=>{const r=t[0];return{type:"phantom",mode:e.mode,body:p(r)}},mathmlBuilder:(e,t)=>{const r=ie(e.body,t);return new N.MathNode("mphantom",r)}}),c({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=ie(p(e.body),t),n=new N.MathNode("mphantom",r),s=new N.MathNode("mpadded",[n]);return s.setAttribute("height","0px"),s.setAttribute("depth","0px"),s}}),c({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=ie(p(e.body),t),n=new N.MathNode("mphantom",r),s=new N.MathNode("mpadded",[n]);return s.setAttribute("width","0px"),s}}),c({type:"pmb",names:["\\pmb"],props:{numArgs:1,allowedInText:!0},handler:({parser:e},t)=>({type:"pmb",mode:e.mode,body:p(t[0])}),mathmlBuilder(e,t){const r=ie(e.body,t),n=A(r);return n.setAttribute("style","font-weight:bold"),n}});const Rt=(e,t)=>{const r=t.withLevel(st),n=new N.MathNode("mpadded",[ce(e.body,r)]),s=ve(e.dy,t);return n.setAttribute("voffset",s.number+s.unit),s.number>0?n.style.padding=s.number+s.unit+" 0 0 0":n.style.padding="0 0 "+Math.abs(s.number)+s.unit+" 0",n};c({type:"raise",names:["\\raise","\\lower"],props:{numArgs:2,argTypes:["size","primitive"],primitive:!0},handler({parser:e,funcName:t},r){const n=Oe(r[0],"size").value;"\\lower"===t&&(n.number*=-1);const s=r[1];return{type:"raise",mode:e.mode,dy:n,body:s}},mathmlBuilder:Rt}),c({type:"raise",names:["\\raisebox"],props:{numArgs:2,argTypes:["size","hbox"],allowedInText:!0},handler({parser:e,funcName:t},r){const n=Oe(r[0],"size").value,s=r[1];return{type:"raise",mode:e.mode,dy:n,body:s}},mathmlBuilder:Rt}),c({type:"ref",names:["\\ref","\\eqref"],props:{numArgs:1,argTypes:["raw"]},handler:({parser:e,funcName:t},r)=>({type:"ref",mode:e.mode,funcName:t,string:r[0].string.replace(Tt,"")}),mathmlBuilder(e,t){const r="\\ref"===e.funcName?["tml-ref"]:["tml-ref","tml-eqref"],n=new N.MathNode("mtext",[new N.TextNode("")],r);return n.setAttribute("href","#"+e.string),n}}),c({type:"reflect",names:["\\reflectbox"],props:{numArgs:1,argTypes:["hbox"],allowedInText:!0},handler:({parser:e},t)=>({type:"reflect",mode:e.mode,body:t[0]}),mathmlBuilder(e,t){const r=ce(e.body,t);return r.style.transform="scaleX(-1)",r}}),c({type:"internal",names:["\\relax"],props:{numArgs:0,allowedInText:!0},handler:({parser:e})=>({type:"internal",mode:e.mode})}),c({type:"rule",names:["\\rule"],props:{numArgs:2,numOptionalArgs:1,argTypes:["size","size","size"]},handler({parser:e},t,r){const n=r[0],s=Oe(t[0],"size"),o=Oe(t[1],"size");return{type:"rule",mode:e.mode,shift:n&&Oe(n,"size").value,width:s.value,height:o.value}},mathmlBuilder(e,t){const r=ve(e.width,t),n=ve(e.height,t),s=e.shift?ve(e.shift,t):{number:0,unit:"em"},o=t.color&&t.getColor()||"black",a=new N.MathNode("mspace");if(r.number>0&&n.number>0&&a.setAttribute("mathbackground",o),a.setAttribute("width",r.number+r.unit),a.setAttribute("height",n.number+n.unit),0===s.number)return a;const i=new N.MathNode("mpadded",[a]);return s.number>=0?i.setAttribute("height","+"+s.number+s.unit):(i.setAttribute("height",s.number+s.unit),i.setAttribute("depth","+"+-s.number+s.unit)),i.setAttribute("voffset",s.number+s.unit),i}});const jt={"\\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};c({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},n)=>{r.settings.strict&&"math"===r.mode&&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(jt[e.funcName]),n=ie(e.body,r),s=A(n),o=(jt[e.funcName]/t.fontSize).toFixed(4);return s.setAttribute("mathsize",o+"em"),s}}),c({type:"smash",names:["\\smash"],props:{numArgs:1,numOptionalArgs:1,allowedInText:!0},handler:({parser:e},t,r)=>{let n=!1,s=!1;const o=r[0]&&Oe(r[0],"ordgroup");if(o){let e="";for(let t=0;t{const r=new N.MathNode("mpadded",[ce(e.body,t)]);return e.smashHeight&&r.setAttribute("height","0px"),e.smashDepth&&r.setAttribute("depth","0px"),r}}),c({type:"sqrt",names:["\\sqrt"],props:{numArgs:1,numOptionalArgs:1},handler({parser:e},t,r){const n=r[0],s=t[0];return{type:"sqrt",mode:e.mode,body:s,index:n}},mathmlBuilder(e,t){const{body:r,index:n}=e;return n?new N.MathNode("mroot",[ce(r,t),ce(n,t.incrementLevel())]):new N.MathNode("msqrt",[ce(r,t)])}});const Ut={display:0,text:1,script:2,scriptscript:3},Ht={display:["0","true"],text:["0","false"],script:["1","false"],scriptscript:["2","false"]};c({type:"styling",names:["\\displaystyle","\\textstyle","\\scriptstyle","\\scriptscriptstyle"],props:{numArgs:0,allowedInText:!0,primitive:!0},handler({breakOnTokenText:e,funcName:t,parser:r},n){const s=r.parseExpression(!0,e,!0),o=t.slice(1,t.length-5);return{type:"styling",mode:r.mode,scriptLevel:o,body:s}},mathmlBuilder(e,t){const r=t.withLevel(Ut[e.scriptLevel]),n=ie(e.body,r),s=A(n),o=Ht[e.scriptLevel];return s.setAttribute("scriptlevel",o[0]),s.setAttribute("displaystyle",o[1]),s}});const Vt=/^m(over|under|underover)$/;m({type:"supsub",mathmlBuilder(e,t){let r,n,s=!1,o=!1,a=!1,i=!1;e.base&&"horizBrace"===e.base.type&&(n=!!e.sup,n===e.base.isOver&&(s=!0,r=e.base.isOver)),!e.base||e.base.stack||"op"!==e.base.type&&"operatorname"!==e.base.type||(e.base.parentIsSupSub=!0,o=!e.base.symbol,a=o&&!e.isFollowedByDelimiter,i=e.base.needsLeadingSpace);const l=e.base&&e.base.stack?[ce(e.base.body[0],t)]:[ce(e.base,t)],c=t.inSubOrSup();if(e.sub&&l.push(ce(e.sub,c)),e.sup){const t=ce(e.sup,c),r="mrow"===t.type?t.children[0]:t;"mo"===r.type&&r.classes.includes("tml-prime")&&e.base&&e.base.text&&"f"===e.base.text&&r.classes.push("prime-pad"),l.push(t)}let m;if(s)m=r?"mover":"munder";else if(e.sub)if(e.sup){const r=e.base;m=r&&("op"===r.type&&r.limits||"multiscript"===r.type)&&(t.level===nt||r.alwaysHandleSupSub)||r&&"operatorname"===r.type&&r.alwaysHandleSupSub&&(t.level===nt||r.limits)?"munderover":"msubsup"}else{const r=e.base;m=r&&"op"===r.type&&r.limits&&(t.level===nt||r.alwaysHandleSupSub)||r&&"operatorname"===r.type&&r.alwaysHandleSupSub&&(r.limits||t.level===nt)?"munder":"msub"}else{const r=e.base;m=r&&"op"===r.type&&r.limits&&(t.level===nt||r.alwaysHandleSupSub)||r&&"operatorname"===r.type&&r.alwaysHandleSupSub&&(r.limits||t.level===nt)?"mover":"msup"}let u=new N.MathNode(m,l);if(o){const e=new N.MathNode("mo",[re("⁡","text")]);if(i){const t=new N.MathNode("mspace");t.setAttribute("width","0.1667em"),u=N.newDocumentFragment([t,u,e])}else u=N.newDocumentFragment([u,e]);if(a){const e=new N.MathNode("mspace");e.setAttribute("width","0.1667em"),u.children.push(e)}}else Vt.test(m)&&(u=new N.MathNode("mrow",[u]));return u}});const _t=["\\shortmid","\\nshortmid","\\shortparallel","\\nshortparallel","\\smallsetminus"],Wt=["\\Rsh","\\Lsh","\\restriction"];m({type:"atom",mathmlBuilder(e,t){const r=new N.MathNode("mo",[re(e.text,e.mode)]);return"punct"===e.family?r.setAttribute("separator","true"):"open"===e.family||"close"===e.family?"open"===e.family?(r.setAttribute("form","prefix"),r.setAttribute("stretchy","false")):"close"===e.family&&(r.setAttribute("form","postfix"),r.setAttribute("stretchy","false")):"\\mid"===e.text?(r.setAttribute("lspace","0.22em"),r.setAttribute("rspace","0.22em"),r.setAttribute("stretchy","false")):"rel"===e.family&&(e=>{if(1===e.length){const t=e.codePointAt(0);return 8591-1||e.indexOf("harpoon")>-1||Wt.includes(e)})(e.text)?r.setAttribute("stretchy","false"):_t.includes(e.text)?r.setAttribute("mathsize","70%"):":"===e.text&&(r.attributes.lspace="0.2222em",r.attributes.rspace="0.2222em"),r}});const Xt={mathbf:"bold",mathrm:"normal",textit:"italic",mathit:"italic",mathnormal:"italic",mathbb:"double-struck",mathcal:"script",mathfrak:"fraktur",mathscr:"script",mathsf:"sans-serif",mathtt:"monospace"},Zt=function(e,t){if("texttt"===t.fontFamily)return"monospace";if("textsc"===t.fontFamily)return"normal";if("textsf"===t.fontFamily)return"textit"===t.fontShape&&"textbf"===t.fontWeight?"sans-serif-bold-italic":"textit"===t.fontShape?"sans-serif-italic":"textbf"===t.fontWeight?"sans-serif-bold":"sans-serif";if("textit"===t.fontShape&&"textbf"===t.fontWeight)return"bold-italic";if("textit"===t.fontShape)return"italic";if("textbf"===t.fontWeight)return"bold";const r=t.font;if(!r||"mathnormal"===r)return null;const n=e.mode;switch(r){case"mathit":case"greekItalic":return"italic";case"mathrm":{const t=e.text.codePointAt(0);return 9390,bold:e=>119743,italic:e=>119795,"bold-italic":e=>119847,script:e=>Yt[e]||119899,"script-bold":e=>119951,fraktur:e=>Kt[e]||120003,"fraktur-bold":e=>120107,"double-struck":e=>Jt[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=>"h"===e?8358:119789,"bold-italic":e=>119841,script:e=>Yt[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=>Qt[e]||-51,italic:e=>0,"bold-italic":e=>er[e]||58,script:e=>0,"script-bold":e=>0,fraktur:e=>0,"fraktur-bold":e=>0,"double-struck":e=>0,"sans-serif":e=>tr[e]||116,"sans-serif-bold":e=>tr[e]||116,"sans-serif-italic":e=>0,"sans-serif-bold-italic":e=>rr[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}}),sr=(e,t)=>{const r=e.codePointAt(0),n=64{const n=new N.MathNode(r,[e]),s=new N.MathNode("mstyle",[n]);return s.style["font-style"]="italic",s.style["font-family"]="Cambria, 'Times New Roman', serif","bold-italic"===t&&(s.style["font-weight"]="bold"),s})(s,o,t);"normal"!==o&&(s.text=s.text.split("").map((e=>sr(e,o))).join("")),a=new N.MathNode(t,[s])}else if("text"===e.mode)"normal"!==o&&(s.text=sr(s.text,o)),a=new N.MathNode("mtext",[s]);else if(lr.has(e.text))a=new N.MathNode("mo",[s]),a.classes.push("tml-prime");else{const e=s.text;"italic"!==o&&(s.text=sr(s.text,o)),a=new N.MathNode("mi",[s]),s.text===e&&ir.test(e)&&a.setAttribute("mathvariant","italic")}return a}});const cr={"\\nobreak":"nobreak","\\allowbreak":"allowbreak"},mr={" ":{},"\\ ":{},"~":{className:"nobreak"},"\\space":{},"\\nobreakspace":{className:"nobreak"}};m({type:"spacing",mathmlBuilder(t,r){let n;if(Object.prototype.hasOwnProperty.call(mr,t.text))n=new N.MathNode("mtext",[new N.TextNode(" ")]);else{if(!Object.prototype.hasOwnProperty.call(cr,t.text))throw new e(`Unknown type of space "${t.text}"`);n=new N.MathNode("mo"),"\\nobreak"===t.text&&n.setAttribute("linebreak","nobreak")}return n}}),m({type:"tag"});const ur={"\\text":void 0,"\\textrm":"textrm","\\textsf":"textsf","\\texttt":"texttt","\\textnormal":"textrm","\\textsc":"textsc"},pr={"\\textbf":"textbf","\\textmd":"textmd"},dr={"\\textit":"textit","\\textup":"textup"};c({type:"text",names:["\\text","\\textrm","\\textsf","\\texttt","\\textnormal","\\textsc","\\textbf","\\textmd","\\textit","\\textup"],props:{numArgs:1,argTypes:["text"],allowedInArgument:!0,allowedInText:!0},handler({parser:e,funcName:t},r){const n=r[0];return{type:"text",mode:e.mode,body:p(n),font:t}},mathmlBuilder(e,t){const r=((e,t)=>{const r=e.font;return r?ur[r]?t.withTextFontFamily(ur[r]):pr[r]?t.withTextFontWeight(pr[r]):t.withTextFontShape(dr[r]):t})(e,t),n=le(e.body,r);return ne(n)}}),c({type:"verb",names:["\\verb"],props:{numArgs:0,allowedInText:!0},handler(t,r,n){throw new e("\\verb ended by end of line instead of matching delimiter")},mathmlBuilder(e,t){const r=new N.TextNode(hr(e)),n=new N.MathNode("mtext",[r]);return n.setAttribute("mathvariant","monospace"),n}});const hr=e=>e.body.replace(/ /g,e.star?"␣":" "),gr=i;class fr{constructor(e,t,r){this.lexer=e,this.start=t,this.end=r}static range(e,t){return t?e&&e.loc&&t.loc&&e.loc.lexer===t.loc.lexer?new fr(e.loc.lexer,e.loc.start,t.loc.end):null:e&&e.loc}}class br{constructor(e,t){this.text=e,this.loc=t}range(e,t){return new br(t,fr.range(this,e))}}const yr="[ \r\n\t]",xr=`(\\\\[a-zA-Z@]+)${yr}*`,wr="[̀-ͯ]",kr=new RegExp(`${wr}+$`),vr=`(${yr}+)|\\\\(\n|[ \r\t]+\n?)[ \r\t]*|([!-\\[\\]-‧‪-퟿豈-￿]${wr}*|[\ud800-\udbff][\udc00-\udfff]${wr}*|\\\\verb\\*([^]).*?\\4|\\\\verb([^*a-zA-Z]).*?\\5|${xr}|\\\\[^\ud800-\udfff])`;class Ar{constructor(e,t){this.input=e,this.settings=t,this.tokenRegex=new RegExp(vr,"g"),this.catcodes={"%":14,"~":13}}setCatcode(e,t){this.catcodes[e]=t}lex(){const t=this.input,r=this.tokenRegex.lastIndex;if(r===t.length)return new br("EOF",new fr(this,r,r));const n=this.tokenRegex.exec(t);if(null===n||n.index!==r)throw new e(`Unexpected character: '${t[r]}'`,new br(t[r],new fr(this,r,r+1)));const s=n[6]||n[3]||(n[2]?"\\ ":" ");if(14===this.catcodes[s]){const r=t.indexOf("\n",this.tokenRegex.lastIndex);if(-1===r){if(this.tokenRegex.lastIndex=t.length,this.settings.strict)throw new e("% comment has no terminating newline; LaTeX would fail because of commenting the end of math mode")}else this.tokenRegex.lastIndex=r+1;return this.lex()}return new br(s,new fr(this,r,this.tokenRegex.lastIndex))}}class Nr{constructor(e={},t={}){this.current=t,this.builtins=e,this.undefStack=[]}beginGroup(){this.undefStack.push({})}endGroup(){if(0===this.undefStack.length)throw new e("Unbalanced namespace destruction: attempt to pop global namespace; please report this as a bug");const t=this.undefStack.pop();for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&(void 0===t[e]?delete this.current[e]:this.current[e]=t[e])}has(e){return Object.prototype.hasOwnProperty.call(this.current,e)||Object.prototype.hasOwnProperty.call(this.builtins,e)}get(e){return Object.prototype.hasOwnProperty.call(this.current,e)?this.current[e]:this.builtins[e]}set(e,t,r=!1){if(r){for(let t=0;t0&&(this.undefStack[this.undefStack.length-1][e]=t)}else{const t=this.undefStack[this.undefStack.length-1];t&&!Object.prototype.hasOwnProperty.call(t,e)&&(t[e]=this.current[e])}this.current[e]=t}}const Tr=Dt;Pt("\\noexpand",(function(e){const t=e.popToken();return e.isExpandable(t.text)&&(t.noexpand=!0,t.treatAsRelax=!0),{tokens:[t],numArgs:0}})),Pt("\\expandafter",(function(e){const t=e.popToken();return e.expandOnce(!0),{tokens:[t],numArgs:0}})),Pt("\\@firstoftwo",(function(e){return{tokens:e.consumeArgs(2)[0],numArgs:0}})),Pt("\\@secondoftwo",(function(e){return{tokens:e.consumeArgs(2)[1],numArgs:0}})),Pt("\\@ifnextchar",(function(e){const t=e.consumeArgs(3);e.consumeSpaces();const r=e.future();return 1===t[0].length&&t[0][0].text===r.text?{tokens:t[1],numArgs:0}:{tokens:t[2],numArgs:0}})),Pt("\\@ifstar","\\@ifnextchar *{\\@firstoftwo{#1}}"),Pt("\\TextOrMath",(function(e){const t=e.consumeArgs(2);return"text"===e.mode?{tokens:t[0],numArgs:0}:{tokens:t[1],numArgs:0}}));const qr={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},Sr=e=>{const t=e.future().text;return"EOF"===t?[null,""]:[qr[t.charAt(0)],t]},Or=(e,t,r)=>{for(let n=1;n=0;e--){const s=t[e].loc.start;s>n&&(r+=" ",n=s),r+=t[e].text,n+=t[e].text.length}return r}Pt("\\char",(function(t){let r,n=t.popToken(),s="";if("'"===n.text)r=8,n=t.popToken();else if('"'===n.text)r=16,n=t.popToken();else if("`"===n.text)if(n=t.popToken(),"\\"===n.text[0])s=n.text.charCodeAt(1);else{if("EOF"===n.text)throw new e("\\char` missing argument");s=n.text.charCodeAt(0)}else r=10;if(r){let o,a=n.text;if(s=qr[a.charAt(0)],null==s||s>=r)throw new e(`Invalid base-${r} digit ${n.text}`);for(s=Or(s,a,r),[o,a]=Sr(t);null!=o&&o":"\\dotsb","-":"\\dotsb","*":"\\dotsb",":":"\\dotsb","\\DOTSB":"\\dotsb","\\coprod":"\\dotsb","\\bigvee":"\\dotsb","\\bigwedge":"\\dotsb","\\biguplus":"\\dotsb","\\bigcap":"\\dotsb","\\bigcup":"\\dotsb","\\prod":"\\dotsb","\\sum":"\\dotsb","\\bigotimes":"\\dotsb","\\bigoplus":"\\dotsb","\\bigodot":"\\dotsb","\\bigsqcap":"\\dotsb","\\bigsqcup":"\\dotsb","\\bigtimes":"\\dotsb","\\And":"\\dotsb","\\longrightarrow":"\\dotsb","\\Longrightarrow":"\\dotsb","\\longleftarrow":"\\dotsb","\\Longleftarrow":"\\dotsb","\\longleftrightarrow":"\\dotsb","\\Longleftrightarrow":"\\dotsb","\\mapsto":"\\dotsb","\\longmapsto":"\\dotsb","\\hookrightarrow":"\\dotsb","\\doteq":"\\dotsb","\\mathbin":"\\dotsb","\\mathrel":"\\dotsb","\\relbar":"\\dotsb","\\Relbar":"\\dotsb","\\xrightarrow":"\\dotsb","\\xleftarrow":"\\dotsb","\\DOTSI":"\\dotsi","\\int":"\\dotsi","\\oint":"\\dotsi","\\iint":"\\dotsi","\\iiint":"\\dotsi","\\iiiint":"\\dotsi","\\idotsint":"\\dotsi","\\DOTSX":"\\dotsx"};Pt("\\dots",(function(e){let t="\\dotso";const r=e.expandAfterFuture().text;return r in Mr?t=Mr[r]:("\\not"===r.slice(0,4)||r in E.math&&["bin","rel"].includes(E.math[r].group))&&(t="\\dotsb"),t}));const Cr={")":!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};Pt("\\dotso",(function(e){return e.future().text in Cr?"\\ldots\\,":"\\ldots"})),Pt("\\dotsc",(function(e){const t=e.future().text;return t in Cr&&","!==t?"\\ldots\\,":"\\ldots"})),Pt("\\cdots",(function(e){return e.future().text in Cr?"\\@cdots\\,":"\\@cdots"})),Pt("\\dotsb","\\cdots"),Pt("\\dotsm","\\cdots"),Pt("\\dotsi","\\!\\cdots"),Pt("\\idotsint","\\dotsi"),Pt("\\dotsx","\\ldots\\,"),Pt("\\DOTSI","\\relax"),Pt("\\DOTSB","\\relax"),Pt("\\DOTSX","\\relax"),Pt("\\tmspace","\\TextOrMath{\\kern#1#3}{\\mskip#1#2}\\relax"),Pt("\\,","{\\tmspace+{3mu}{.1667em}}"),Pt("\\thinspace","\\,"),Pt("\\>","\\mskip{4mu}"),Pt("\\:","{\\tmspace+{4mu}{.2222em}}"),Pt("\\medspace","\\:"),Pt("\\;","{\\tmspace+{5mu}{.2777em}}"),Pt("\\thickspace","\\;"),Pt("\\!","{\\tmspace-{3mu}{.1667em}}"),Pt("\\negthinspace","\\!"),Pt("\\negmedspace","{\\tmspace-{4mu}{.2222em}}"),Pt("\\negthickspace","{\\tmspace-{5mu}{.277em}}"),Pt("\\enspace","\\kern.5em "),Pt("\\enskip","\\hskip.5em\\relax"),Pt("\\quad","\\hskip1em\\relax"),Pt("\\qquad","\\hskip2em\\relax"),Pt("\\AA","\\TextOrMath{\\Angstrom}{\\mathring{A}}\\relax"),Pt("\\tag","\\@ifstar\\tag@literal\\tag@paren"),Pt("\\tag@paren","\\tag@literal{({#1})}"),Pt("\\tag@literal",(t=>{if(t.macros.get("\\df@tag"))throw new e("Multiple \\tag");return"\\def\\df@tag{\\text{#1}}"})),Pt("\\bmod","\\mathbin{\\text{mod}}"),Pt("\\pod","\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern8mu}{\\mkern8mu}{\\mkern8mu}(#1)"),Pt("\\pmod","\\pod{{\\rm mod}\\mkern6mu#1}"),Pt("\\mod","\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern12mu}{\\mkern12mu}{\\mkern12mu}{\\rm mod}\\,\\,#1"),Pt("\\newline","\\\\\\relax"),Pt("\\TeX","\\textrm{T}\\kern-.1667em\\raisebox{-.5ex}{E}\\kern-.125em\\textrm{X}"),Pt("\\LaTeX","\\textrm{L}\\kern-.35em\\raisebox{0.2em}{\\scriptstyle A}\\kern-.15em\\TeX"),Pt("\\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}}"),Pt("\\hspace","\\@ifstar\\@hspacer\\@hspace"),Pt("\\@hspace","\\hskip #1\\relax"),Pt("\\@hspacer","\\rule{0pt}{0pt}\\hskip #1\\relax"),Pt("\\colon",'\\mathpunct{\\char"3a}'),Pt("\\prescript","\\pres@cript{_{#1}^{#2}}{}{#3}"),Pt("\\ordinarycolon",'\\char"3a'),Pt("\\vcentcolon","\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}}"),Pt("\\coloneq",'\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}\\char"2212}'),Pt("\\Coloneq",'\\mathrel{\\char"2237\\char"2212}'),Pt("\\Eqqcolon",'\\mathrel{\\char"3d\\char"2237}'),Pt("\\Eqcolon",'\\mathrel{\\char"2212\\char"2237}'),Pt("\\colonapprox",'\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}\\char"2248}'),Pt("\\Colonapprox",'\\mathrel{\\char"2237\\char"2248}'),Pt("\\colonsim",'\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}\\char"223c}'),Pt("\\Colonsim",'\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}\\char"223c}'),Pt("\\ratio","\\vcentcolon"),Pt("\\coloncolon","\\dblcolon"),Pt("\\colonequals","\\coloneqq"),Pt("\\coloncolonequals","\\Coloneqq"),Pt("\\equalscolon","\\eqqcolon"),Pt("\\equalscoloncolon","\\Eqqcolon"),Pt("\\colonminus","\\coloneq"),Pt("\\coloncolonminus","\\Coloneq"),Pt("\\minuscolon","\\eqcolon"),Pt("\\minuscoloncolon","\\Eqcolon"),Pt("\\coloncolonapprox","\\Colonapprox"),Pt("\\coloncolonsim","\\Colonsim"),Pt("\\notni","\\mathrel{\\char`∌}"),Pt("\\limsup","\\DOTSB\\operatorname*{lim\\,sup}"),Pt("\\liminf","\\DOTSB\\operatorname*{lim\\,inf}"),Pt("\\injlim","\\DOTSB\\operatorname*{inj\\,lim}"),Pt("\\projlim","\\DOTSB\\operatorname*{proj\\,lim}"),Pt("\\varlimsup","\\DOTSB\\operatorname*{\\overline{\\text{lim}}}"),Pt("\\varliminf","\\DOTSB\\operatorname*{\\underline{\\text{lim}}}"),Pt("\\varinjlim","\\DOTSB\\operatorname*{\\underrightarrow{\\text{lim}}}"),Pt("\\varprojlim","\\DOTSB\\operatorname*{\\underleftarrow{\\text{lim}}}"),Pt("\\centerdot","{\\medspace\\rule{0.167em}{0.189em}\\medspace}"),Pt("\\argmin","\\DOTSB\\operatorname*{arg\\,min}"),Pt("\\argmax","\\DOTSB\\operatorname*{arg\\,max}"),Pt("\\plim","\\DOTSB\\operatorname*{plim}"),Pt("\\leftmodels","\\mathop{\\reflectbox{$\\models$}}"),Pt("\\bra","\\mathinner{\\langle{#1}|}"),Pt("\\ket","\\mathinner{|{#1}\\rangle}"),Pt("\\braket","\\mathinner{\\langle{#1}\\rangle}"),Pt("\\Bra","\\left\\langle#1\\right|"),Pt("\\Ket","\\left|#1\\right\\rangle");const zr=(e,t)=>{const r=`}\\,\\middle${"|"===t[0]?"\\vert":"\\Vert"}\\,{`;return e.slice(0,t.index)+r+e.slice(t.index+t[0].length)};Pt("\\Braket",(function(e){let t=Br(e);const r=/\|\||\||\\\|/g;let n;for(;null!==(n=r.exec(t));)t=zr(t,n);return"\\left\\langle{"+t+"}\\right\\rangle"})),Pt("\\Set",(function(e){let t=Br(e);const r=/\|\||\||\\\|/.exec(t);return r&&(t=zr(t,r)),"\\left\\{\\:{"+t+"}\\:\\right\\}"})),Pt("\\set",(function(e){return"\\{{"+Br(e).replace(/\|/,"}\\mid{")+"}\\}"})),Pt("\\angln","{\\angl n}"),Pt("\\odv","\\@ifstar\\odv@next\\odv@numerator"),Pt("\\odv@numerator","\\frac{\\mathrm{d}#1}{\\mathrm{d}#2}"),Pt("\\odv@next","\\frac{\\mathrm{d}}{\\mathrm{d}#2}#1"),Pt("\\pdv","\\@ifstar\\pdv@next\\pdv@numerator");const Er=e=>{const t=e[0][0].text,r=(e=>{let t="";for(let r=e.length-1;r>-1;r--)t+=e[r].text;return t})(e[1]).split(","),n=String(r.length),s="1"===n?"\\partial":`\\partial^${n}`;let o="";return r.map((e=>{o+="\\partial "+e.trim()+"\\,"})),[t,s,o.replace(/\\,$/,"")]};Pt("\\pdv@numerator",(function(e){const[t,r,n]=Er(e.consumeArgs(2));return`\\frac{${r} ${t}}{${n}}`})),Pt("\\pdv@next",(function(e){const[t,r,n]=Er(e.consumeArgs(2));return`\\frac{${r}}{${n}} ${t}`})),Pt("\\upalpha","\\up@greek{\\alpha}"),Pt("\\upbeta","\\up@greek{\\beta}"),Pt("\\upgamma","\\up@greek{\\gamma}"),Pt("\\updelta","\\up@greek{\\delta}"),Pt("\\upepsilon","\\up@greek{\\epsilon}"),Pt("\\upzeta","\\up@greek{\\zeta}"),Pt("\\upeta","\\up@greek{\\eta}"),Pt("\\uptheta","\\up@greek{\\theta}"),Pt("\\upiota","\\up@greek{\\iota}"),Pt("\\upkappa","\\up@greek{\\kappa}"),Pt("\\uplambda","\\up@greek{\\lambda}"),Pt("\\upmu","\\up@greek{\\mu}"),Pt("\\upnu","\\up@greek{\\nu}"),Pt("\\upxi","\\up@greek{\\xi}"),Pt("\\upomicron","\\up@greek{\\omicron}"),Pt("\\uppi","\\up@greek{\\pi}"),Pt("\\upalpha","\\up@greek{\\alpha}"),Pt("\\uprho","\\up@greek{\\rho}"),Pt("\\upsigma","\\up@greek{\\sigma}"),Pt("\\uptau","\\up@greek{\\tau}"),Pt("\\upupsilon","\\up@greek{\\upsilon}"),Pt("\\upphi","\\up@greek{\\phi}"),Pt("\\upchi","\\up@greek{\\chi}"),Pt("\\uppsi","\\up@greek{\\psi}"),Pt("\\upomega","\\up@greek{\\omega}"),Pt("\\invamp",'\\mathbin{\\char"214b}'),Pt("\\parr",'\\mathbin{\\char"214b}'),Pt("\\with",'\\mathbin{\\char"26}'),Pt("\\multimapinv",'\\mathrel{\\char"27dc}'),Pt("\\multimapboth",'\\mathrel{\\char"29df}'),Pt("\\scoh",'{\\mkern5mu\\char"2322\\mkern5mu}'),Pt("\\sincoh",'{\\mkern5mu\\char"2323\\mkern5mu}'),Pt("\\coh",'{\\mkern5mu\\rule{}{0.7em}\\mathrlap{\\smash{\\raise2mu{\\char"2322}}}\n{\\smash{\\lower4mu{\\char"2323}}}\\mkern5mu}'),Pt("\\incoh",'{\\mkern5mu\\rule{}{0.7em}\\mathrlap{\\smash{\\raise2mu{\\char"2323}}}\n{\\smash{\\lower4mu{\\char"2322}}}\\mkern5mu}'),Pt("\\standardstate","\\text{\\tiny\\char`⦵}");const Ir={"^":!0,_:!0,"\\limits":!0,"\\nolimits":!0};class $r{constructor(e,t,r){this.settings=t,this.expansionCount=0,this.feed(e),this.macros=new Nr(Tr,t.macros),this.mode=r,this.stack=[]}feed(e){this.lexer=new Ar(e,this.settings)}switchMode(e){this.mode=e}beginGroup(){this.macros.beginGroup()}endGroup(){this.macros.endGroup()}future(){return 0===this.stack.length&&this.pushToken(this.lexer.lex()),this.stack[this.stack.length-1]}popToken(){return this.future(),this.stack.pop()}pushToken(e){this.stack.push(e)}pushTokens(e){this.stack.push(...e)}scanArgument(e){let t,r,n;if(e){if(this.consumeSpaces(),"["!==this.future().text)return null;t=this.popToken(),({tokens:n,end:r}=this.consumeArg(["]"]))}else({tokens:n,start:t,end:r}=this.consumeArg());return this.pushToken(new br("EOF",r.loc)),this.pushTokens(n),t.range(r,"")}consumeSpaces(){for(;;){if(" "!==this.future().text)break;this.stack.pop()}}consumeArg(t){const r=[],n=t&&t.length>0;n||this.consumeSpaces();const s=this.future();let o,a=0,i=0;do{if(o=this.popToken(),r.push(o),"{"===o.text)++a;else if("}"===o.text){if(--a,-1===a)throw new e("Extra }",o)}else if("EOF"===o.text)throw new e("Unexpected end of input in a macro argument, expected '"+(t&&n?t[i]:"}")+"'",o);if(t&&n)if((0===a||1===a&&"{"===t[i])&&o.text===t[i]){if(++i,i===t.length){r.splice(-i,i);break}}else i=0}while(0!==a||n);return"{"===s.text&&"}"===r[r.length-1].text&&(r.pop(),r.shift()),r.reverse(),{tokens:r,start:s,end:o}}consumeArgs(t,r){if(r){if(r.length!==t+1)throw new e("The length of delimiters doesn't match the number of args!");const n=r[0];for(let t=0;tthis.settings.maxExpand)throw new e("Too many expansions: infinite loop or need to increase maxExpand setting");let o=s.tokens;const a=this.consumeArgs(s.numArgs,s.delimiters);if(s.numArgs){o=o.slice();for(let t=o.length-1;t>=0;--t){let r=o[t];if("#"===r.text){if(0===t)throw new e("Incomplete placeholder at end of macro body",r);if(r=o[--t],"#"===r.text)o.splice(t+1,1);else{if(!/^[1-9]$/.test(r.text))throw new e("Not a valid argument number",r);o.splice(t,2,...a[+r.text-1])}}}}return this.pushTokens(o),o.length}expandAfterFuture(){return this.expandOnce(),this.future()}expandNextToken(){for(;;)if(!1===this.expandOnce()){const e=this.stack.pop();return e.treatAsRelax&&(e.text="\\relax"),e}throw new Error}expandMacro(e){return this.macros.has(e)?this.expandTokens([new br(e)]):void 0}expandTokens(e){const t=[],r=this.stack.length;for(this.pushTokens(e);this.stack.length>r;)if(!1===this.expandOnce(!0)){const e=this.stack.pop();e.treatAsRelax&&(e.noexpand=!1,e.treatAsRelax=!1),t.push(e)}return t}expandMacroAsText(e){const t=this.expandMacro(e);return t?t.map((e=>e.text)).join(""):t}_getExpansion(e){const t=this.macros.get(e);if(null==t)return t;if(1===e.length){const t=this.lexer.catcodes[e];if(null!=t&&13!==t)return}const r="function"==typeof t?t(this):t;if("string"==typeof r){let e=0;if(-1!==r.indexOf("#")){const t=r.replace(/##/g,"");for(;-1!==t.indexOf("#"+(e+1));)++e}const t=new Ar(r,this.settings),n=[];let s=t.lex();for(;"EOF"!==s.text;)n.push(s),s=t.lex();n.reverse();return{tokens:n,numArgs:e}}return r}isDefined(e){return this.macros.has(e)||Object.prototype.hasOwnProperty.call(gr,e)||Object.prototype.hasOwnProperty.call(E.math,e)||Object.prototype.hasOwnProperty.call(E.text,e)||Object.prototype.hasOwnProperty.call(Ir,e)}isExpandable(e){const t=this.macros.get(e);return null!=t?"string"==typeof t||"function"==typeof t||!t.unexpandable:Object.prototype.hasOwnProperty.call(gr,e)&&!gr[e].primitive}}const Lr=/^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/,Fr=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","ᵝ":"β","ᵞ":"γ","ᵟ":"δ","ᵠ":"ϕ","ᵡ":"χ","ᶿ":"θ"}),Gr=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 Dr={"́":{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"}},Pr={"á":"á","à":"à","ä":"ä","ǟ":"ǟ","ã":"ã","ā":"ā","ă":"ă","ắ":"ắ","ằ":"ằ","ẵ":"ẵ","ǎ":"ǎ","â":"â","ấ":"ấ","ầ":"ầ","ẫ":"ẫ","ȧ":"ȧ","ǡ":"ǡ","å":"å","ǻ":"ǻ","ḃ":"ḃ","ć":"ć","č":"č","ĉ":"ĉ","ċ":"ċ","ď":"ď","ḋ":"ḋ","é":"é","è":"è","ë":"ë","ẽ":"ẽ","ē":"ē","ḗ":"ḗ","ḕ":"ḕ","ĕ":"ĕ","ě":"ě","ê":"ê","ế":"ế","ề":"ề","ễ":"ễ","ė":"ė","ḟ":"ḟ","ǵ":"ǵ","ḡ":"ḡ","ğ":"ğ","ǧ":"ǧ","ĝ":"ĝ","ġ":"ġ","ḧ":"ḧ","ȟ":"ȟ","ĥ":"ĥ","ḣ":"ḣ","í":"í","ì":"ì","ï":"ï","ḯ":"ḯ","ĩ":"ĩ","ī":"ī","ĭ":"ĭ","ǐ":"ǐ","î":"î","ǰ":"ǰ","ĵ":"ĵ","ḱ":"ḱ","ǩ":"ǩ","ĺ":"ĺ","ľ":"ľ","ḿ":"ḿ","ṁ":"ṁ","ń":"ń","ǹ":"ǹ","ñ":"ñ","ň":"ň","ṅ":"ṅ","ó":"ó","ò":"ò","ö":"ö","ȫ":"ȫ","õ":"õ","ṍ":"ṍ","ṏ":"ṏ","ȭ":"ȭ","ō":"ō","ṓ":"ṓ","ṑ":"ṑ","ŏ":"ŏ","ǒ":"ǒ","ô":"ô","ố":"ố","ồ":"ồ","ỗ":"ỗ","ȯ":"ȯ","ȱ":"ȱ","ő":"ő","ṕ":"ṕ","ṗ":"ṗ","ŕ":"ŕ","ř":"ř","ṙ":"ṙ","ś":"ś","ṥ":"ṥ","š":"š","ṧ":"ṧ","ŝ":"ŝ","ṡ":"ṡ","ẗ":"ẗ","ť":"ť","ṫ":"ṫ","ú":"ú","ù":"ù","ü":"ü","ǘ":"ǘ","ǜ":"ǜ","ǖ":"ǖ","ǚ":"ǚ","ũ":"ũ","ṹ":"ṹ","ū":"ū","ṻ":"ṻ","ŭ":"ŭ","ǔ":"ǔ","û":"û","ů":"ů","ű":"ű","ṽ":"ṽ","ẃ":"ẃ","ẁ":"ẁ","ẅ":"ẅ","ŵ":"ŵ","ẇ":"ẇ","ẘ":"ẘ","ẍ":"ẍ","ẋ":"ẋ","ý":"ý","ỳ":"ỳ","ÿ":"ÿ","ỹ":"ỹ","ȳ":"ȳ","ŷ":"ŷ","ẏ":"ẏ","ẙ":"ẙ","ź":"ź","ž":"ž","ẑ":"ẑ","ż":"ż","Á":"Á","À":"À","Ä":"Ä","Ǟ":"Ǟ","Ã":"Ã","Ā":"Ā","Ă":"Ă","Ắ":"Ắ","Ằ":"Ằ","Ẵ":"Ẵ","Ǎ":"Ǎ","Â":"Â","Ấ":"Ấ","Ầ":"Ầ","Ẫ":"Ẫ","Ȧ":"Ȧ","Ǡ":"Ǡ","Å":"Å","Ǻ":"Ǻ","Ḃ":"Ḃ","Ć":"Ć","Č":"Č","Ĉ":"Ĉ","Ċ":"Ċ","Ď":"Ď","Ḋ":"Ḋ","É":"É","È":"È","Ë":"Ë","Ẽ":"Ẽ","Ē":"Ē","Ḗ":"Ḗ","Ḕ":"Ḕ","Ĕ":"Ĕ","Ě":"Ě","Ê":"Ê","Ế":"Ế","Ề":"Ề","Ễ":"Ễ","Ė":"Ė","Ḟ":"Ḟ","Ǵ":"Ǵ","Ḡ":"Ḡ","Ğ":"Ğ","Ǧ":"Ǧ","Ĝ":"Ĝ","Ġ":"Ġ","Ḧ":"Ḧ","Ȟ":"Ȟ","Ĥ":"Ĥ","Ḣ":"Ḣ","Í":"Í","Ì":"Ì","Ï":"Ï","Ḯ":"Ḯ","Ĩ":"Ĩ","Ī":"Ī","Ĭ":"Ĭ","Ǐ":"Ǐ","Î":"Î","İ":"İ","Ĵ":"Ĵ","Ḱ":"Ḱ","Ǩ":"Ǩ","Ĺ":"Ĺ","Ľ":"Ľ","Ḿ":"Ḿ","Ṁ":"Ṁ","Ń":"Ń","Ǹ":"Ǹ","Ñ":"Ñ","Ň":"Ň","Ṅ":"Ṅ","Ó":"Ó","Ò":"Ò","Ö":"Ö","Ȫ":"Ȫ","Õ":"Õ","Ṍ":"Ṍ","Ṏ":"Ṏ","Ȭ":"Ȭ","Ō":"Ō","Ṓ":"Ṓ","Ṑ":"Ṑ","Ŏ":"Ŏ","Ǒ":"Ǒ","Ô":"Ô","Ố":"Ố","Ồ":"Ồ","Ỗ":"Ỗ","Ȯ":"Ȯ","Ȱ":"Ȱ","Ő":"Ő","Ṕ":"Ṕ","Ṗ":"Ṗ","Ŕ":"Ŕ","Ř":"Ř","Ṙ":"Ṙ","Ś":"Ś","Ṥ":"Ṥ","Š":"Š","Ṧ":"Ṧ","Ŝ":"Ŝ","Ṡ":"Ṡ","Ť":"Ť","Ṫ":"Ṫ","Ú":"Ú","Ù":"Ù","Ü":"Ü","Ǘ":"Ǘ","Ǜ":"Ǜ","Ǖ":"Ǖ","Ǚ":"Ǚ","Ũ":"Ũ","Ṹ":"Ṹ","Ū":"Ū","Ṻ":"Ṻ","Ŭ":"Ŭ","Ǔ":"Ǔ","Û":"Û","Ů":"Ů","Ű":"Ű","Ṽ":"Ṽ","Ẃ":"Ẃ","Ẁ":"Ẁ","Ẅ":"Ẅ","Ŵ":"Ŵ","Ẇ":"Ẇ","Ẍ":"Ẍ","Ẋ":"Ẋ","Ý":"Ý","Ỳ":"Ỳ","Ÿ":"Ÿ","Ỹ":"Ỹ","Ȳ":"Ȳ","Ŷ":"Ŷ","Ẏ":"Ẏ","Ź":"Ź","Ž":"Ž","Ẑ":"Ẑ","Ż":"Ż","ά":"ά","ὰ":"ὰ","ᾱ":"ᾱ","ᾰ":"ᾰ","έ":"έ","ὲ":"ὲ","ή":"ή","ὴ":"ὴ","ί":"ί","ὶ":"ὶ","ϊ":"ϊ","ΐ":"ΐ","ῒ":"ῒ","ῑ":"ῑ","ῐ":"ῐ","ό":"ό","ὸ":"ὸ","ύ":"ύ","ὺ":"ὺ","ϋ":"ϋ","ΰ":"ΰ","ῢ":"ῢ","ῡ":"ῡ","ῠ":"ῠ","ώ":"ώ","ὼ":"ὼ","Ύ":"Ύ","Ὺ":"Ὺ","Ϋ":"Ϋ","Ῡ":"Ῡ","Ῠ":"Ῠ","Ώ":"Ώ","Ὼ":"Ὼ"};const Rr=["bin","op","open","punct","rel"];class jr{constructor(e,t,r=!1){this.mode="math",this.gullet=new $r(e,t,this.mode),this.settings=t,this.isPreamble=r,this.leftrightDepth=0,this.prevAtomType=""}expect(t,r=!0){if(this.fetch().text!==t)throw new e(`Expected '${t}', got '${this.fetch().text}'`,this.fetch());r&&this.consume()}consume(){this.nextToken=null}fetch(){return null==this.nextToken&&(this.nextToken=this.gullet.expandNextToken()),this.nextToken}switchMode(e){this.mode=e,this.gullet.switchMode(e)}parse(){this.gullet.beginGroup(),this.settings.colorIsTextColor&&this.gullet.macros.set("\\color","\\textcolor");const e=this.parseExpression(!1);if(this.expect("EOF"),this.isPreamble){const e=Object.create(null);return Object.entries(this.gullet.macros.current).forEach((([t,r])=>{e[t]=r})),this.gullet.endGroup(),e}const t=this.gullet.macros.get("\\df@tag");return this.gullet.endGroup(),t&&(this.gullet.macros.current["\\df@tag"]=t),e}static get endOfExpression(){return["}","\\endgroup","\\end","\\right","\\endtoggle","&"]}subparse(e){const t=this.nextToken;this.consume(),this.gullet.pushToken(new br("}")),this.gullet.pushTokens(e);const r=this.parseExpression(!1);return this.expect("}"),this.nextToken=t,r}parseExpression(e,t,r){const n=[];for(;;){"math"===this.mode&&this.consumeSpaces();const s=this.fetch();if(-1!==jr.endOfExpression.indexOf(s.text))break;if(t&&s.text===t)break;if(r&&"\\middle"===s.text)break;if(e&&gr[s.text]&&gr[s.text].infix)break;const o=this.parseAtom(t);if(!o)break;"internal"!==o.type&&(n.push(o),this.prevAtomType="atom"===o.type?o.family:o.type)}return"text"===this.mode&&this.formLigatures(n),this.handleInfixNodes(n)}handleInfixNodes(t){let r,n=-1;for(let s=0;s=128))return null;if(this.settings.strict&&"math"===this.mode)throw new e(`Unicode text character "${r[0]}" used in math mode`,t);s={type:"textord",mode:"text",loc:fr.range(t),text:r}}if(this.consume(),n)for(let r=0;r0&&s[0].type&&"array"===s[0].type&&s[0].addEqnNum)&&n.gullet.macros.get("\\df@tag")){if(!r.displayMode)throw new e("\\tag works only in display mode");n.gullet.feed("\\df@tag"),s=[{type:"tag",mode:"text",body:s,tag:n.parse()}]}return s},Hr=[2,2,3,3];class Vr{constructor(e){this.level=e.level,this.color=e.color,this.font=e.font||"",this.fontFamily=e.fontFamily||"",this.fontSize=e.fontSize||1,this.fontWeight=e.fontWeight||"",this.fontShape=e.fontShape||"",this.maxSize=e.maxSize}extend(e){const t={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 r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return new Vr(t)}withLevel(e){return this.extend({level:e})}incrementLevel(){return this.extend({level:Math.min(this.level+1,3)})}inSubOrSup(){return this.extend({level:Hr[this.level]})}withColor(e){return this.extend({color:e})}withFont(e){return this.extend({font:e})}withTextFontFamily(e){return this.extend({fontFamily:e,font:""})}withFontSize(e){return this.extend({fontSize:e})}withTextFontWeight(e){return this.extend({fontWeight:e,font:""})}withTextFontShape(e){return this.extend({fontShape:e,font:""})}getColor(){return this.color}}let _r=function(e,t,r={}){t.textContent="";const n="math"===t.tagName.toLowerCase();n&&(r.wrap="none");const s=Wr(e,r);n||s.children.length>1?(t.textContent="",s.children.forEach((e=>{t.appendChild(e.toNode())}))):t.appendChild(s.toNode())};"undefined"!=typeof document&&"CSS1Compat"!==document.compatMode&&("undefined"!=typeof console&&console.warn("Warning: Temml doesn't work in quirks mode. Make sure your website has a suitable doctype."),_r=function(){throw new e("Temml doesn't work in quirks mode.")});const Wr=function(t,r){const n=new a(r);try{const e=Ur(t,n);return ue(e,t,new Vr({level:n.displayMode?nt:st,maxSize:n.maxSize}),n)}catch(r){return function(t,r,n){if(n.throwOnError||!(t instanceof e))throw t;const s=new y(["temml-error"],[new x(r+"\n"+t.toString())]);return s.style.color=n.errorColor,s.style.whiteSpace="pre-line",s}(r,t,n)}};return{version:"0.10.23",render:_r,renderToString:function(e,t){return Wr(e,t).toMarkup()},postProcess:function(e){const t={};let r=0;const n=e.getElementsByClassName("tml-tageqn");for(const e of n){const n=e.getElementsByClassName("tml-eqn");n.length>0&&(r+=1,n[0].id="tml-eqn-"+r);const s=e.getElementsByClassName("tml-label");if(0!==s.length)if(n.length>0)t[s[0].id]=String(r);else{const r=e.getElementsByClassName("tml-tag");r.length>0&&(t[s[0].id]=r[0].textContent)}}[...e.getElementsByClassName("tml-ref")].forEach((e=>{let r=t[e.getAttribute("href").slice(1)];-1===e.className.indexOf("tml-eqref")&&(r=r.replace(/^\(/,""),r=r.replace(/\($/,"")),"("!==r.charAt(0)&&(r="("+r),")"!==r.slice(-1)&&(r+=")"),e.textContent=r}))},ParseError:e,definePreamble:function(e,t){const r=new a(t);if(r.macros={},!("string"==typeof e||e instanceof String))throw new TypeError("Temml can only parse string typed expression");const n=new jr(e,r,!0);delete n.gullet.macros.current["\\df@tag"];return n.parse()},__parse:function(e,t){const r=new a(t);return Ur(e,r)},__renderToMathMLTree:Wr,__defineSymbol:I,__defineMacro:Pt}}(); \ No newline at end of file +var temml=function(){"use strict";class e{constructor(t,r){let n,o=" "+t;const s=r&&r.loc;if(s&&s.start<=s.end){const e=s.lexer.input;n=s.start;const t=s.end;n===e.length?o+=" at end of input: ":o+=" at position "+(n+1)+": ";const r=e.slice(n,t).replace(/[^]/g,"$&̲");let a,i;a=n>15?"…"+e.slice(n-15,n):e.slice(0,n),i=t+15":">","<":"<",'"':""","'":"'"},n=/[&><"']/g;const o=function(e){return"ordgroup"===e.type||"color"===e.type?1===e.body.length?o(e.body[0]):e:"font"===e.type?o(e.body):e};var s={deflt:function(e,t){return void 0===e?t:e},escape:function(e){return String(e).replace(n,(e=>r[e]))},hyphenate:function(e){return e.replace(t,"-$1").toLowerCase()},getBaseElem:o,isCharacterBox:function(e){const t=o(e);return"mathord"===t.type||"textord"===t.type||"atom"===t.type},protocolFromUrl:function(e){const t=/^[\x00-\x20]*([^\\/#?]*?)(:|�*58|�*3a|&colon)/i.exec(e);return t?":"!==t[2]?null:/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(t[1])?t[1].toLowerCase():null:"_relative"},round:function(e){return+e.toFixed(4)}};class a{constructor(e){e=e||{},this.displayMode=s.deflt(e.displayMode,!1),this.annotate=s.deflt(e.annotate,!1),this.leqno=s.deflt(e.leqno,!1),this.throwOnError=s.deflt(e.throwOnError,!1),this.errorColor=s.deflt(e.errorColor,"#b22222"),this.macros=e.macros||{},this.wrap=s.deflt(e.wrap,"tex"),this.xml=s.deflt(e.xml,!1),this.colorIsTextColor=s.deflt(e.colorIsTextColor,!1),this.strict=s.deflt(e.strict,!1),this.trust=s.deflt(e.trust,!1),this.maxSize=void 0===e.maxSize?[1/0,1/0]:Array.isArray(e.maxSize)?e.maxSize:[1/0,1/0],this.maxExpand=Math.max(0,s.deflt(e.maxExpand,1e3))}isTrusted(e){if(e.url&&!e.protocol){const t=s.protocolFromUrl(e.url);if(null==t)return!1;e.protocol=t}const t="function"==typeof this.trust?this.trust(e):this.trust;return Boolean(t)}}const i={},l={};function c({type:e,names:t,props:r,handler:n,mathmlBuilder:o}){const s={type:e,numArgs:r.numArgs,argTypes:r.argTypes,allowedInArgument:!!r.allowedInArgument,allowedInText:!!r.allowedInText,allowedInMath:void 0===r.allowedInMath||r.allowedInMath,numOptionalArgs:r.numOptionalArgs||0,infix:!!r.infix,primitive:!!r.primitive,handler:n};for(let e=0;ee.toText())).join("")}}const h=function(e){return e.filter((e=>e)).join(" ")},g=function(e,t){this.classes=e||[],this.attributes={},this.style=t||{}},f=function(e){const t=document.createElement(e);t.className=h(this.classes);for(const e in this.style)Object.prototype.hasOwnProperty.call(this.style,e)&&(t.style[e]=this.style[e]);for(const e in this.attributes)Object.prototype.hasOwnProperty.call(this.attributes,e)&&t.setAttribute(e,this.attributes[e]);for(let e=0;e`,t};class y{constructor(e,t,r){g.call(this,e,r),this.children=t||[]}setAttribute(e,t){this.attributes[e]=t}toNode(){return f.call(this,"span")}toMarkup(){return b.call(this,"span")}}class x{constructor(e){this.text=e}toNode(){return document.createTextNode(this.text)}toMarkup(){return s.escape(this.text)}}class w{constructor(e,t,r){this.alt=t,this.src=e,this.classes=["mord"],this.style=r}hasClass(e){return this.classes.includes(e)}toNode(){const e=document.createElement("img");e.src=this.src,e.alt=this.alt,e.className="mord";for(const t in this.style)Object.prototype.hasOwnProperty.call(this.style,t)&&(e.style[t]=this.style[t]);return e}toMarkup(){let e=`${this.alt}0&&(e.className=h(this.classes));for(const t in this.style)Object.prototype.hasOwnProperty.call(this.style,t)&&(e.style[t]=this.style[t]);for(let t=0;t0&&(e+=` class="${s.escape(h(this.classes))}"`);let t="";for(const e in this.style)Object.prototype.hasOwnProperty.call(this.style,e)&&(t+=`${s.hyphenate(e)}:${this.style[e]};`);t&&(e+=` style="${t}"`),e+=">";for(let t=0;t",e}toText(){return this.children.map((e=>e.toText())).join("")}}class v{constructor(e){this.text=e}toNode(){return document.createTextNode(this.text)}toMarkup(){return s.escape(this.toText())}toText(){return this.text}}const A=e=>{let t;return 1===e.length&&"mrow"===e[0].type?(t=e.pop(),t.type="mstyle"):t=new k("mstyle",e),t};var N={MathNode:k,TextNode:v,newDocumentFragment:function(e){return new p(e)}};const T=e=>{let t=0;if(e.body)for(const r of e.body)t+=T(r);else if("supsub"===e.type)t+=T(e.base),e.sub&&(t+=.7*T(e.sub)),e.sup&&(t+=.7*T(e.sup));else if("mathord"===e.type||"textord"===e.type)for(const r of e.text.split("")){const e=r.codePointAt(0);t+=96{const t=S(e.label);if(O.includes(e.label)){const r=T(e.base);1","\\gt",!0),I($,V,"∈","\\in",!0),I($,V,"∉","\\notin",!0),I($,V,"","\\@not"),I($,V,"⊂","\\subset",!0),I($,V,"⊃","\\supset",!0),I($,V,"⊆","\\subseteq",!0),I($,V,"⊇","\\supseteq",!0),I($,V,"⊈","\\nsubseteq",!0),I($,V,"⊈","\\nsubseteqq"),I($,V,"⊉","\\nsupseteq",!0),I($,V,"⊉","\\nsupseteqq"),I($,V,"⊨","\\models"),I($,V,"←","\\leftarrow",!0),I($,V,"≤","\\le"),I($,V,"≤","\\leq",!0),I($,V,"<","\\lt",!0),I($,V,"→","\\rightarrow",!0),I($,V,"→","\\to"),I($,V,"≱","\\ngeq",!0),I($,V,"≱","\\ngeqq"),I($,V,"≱","\\ngeqslant"),I($,V,"≰","\\nleq",!0),I($,V,"≰","\\nleqq"),I($,V,"≰","\\nleqslant"),I($,V,"⫫","\\Perp",!0),I($,_," ","\\ "),I($,_," ","\\space"),I($,_," ","\\nobreakspace"),I(L,_," ","\\ "),I(L,_," "," "),I(L,_," ","\\space"),I(L,_," ","\\nobreakspace"),I($,_,null,"\\nobreak"),I($,_,null,"\\allowbreak"),I($,H,",",","),I(L,H,":",":"),I($,H,";",";"),I($,G,"⊼","\\barwedge"),I($,G,"⊻","\\veebar"),I($,G,"⊙","\\odot",!0),I($,G,"⊕︎","\\oplus"),I($,G,"⊗","\\otimes",!0),I($,W,"∂","\\partial",!0),I($,G,"⊘","\\oslash",!0),I($,G,"⊚","\\circledcirc",!0),I($,G,"⊡","\\boxdot",!0),I($,G,"△","\\bigtriangleup"),I($,G,"▽","\\bigtriangledown"),I($,G,"†","\\dagger"),I($,G,"⋄","\\diamond"),I($,G,"◃","\\triangleleft"),I($,G,"▹","\\triangleright"),I($,U,"{","\\{"),I(L,W,"{","\\{"),I(L,W,"{","\\textbraceleft"),I($,D,"}","\\}"),I(L,W,"}","\\}"),I(L,W,"}","\\textbraceright"),I($,U,"{","\\lbrace"),I($,D,"}","\\rbrace"),I($,U,"[","\\lbrack",!0),I(L,W,"[","\\lbrack",!0),I($,D,"]","\\rbrack",!0),I(L,W,"]","\\rbrack",!0),I($,U,"(","\\lparen",!0),I($,D,")","\\rparen",!0),I($,U,"⦇","\\llparenthesis",!0),I($,D,"⦈","\\rrparenthesis",!0),I(L,W,"<","\\textless",!0),I(L,W,">","\\textgreater",!0),I($,U,"⌊","\\lfloor",!0),I($,D,"⌋","\\rfloor",!0),I($,U,"⌈","\\lceil",!0),I($,D,"⌉","\\rceil",!0),I($,W,"\\","\\backslash"),I($,W,"|","|"),I($,W,"|","\\vert"),I(L,W,"|","\\textbar",!0),I($,W,"‖","\\|"),I($,W,"‖","\\Vert"),I(L,W,"‖","\\textbardbl"),I(L,W,"~","\\textasciitilde"),I(L,W,"\\","\\textbackslash"),I(L,W,"^","\\textasciicircum"),I($,V,"↑","\\uparrow",!0),I($,V,"⇑","\\Uparrow",!0),I($,V,"↓","\\downarrow",!0),I($,V,"⇓","\\Downarrow",!0),I($,V,"↕","\\updownarrow",!0),I($,V,"⇕","\\Updownarrow",!0),I($,j,"∐","\\coprod"),I($,j,"⋁","\\bigvee"),I($,j,"⋀","\\bigwedge"),I($,j,"⨄","\\biguplus"),I($,j,"⋂","\\bigcap"),I($,j,"⋃","\\bigcup"),I($,j,"∫","\\int"),I($,j,"∫","\\intop"),I($,j,"∬","\\iint"),I($,j,"∭","\\iiint"),I($,j,"∏","\\prod"),I($,j,"∑","\\sum"),I($,j,"⨂","\\bigotimes"),I($,j,"⨁","\\bigoplus"),I($,j,"⨀","\\bigodot"),I($,j,"⨉","\\bigtimes"),I($,j,"∮","\\oint"),I($,j,"∯","\\oiint"),I($,j,"∰","\\oiiint"),I($,j,"∱","\\intclockwise"),I($,j,"∲","\\varointclockwise"),I($,j,"⨌","\\iiiint"),I($,j,"⨍","\\intbar"),I($,j,"⨎","\\intBar"),I($,j,"⨏","\\fint"),I($,j,"⨒","\\rppolint"),I($,j,"⨓","\\scpolint"),I($,j,"⨕","\\pointint"),I($,j,"⨖","\\sqint"),I($,j,"⨗","\\intlarhk"),I($,j,"⨘","\\intx"),I($,j,"⨙","\\intcap"),I($,j,"⨚","\\intcup"),I($,j,"⨅","\\bigsqcap"),I($,j,"⨆","\\bigsqcup"),I($,j,"∫","\\smallint"),I(L,P,"…","\\textellipsis"),I($,P,"…","\\mathellipsis"),I(L,P,"…","\\ldots",!0),I($,P,"…","\\ldots",!0),I($,P,"⋰","\\iddots",!0),I($,P,"⋯","\\@cdots",!0),I($,P,"⋱","\\ddots",!0),I($,W,"⋮","\\varvdots"),I($,F,"ˊ","\\acute"),I($,F,"`","\\grave"),I($,F,"¨","\\ddot"),I($,F,"…","\\dddot"),I($,F,"….","\\ddddot"),I($,F,"~","\\tilde"),I($,F,"‾","\\bar"),I($,F,"˘","\\breve"),I($,F,"ˇ","\\check"),I($,F,"^","\\hat"),I($,F,"→","\\vec"),I($,F,"˙","\\dot"),I($,F,"˚","\\mathring"),I($,R,"ı","\\imath",!0),I($,R,"ȷ","\\jmath",!0),I($,W,"ı","ı"),I($,W,"ȷ","ȷ"),I(L,W,"ı","\\i",!0),I(L,W,"ȷ","\\j",!0),I(L,W,"ß","\\ss",!0),I(L,W,"æ","\\ae",!0),I(L,W,"œ","\\oe",!0),I(L,W,"ø","\\o",!0),I($,R,"ø","\\o",!0),I(L,W,"Æ","\\AE",!0),I(L,W,"Œ","\\OE",!0),I(L,W,"Ø","\\O",!0),I($,R,"Ø","\\O",!0),I(L,F,"ˊ","\\'"),I(L,F,"ˋ","\\`"),I(L,F,"ˆ","\\^"),I(L,F,"˜","\\~"),I(L,F,"ˉ","\\="),I(L,F,"˘","\\u"),I(L,F,"˙","\\."),I(L,F,"¸","\\c"),I(L,F,"˚","\\r"),I(L,F,"ˇ","\\v"),I(L,F,"¨",'\\"'),I(L,F,"˝","\\H"),I($,F,"ˊ","\\'"),I($,F,"ˋ","\\`"),I($,F,"ˆ","\\^"),I($,F,"˜","\\~"),I($,F,"ˉ","\\="),I($,F,"˘","\\u"),I($,F,"˙","\\."),I($,F,"¸","\\c"),I($,F,"˚","\\r"),I($,F,"ˇ","\\v"),I($,F,"¨",'\\"'),I($,F,"˝","\\H");const X={"--":!0,"---":!0,"``":!0,"''":!0};I(L,W,"–","--",!0),I(L,W,"–","\\textendash"),I(L,W,"—","---",!0),I(L,W,"—","\\textemdash"),I(L,W,"‘","`",!0),I(L,W,"‘","\\textquoteleft"),I(L,W,"’","'",!0),I(L,W,"’","\\textquoteright"),I(L,W,"“","``",!0),I(L,W,"“","\\textquotedblleft"),I(L,W,"”","''",!0),I(L,W,"”","\\textquotedblright"),I($,W,"°","\\degree",!0),I(L,W,"°","\\degree"),I(L,W,"°","\\textdegree",!0),I($,W,"£","\\pounds"),I($,W,"£","\\mathsterling",!0),I(L,W,"£","\\pounds"),I(L,W,"£","\\textsterling",!0),I($,W,"✠","\\maltese"),I(L,W,"✠","\\maltese"),I($,W,"€","\\euro",!0),I(L,W,"€","\\euro",!0),I(L,W,"€","\\texteuro"),I($,W,"©","\\copyright",!0),I(L,W,"©","\\textcopyright"),I($,W,"⌀","\\diameter",!0),I(L,W,"⌀","\\diameter"),I($,W,"𝛤","\\varGamma"),I($,W,"𝛥","\\varDelta"),I($,W,"𝛩","\\varTheta"),I($,W,"𝛬","\\varLambda"),I($,W,"𝛯","\\varXi"),I($,W,"𝛱","\\varPi"),I($,W,"𝛴","\\varSigma"),I($,W,"𝛶","\\varUpsilon"),I($,W,"𝛷","\\varPhi"),I($,W,"𝛹","\\varPsi"),I($,W,"𝛺","\\varOmega"),I(L,W,"𝛤","\\varGamma"),I(L,W,"𝛥","\\varDelta"),I(L,W,"𝛩","\\varTheta"),I(L,W,"𝛬","\\varLambda"),I(L,W,"𝛯","\\varXi"),I(L,W,"𝛱","\\varPi"),I(L,W,"𝛴","\\varSigma"),I(L,W,"𝛶","\\varUpsilon"),I(L,W,"𝛷","\\varPhi"),I(L,W,"𝛹","\\varPsi"),I(L,W,"𝛺","\\varOmega");const Z='0123456789/@."';for(let e=0;e<14;e++){const t=Z.charAt(e);I($,W,t,t)}const Y='0123456789!@*()-=+";:?/.,';for(let e=0;e<25;e++){const t=Y.charAt(e);I(L,W,t,t)}const K="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";for(let e=0;e<52;e++){const t=K.charAt(e);I($,R,t,t),I(L,W,t,t)}const J="ÇÐÞçþℂℍℕℙℚℝℤℎℏℊℋℌℐℑℒℓ℘ℛℜℬℰℱℳℭℨ";for(let e=0;e<30;e++){const t=J.charAt(e);I($,R,t,t),I(L,W,t,t)}let Q="";for(let e=0;e<52;e++){Q=String.fromCharCode(55349,56320+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,56372+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,56424+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,56580+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,56736+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,56788+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,56840+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,56944+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,56632+e),I($,R,Q,Q),I(L,W,Q,Q);const t=K.charAt(e);Q=String.fromCharCode(55349,56476+e),I($,R,t,Q),I(L,W,t,Q)}for(let e=0;e<10;e++)Q=String.fromCharCode(55349,57294+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,57314+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,57324+e),I($,R,Q,Q),I(L,W,Q,Q),Q=String.fromCharCode(55349,57334+e),I($,R,Q,Q),I(L,W,Q,Q);const ee="([{⌊⌈⟨⟮⎰⟦⦃",te=")]}⌋⌉⟩⟯⎱⟦⦄";const re=function(e,t,r){return!E[t][e]||!E[t][e].replace||55349===e.charCodeAt(0)||Object.prototype.hasOwnProperty.call(X,e)&&r&&(r.fontFamily&&"tt"===r.fontFamily.slice(4,6)||r.font&&"tt"===r.font.slice(4,6))||(e=E[t][e].replace),new N.TextNode(e)},ne=e=>{if("mrow"!==e.type&&"mstyle"!==e.type)return e;if(0===e.children.length)return e;if(!e.children[0].attributes||"mtext"!==e.children[0].type)return e;const t=e.children[0].attributes.mathvariant||"",r=new N.MathNode("mtext",[new N.TextNode(e.children[0].children[0].text)]);for(let n=1;n0&&" "===r.children[0].text.charAt(n-1)&&(r.children[0].text=r.children[0].text.slice(0,-1)+" ");for(const[t,n]of Object.entries(e.attributes))r.attributes[t]=n;return r},oe=/^[0-9]$/,se=function(e,t=!1){if(!(1!==e.length||e[0]instanceof p))return e[0];if(!t){e[0]instanceof k&&"mo"===e[0].type&&!e[0].attributes.fence&&(e[0].attributes.lspace="0em",e[0].attributes.rspace="0em");const t=e.length-1;e[t]instanceof k&&"mo"===e[t].type&&!e[t].attributes.fence&&(e[t].attributes.lspace="0em",e[t].attributes.rspace="0em")}return new N.MathNode("mrow",e)},ae=e=>"atom"===e.type&&"rel"===e.family||"mclass"===e.type&&"mrel"===e.mclass,ie=function(e,t,r=!1){if(!r&&1===e.length){const r=ce(e[0],t);return r instanceof k&&"mo"===r.type&&(r.setAttribute("lspace","0em"),r.setAttribute("rspace","0em")),[r]}(e=>{if(e.length<2)return;const t=[];let r=!1;for(let n=0;n0;r--)t[r-1].end===t[r].start-2&&(n=e[t[r].start-1],o=e[t[r].start],("textord"===n.type&&"."===n.text||"atom"===n.type&&","===n.text)&&n.loc&&o.loc&&n.loc.end===o.loc.start)&&(t[r-1].end=t[r].end,t.splice(r,1));var n,o;for(let r=t.length-1;r>=0;r--){for(let n=t[r].start+1;n<=t[r].end;n++)e[t[r].start].text+=e[n].text;if(e.splice(t[r].start+1,t[r].end-t[r].start),e.length>t[r].start+1){const n=e[t[r].start+1];"supsub"===n.type&&n.base&&"textord"===n.base.type&&oe.test(n.base.text)&&(n.base.text=e[t[r].start].text+n.base.text,e.splice(t[r].start,1))}}})(e);const n=[];for(let r=0;r0&&ae(e[r])&&ae(e[r-1])&&o.setAttribute("lspace","0em"),n.push(o)}return n},le=function(e,t,r=!1){return se(ie(e,t,r),r)},ce=function(t,r){if(!t)return new N.MathNode("mrow");if(l[t.type]){return l[t.type](t,r)}throw new e("Got group of unknown type: '"+t.type+"'")},me=e=>new N.MathNode("mtd",[],[],{padding:"0",width:"50%"});function ue(e,t,r,n){let o=null;1===e.length&&"tag"===e[0].type&&(o=e[0].tag,e=e[0].body);const s=ie(e,r),a=n.displayMode||n.annotate?"none":n.wrap,i=0===s.length?null:s[0];let l=1===s.length&&null===o&&i instanceof k?s[0]:function(e,t,r){const n=[];let o=[],s=[],a=0,i=0,l=0;for(;i0&&o.push(new N.MathNode("mrow",s)),o.push(r),s=[];const e=new N.MathNode("mtd",o);e.style.textAlign="left",n.push(new N.MathNode("mtr",[e])),o=[],i+=1}else{if(s.push(r),r.type&&"mo"===r.type&&1===r.children.length&&!Object.hasOwn(r.attributes,"movablelimits")){const n=r.children[0].text;if(ee.indexOf(n)>-1)l+=1;else if(te.indexOf(n)>-1)l-=1;else if(0===l&&"="===t&&"="===n){if(a+=1,a>1){s.pop();const e=new N.MathNode("mrow",s);o.push(e),s=[r]}}else if(0===l&&"tex"===t&&"∇"!==n){const t=i0){const e=new N.MathNode("mrow",s);o.push(e)}if(n.length>0){const e=new N.MathNode("mtd",o);e.style.textAlign="left";const t=new N.MathNode("mtr",[e]);n.push(t);const s=new N.MathNode("mtable",n);return r||(s.setAttribute("columnalign","left"),s.setAttribute("rowspacing","0em")),s}return N.newDocumentFragment(o)}(s,a,n.displayMode);if(o&&(l=((e,t,r,n)=>{t=le(t[0].body,r),(t=ne(t)).classes.push("tml-tag"),e=new N.MathNode("mtd",[e]);const o=[me(),e,me()];o[n?0:2].classes.push(n?"tml-left":"tml-right"),o[n?0:2].children.push(t);const s=new N.MathNode("mtr",o,["tml-tageqn"]),a=new N.MathNode("mtable",[s]);return a.style.width="100%",a.setAttribute("displaystyle","true"),a})(l,o,r,n.leqno)),n.annotate){const e=new N.MathNode("annotation",[new N.TextNode(t)]);e.setAttribute("encoding","application/x-tex"),l=new N.MathNode("semantics",[l,e])}const c=new N.MathNode("math",[l]);return n.xml&&c.setAttribute("xmlns","http://www.w3.org/1998/Math/MathML"),n.displayMode&&(c.setAttribute("display","block"),c.style.display="block math",c.classes=["tml-display"]),c}const de="ABCDEFGHIJKLMNOPQRSTUVWXYZbdfhkltΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩβδλζφθψ𝐀𝐁𝐂𝐃𝐄𝐅𝐆𝐇𝐈𝐉𝐊𝐋𝐌𝐍𝐎𝐏𝐐𝐑𝐒𝐓𝐔𝐕𝐖𝐗𝐘𝐙𝐛𝐝𝐟𝐡𝐤𝐥𝐭",pe=new Set(["\\alpha","\\gamma","\\delta","\\epsilon","\\eta","\\iota","\\kappa","\\mu","\\nu","\\pi","\\rho","\\sigma","\\tau","\\upsilon","\\chi","\\psi","\\omega","\\imath","\\jmath"]),he=new Set(["\\Gamma","\\Delta","\\Sigma","\\Omega","\\beta","\\delta","\\lambda","\\theta","\\psi"]),ge=(e,t)=>{const r=e.isStretchy?M(e):new N.MathNode("mo",[re(e.label,e.mode)]);if("\\vec"===e.label)r.style.transform="scale(0.75) translate(10%, 30%)";else if(r.style.mathStyle="normal",r.style.mathDepth="0",be.has(e.label)&&s.isCharacterBox(e.base)){let t="";const n=e.base.text;("acegıȷmnopqrsuvwxyzαγεηικμνοπρςστυχωϕ𝐚𝐜𝐞𝐠𝐦𝐧𝐨𝐩𝐪𝐫𝐬𝐮𝐯𝐰𝐱𝐲𝐳".indexOf(n)>-1||pe.has(n))&&(t="tml-xshift"),(de.indexOf(n)>-1||he.has(n))&&(t="tml-capshift"),t&&r.classes.push(t)}e.isStretchy||r.setAttribute("stretchy","false");return new N.MathNode("\\c"===e.label?"munder":"mover",[ce(e.base,t),r])},fe=new Set(["\\acute","\\grave","\\ddot","\\dddot","\\ddddot","\\tilde","\\bar","\\breve","\\check","\\hat","\\vec","\\dot","\\mathring"]),be=new Set(["\\acute","\\bar","\\breve","\\check","\\dot","\\ddot","\\grave","\\hat","\\mathring","\\'","\\^","\\~","\\=","\\u","\\.",'\\"',"\\r","\\H","\\v"]);c({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=u(t[0]),n=!fe.has(e.funcName);return{type:"accent",mode:e.parser.mode,label:e.funcName,isStretchy:n,base:r}},mathmlBuilder:ge}),c({type:"accent",names:["\\'","\\`","\\^","\\~","\\=","\\c","\\u","\\.",'\\"',"\\r","\\H","\\v"],props:{numArgs:1,allowedInText:!0,allowedInMath:!0,argTypes:["primitive"]},handler:(e,t)=>{const r=u(t[0]),n=e.parser.mode;return"math"===n&&e.parser.settings.strict&&console.log(`Temml parse error: Command ${e.funcName} is invalid in math mode.`),{type:"accent",mode:n,label:e.funcName,isStretchy:!1,base:r}},mathmlBuilder:ge}),c({type:"accentUnder",names:["\\underleftarrow","\\underrightarrow","\\underleftrightarrow","\\undergroup","\\underparen","\\utilde"],props:{numArgs:1},handler:({parser:e,funcName:t},r)=>{const n=r[0];return{type:"accentUnder",mode:e.mode,label:t,base:n}},mathmlBuilder:(e,t)=>{const r=M(e);r.style["math-depth"]=0;return new N.MathNode("munder",[ce(e.base,t),r])}});const ye={pt:800/803,pc:9600/803,dd:1238/1157*800/803,cc:12.792133216944668,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},xe=["em","ex","mu","pt","mm","cm","in","px","bp","pc","dd","cc","nd","nc","sp"],we=function(e){return"string"!=typeof e&&(e=e.unit),xe.indexOf(e)>-1},ke=e=>[1,.7,.5][Math.max(e-1,0)],ve=function(t,r){let n=t.number;if(r.maxSize[0]<0&&n>0)return{number:0,unit:"em"};const o=t.unit;switch(o){case"mm":case"cm":case"in":case"px":return n*ye[o]>r.maxSize[1]?{number:r.maxSize[1],unit:"pt"}:{number:n,unit:o};case"em":case"ex":return"ex"===o&&(n*=.431),n=Math.min(n/ke(r.level),r.maxSize[0]),{number:s.round(n),unit:"em"};case"bp":return n>r.maxSize[1]&&(n=r.maxSize[1]),{number:n,unit:"pt"};case"pt":case"pc":case"dd":case"cc":case"nd":case"nc":case"sp":return n=Math.min(n*ye[o],r.maxSize[1]),{number:s.round(n),unit:"pt"};case"mu":return n=Math.min(n/18,r.maxSize[0]),{number:s.round(n),unit:"em"};default:throw new e("Invalid unit: '"+o+"'")}},Ae=e=>{const t=new N.MathNode("mspace");return t.setAttribute("width",e+"em"),t},Ne=(e,t=.3,r=0)=>{if(null==e&&0===r)return Ae(t);const n=e?[e]:[];return 0!==t&&n.unshift(Ae(t)),r>0&&n.push(Ae(r)),new N.MathNode("mrow",n)},Te=(e,t)=>Number(e)/ke(t),qe=(e,t,r,n)=>{const o=B(e),s="eq"===e.slice(1,3),a="x"===e.charAt(1)?"1.75":"cd"===e.slice(2,4)?"3.0":s?"1.0":"2.0";o.setAttribute("lspace","0"),o.setAttribute("rspace",s?"0.5em":"0");const i=n.withLevel(n.level<2?2:3),l=Te(a,i.level),c=Te(a,3),m=Ne(null,l.toFixed(4),0),u=Ne(null,c.toFixed(4),0),d=Te(s?0:.3,i.level).toFixed(4);let p,h;const g=t&&t.body&&(t.body.body||t.body.length>0);if(g){let e=ce(t,i);e=Ne(e,d,d),p=new N.MathNode("mover",[e,u])}const f=r&&r.body&&(r.body.body||r.body.length>0);if(f){let e=ce(r,i);e=Ne(e,d,d),h=new N.MathNode("munder",[e,u])}let b;return b=g||f?g&&f?new N.MathNode("munderover",[o,h,p]):g?new N.MathNode("mover",[o,p]):new N.MathNode("munder",[o,h]):new N.MathNode("mover",[o,m]),"3.0"===a&&(b.style.height="1em"),b.setAttribute("accent","false"),b};c({type:"xArrow",names:["\\xleftarrow","\\xrightarrow","\\xLeftarrow","\\xRightarrow","\\xleftrightarrow","\\xLeftrightarrow","\\xhookleftarrow","\\xhookrightarrow","\\xmapsto","\\xrightharpoondown","\\xrightharpoonup","\\xleftharpoondown","\\xleftharpoonup","\\xlongequal","\\xtwoheadrightarrow","\\xtwoheadleftarrow","\\yields","\\yieldsLeft","\\mesomerism","\\longrightharpoonup","\\longleftharpoondown","\\\\cdrightarrow","\\\\cdleftarrow","\\\\cdlongequal"],props:{numArgs:1,numOptionalArgs:1},handler:({parser:e,funcName:t},r,n)=>({type:"xArrow",mode:e.mode,name:t,body:r[0],below:n[0]}),mathmlBuilder(e,t){const r=[qe(e.name,e.body,e.below,t)];return r.unshift(Ae(.2778)),r.push(Ae(.2778)),new N.MathNode("mrow",r)}});const Se={"\\xtofrom":["\\xrightarrow","\\xleftarrow"],"\\xleftrightharpoons":["\\xleftharpoonup","\\xrightharpoondown"],"\\xrightleftharpoons":["\\xrightharpoonup","\\xleftharpoondown"],"\\yieldsLeftRight":["\\yields","\\yieldsLeft"],"\\equilibrium":["\\longrightharpoonup","\\longleftharpoondown"],"\\equilibriumRight":["\\longrightharpoonup","\\eqleftharpoondown"],"\\equilibriumLeft":["\\eqrightharpoonup","\\longleftharpoondown"]};function Oe(e,t){if(!e||e.type!==t)throw new Error(`Expected node of type ${t}, but got `+(e?`node of type ${e.type}`:String(e)));return e}function Be(e){const t=Me(e);if(!t)throw new Error("Expected node of symbol group type, but got "+(e?`node of type ${e.type}`:String(e)));return t}function Me(e){return e&&("atom"===e.type||Object.prototype.hasOwnProperty.call(z,e.type))?e:null}c({type:"stackedArrow",names:["\\xtofrom","\\xleftrightharpoons","\\xrightleftharpoons","\\yieldsLeftRight","\\equilibrium","\\equilibriumRight","\\equilibriumLeft"],props:{numArgs:1,numOptionalArgs:1},handler({parser:e,funcName:t},r,n){const o=r[0]?{type:"hphantom",mode:e.mode,body:r[0]}:null,s=n[0]?{type:"hphantom",mode:e.mode,body:n[0]}:null;return{type:"stackedArrow",mode:e.mode,name:t,body:r[0],upperArrowBelow:s,lowerArrowBody:o,below:n[0]}},mathmlBuilder(e,t){const r=Se[e.name][0],n=Se[e.name][1],o=qe(r,e.body,e.upperArrowBelow,t),s=qe(n,e.lowerArrowBody,e.below,t);let a;const i=new N.MathNode("mpadded",[o]);if(i.setAttribute("voffset","0.3em"),i.setAttribute("height","+0.3em"),i.setAttribute("depth","-0.3em"),"\\equilibriumLeft"===e.name){const e=new N.MathNode("mpadded",[s]);e.setAttribute("width","0.5em"),a=new N.MathNode("mpadded",[Ae(.2778),e,i,Ae(.2778)])}else i.setAttribute("width","\\equilibriumRight"===e.name?"0.5em":"0"),a=new N.MathNode("mpadded",[Ae(.2778),i,s,Ae(.2778)]);return a.setAttribute("voffset","-0.18em"),a.setAttribute("height","-0.18em"),a.setAttribute("depth","+0.18em"),a}});const Ce={">":"\\\\cdrightarrow","<":"\\\\cdleftarrow","=":"\\\\cdlongequal",A:"\\uparrow",V:"\\downarrow","|":"\\Vert",".":"no arrow"},ze=e=>"textord"===e.type&&"@"===e.text;function Ee(e,t,r){const n=Ce[e];switch(n){case"\\\\cdrightarrow":case"\\\\cdleftarrow":return r.callFunction(n,[t[0]],[t[1]]);case"\\uparrow":case"\\downarrow":{const e={type:"atom",text:n,mode:"math",family:"rel"},o={type:"ordgroup",mode:"math",body:[r.callFunction("\\\\cdleft",[t[0]],[]),r.callFunction("\\Big",[e],[]),r.callFunction("\\\\cdright",[t[1]],[])],semisimple:!0};return r.callFunction("\\\\cdparent",[o],[])}case"\\\\cdlongequal":return r.callFunction("\\\\cdlongequal",[],[]);case"\\Vert":{const e={type:"textord",text:"\\Vert",mode:"math"};return r.callFunction("\\Big",[e],[])}default:return{type:"textord",text:" ",mode:"math"}}}c({type:"cdlabel",names:["\\\\cdleft","\\\\cdright"],props:{numArgs:1},handler:({parser:e,funcName:t},r)=>({type:"cdlabel",mode:e.mode,side:t.slice(4),label:r[0]}),mathmlBuilder(e,t){let r=new N.MathNode("mrow",[ce(e.label,t)]);return r=new N.MathNode("mpadded",[r]),r.setAttribute("width","0"),"left"===e.side&&r.setAttribute("lspace","-1width"),r.setAttribute("voffset","0.7em"),r=new N.MathNode("mstyle",[r]),r.setAttribute("displaystyle","false"),r.setAttribute("scriptlevel","1"),r}}),c({type:"cdlabelparent",names:["\\\\cdparent"],props:{numArgs:1},handler:({parser:e},t)=>({type:"cdlabelparent",mode:e.mode,fragment:t[0]}),mathmlBuilder:(e,t)=>new N.MathNode("mrow",[ce(e.fragment,t)])}),c({type:"textord",names:["\\@char"],props:{numArgs:1,allowedInText:!0},handler({parser:t,token:r},n){const o=Oe(n[0],"ordgroup").body;let s="";for(let e=0;e{let t=e.toString(16);return 1===t.length&&(t="0"+t),t},Pe=JSON.parse('{\n "Apricot": "#ffb484",\n "Aquamarine": "#08b4bc",\n "Bittersweet": "#c84c14",\n "blue": "#0000FF",\n "Blue": "#303494",\n "BlueGreen": "#08b4bc",\n "BlueViolet": "#503c94",\n "BrickRed": "#b8341c",\n "brown": "#BF8040",\n "Brown": "#802404",\n "BurntOrange": "#f8941c",\n "CadetBlue": "#78749c",\n "CarnationPink": "#f884b4",\n "Cerulean": "#08a4e4",\n "CornflowerBlue": "#40ace4",\n "cyan": "#00FFFF",\n "Cyan": "#08acec",\n "Dandelion": "#ffbc44",\n "darkgray": "#404040",\n "DarkOrchid": "#a8548c",\n "Emerald": "#08ac9c",\n "ForestGreen": "#089c54",\n "Fuchsia": "#90348c",\n "Goldenrod": "#ffdc44",\n "gray": "#808080",\n "Gray": "#98949c",\n "green": "#00FF00",\n "Green": "#08a44c",\n "GreenYellow": "#e0e474",\n "JungleGreen": "#08ac9c",\n "Lavender": "#f89cc4",\n "lightgray": "#c0c0c0",\n "lime": "#BFFF00",\n "LimeGreen": "#90c43c",\n "magenta": "#FF00FF",\n "Magenta": "#f0048c",\n "Mahogany": "#b0341c",\n "Maroon": "#b03434",\n "Melon": "#f89c7c",\n "MidnightBlue": "#086494",\n "Mulberry": "#b03c94",\n "NavyBlue": "#086cbc",\n "olive": "#7F7F00",\n "OliveGreen": "#407c34",\n "orange": "#FF8000",\n "Orange": "#f8843c",\n "OrangeRed": "#f0145c",\n "Orchid": "#b074ac",\n "Peach": "#f8945c",\n "Periwinkle": "#8074bc",\n "PineGreen": "#088c74",\n "pink": "#ff7f7f",\n "Plum": "#98248c",\n "ProcessBlue": "#08b4ec",\n "purple": "#BF0040",\n "Purple": "#a0449c",\n "RawSienna": "#983c04",\n "red": "#ff0000",\n "Red": "#f01c24",\n "RedOrange": "#f86434",\n "RedViolet": "#a0246c",\n "Rhodamine": "#f0549c",\n "Royallue": "#0874bc",\n "RoyalPurple": "#683c9c",\n "RubineRed": "#f0047c",\n "Salmon": "#f8948c",\n "SeaGreen": "#30bc9c",\n "Sepia": "#701404",\n "SkyBlue": "#48c4dc",\n "SpringGreen": "#c8dc64",\n "Tan": "#e09c74",\n "teal": "#007F7F",\n "TealBlue": "#08acb4",\n "Thistle": "#d884b4",\n "Turquoise": "#08b4cc",\n "violet": "#800080",\n "Violet": "#60449c",\n "VioletRed": "#f054a4",\n "WildStrawberry": "#f0246c",\n "yellow": "#FFFF00",\n "Yellow": "#fff404",\n "YellowGreen": "#98cc6c",\n "YellowOrange": "#ffa41c"\n}'),Re=(t,r)=>{let n="";if("HTML"===t){if(!Ie.test(r))throw new e("Invalid HTML input.");n=r}else if("RGB"===t){if(!Le.test(r))throw new e("Invalid RGB input.");r.split(",").map((e=>{n+=De(Number(e.trim()))}))}else{if(!Fe.test(r))throw new e("Invalid rbg input.");r.split(",").map((t=>{const r=Number(t.trim());if(r>1)throw new e("Color rgb input must be < 1.");n+=De(Number((255*r).toFixed(0)))}))}return"#"!==n.charAt(0)&&(n="#"+n),n},je=(t,r,n)=>{const o=`\\\\color@${t}`;if(!$e.exec(t))throw new e("Invalid color: '"+t+"'",n);return Ge.test(t)?"#"+t:("#"===t.charAt(0)||(r.has(o)?t=r.get(o).tokens[0].text:Pe[t]&&(t=Pe[t])),t)},Ue=(e,t)=>{let r=ie(e.body,t.withColor(e.color));return r=r.map((t=>(t.style.color=e.color,t))),N.newDocumentFragment(r)};c({type:"color",names:["\\textcolor"],props:{numArgs:2,numOptionalArgs:1,allowedInText:!0,argTypes:["raw","raw","original"]},handler({parser:e,token:t},r,n){const o=n[0]&&Oe(n[0],"raw").string;let s="";if(o){const e=Oe(r[0],"raw").string;s=Re(o,e)}else s=je(Oe(r[0],"raw").string,e.gullet.macros,t);const a=r[1];return{type:"color",mode:e.mode,color:s,body:d(a)}},mathmlBuilder:Ue}),c({type:"color",names:["\\color"],props:{numArgs:1,numOptionalArgs:1,allowedInText:!0,argTypes:["raw","raw"]},handler({parser:e,breakOnTokenText:t,token:r},n,o){const s=o[0]&&Oe(o[0],"raw").string;let a="";if(s){const e=Oe(n[0],"raw").string;a=Re(s,e)}else a=je(Oe(n[0],"raw").string,e.gullet.macros,r);const i=e.parseExpression(!0,t,!0);return{type:"color",mode:e.mode,color:a,body:i}},mathmlBuilder:Ue}),c({type:"color",names:["\\definecolor"],props:{numArgs:3,allowedInText:!0,argTypes:["raw","raw","raw"]},handler({parser:t,funcName:r,token:n},o){const s=Oe(o[0],"raw").string;if(!/^[A-Za-z]+$/.test(s))throw new e("Color name must be latin letters.",n);const a=Oe(o[1],"raw").string;if(!["HTML","RGB","rgb"].includes(a))throw new e("Color model must be HTML, RGB, or rgb.",n);const i=Oe(o[2],"raw").string,l=Re(a,i);return t.gullet.macros.set(`\\\\color@${s}`,{tokens:[{text:l}],numArgs:0}),{type:"internal",mode:t.mode}}}),c({type:"cr",names:["\\\\"],props:{numArgs:0,numOptionalArgs:0,allowedInText:!0},handler({parser:e},t,r){const n="["===e.gullet.future().text?e.parseSizeGroup(!0):null,o=!e.settings.displayMode;return{type:"cr",mode:e.mode,newLine:o,size:n&&Oe(n,"size").value}},mathmlBuilder(e,t){const r=new N.MathNode("mo");if(e.newLine&&(r.setAttribute("linebreak","newline"),e.size)){const n=ve(e.size,t);r.setAttribute("height",n.number+n.unit)}return r}});const He={"\\global":"\\global","\\long":"\\\\globallong","\\\\globallong":"\\\\globallong","\\def":"\\gdef","\\gdef":"\\gdef","\\edef":"\\xdef","\\xdef":"\\xdef","\\let":"\\\\globallet","\\futurelet":"\\\\globalfuture"},Ve=t=>{const r=t.text;if(/^(?:[\\{}$&#^_]|EOF)$/.test(r))throw new e("Expected a control sequence",t);return r},_e=(e,t,r,n)=>{let o=e.gullet.macros.get(r.text);null==o&&(r.noexpand=!0,o={tokens:[r],numArgs:0,unexpandable:!e.gullet.isExpandable(r.text)}),e.gullet.macros.set(t,o,n)};c({type:"internal",names:["\\global","\\long","\\\\globallong"],props:{numArgs:0,allowedInText:!0},handler({parser:t,funcName:r}){t.consumeSpaces();const n=t.fetch();if(He[n.text])return"\\global"!==r&&"\\\\globallong"!==r||(n.text=He[n.text]),Oe(t.parseFunction(),"internal");throw new e("Invalid token after macro prefix",n)}}),c({type:"internal",names:["\\def","\\gdef","\\edef","\\xdef"],props:{numArgs:0,allowedInText:!0,primitive:!0},handler({parser:t,funcName:r}){let n=t.gullet.popToken();const o=n.text;if(/^(?:[\\{}$&#^_]|EOF)$/.test(o))throw new e("Expected a control sequence",n);let s,a=0;const i=[[]];for(;"{"!==t.gullet.future().text;)if(n=t.gullet.popToken(),"#"===n.text){if("{"===t.gullet.future().text){s=t.gullet.future(),i[a].push("{");break}if(n=t.gullet.popToken(),!/^[1-9]$/.test(n.text))throw new e(`Invalid argument number "${n.text}"`);if(parseInt(n.text)!==a+1)throw new e(`Argument number "${n.text}" out of order`);a++,i.push([])}else{if("EOF"===n.text)throw new e("Expected a macro definition");i[a].push(n.text)}let{tokens:l}=t.gullet.consumeArg();if(s&&l.unshift(s),"\\edef"===r||"\\xdef"===r){if(l=t.gullet.expandTokens(l),l.length>t.gullet.settings.maxExpand)throw new e("Too many expansions in an "+r);l.reverse()}return t.gullet.macros.set(o,{tokens:l,numArgs:a,delimiters:i},r===He[r]),{type:"internal",mode:t.mode}}}),c({type:"internal",names:["\\let","\\\\globallet"],props:{numArgs:0,allowedInText:!0,primitive:!0},handler({parser:e,funcName:t}){const r=Ve(e.gullet.popToken());e.gullet.consumeSpaces();const n=(e=>{let t=e.gullet.popToken();return"="===t.text&&(t=e.gullet.popToken()," "===t.text&&(t=e.gullet.popToken())),t})(e);return _e(e,r,n,"\\\\globallet"===t),{type:"internal",mode:e.mode}}}),c({type:"internal",names:["\\futurelet","\\\\globalfuture"],props:{numArgs:0,allowedInText:!0,primitive:!0},handler({parser:e,funcName:t}){const r=Ve(e.gullet.popToken()),n=e.gullet.popToken(),o=e.gullet.popToken();return _e(e,r,o,"\\\\globalfuture"===t),e.gullet.pushToken(o),e.gullet.pushToken(n),{type:"internal",mode:e.mode}}}),c({type:"internal",names:["\\newcommand","\\renewcommand","\\providecommand"],props:{numArgs:0,allowedInText:!0,primitive:!0},handler({parser:t,funcName:r}){let n="";const o=t.gullet.popToken();"{"===o.text?(n=Ve(t.gullet.popToken()),t.gullet.popToken()):n=Ve(o);const s=t.gullet.isDefined(n);if(s&&"\\newcommand"===r)throw new e(`\\newcommand{${n}} attempting to redefine ${n}; use \\renewcommand`);if(!s&&"\\renewcommand"===r)throw new e(`\\renewcommand{${n}} when command ${n} does not yet exist; use \\newcommand`);let a=0;if("["===t.gullet.future().text){let r=t.gullet.popToken();if(r=t.gullet.popToken(),!/^[0-9]$/.test(r.text))throw new e(`Invalid number of arguments: "${r.text}"`);if(a=parseInt(r.text),r=t.gullet.popToken(),"]"!==r.text)throw new e(`Invalid argument "${r.text}"`)}const{tokens:i}=t.gullet.consumeArg();return t.gullet.macros.set(n,{tokens:i,numArgs:a},!t.settings.strict),{type:"internal",mode:t.mode}}});const We={"\\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}},Xe=["(","\\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","."],Ze=["}","\\left","\\middle","\\right"],Ye=e=>e.length>0&&(Xe.includes(e)||We[e]||Ze.includes(e)),Ke=[0,1.2,1.8,2.4,3];function Je(t,r){const n=Me(t);if(n&&Xe.includes(n.text))return["/","⁄"].includes(n.text)&&(n.text="∕"),["<","\\lt"].includes(n.text)&&(n.text="⟨"),[">","\\gt"].includes(n.text)&&(n.text="⟩"),"\\backslash"===n.text&&(n.text="∖"),n;throw new e(n?`Invalid delimiter '${n.text}' after '${r.funcName}'`:`Invalid delimiter type '${t.type}'`,t)}c({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=Je(t[0],e);return{type:"delimsizing",mode:e.parser.mode,size:We[e.funcName].size,mclass:We[e.funcName].mclass,delim:r.text}},mathmlBuilder:e=>{const t=[];"."===e.delim&&(e.delim=""),t.push(re(e.delim,e.mode));const r=new N.MathNode("mo",t);return"mopen"===e.mclass||"mclose"===e.mclass?r.setAttribute("fence","true"):r.setAttribute("fence","false"),("∖"===e.delim||"\\vert"===e.delim||"|"===e.delim||e.delim.indexOf("arrow")>-1)&&r.setAttribute("stretchy","true"),r.setAttribute("symmetric","true"),r.setAttribute("minsize",Ke[e.size]+"em"),r.setAttribute("maxsize",Ke[e.size]+"em"),r}}),c({type:"leftright-right",names:["\\right"],props:{numArgs:1,argTypes:["primitive"]},handler:(e,t)=>({type:"leftright-right",mode:e.parser.mode,delim:Je(t[0],e).text})}),c({type:"leftright",names:["\\left"],props:{numArgs:1,argTypes:["primitive"]},handler:(t,r)=>{const n=Je(r[0],t),o=t.parser;++o.leftrightDepth;let s=o.parseExpression(!1,null,!0),a=o.fetch();for(;"\\middle"===a.text;){o.consume();const t=o.fetch().text;if(!E.math[t])throw new e(`Invalid delimiter '${t}' after '\\middle'`);Je({type:"atom",mode:"math",text:t},{funcName:"\\middle"}),s.push({type:"middle",mode:"math",delim:t}),o.consume(),s=s.concat(o.parseExpression(!1,null,!0)),a=o.fetch()}--o.leftrightDepth,o.expect("\\right",!1);const i=Oe(o.parseFunction(),"leftright-right");return{type:"leftright",mode:o.mode,body:s,left:n.text,right:i.delim}},mathmlBuilder:(e,t)=>{!function(e){if(!e.body)throw new Error("Bug: The leftright ParseNode wasn't fully parsed.")}(e);const r=ie(e.body,t);"."===e.left&&(e.left="");const n=new N.MathNode("mo",[re(e.left,e.mode)]);n.setAttribute("fence","true"),n.setAttribute("form","prefix"),("∖"===e.left||e.left.indexOf("arrow")>-1)&&n.setAttribute("stretchy","true"),r.unshift(n),"."===e.right&&(e.right="");const o=new N.MathNode("mo",[re(e.right,e.mode)]);return o.setAttribute("fence","true"),o.setAttribute("form","postfix"),("∖"===e.right||e.right.indexOf("arrow")>-1)&&o.setAttribute("stretchy","true"),r.push(o),se(r)}}),c({type:"middle",names:["\\middle"],props:{numArgs:1,argTypes:["primitive"]},handler:(t,r)=>{const n=Je(r[0],t);if(!t.parser.leftrightDepth)throw new e("\\middle without preceding \\left",n);return{type:"middle",mode:t.parser.mode,delim:n.text}},mathmlBuilder:(e,t)=>{const r=re(e.delim,e.mode),n=new N.MathNode("mo",[r]);return n.setAttribute("fence","true"),e.delim.indexOf("arrow")>-1&&n.setAttribute("stretchy","true"),n.setAttribute("form","prefix"),n.setAttribute("lspace","0.05em"),n.setAttribute("rspace","0.05em"),n}});const Qe=e=>{const t=new N.MathNode("mspace");return t.setAttribute("width","3pt"),t},et=(e,t)=>{let r;switch(r=e.label.indexOf("colorbox")>-1||"\\boxed"===e.label?new N.MathNode("mrow",[Qe(),ce(e.body,t),Qe()]):new N.MathNode("mrow",[ce(e.body,t)]),e.label){case"\\overline":r.style.padding="0.1em 0 0 0",r.style.borderTop="0.065em solid";break;case"\\underline":r.style.padding="0 0 0.1em 0",r.style.borderBottom="0.065em solid";break;case"\\cancel":r.classes.push("tml-cancel");break;case"\\bcancel":r.classes.push("tml-bcancel");break;case"\\angl":r.style.padding="0.03889em 0.03889em 0 0.03889em",r.style.borderTop="0.049em solid",r.style.borderRight="0.049em solid",r.style.marginRight="0.03889em";break;case"\\sout":r.style.backgroundImage="linear-gradient(black, black)",r.style.backgroundRepeat="no-repeat",r.style.backgroundSize="100% 1.5px",r.style.backgroundPosition="0 center";break;case"\\boxed":r.style={padding:"3pt 0 3pt 0",border:"1px solid"},r.setAttribute("scriptlevel","0"),r.setAttribute("displaystyle","true");break;case"\\fbox":r.style={padding:"3pt",border:"1px solid"};break;case"\\fcolorbox":case"\\colorbox":{const t={padding:"3pt 0 3pt 0"};"\\fcolorbox"===e.label&&(t.border="0.06em solid "+String(e.borderColor)),r.style=t;break}case"\\xcancel":r.classes.push("tml-xcancel")}return e.backgroundColor&&r.setAttribute("mathbackground",e.backgroundColor),r};c({type:"enclose",names:["\\colorbox"],props:{numArgs:2,numOptionalArgs:1,allowedInText:!0,argTypes:["raw","raw","text"]},handler({parser:e,funcName:t},r,n){const o=n[0]&&Oe(n[0],"raw").string;let s="";if(o){const e=Oe(r[0],"raw").string;s=Re(o,e)}else s=je(Oe(r[0],"raw").string,e.gullet.macros);const a=r[1];return{type:"enclose",mode:e.mode,label:t,backgroundColor:s,body:a}},mathmlBuilder:et}),c({type:"enclose",names:["\\fcolorbox"],props:{numArgs:3,numOptionalArgs:1,allowedInText:!0,argTypes:["raw","raw","raw","text"]},handler({parser:e,funcName:t},r,n){const o=n[0]&&Oe(n[0],"raw").string;let s,a="";if(o){const e=Oe(r[0],"raw").string,t=Oe(r[0],"raw").string;a=Re(o,e),s=Re(o,t)}else a=je(Oe(r[0],"raw").string,e.gullet.macros),s=je(Oe(r[1],"raw").string,e.gullet.macros);const i=r[2];return{type:"enclose",mode:e.mode,label:t,backgroundColor:s,borderColor:a,body:i}},mathmlBuilder:et}),c({type:"enclose",names:["\\fbox"],props:{numArgs:1,argTypes:["hbox"],allowedInText:!0},handler:({parser:e},t)=>({type:"enclose",mode:e.mode,label:"\\fbox",body:t[0]})}),c({type:"enclose",names:["\\angl","\\cancel","\\bcancel","\\xcancel","\\sout","\\overline","\\boxed"],props:{numArgs:1},handler({parser:e,funcName:t},r){const n=r[0];return{type:"enclose",mode:e.mode,label:t,body:n}},mathmlBuilder:et}),c({type:"enclose",names:["\\underline"],props:{numArgs:1,allowedInText:!0},handler({parser:e,funcName:t},r){const n=r[0];return{type:"enclose",mode:e.mode,label:t,body:n}},mathmlBuilder:et});const tt={};function rt({type:e,names:t,props:r,handler:n,mathmlBuilder:o}){const s={type:e,numArgs:r.numArgs||0,allowedInText:!1,numOptionalArgs:0,handler:n};for(let e=0;e{if(!t.parser.settings.displayMode)throw new e(`{${t.envName}} can be used only in display mode.`)},ct=(e,t,r)=>{let n;const o=e.tags.shift();if(o){if(!o.body)return n=new N.MathNode("mtext",[],[]),n;n=le(o.body,t,!0),n.classes=["tml-tag"]}else{if(e.envClasses.includes("multline")&&(e.leqno&&0!==r||!e.leqno&&r!==e.body.length-1))return n=new N.MathNode("mtext",[],[]),n;n=new N.MathNode("mtext",[new y(["tml-eqn"])])}return n};function mt(t,{cols:r,envClasses:n,addEqnNum:o,singleRow:s,emptySingleRow:a,maxNumCols:i,leqno:l},c){t.gullet.beginGroup(),s||t.gullet.macros.set("\\cr","\\\\\\relax"),o&&(t.gullet.macros.set("\\tag","\\@ifstar\\envtag@literal\\envtag@paren"),t.gullet.macros.set("\\envtag@paren","\\env@tag{{(\\text{#1})}}"),t.gullet.macros.set("\\envtag@literal","\\env@tag{\\text{#1}}"),t.gullet.macros.set("\\notag","\\env@notag"),t.gullet.macros.set("\\nonumber","\\env@notag")),t.gullet.beginGroup();let m=[];const u=[m],d=[],p=[];let h;const g=[];for(g.push(it(t));;){let r=t.parseExpression(!1,s?"\\end":"\\\\");if(o&&!h)for(let e=0;e1||!a)&&u.pop(),g.length{const t=new N.MathNode("mtd",[]);return t.style={padding:"0",width:"50%"},e.envClasses.includes("multline")&&(t.style.width="7.5%"),t},ht=function(e,t){const r=[],n=e.body.length,o=e.hLinesBeforeRow;for(let s=0;s0&&(2===o[0].length?c.children.forEach((e=>{e.style.borderTop="0.15em double"})):c.children.forEach((e=>{e.style.borderTop=o[0][0]?"0.06em dashed":"0.06em solid"}))),o[s+1].length>0&&(2===o[s+1].length?c.children.forEach((e=>{e.style.borderBottom="0.15em double"})):c.children.forEach((e=>{e.style.borderBottom=o[s+1][0]?"0.06em dashed":"0.06em solid"}))),r.push(c)}if(e.envClasses.length>0){const t=e.envClasses.includes("jot")?"0.7":e.envClasses.includes("small")?"0.35":"0.5",n=e.envClasses.includes("abut")||e.envClasses.includes("cases")?"0":e.envClasses.includes("small")?"0.1389":e.envClasses.includes("cd")?"0.25":"0.4",o=0===r.length?0:r[0].children.length,s=(t,r)=>0===t&&0===r||t===o-1&&1===r?"0":"align"!==e.envClasses[0]?n:1===r?"0":e.addEqnNum?t%2?"1":"0":t%2?"0":"1";for(let e=0;e1&&e.envClasses.includes("cases")&&(n.children[1].style.padding=n.children[1].style.padding.replace(/0em$/,"1em")),e.envClasses.includes("cases")||e.envClasses.includes("subarray"))for(const e of n.children)e.classes.push("tml-left")}}else for(let e=0;e0){const t=e.cols;let r=!1,n=0,o=t.length;for(;"separator"===t[n].type;)n+=1;for(;"separator"===t[o-1].type;)o-=1;if("separator"===t[0].type){const e="separator"===t[1].type?"0.15em double":"|"===t[0].separator?"0.06em solid ":"0.06em dashed ";for(const t of s.children)t.children[0].style.borderLeft=e}let i=e.addEqnNum?0:-1;for(let e=n;e0?a:"center ")+"right "),a&&s.setAttribute("columnalign",a.trim()),e.envClasses.includes("small")&&(s=new N.MathNode("mstyle",[s]),s.setAttribute("scriptlevel","1")),s},gt=function(t,r){-1===t.envName.indexOf("ed")&<(t);const n=[],o=mt(t.parser,{cols:n,addEqnNum:"align"===t.envName||"alignat"===t.envName,emptySingleRow:!0,envClasses:["abut","jot"],maxNumCols:"split"===t.envName?2:void 0,leqno:t.parser.settings.leqno},"display");let s,a=0;const i=t.envName.indexOf("at")>-1;if(r[0]&&i){let t="";for(let e=0;e1)throw new e("{subarray} can contain only one column");let o={cols:n,envClasses:["small"]};if(o=mt(t.parser,o,"script"),o.body.length>0&&o.body[0].length>1)throw new e("{subarray} can contain only one column");return o},mathmlBuilder:ht}),rt({type:"array",names:["cases","dcases","rcases","drcases"],props:{numArgs:0},handler(e){const t=mt(e.parser,{cols:[],envClasses:["cases"]},ut(e.envName));return{type:"leftright",mode:e.mode,body:[t],left:e.envName.indexOf("r")>-1?".":"\\{",right:e.envName.indexOf("r")>-1?"\\}":".",rightColor:void 0}},mathmlBuilder:ht}),rt({type:"array",names:["align","align*","aligned","split"],props:{numArgs:0},handler:gt,mathmlBuilder:ht}),rt({type:"array",names:["alignat","alignat*","alignedat"],props:{numArgs:1},handler:gt,mathmlBuilder:ht}),rt({type:"array",names:["gathered","gather","gather*"],props:{numArgs:0},handler(e){"gathered"!==e.envName&<(e);const t={cols:[],envClasses:["abut","jot"],addEqnNum:"gather"===e.envName,emptySingleRow:!0,leqno:e.parser.settings.leqno};return mt(e.parser,t,"display")},mathmlBuilder:ht}),rt({type:"array",names:["equation","equation*"],props:{numArgs:0},handler(e){lt(e);const t={addEqnNum:"equation"===e.envName,emptySingleRow:!0,singleRow:!0,maxNumCols:1,envClasses:["align"],leqno:e.parser.settings.leqno};return mt(e.parser,t,"display")},mathmlBuilder:ht}),rt({type:"array",names:["multline","multline*"],props:{numArgs:0},handler(e){lt(e);const t={addEqnNum:"multline"===e.envName,maxNumCols:1,envClasses:["jot","multline"],leqno:e.parser.settings.leqno};return mt(e.parser,t,"display")},mathmlBuilder:ht}),rt({type:"array",names:["CD"],props:{numArgs:0},handler:t=>(lt(t),function(t){const r=[];for(t.gullet.beginGroup(),t.gullet.macros.set("\\cr","\\\\\\relax"),t.gullet.beginGroup();;){r.push(t.parseExpression(!1,"\\\\")),t.gullet.endGroup(),t.gullet.beginGroup();const n=t.fetch().text;if("&"!==n&&"\\\\"!==n){if("\\end"===n){0===r[r.length-1].length&&r.pop();break}throw new e("Expected \\\\ or \\cr or \\end",t.nextToken)}t.consume()}let n=[];const o=[n];for(let i=0;i-1);else{if(!("<>AV".indexOf(o)>-1))throw new e('Expected one of "<>AV=|." after @.');for(let t=0;t<2;t++){let n=!0;for(let c=r+1;c({type:"envTag",mode:e.mode,body:t[0]}),mathmlBuilder:(e,t)=>new N.MathNode("mrow")}),c({type:"noTag",names:["\\env@notag"],props:{numArgs:0},handler:({parser:e})=>({type:"noTag",mode:e.mode}),mathmlBuilder:(e,t)=>new N.MathNode("mrow")});const bt=(e,t)=>{const r=e.font,n=t.withFont(r),o=ce(e.body,n);if(0===o.children.length)return o;if("boldsymbol"===r&&["mo","mpadded","mrow"].includes(o.type))return o.style.fontWeight="bold",o;if(((e,t)=>{if("mathrm"!==t||"ordgroup"!==e.body.type||1===e.body.body.length)return!1;if("mathord"!==e.body.body[0].type)return!1;for(let t=1;t{const n=u(r[0]);let o=t;return o in yt&&(o=yt[o]),{type:"font",mode:e.mode,font:o.slice(1),body:n}},mathmlBuilder:bt}),c({type:"font",names:["\\rm","\\sf","\\tt","\\bf","\\it","\\cal"],props:{numArgs:0,allowedInText:!0},handler:({parser:e,funcName:t,breakOnTokenText:r},n)=>{const{mode:o}=e,s=e.parseExpression(!0,r,!0);return{type:"font",mode:o,font:`math${t.slice(1)}`,body:{type:"ordgroup",mode:e.mode,body:s}}},mathmlBuilder:bt});const xt=["display","text","script","scriptscript"],wt={auto:-1,display:0,text:0,script:1,scriptscript:2},kt=(e,t)=>{const r="auto"===e.scriptLevel?t.incrementLevel():"display"===e.scriptLevel?t.withLevel(ot):"text"===e.scriptLevel?t.withLevel(st):t.withLevel(at);let n=new N.MathNode("mfrac",[ce(e.numer,r),ce(e.denom,r)]);if(e.hasBarLine){if(e.barSize){const r=ve(e.barSize,t);n.setAttribute("linethickness",r.number+r.unit)}}else n.setAttribute("linethickness","0px");if(null!=e.leftDelim||null!=e.rightDelim){const t=[];if(null!=e.leftDelim){const r=new N.MathNode("mo",[new N.TextNode(e.leftDelim.replace("\\",""))]);r.setAttribute("fence","true"),t.push(r)}if(t.push(n),null!=e.rightDelim){const r=new N.MathNode("mo",[new N.TextNode(e.rightDelim.replace("\\",""))]);r.setAttribute("fence","true"),t.push(r)}n=se(t)}return"auto"!==e.scriptLevel&&(n=new N.MathNode("mstyle",[n]),n.setAttribute("displaystyle",String("display"===e.scriptLevel)),n.setAttribute("scriptlevel",wt[e.scriptLevel])),n};c({type:"genfrac",names:["\\dfrac","\\frac","\\tfrac","\\dbinom","\\binom","\\tbinom","\\\\atopfrac","\\\\bracefrac","\\\\brackfrac"],props:{numArgs:2,allowedInArgument:!0},handler:({parser:e,funcName:t},r)=>{const n=r[0],o=r[1];let s=!1,a=null,i=null,l="auto";switch(t){case"\\dfrac":case"\\frac":case"\\tfrac":s=!0;break;case"\\\\atopfrac":s=!1;break;case"\\dbinom":case"\\binom":case"\\tbinom":a="(",i=")";break;case"\\\\bracefrac":a="\\{",i="\\}";break;case"\\\\brackfrac":a="[",i="]";break;default:throw new Error("Unrecognized genfrac command")}switch(t){case"\\dfrac":case"\\dbinom":l="display";break;case"\\tfrac":case"\\tbinom":l="text"}return{type:"genfrac",mode:e.mode,continued:!1,numer:n,denom:o,hasBarLine:s,leftDelim:a,rightDelim:i,scriptLevel:l,barSize:null}},mathmlBuilder:kt}),c({type:"genfrac",names:["\\cfrac"],props:{numArgs:2},handler:({parser:e,funcName:t},r)=>{const n=r[0],o=r[1];return{type:"genfrac",mode:e.mode,continued:!0,numer:n,denom:o,hasBarLine:!0,leftDelim:null,rightDelim:null,scriptLevel:"display",barSize:null}}}),c({type:"infix",names:["\\over","\\choose","\\atop","\\brace","\\brack"],props:{numArgs:0,infix:!0},handler({parser:e,funcName:t,token:r}){let n;switch(t){case"\\over":n="\\frac";break;case"\\choose":n="\\binom";break;case"\\atop":n="\\\\atopfrac";break;case"\\brace":n="\\\\bracefrac";break;case"\\brack":n="\\\\brackfrac";break;default:throw new Error("Unrecognized infix genfrac command")}return{type:"infix",mode:e.mode,replaceWith:n,token:r}}});const vt=function(e){let t=null;return e.length>0&&(t=e,t="."===t?null:t),t};c({type:"genfrac",names:["\\genfrac"],props:{numArgs:6,allowedInArgument:!0,argTypes:["math","math","size","text","math","math"]},handler({parser:e},t){const r=t[4],n=t[5],o=u(t[0]),s="atom"===o.type&&"open"===o.family?vt(o.text):null,a=u(t[1]),i="atom"===a.type&&"close"===a.family?vt(a.text):null,l=Oe(t[2],"size");let c,m=null;l.isBlank?c=!0:(m=l.value,c=m.number>0);let d="auto",p=t[3];if("ordgroup"===p.type){if(p.body.length>0){const e=Oe(p.body[0],"textord");d=xt[Number(e.text)]}}else p=Oe(p,"textord"),d=xt[Number(p.text)];return{type:"genfrac",mode:e.mode,numer:r,denom:n,continued:!1,hasBarLine:c,barSize:m,leftDelim:s,rightDelim:i,scriptLevel:d}},mathmlBuilder:kt}),c({type:"infix",names:["\\above"],props:{numArgs:1,argTypes:["size"],infix:!0},handler:({parser:e,funcName:t,token:r},n)=>({type:"infix",mode:e.mode,replaceWith:"\\\\abovefrac",barSize:Oe(n[0],"size").value,token:r})}),c({type:"genfrac",names:["\\\\abovefrac"],props:{numArgs:3,argTypes:["math","size","math"]},handler:({parser:e,funcName:t},r)=>{const n=r[0],o=function(e){if(!e)throw new Error("Expected non-null, but got "+String(e));return e}(Oe(r[1],"infix").barSize),s=r[2],a=o.number>0;return{type:"genfrac",mode:e.mode,numer:n,denom:s,continued:!1,hasBarLine:a,barSize:o,leftDelim:null,rightDelim:null,scriptLevel:"auto"}},mathmlBuilder:kt}),c({type:"hbox",names:["\\hbox"],props:{numArgs:1,argTypes:["hbox"],allowedInArgument:!0,allowedInText:!1},handler:({parser:e},t)=>({type:"hbox",mode:e.mode,body:d(t[0])}),mathmlBuilder(e,t){const r=t.withLevel(ot),n=le(e.body,r);return ne(n)}});c({type:"horizBrace",names:["\\overbrace","\\underbrace"],props:{numArgs:1},handler:({parser:e,funcName:t},r)=>({type:"horizBrace",mode:e.mode,label:t,isOver:/^\\over/.test(t),base:r[0]}),mathmlBuilder:(e,t)=>{const r=B(e.label);return r.style["math-depth"]=0,new N.MathNode(e.isOver?"mover":"munder",[ce(e.base,t),r])}}),c({type:"href",names:["\\href"],props:{numArgs:2,argTypes:["url","original"],allowedInText:!0},handler:({parser:t,token:r},n)=>{const o=n[1],s=Oe(n[0],"url").url;if(!t.settings.isTrusted({command:"\\href",url:s}))throw new e('Function "\\href" is not trusted',r);return{type:"href",mode:t.mode,href:s,body:d(o)}},mathmlBuilder:(e,t)=>{let r=le(e.body,t);return r instanceof k||(r=new k("mrow",[r])),r.setAttribute("href",e.href),r}}),c({type:"href",names:["\\url"],props:{numArgs:1,argTypes:["url"],allowedInText:!0},handler:({parser:t,token:r},n)=>{const o=Oe(n[0],"url").url;if(!t.settings.isTrusted({command:"\\url",url:o}))throw new e('Function "\\url" is not trusted',r);const s=[];for(let e=0;e{const s=Oe(o[0],"raw").string,a=o[1];if(t.settings.strict)throw new e(`Function "${r}" is disabled in strict mode`,n);let i;const l={};switch(r){case"\\class":l.class=s,i={command:"\\class",class:s};break;case"\\id":l.id=s,i={command:"\\id",id:s};break;case"\\style":l.style=s,i={command:"\\style",style:s};break;case"\\data":{const t=s.split(",");for(let r=0;r{const r=le(e.body,t),n=[];e.attributes.class&&n.push(...e.attributes.class.trim().split(/\s+/)),r.classes=n;for(const t in e.attributes)"class"!==t&&Object.prototype.hasOwnProperty.call(e.attributes,t)&&r.setAttribute(t,e.attributes[t]);return r}});const At=function(t){if(/^[-+]? *(\d+(\.\d*)?|\.\d+)$/.test(t))return{number:+t,unit:"bp"};{const r=/([-+]?) *(\d+(?:\.\d*)?|\.\d+) *([a-z]{2})/.exec(t);if(!r)throw new e("Invalid size: '"+t+"' in \\includegraphics");const n={number:+(r[1]+r[2]),unit:r[3]};if(!we(n))throw new e("Invalid unit: '"+n.unit+"' in \\includegraphics.");return n}};c({type:"includegraphics",names:["\\includegraphics"],props:{numArgs:1,numOptionalArgs:1,argTypes:["raw","url"],allowedInText:!1},handler:({parser:t,token:r},n,o)=>{let s={number:0,unit:"em"},a={number:.9,unit:"em"},i={number:0,unit:"em"},l="";if(o[0]){const t=Oe(o[0],"raw").string.split(",");for(let r=0;r{const r=ve(e.height,t),n={number:0,unit:"em"};e.totalheight.number>0&&e.totalheight.unit===r.unit&&e.totalheight.number>r.number&&(n.number=e.totalheight.number-r.number,n.unit=r.unit);let o=0;e.width.number>0&&(o=ve(e.width,t));const s={height:r.number+n.number+"em"};o.number>0&&(s.width=o.number+o.unit),n.number>0&&(s.verticalAlign=-n.number+n.unit);const a=new w(e.src,e.alt,s);return a.height=r,a.depth=n,new N.MathNode("mtext",[a])}}),c({type:"kern",names:["\\kern","\\mkern","\\hskip","\\mskip"],props:{numArgs:1,argTypes:["size"],primitive:!0,allowedInText:!0},handler({parser:t,funcName:r,token:n},o){const s=Oe(o[0],"size");if(t.settings.strict){const o="m"===r[1],a="mu"===s.value.unit;if(o){if(!a)throw new e(`LaTeX's ${r} supports only mu units, not ${s.value.unit} units`,n);if("math"!==t.mode)throw new e(`LaTeX's ${r} works only in math mode`,n)}else if(a)throw new e(`LaTeX's ${r} doesn't support mu units`,n)}return{type:"kern",mode:t.mode,dimension:s.value}},mathmlBuilder(e,t){const r=ve(e.dimension,t),n="em"===r.unit?Nt(r.number):"";if("text"===e.mode&&n.length>0){const e=new N.TextNode(n);return new N.MathNode("mtext",[e])}{const e=new N.MathNode("mspace");return e.setAttribute("width",r.number+r.unit),r.number<0&&(e.style.marginLeft=r.number+r.unit),e}}});const Nt=function(e){return e>=.05555&&e<=.05556?" ":e>=.1666&&e<=.1667?" ":e>=.2222&&e<=.2223?" ":e>=.2777&&e<=.2778?"  ":""},Tt=/[^A-Za-z_0-9-]/g;c({type:"label",names:["\\label"],props:{numArgs:1,argTypes:["raw"]},handler:({parser:e},t)=>({type:"label",mode:e.mode,string:t[0].string.replace(Tt,"")}),mathmlBuilder(e,t){const r=new N.MathNode("mrow",[],["tml-label"]);return e.string.length>0&&r.setAttribute("id",e.string),r}});const qt=["\\clap","\\llap","\\rlap"];c({type:"lap",names:["\\mathllap","\\mathrlap","\\mathclap","\\clap","\\llap","\\rlap"],props:{numArgs:1,allowedInText:!0},handler:({parser:t,funcName:r,token:n},o)=>{if(qt.includes(r)){if(t.settings.strict&&"text"!==t.mode)throw new e(`{${r}} can be used only in text mode.\n Try \\math${r.slice(1)}`,n);r=r.slice(1)}else r=r.slice(5);const s=o[0];return{type:"lap",mode:t.mode,alignment:r,body:s}},mathmlBuilder:(e,t)=>{let r;if("llap"===e.alignment){const n=ie(d(e.body),t),o=new N.MathNode("mphantom",n);r=new N.MathNode("mpadded",[o]),r.setAttribute("width","0px")}const n=ce(e.body,t);let o;if("llap"===e.alignment?(n.style.position="absolute",n.style.right="0",n.style.bottom="0",o=new N.MathNode("mpadded",[r,n])):o=new N.MathNode("mpadded",[n]),"rlap"===e.alignment)e.body.body.length>0&&"genfrac"===e.body.body[0].type&&o.setAttribute("lspace","0.16667em");else{const t="llap"===e.alignment?"-1":"-0.5";o.setAttribute("lspace",t+"width"),"llap"===e.alignment?o.style.position="relative":(o.style.display="flex",o.style.justifyContent="center")}return o.setAttribute("width","0px"),o}}),c({type:"ordgroup",names:["\\(","$"],props:{numArgs:0,allowedInText:!0,allowedInMath:!1},handler({funcName:e,parser:t},r){const n=t.mode;t.switchMode("math");const o="\\("===e?"\\)":"$",s=t.parseExpression(!1,o);return t.expect(o),t.switchMode(n),{type:"ordgroup",mode:t.mode,body:s}}}),c({type:"text",names:["\\)","\\]"],props:{numArgs:0,allowedInText:!0,allowedInMath:!1},handler(t,r){throw new e(`Mismatched ${t.funcName}`,r)}});c({type:"mathchoice",names:["\\mathchoice"],props:{numArgs:4,primitive:!0},handler:({parser:e},t)=>({type:"mathchoice",mode:e.mode,display:d(t[0]),text:d(t[1]),script:d(t[2]),scriptscript:d(t[3])}),mathmlBuilder:(e,t)=>{const r=((e,t)=>{switch(t.level){case nt:return e.display;case ot:return e.text;case st:return e.script;case at:return e.scriptscript;default:return e.text}})(e,t);return le(r,t)}});const St=["text","textord","mathord","atom"],Ot=e=>{const t=new N.MathNode("mspace");return t.setAttribute("width",e+"em"),t};function Bt(e,t){let r;const n=ie(e.body,t);if("minner"===e.mclass)r=new N.MathNode("mpadded",n);else if("mord"===e.mclass)e.isCharacterBox||"mathord"===n[0].type?(r=n[0],r.type="mi",1===r.children.length&&r.children[0].text&&"∇"===r.children[0].text&&r.setAttribute("mathvariant","normal")):r=new N.MathNode("mi",n);else{r=new N.MathNode("mrow",n),e.mustPromote?(r=n[0],r.type="mo",e.isCharacterBox&&e.body[0].text&&/[A-Za-z]/.test(e.body[0].text)&&r.setAttribute("mathvariant","italic")):r=new N.MathNode("mrow",n);const o=t.level<2;"mrow"===r.type?o&&("mbin"===e.mclass?(r.children.unshift(Ot(.2222)),r.children.push(Ot(.2222))):"mrel"===e.mclass?(r.children.unshift(Ot(.2778)),r.children.push(Ot(.2778))):"mpunct"===e.mclass?r.children.push(Ot(.1667)):"minner"===e.mclass&&(r.children.unshift(Ot(.0556)),r.children.push(Ot(.0556)))):"mbin"===e.mclass?(r.attributes.lspace=o?"0.2222em":"0",r.attributes.rspace=o?"0.2222em":"0"):"mrel"===e.mclass?(r.attributes.lspace=o?"0.2778em":"0",r.attributes.rspace=o?"0.2778em":"0"):"mpunct"===e.mclass?(r.attributes.lspace="0em",r.attributes.rspace=o?"0.1667em":"0"):"mopen"===e.mclass||"mclose"===e.mclass?(r.attributes.lspace="0em",r.attributes.rspace="0em"):"minner"===e.mclass&&o&&(r.attributes.lspace="0.0556em",r.attributes.width="+0.1111em"),"mopen"!==e.mclass&&"mclose"!==e.mclass&&(delete r.attributes.stretchy,delete r.attributes.form)}return r}c({type:"mclass",names:["\\mathord","\\mathbin","\\mathrel","\\mathopen","\\mathclose","\\mathpunct","\\mathinner"],props:{numArgs:1,primitive:!0},handler({parser:e,funcName:t},r){const n=r[0],o=s.isCharacterBox(n);let a=!0;const i={type:"mathord",text:"",mode:e.mode},l=n.body?n.body:[n];for(const t of l){if(!St.includes(t.type)){a=!1;break}E[e.mode][t.text]?i.text+=E[e.mode][t.text].replace:t.text?i.text+=t.text:t.body&&t.body.map((e=>{i.text+=e.text}))}return{type:"mclass",mode:e.mode,mclass:"m"+t.slice(5),body:d(a?i:n),isCharacterBox:o,mustPromote:a}},mathmlBuilder:Bt});const Mt=e=>{const t="ordgroup"===e.type&&e.body.length?e.body[0]:e;return"atom"!==t.type||"bin"!==t.family&&"rel"!==t.family?"mord":"m"+t.family};c({type:"mclass",names:["\\@binrel"],props:{numArgs:2},handler:({parser:e},t)=>({type:"mclass",mode:e.mode,mclass:Mt(t[0]),body:d(t[1]),isCharacterBox:s.isCharacterBox(t[1])})}),c({type:"mclass",names:["\\stackrel","\\overset","\\underset"],props:{numArgs:2},handler({parser:e,funcName:t},r){const n=r[1],o=r[0],s={type:"op",mode:n.mode,limits:!0,alwaysHandleSupSub:!0,parentIsSupSub:!1,symbol:!1,stack:!0,suppressBaseShift:"\\stackrel"!==t,body:d(n)};return{type:"supsub",mode:o.mode,base:s,sup:"\\underset"===t?null:o,sub:"\\underset"===t?o:null}},mathmlBuilder:Bt});const Ct=(e,t,r)=>{if(!e)return r;const n=ce(e,t);return"mrow"===n.type&&0===n.children.length?r:n};c({type:"multiscript",names:["\\sideset","\\pres@cript"],props:{numArgs:3},handler({parser:t,funcName:r,token:n},o){if(0===o[2].body.length)throw new e(r+"cannot parse an empty base.");const s=o[2].body[0];if(t.settings.strict&&"\\sideset"===r&&!s.symbol)throw new e("The base of \\sideset must be a big operator. Try \\prescript.");if(o[0].body.length>0&&"supsub"!==o[0].body[0].type||o[1].body.length>0&&"supsub"!==o[1].body[0].type)throw new e("\\sideset can parse only subscripts and superscripts in its first two arguments",n);const a=o[0].body.length>0?o[0].body[0]:null,i=o[1].body.length>0?o[1].body[0]:null;return a||i?a?{type:"multiscript",mode:t.mode,isSideset:"\\sideset"===r,prescripts:a,postscripts:i,base:s}:{type:"styling",mode:t.mode,scriptLevel:"text",body:[{type:"supsub",mode:t.mode,base:s,sup:i.sup,sub:i.sub}]}:s},mathmlBuilder(e,t){const r=ce(e.base,t),n=new N.MathNode("mprescripts"),o=new N.MathNode("none");let s=[];const a=Ct(e.prescripts.sub,t,o),i=Ct(e.prescripts.sup,t,o);if(e.isSideset&&(a.setAttribute("style","text-align: left;"),i.setAttribute("style","text-align: left;")),e.postscripts){s=[r,Ct(e.postscripts.sub,t,o),Ct(e.postscripts.sup,t,o),n,a,i]}else s=[r,n,a,i];return new N.MathNode("mmultiscripts",s)}}),c({type:"not",names:["\\not"],props:{numArgs:1,primitive:!0,allowedInText:!1},handler({parser:e},t){const r=s.isCharacterBox(t[0]);let n;if(r)n=d(t[0]),"\\"===n[0].text.charAt(0)&&(n[0].text=E.math[n[0].text].replace),n[0].text=n[0].text.slice(0,1)+"̸"+n[0].text.slice(1);else{n=[{type:"textord",mode:"math",text:"̸"},{type:"kern",mode:"math",dimension:{number:-.6,unit:"em"}},t[0]]}return{type:"not",mode:e.mode,body:n,isCharacterBox:r}},mathmlBuilder(e,t){if(e.isCharacterBox){return ie(e.body,t,!0)[0]}return le(e.body,t)}});const zt=["textord","mathord","atom"],Et=["\\smallint"],It=["textord","mathord","ordgroup","close","leftright"],$t=e=>{e.attributes.lspace="0.1667em",e.attributes.rspace="0.1667em"},Lt=(e,t)=>{let r;if(e.symbol)r=new k("mo",[re(e.name,e.mode)]),Et.includes(e.name)?r.setAttribute("largeop","false"):r.setAttribute("movablelimits","false"),e.fromMathOp&&$t(r);else if(e.body)r=new k("mo",ie(e.body,t)),e.fromMathOp&&$t(r);else if(r=new k("mi",[new v(e.name.slice(1))]),!e.parentIsSupSub){const t=[r,new k("mo",[re("⁡","text")])];if(e.needsLeadingSpace){const e=new k("mspace");e.setAttribute("width","0.1667em"),t.unshift(e)}if(!e.isFollowedByDelimiter){const e=new k("mspace");e.setAttribute("width","0.1667em"),t.push(e)}r=new k("mrow",t)}return r},Ft={"∏":"\\prod","∐":"\\coprod","∑":"\\sum","⋀":"\\bigwedge","⋁":"\\bigvee","⋂":"\\bigcap","⋃":"\\bigcup","⨀":"\\bigodot","⨁":"\\bigoplus","⨂":"\\bigotimes","⨄":"\\biguplus","⨅":"\\bigsqcap","⨆":"\\bigsqcup","⨉":"\\bigtimes"};c({type:"op",names:["\\coprod","\\bigvee","\\bigwedge","\\biguplus","\\bigcap","\\bigcup","\\intop","\\prod","\\sum","\\bigotimes","\\bigoplus","\\bigodot","\\bigsqcap","\\bigsqcup","\\bigtimes","\\smallint","∏","∐","∑","⋀","⋁","⋂","⋃","⨀","⨁","⨂","⨄","⨆"],props:{numArgs:0},handler:({parser:e,funcName:t},r)=>{let n=t;return 1===n.length&&(n=Ft[n]),{type:"op",mode:e.mode,limits:!0,parentIsSupSub:!1,symbol:!0,stack:!1,name:n}},mathmlBuilder:Lt}),c({type:"op",names:["\\mathop"],props:{numArgs:1,primitive:!0},handler:({parser:e},t)=>{const r=t[0],n=r.body?r.body:[r],o=1===n.length&&zt.includes(n[0].type);return{type:"op",mode:e.mode,limits:!0,parentIsSupSub:!1,symbol:o,fromMathOp:!0,stack:!1,name:o?n[0].text:null,body:o?null:d(r)}},mathmlBuilder:Lt});const Gt={"∫":"\\int","∬":"\\iint","∭":"\\iiint","∮":"\\oint","∯":"\\oiint","∰":"\\oiiint","∱":"\\intclockwise","∲":"\\varointclockwise","⨌":"\\iiiint","⨍":"\\intbar","⨎":"\\intBar","⨏":"\\fint","⨒":"\\rppolint","⨓":"\\scpolint","⨕":"\\pointint","⨖":"\\sqint","⨗":"\\intlarhk","⨘":"\\intx","⨙":"\\intcap","⨚":"\\intcup"};c({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,n=e.gullet.future().text;return{type:"op",mode:e.mode,limits:!1,parentIsSupSub:!1,symbol:!1,stack:!1,isFollowedByDelimiter:Ye(n),needsLeadingSpace:r.length>0&&It.includes(r),name:t}},mathmlBuilder:Lt}),c({type:"op",names:["\\det","\\gcd","\\inf","\\lim","\\max","\\min","\\Pr","\\sup"],props:{numArgs:0},handler({parser:e,funcName:t}){const r=e.prevAtomType,n=e.gullet.future().text;return{type:"op",mode:e.mode,limits:!0,parentIsSupSub:!1,symbol:!1,stack:!1,isFollowedByDelimiter:Ye(n),needsLeadingSpace:r.length>0&&It.includes(r),name:t}},mathmlBuilder:Lt}),c({type:"op",names:["\\int","\\iint","\\iiint","\\iiiint","\\oint","\\oiint","\\oiiint","\\intclockwise","\\varointclockwise","\\intbar","\\intBar","\\fint","\\rppolint","\\scpolint","\\pointint","\\sqint","\\intlarhk","\\intx","\\intcap","\\intcup","∫","∬","∭","∮","∯","∰","∱","∲","⨌","⨍","⨎","⨏","⨒","⨓","⨕","⨖","⨗","⨘","⨙","⨚"],props:{numArgs:0},handler({parser:e,funcName:t}){let r=t;return 1===r.length&&(r=Gt[r]),{type:"op",mode:e.mode,limits:!1,parentIsSupSub:!1,symbol:!0,stack:!1,name:r}},mathmlBuilder:Lt});const Dt={};function Pt(e,t){Dt[e]=t}c({type:"operatorname",names:["\\operatorname@","\\operatornamewithlimits"],props:{numArgs:1,allowedInArgument:!0},handler:({parser:e,funcName:t},r)=>{const n=r[0],o=e.prevAtomType,s=e.gullet.future().text;return{type:"operatorname",mode:e.mode,body:d(n),alwaysHandleSupSub:"\\operatornamewithlimits"===t,limits:!1,parentIsSupSub:!1,isFollowedByDelimiter:Ye(s),needsLeadingSpace:o.length>0&&It.includes(o)}},mathmlBuilder:(e,t)=>{let r,n=ie(e.body,t.withFont("mathrm")),o=!0;for(let e=0;ee.toText())).join("");n=[new N.TextNode(e)]}else if(1===n.length&&["mover","munder"].includes(n[0].type)&&("mi"===n[0].children[0].type||"mtext"===n[0].children[0].type)){if(n[0].children[0].type="mi",e.parentIsSupSub)return new N.MathNode("mrow",n);{const e=new N.MathNode("mo",[re("⁡","text")]);return N.newDocumentFragment([n[0],e])}}if(o?(r=new N.MathNode("mi",n),1===n[0].text.length&&r.setAttribute("mathvariant","normal")):r=new N.MathNode("mrow",n),!e.parentIsSupSub){const t=[r,new N.MathNode("mo",[re("⁡","text")])];if(e.needsLeadingSpace){const e=new N.MathNode("mspace");e.setAttribute("width","0.1667em"),t.unshift(e)}if(!e.isFollowedByDelimiter){const e=new N.MathNode("mspace");e.setAttribute("width","0.1667em"),t.push(e)}return N.newDocumentFragment(t)}return r}}),Pt("\\operatorname","\\@ifstar\\operatornamewithlimits\\operatorname@"),m({type:"ordgroup",mathmlBuilder:(e,t)=>le(e.body,t,e.semisimple)}),c({type:"phantom",names:["\\phantom"],props:{numArgs:1,allowedInText:!0},handler:({parser:e},t)=>{const r=t[0];return{type:"phantom",mode:e.mode,body:d(r)}},mathmlBuilder:(e,t)=>{const r=ie(e.body,t);return new N.MathNode("mphantom",r)}}),c({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=ie(d(e.body),t),n=new N.MathNode("mphantom",r),o=new N.MathNode("mpadded",[n]);return o.setAttribute("height","0px"),o.setAttribute("depth","0px"),o}}),c({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=ie(d(e.body),t),n=new N.MathNode("mphantom",r),o=new N.MathNode("mpadded",[n]);return o.setAttribute("width","0px"),o}}),c({type:"pmb",names:["\\pmb"],props:{numArgs:1,allowedInText:!0},handler:({parser:e},t)=>({type:"pmb",mode:e.mode,body:d(t[0])}),mathmlBuilder(e,t){const r=ie(e.body,t),n=A(r);return n.setAttribute("style","font-weight:bold"),n}});const Rt=(e,t)=>{const r=t.withLevel(ot),n=new N.MathNode("mpadded",[ce(e.body,r)]),o=ve(e.dy,t);return n.setAttribute("voffset",o.number+o.unit),o.number>0?n.style.padding=o.number+o.unit+" 0 0 0":n.style.padding="0 0 "+Math.abs(o.number)+o.unit+" 0",n};c({type:"raise",names:["\\raise","\\lower"],props:{numArgs:2,argTypes:["size","primitive"],primitive:!0},handler({parser:e,funcName:t},r){const n=Oe(r[0],"size").value;"\\lower"===t&&(n.number*=-1);const o=r[1];return{type:"raise",mode:e.mode,dy:n,body:o}},mathmlBuilder:Rt}),c({type:"raise",names:["\\raisebox"],props:{numArgs:2,argTypes:["size","hbox"],allowedInText:!0},handler({parser:e,funcName:t},r){const n=Oe(r[0],"size").value,o=r[1];return{type:"raise",mode:e.mode,dy:n,body:o}},mathmlBuilder:Rt}),c({type:"ref",names:["\\ref","\\eqref"],props:{numArgs:1,argTypes:["raw"]},handler:({parser:e,funcName:t},r)=>({type:"ref",mode:e.mode,funcName:t,string:r[0].string.replace(Tt,"")}),mathmlBuilder(e,t){const r="\\ref"===e.funcName?["tml-ref"]:["tml-ref","tml-eqref"],n=new N.MathNode("mtext",[new N.TextNode("")],r);return n.setAttribute("href","#"+e.string),n}}),c({type:"reflect",names:["\\reflectbox"],props:{numArgs:1,argTypes:["hbox"],allowedInText:!0},handler:({parser:e},t)=>({type:"reflect",mode:e.mode,body:t[0]}),mathmlBuilder(e,t){const r=ce(e.body,t);return r.style.transform="scaleX(-1)",r}}),c({type:"internal",names:["\\relax"],props:{numArgs:0,allowedInText:!0},handler:({parser:e})=>({type:"internal",mode:e.mode})}),c({type:"rule",names:["\\rule"],props:{numArgs:2,numOptionalArgs:1,argTypes:["size","size","size"]},handler({parser:e},t,r){const n=r[0],o=Oe(t[0],"size"),s=Oe(t[1],"size");return{type:"rule",mode:e.mode,shift:n&&Oe(n,"size").value,width:o.value,height:s.value}},mathmlBuilder(e,t){const r=ve(e.width,t),n=ve(e.height,t),o=e.shift?ve(e.shift,t):{number:0,unit:"em"},s=t.color&&t.getColor()||"black",a=new N.MathNode("mspace");if(r.number>0&&n.number>0&&a.setAttribute("mathbackground",s),a.setAttribute("width",r.number+r.unit),a.setAttribute("height",n.number+n.unit),0===o.number)return a;const i=new N.MathNode("mpadded",[a]);return o.number>=0?i.setAttribute("height","+"+o.number+o.unit):(i.setAttribute("height",o.number+o.unit),i.setAttribute("depth","+"+-o.number+o.unit)),i.setAttribute("voffset",o.number+o.unit),i}});const jt={"\\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};c({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},n)=>{r.settings.strict&&"math"===r.mode&&console.log(`Temml strict-mode warning: Command ${t} is invalid in math mode.`);const o=r.parseExpression(!1,e,!0);return{type:"sizing",mode:r.mode,funcName:t,body:o}},mathmlBuilder:(e,t)=>{const r=t.withFontSize(jt[e.funcName]),n=ie(e.body,r),o=A(n),s=(jt[e.funcName]/t.fontSize).toFixed(4);return o.setAttribute("mathsize",s+"em"),o}}),c({type:"smash",names:["\\smash"],props:{numArgs:1,numOptionalArgs:1,allowedInText:!0},handler:({parser:e},t,r)=>{let n=!1,o=!1;const s=r[0]&&Oe(r[0],"ordgroup");if(s){let e="";for(let t=0;t{const r=new N.MathNode("mpadded",[ce(e.body,t)]);return e.smashHeight&&r.setAttribute("height","0px"),e.smashDepth&&r.setAttribute("depth","0px"),r}}),c({type:"sqrt",names:["\\sqrt"],props:{numArgs:1,numOptionalArgs:1},handler({parser:e},t,r){const n=r[0],o=t[0];return{type:"sqrt",mode:e.mode,body:o,index:n}},mathmlBuilder(e,t){const{body:r,index:n}=e;return n?new N.MathNode("mroot",[ce(r,t),ce(n,t.incrementLevel())]):new N.MathNode("msqrt",[ce(r,t)])}});const Ut={display:0,text:1,script:2,scriptscript:3},Ht={display:["0","true"],text:["0","false"],script:["1","false"],scriptscript:["2","false"]};c({type:"styling",names:["\\displaystyle","\\textstyle","\\scriptstyle","\\scriptscriptstyle"],props:{numArgs:0,allowedInText:!0,primitive:!0},handler({breakOnTokenText:e,funcName:t,parser:r},n){const o=r.parseExpression(!0,e,!0),s=t.slice(1,t.length-5);return{type:"styling",mode:r.mode,scriptLevel:s,body:o}},mathmlBuilder(e,t){const r=t.withLevel(Ut[e.scriptLevel]),n=ie(e.body,r),o=A(n),s=Ht[e.scriptLevel];return o.setAttribute("scriptlevel",s[0]),o.setAttribute("displaystyle",s[1]),o}});const Vt=/^m(over|under|underover)$/;m({type:"supsub",mathmlBuilder(e,t){let r,n,o=!1,s=!1,a=!1,i=!1;e.base&&"horizBrace"===e.base.type&&(n=!!e.sup,n===e.base.isOver&&(o=!0,r=e.base.isOver)),!e.base||e.base.stack||"op"!==e.base.type&&"operatorname"!==e.base.type||(e.base.parentIsSupSub=!0,s=!e.base.symbol,a=s&&!e.isFollowedByDelimiter,i=e.base.needsLeadingSpace);const l=e.base&&e.base.stack?[ce(e.base.body[0],t)]:[ce(e.base,t)],c=t.inSubOrSup();if(e.sub&&l.push(ce(e.sub,c)),e.sup){const t=ce(e.sup,c),r="mrow"===t.type?t.children[0]:t;"mo"===r.type&&r.classes.includes("tml-prime")&&e.base&&e.base.text&&"f"===e.base.text&&r.classes.push("prime-pad"),l.push(t)}let m;if(o)m=r?"mover":"munder";else if(e.sub)if(e.sup){const r=e.base;m=r&&("op"===r.type&&r.limits||"multiscript"===r.type)&&(t.level===nt||r.alwaysHandleSupSub)||r&&"operatorname"===r.type&&r.alwaysHandleSupSub&&(t.level===nt||r.limits)?"munderover":"msubsup"}else{const r=e.base;m=r&&"op"===r.type&&r.limits&&(t.level===nt||r.alwaysHandleSupSub)||r&&"operatorname"===r.type&&r.alwaysHandleSupSub&&(r.limits||t.level===nt)?"munder":"msub"}else{const r=e.base;m=r&&"op"===r.type&&r.limits&&(t.level===nt||r.alwaysHandleSupSub)||r&&"operatorname"===r.type&&r.alwaysHandleSupSub&&(r.limits||t.level===nt)?"mover":"msup"}let u=new N.MathNode(m,l);if(s){const e=new N.MathNode("mo",[re("⁡","text")]);if(i){const t=new N.MathNode("mspace");t.setAttribute("width","0.1667em"),u=N.newDocumentFragment([t,u,e])}else u=N.newDocumentFragment([u,e]);if(a){const e=new N.MathNode("mspace");e.setAttribute("width","0.1667em"),u.children.push(e)}}else Vt.test(m)&&(u=new N.MathNode("mrow",[u]));return u}});const _t=["\\shortmid","\\nshortmid","\\shortparallel","\\nshortparallel","\\smallsetminus"],Wt=["\\Rsh","\\Lsh","\\restriction"];m({type:"atom",mathmlBuilder(e,t){const r=new N.MathNode("mo",[re(e.text,e.mode)]);return"punct"===e.family?r.setAttribute("separator","true"):"open"===e.family||"close"===e.family?"open"===e.family?(r.setAttribute("form","prefix"),r.setAttribute("stretchy","false")):"close"===e.family&&(r.setAttribute("form","postfix"),r.setAttribute("stretchy","false")):"\\mid"===e.text?(r.setAttribute("lspace","0.22em"),r.setAttribute("rspace","0.22em"),r.setAttribute("stretchy","false")):"rel"===e.family&&(e=>{if(1===e.length){const t=e.codePointAt(0);return 8591-1||e.indexOf("harpoon")>-1||Wt.includes(e)})(e.text)?r.setAttribute("stretchy","false"):_t.includes(e.text)?r.setAttribute("mathsize","70%"):":"===e.text&&(r.attributes.lspace="0.2222em",r.attributes.rspace="0.2222em"),r}});const Xt={mathbf:"bold",mathrm:"normal",textit:"italic",mathit:"italic",mathnormal:"italic",mathbb:"double-struck",mathcal:"script",mathfrak:"fraktur",mathscr:"script",mathsf:"sans-serif",mathtt:"monospace"},Zt=function(e,t){if("texttt"===t.fontFamily)return"monospace";if("textsc"===t.fontFamily)return"normal";if("textsf"===t.fontFamily)return"textit"===t.fontShape&&"textbf"===t.fontWeight?"sans-serif-bold-italic":"textit"===t.fontShape?"sans-serif-italic":"textbf"===t.fontWeight?"sans-serif-bold":"sans-serif";if("textit"===t.fontShape&&"textbf"===t.fontWeight)return"bold-italic";if("textit"===t.fontShape)return"italic";if("textbf"===t.fontWeight)return"bold";const r=t.font;if(!r||"mathnormal"===r)return null;const n=e.mode;switch(r){case"mathit":case"greekItalic":return"italic";case"mathrm":{const t=e.text.codePointAt(0);return 9390,bold:e=>119743,italic:e=>119795,"bold-italic":e=>119847,script:e=>Yt[e]||119899,"script-bold":e=>119951,fraktur:e=>Kt[e]||120003,"fraktur-bold":e=>120107,"double-struck":e=>Jt[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=>"h"===e?8358:119789,"bold-italic":e=>119841,script:e=>Yt[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=>Qt[e]||-51,italic:e=>0,"bold-italic":e=>er[e]||58,script:e=>0,"script-bold":e=>0,fraktur:e=>0,"fraktur-bold":e=>0,"double-struck":e=>0,"sans-serif":e=>tr[e]||116,"sans-serif-bold":e=>tr[e]||116,"sans-serif-italic":e=>0,"sans-serif-bold-italic":e=>rr[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}}),or=(e,t)=>{const r=e.codePointAt(0),n=64{const n=new N.MathNode(r,[e]),o=new N.MathNode("mstyle",[n]);return o.style["font-style"]="italic",o.style["font-family"]="Cambria, 'Times New Roman', serif","bold-italic"===t&&(o.style["font-weight"]="bold"),o})(o,s,t);"normal"!==s&&(o.text=o.text.split("").map((e=>or(e,s))).join("")),a=new N.MathNode(t,[o])}else if("text"===e.mode)"normal"!==s&&(o.text=or(o.text,s)),a=new N.MathNode("mtext",[o]);else if(lr.has(e.text))a=new N.MathNode("mo",[o]),a.classes.push("tml-prime");else{const e=o.text;"italic"!==s&&(o.text=or(o.text,s)),a=new N.MathNode("mi",[o]),o.text===e&&ir.test(e)&&a.setAttribute("mathvariant","italic")}return a}});const cr={"\\nobreak":"nobreak","\\allowbreak":"allowbreak"},mr={" ":{},"\\ ":{},"~":{className:"nobreak"},"\\space":{},"\\nobreakspace":{className:"nobreak"}};m({type:"spacing",mathmlBuilder(t,r){let n;if(Object.prototype.hasOwnProperty.call(mr,t.text))n=new N.MathNode("mtext",[new N.TextNode(" ")]);else{if(!Object.prototype.hasOwnProperty.call(cr,t.text))throw new e(`Unknown type of space "${t.text}"`);n=new N.MathNode("mo"),"\\nobreak"===t.text&&n.setAttribute("linebreak","nobreak")}return n}}),m({type:"tag"});const ur={"\\text":void 0,"\\textrm":"textrm","\\textsf":"textsf","\\texttt":"texttt","\\textnormal":"textrm","\\textsc":"textsc"},dr={"\\textbf":"textbf","\\textmd":"textmd"},pr={"\\textit":"textit","\\textup":"textup"};c({type:"text",names:["\\text","\\textrm","\\textsf","\\texttt","\\textnormal","\\textsc","\\textbf","\\textmd","\\textit","\\textup"],props:{numArgs:1,argTypes:["text"],allowedInArgument:!0,allowedInText:!0},handler({parser:e,funcName:t},r){const n=r[0];return{type:"text",mode:e.mode,body:d(n),font:t}},mathmlBuilder(e,t){const r=((e,t)=>{const r=e.font;return r?ur[r]?t.withTextFontFamily(ur[r]):dr[r]?t.withTextFontWeight(dr[r]):t.withTextFontShape(pr[r]):t})(e,t),n=le(e.body,r);return ne(n)}}),c({type:"verb",names:["\\verb"],props:{numArgs:0,allowedInText:!0},handler(t,r,n){throw new e("\\verb ended by end of line instead of matching delimiter")},mathmlBuilder(e,t){const r=new N.TextNode(hr(e)),n=new N.MathNode("mtext",[r]);return n.setAttribute("mathvariant","monospace"),n}});const hr=e=>e.body.replace(/ /g,e.star?"␣":" "),gr=i;class fr{constructor(e,t,r){this.lexer=e,this.start=t,this.end=r}static range(e,t){return t?e&&e.loc&&t.loc&&e.loc.lexer===t.loc.lexer?new fr(e.loc.lexer,e.loc.start,t.loc.end):null:e&&e.loc}}class br{constructor(e,t){this.text=e,this.loc=t}range(e,t){return new br(t,fr.range(this,e))}}const yr="[ \r\n\t]",xr=`(\\\\[a-zA-Z@]+)${yr}*`,wr="[̀-ͯ]",kr=new RegExp(`${wr}+$`),vr=`(${yr}+)|\\\\(\n|[ \r\t]+\n?)[ \r\t]*|([!-\\[\\]-‧‪-퟿豈-￿]${wr}*|[\ud800-\udbff][\udc00-\udfff]${wr}*|\\\\verb\\*([^]).*?\\4|\\\\verb([^*a-zA-Z]).*?\\5|${xr}|\\\\[^\ud800-\udfff])`;class Ar{constructor(e,t){this.input=e,this.settings=t,this.tokenRegex=new RegExp(vr,"g"),this.catcodes={"%":14,"~":13}}setCatcode(e,t){this.catcodes[e]=t}lex(){const t=this.input,r=this.tokenRegex.lastIndex;if(r===t.length)return new br("EOF",new fr(this,r,r));const n=this.tokenRegex.exec(t);if(null===n||n.index!==r)throw new e(`Unexpected character: '${t[r]}'`,new br(t[r],new fr(this,r,r+1)));const o=n[6]||n[3]||(n[2]?"\\ ":" ");if(14===this.catcodes[o]){const r=t.indexOf("\n",this.tokenRegex.lastIndex);if(-1===r){if(this.tokenRegex.lastIndex=t.length,this.settings.strict)throw new e("% comment has no terminating newline; LaTeX would fail because of commenting the end of math mode")}else this.tokenRegex.lastIndex=r+1;return this.lex()}return new br(o,new fr(this,r,this.tokenRegex.lastIndex))}}class Nr{constructor(e={},t={}){this.current=t,this.builtins=e,this.undefStack=[]}beginGroup(){this.undefStack.push({})}endGroup(){if(0===this.undefStack.length)throw new e("Unbalanced namespace destruction: attempt to pop global namespace; please report this as a bug");const t=this.undefStack.pop();for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&(void 0===t[e]?delete this.current[e]:this.current[e]=t[e])}has(e){return Object.prototype.hasOwnProperty.call(this.current,e)||Object.prototype.hasOwnProperty.call(this.builtins,e)}get(e){return Object.prototype.hasOwnProperty.call(this.current,e)?this.current[e]:this.builtins[e]}set(e,t,r=!1){if(r){for(let t=0;t0&&(this.undefStack[this.undefStack.length-1][e]=t)}else{const t=this.undefStack[this.undefStack.length-1];t&&!Object.prototype.hasOwnProperty.call(t,e)&&(t[e]=this.current[e])}this.current[e]=t}}const Tr=Dt;Pt("\\noexpand",(function(e){const t=e.popToken();return e.isExpandable(t.text)&&(t.noexpand=!0,t.treatAsRelax=!0),{tokens:[t],numArgs:0}})),Pt("\\expandafter",(function(e){const t=e.popToken();return e.expandOnce(!0),{tokens:[t],numArgs:0}})),Pt("\\@firstoftwo",(function(e){return{tokens:e.consumeArgs(2)[0],numArgs:0}})),Pt("\\@secondoftwo",(function(e){return{tokens:e.consumeArgs(2)[1],numArgs:0}})),Pt("\\@ifnextchar",(function(e){const t=e.consumeArgs(3);e.consumeSpaces();const r=e.future();return 1===t[0].length&&t[0][0].text===r.text?{tokens:t[1],numArgs:0}:{tokens:t[2],numArgs:0}})),Pt("\\@ifstar","\\@ifnextchar *{\\@firstoftwo{#1}}"),Pt("\\TextOrMath",(function(e){const t=e.consumeArgs(2);return"text"===e.mode?{tokens:t[0],numArgs:0}:{tokens:t[1],numArgs:0}}));const qr={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},Sr=e=>{const t=e.future().text;return"EOF"===t?[null,""]:[qr[t.charAt(0)],t]},Or=(e,t,r)=>{for(let n=1;n=0;e--){const o=t[e].loc.start;o>n&&(r+=" ",n=o),r+=t[e].text,n+=t[e].text.length}return r}Pt("\\char",(function(t){let r,n=t.popToken(),o="";if("'"===n.text)r=8,n=t.popToken();else if('"'===n.text)r=16,n=t.popToken();else if("`"===n.text)if(n=t.popToken(),"\\"===n.text[0])o=n.text.charCodeAt(1);else{if("EOF"===n.text)throw new e("\\char` missing argument");o=n.text.charCodeAt(0)}else r=10;if(r){let s,a=n.text;if(o=qr[a.charAt(0)],null==o||o>=r)throw new e(`Invalid base-${r} digit ${n.text}`);for(o=Or(o,a,r),[s,a]=Sr(t);null!=s&&s":"\\dotsb","-":"\\dotsb","*":"\\dotsb",":":"\\dotsb","\\DOTSB":"\\dotsb","\\coprod":"\\dotsb","\\bigvee":"\\dotsb","\\bigwedge":"\\dotsb","\\biguplus":"\\dotsb","\\bigcap":"\\dotsb","\\bigcup":"\\dotsb","\\prod":"\\dotsb","\\sum":"\\dotsb","\\bigotimes":"\\dotsb","\\bigoplus":"\\dotsb","\\bigodot":"\\dotsb","\\bigsqcap":"\\dotsb","\\bigsqcup":"\\dotsb","\\bigtimes":"\\dotsb","\\And":"\\dotsb","\\longrightarrow":"\\dotsb","\\Longrightarrow":"\\dotsb","\\longleftarrow":"\\dotsb","\\Longleftarrow":"\\dotsb","\\longleftrightarrow":"\\dotsb","\\Longleftrightarrow":"\\dotsb","\\mapsto":"\\dotsb","\\longmapsto":"\\dotsb","\\hookrightarrow":"\\dotsb","\\doteq":"\\dotsb","\\mathbin":"\\dotsb","\\mathrel":"\\dotsb","\\relbar":"\\dotsb","\\Relbar":"\\dotsb","\\xrightarrow":"\\dotsb","\\xleftarrow":"\\dotsb","\\DOTSI":"\\dotsi","\\int":"\\dotsi","\\oint":"\\dotsi","\\iint":"\\dotsi","\\iiint":"\\dotsi","\\iiiint":"\\dotsi","\\idotsint":"\\dotsi","\\DOTSX":"\\dotsx"};Pt("\\dots",(function(e){let t="\\dotso";const r=e.expandAfterFuture().text;return r in Mr?t=Mr[r]:("\\not"===r.slice(0,4)||r in E.math&&["bin","rel"].includes(E.math[r].group))&&(t="\\dotsb"),t}));const Cr={")":!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};Pt("\\dotso",(function(e){return e.future().text in Cr?"\\ldots\\,":"\\ldots"})),Pt("\\dotsc",(function(e){const t=e.future().text;return t in Cr&&","!==t?"\\ldots\\,":"\\ldots"})),Pt("\\cdots",(function(e){return e.future().text in Cr?"\\@cdots\\,":"\\@cdots"})),Pt("\\dotsb","\\cdots"),Pt("\\dotsm","\\cdots"),Pt("\\dotsi","\\!\\cdots"),Pt("\\idotsint","\\dotsi"),Pt("\\dotsx","\\ldots\\,"),Pt("\\DOTSI","\\relax"),Pt("\\DOTSB","\\relax"),Pt("\\DOTSX","\\relax"),Pt("\\tmspace","\\TextOrMath{\\kern#1#3}{\\mskip#1#2}\\relax"),Pt("\\,","{\\tmspace+{3mu}{.1667em}}"),Pt("\\thinspace","\\,"),Pt("\\>","\\mskip{4mu}"),Pt("\\:","{\\tmspace+{4mu}{.2222em}}"),Pt("\\medspace","\\:"),Pt("\\;","{\\tmspace+{5mu}{.2777em}}"),Pt("\\thickspace","\\;"),Pt("\\!","{\\tmspace-{3mu}{.1667em}}"),Pt("\\negthinspace","\\!"),Pt("\\negmedspace","{\\tmspace-{4mu}{.2222em}}"),Pt("\\negthickspace","{\\tmspace-{5mu}{.277em}}"),Pt("\\enspace","\\kern.5em "),Pt("\\enskip","\\hskip.5em\\relax"),Pt("\\quad","\\hskip1em\\relax"),Pt("\\qquad","\\hskip2em\\relax"),Pt("\\AA","\\TextOrMath{\\Angstrom}{\\mathring{A}}\\relax"),Pt("\\tag","\\@ifstar\\tag@literal\\tag@paren"),Pt("\\tag@paren","\\tag@literal{({#1})}"),Pt("\\tag@literal",(t=>{if(t.macros.get("\\df@tag"))throw new e("Multiple \\tag");return"\\def\\df@tag{\\text{#1}}"})),Pt("\\bmod","\\mathbin{\\text{mod}}"),Pt("\\pod","\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern8mu}{\\mkern8mu}{\\mkern8mu}(#1)"),Pt("\\pmod","\\pod{{\\rm mod}\\mkern6mu#1}"),Pt("\\mod","\\allowbreak\\mathchoice{\\mkern18mu}{\\mkern12mu}{\\mkern12mu}{\\mkern12mu}{\\rm mod}\\,\\,#1"),Pt("\\newline","\\\\\\relax"),Pt("\\TeX","\\textrm{T}\\kern-.1667em\\raisebox{-.5ex}{E}\\kern-.125em\\textrm{X}"),Pt("\\LaTeX","\\textrm{L}\\kern-.35em\\raisebox{0.2em}{\\scriptstyle A}\\kern-.15em\\TeX"),Pt("\\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}}"),Pt("\\hspace","\\@ifstar\\@hspacer\\@hspace"),Pt("\\@hspace","\\hskip #1\\relax"),Pt("\\@hspacer","\\rule{0pt}{0pt}\\hskip #1\\relax"),Pt("\\colon",'\\mathpunct{\\char"3a}'),Pt("\\prescript","\\pres@cript{_{#1}^{#2}}{}{#3}"),Pt("\\ordinarycolon",'\\char"3a'),Pt("\\vcentcolon","\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}}"),Pt("\\coloneq",'\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}\\char"2212}'),Pt("\\Coloneq",'\\mathrel{\\char"2237\\char"2212}'),Pt("\\Eqqcolon",'\\mathrel{\\char"3d\\char"2237}'),Pt("\\Eqcolon",'\\mathrel{\\char"2212\\char"2237}'),Pt("\\colonapprox",'\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}\\char"2248}'),Pt("\\Colonapprox",'\\mathrel{\\char"2237\\char"2248}'),Pt("\\colonsim",'\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}\\char"223c}'),Pt("\\Colonsim",'\\mathrel{\\raisebox{0.035em}{\\ordinarycolon}\\char"223c}'),Pt("\\ratio","\\vcentcolon"),Pt("\\coloncolon","\\dblcolon"),Pt("\\colonequals","\\coloneqq"),Pt("\\coloncolonequals","\\Coloneqq"),Pt("\\equalscolon","\\eqqcolon"),Pt("\\equalscoloncolon","\\Eqqcolon"),Pt("\\colonminus","\\coloneq"),Pt("\\coloncolonminus","\\Coloneq"),Pt("\\minuscolon","\\eqcolon"),Pt("\\minuscoloncolon","\\Eqcolon"),Pt("\\coloncolonapprox","\\Colonapprox"),Pt("\\coloncolonsim","\\Colonsim"),Pt("\\notni","\\mathrel{\\char`∌}"),Pt("\\limsup","\\DOTSB\\operatorname*{lim\\,sup}"),Pt("\\liminf","\\DOTSB\\operatorname*{lim\\,inf}"),Pt("\\injlim","\\DOTSB\\operatorname*{inj\\,lim}"),Pt("\\projlim","\\DOTSB\\operatorname*{proj\\,lim}"),Pt("\\varlimsup","\\DOTSB\\operatorname*{\\overline{\\text{lim}}}"),Pt("\\varliminf","\\DOTSB\\operatorname*{\\underline{\\text{lim}}}"),Pt("\\varinjlim","\\DOTSB\\operatorname*{\\underrightarrow{\\text{lim}}}"),Pt("\\varprojlim","\\DOTSB\\operatorname*{\\underleftarrow{\\text{lim}}}"),Pt("\\centerdot","{\\medspace\\rule{0.167em}{0.189em}\\medspace}"),Pt("\\argmin","\\DOTSB\\operatorname*{arg\\,min}"),Pt("\\argmax","\\DOTSB\\operatorname*{arg\\,max}"),Pt("\\plim","\\DOTSB\\operatorname*{plim}"),Pt("\\leftmodels","\\mathop{\\reflectbox{$\\models$}}"),Pt("\\bra","\\mathinner{\\langle{#1}|}"),Pt("\\ket","\\mathinner{|{#1}\\rangle}"),Pt("\\braket","\\mathinner{\\langle{#1}\\rangle}"),Pt("\\Bra","\\left\\langle#1\\right|"),Pt("\\Ket","\\left|#1\\right\\rangle");const zr=(e,t)=>{const r=`}\\,\\middle${"|"===t[0]?"\\vert":"\\Vert"}\\,{`;return e.slice(0,t.index)+r+e.slice(t.index+t[0].length)};Pt("\\Braket",(function(e){let t=Br(e);const r=/\|\||\||\\\|/g;let n;for(;null!==(n=r.exec(t));)t=zr(t,n);return"\\left\\langle{"+t+"}\\right\\rangle"})),Pt("\\Set",(function(e){let t=Br(e);const r=/\|\||\||\\\|/.exec(t);return r&&(t=zr(t,r)),"\\left\\{\\:{"+t+"}\\:\\right\\}"})),Pt("\\set",(function(e){return"\\{{"+Br(e).replace(/\|/,"}\\mid{")+"}\\}"})),Pt("\\angln","{\\angl n}"),Pt("\\odv","\\@ifstar\\odv@next\\odv@numerator"),Pt("\\odv@numerator","\\frac{\\mathrm{d}#1}{\\mathrm{d}#2}"),Pt("\\odv@next","\\frac{\\mathrm{d}}{\\mathrm{d}#2}#1"),Pt("\\pdv","\\@ifstar\\pdv@next\\pdv@numerator");const Er=e=>{const t=e[0][0].text,r=(e=>{let t="";for(let r=e.length-1;r>-1;r--)t+=e[r].text;return t})(e[1]).split(","),n=String(r.length),o="1"===n?"\\partial":`\\partial^${n}`;let s="";return r.map((e=>{s+="\\partial "+e.trim()+"\\,"})),[t,o,s.replace(/\\,$/,"")]};Pt("\\pdv@numerator",(function(e){const[t,r,n]=Er(e.consumeArgs(2));return`\\frac{${r} ${t}}{${n}}`})),Pt("\\pdv@next",(function(e){const[t,r,n]=Er(e.consumeArgs(2));return`\\frac{${r}}{${n}} ${t}`})),Pt("\\upalpha","\\up@greek{\\alpha}"),Pt("\\upbeta","\\up@greek{\\beta}"),Pt("\\upgamma","\\up@greek{\\gamma}"),Pt("\\updelta","\\up@greek{\\delta}"),Pt("\\upepsilon","\\up@greek{\\epsilon}"),Pt("\\upzeta","\\up@greek{\\zeta}"),Pt("\\upeta","\\up@greek{\\eta}"),Pt("\\uptheta","\\up@greek{\\theta}"),Pt("\\upiota","\\up@greek{\\iota}"),Pt("\\upkappa","\\up@greek{\\kappa}"),Pt("\\uplambda","\\up@greek{\\lambda}"),Pt("\\upmu","\\up@greek{\\mu}"),Pt("\\upnu","\\up@greek{\\nu}"),Pt("\\upxi","\\up@greek{\\xi}"),Pt("\\upomicron","\\up@greek{\\omicron}"),Pt("\\uppi","\\up@greek{\\pi}"),Pt("\\upalpha","\\up@greek{\\alpha}"),Pt("\\uprho","\\up@greek{\\rho}"),Pt("\\upsigma","\\up@greek{\\sigma}"),Pt("\\uptau","\\up@greek{\\tau}"),Pt("\\upupsilon","\\up@greek{\\upsilon}"),Pt("\\upphi","\\up@greek{\\phi}"),Pt("\\upchi","\\up@greek{\\chi}"),Pt("\\uppsi","\\up@greek{\\psi}"),Pt("\\upomega","\\up@greek{\\omega}"),Pt("\\invamp",'\\mathbin{\\char"214b}'),Pt("\\parr",'\\mathbin{\\char"214b}'),Pt("\\with",'\\mathbin{\\char"26}'),Pt("\\multimapinv",'\\mathrel{\\char"27dc}'),Pt("\\multimapboth",'\\mathrel{\\char"29df}'),Pt("\\scoh",'{\\mkern5mu\\char"2322\\mkern5mu}'),Pt("\\sincoh",'{\\mkern5mu\\char"2323\\mkern5mu}'),Pt("\\coh",'{\\mkern5mu\\rule{}{0.7em}\\mathrlap{\\smash{\\raise2mu{\\char"2322}}}\n{\\smash{\\lower4mu{\\char"2323}}}\\mkern5mu}'),Pt("\\incoh",'{\\mkern5mu\\rule{}{0.7em}\\mathrlap{\\smash{\\raise2mu{\\char"2323}}}\n{\\smash{\\lower4mu{\\char"2322}}}\\mkern5mu}'),Pt("\\standardstate","\\text{\\tiny\\char`⦵}");const Ir={"^":!0,_:!0,"\\limits":!0,"\\nolimits":!0};class $r{constructor(e,t,r){this.settings=t,this.expansionCount=0,this.feed(e),this.macros=new Nr(Tr,t.macros),this.mode=r,this.stack=[]}feed(e){this.lexer=new Ar(e,this.settings)}switchMode(e){this.mode=e}beginGroup(){this.macros.beginGroup()}endGroup(){this.macros.endGroup()}future(){return 0===this.stack.length&&this.pushToken(this.lexer.lex()),this.stack[this.stack.length-1]}popToken(){return this.future(),this.stack.pop()}pushToken(e){this.stack.push(e)}pushTokens(e){this.stack.push(...e)}scanArgument(e){let t,r,n;if(e){if(this.consumeSpaces(),"["!==this.future().text)return null;t=this.popToken(),({tokens:n,end:r}=this.consumeArg(["]"]))}else({tokens:n,start:t,end:r}=this.consumeArg());return this.pushToken(new br("EOF",r.loc)),this.pushTokens(n),t.range(r,"")}consumeSpaces(){for(;;){if(" "!==this.future().text)break;this.stack.pop()}}consumeArg(t){const r=[],n=t&&t.length>0;n||this.consumeSpaces();const o=this.future();let s,a=0,i=0;do{if(s=this.popToken(),r.push(s),"{"===s.text)++a;else if("}"===s.text){if(--a,-1===a)throw new e("Extra }",s)}else if("EOF"===s.text)throw new e("Unexpected end of input in a macro argument, expected '"+(t&&n?t[i]:"}")+"'",s);if(t&&n)if((0===a||1===a&&"{"===t[i])&&s.text===t[i]){if(++i,i===t.length){r.splice(-i,i);break}}else i=0}while(0!==a||n);return"{"===o.text&&"}"===r[r.length-1].text&&(r.pop(),r.shift()),r.reverse(),{tokens:r,start:o,end:s}}consumeArgs(t,r){if(r){if(r.length!==t+1)throw new e("The length of delimiters doesn't match the number of args!");const n=r[0];for(let t=0;tthis.settings.maxExpand)throw new e("Too many expansions: infinite loop or need to increase maxExpand setting");let s=o.tokens;const a=this.consumeArgs(o.numArgs,o.delimiters);if(o.numArgs){s=s.slice();for(let t=s.length-1;t>=0;--t){let r=s[t];if("#"===r.text){if(0===t)throw new e("Incomplete placeholder at end of macro body",r);if(r=s[--t],"#"===r.text)s.splice(t+1,1);else{if(!/^[1-9]$/.test(r.text))throw new e("Not a valid argument number",r);s.splice(t,2,...a[+r.text-1])}}}}return this.pushTokens(s),s.length}expandAfterFuture(){return this.expandOnce(),this.future()}expandNextToken(){for(;;)if(!1===this.expandOnce()){const e=this.stack.pop();return e.treatAsRelax&&(e.text="\\relax"),e}throw new Error}expandMacro(e){return this.macros.has(e)?this.expandTokens([new br(e)]):void 0}expandTokens(e){const t=[],r=this.stack.length;for(this.pushTokens(e);this.stack.length>r;)if(!1===this.expandOnce(!0)){const e=this.stack.pop();e.treatAsRelax&&(e.noexpand=!1,e.treatAsRelax=!1),t.push(e)}return t}expandMacroAsText(e){const t=this.expandMacro(e);return t?t.map((e=>e.text)).join(""):t}_getExpansion(e){const t=this.macros.get(e);if(null==t)return t;if(1===e.length){const t=this.lexer.catcodes[e];if(null!=t&&13!==t)return}const r="function"==typeof t?t(this):t;if("string"==typeof r){let e=0;if(-1!==r.indexOf("#")){const t=r.replace(/##/g,"");for(;-1!==t.indexOf("#"+(e+1));)++e}const t=new Ar(r,this.settings),n=[];let o=t.lex();for(;"EOF"!==o.text;)n.push(o),o=t.lex();n.reverse();return{tokens:n,numArgs:e}}return r}isDefined(e){return this.macros.has(e)||Object.prototype.hasOwnProperty.call(gr,e)||Object.prototype.hasOwnProperty.call(E.math,e)||Object.prototype.hasOwnProperty.call(E.text,e)||Object.prototype.hasOwnProperty.call(Ir,e)}isExpandable(e){const t=this.macros.get(e);return null!=t?"string"==typeof t||"function"==typeof t||!t.unexpandable:Object.prototype.hasOwnProperty.call(gr,e)&&!gr[e].primitive}}const Lr=/^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/,Fr=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","ᵝ":"β","ᵞ":"γ","ᵟ":"δ","ᵠ":"ϕ","ᵡ":"χ","ᶿ":"θ"}),Gr=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 Dr={"́":{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"}},Pr={"á":"á","à":"à","ä":"ä","ǟ":"ǟ","ã":"ã","ā":"ā","ă":"ă","ắ":"ắ","ằ":"ằ","ẵ":"ẵ","ǎ":"ǎ","â":"â","ấ":"ấ","ầ":"ầ","ẫ":"ẫ","ȧ":"ȧ","ǡ":"ǡ","å":"å","ǻ":"ǻ","ḃ":"ḃ","ć":"ć","č":"č","ĉ":"ĉ","ċ":"ċ","ď":"ď","ḋ":"ḋ","é":"é","è":"è","ë":"ë","ẽ":"ẽ","ē":"ē","ḗ":"ḗ","ḕ":"ḕ","ĕ":"ĕ","ě":"ě","ê":"ê","ế":"ế","ề":"ề","ễ":"ễ","ė":"ė","ḟ":"ḟ","ǵ":"ǵ","ḡ":"ḡ","ğ":"ğ","ǧ":"ǧ","ĝ":"ĝ","ġ":"ġ","ḧ":"ḧ","ȟ":"ȟ","ĥ":"ĥ","ḣ":"ḣ","í":"í","ì":"ì","ï":"ï","ḯ":"ḯ","ĩ":"ĩ","ī":"ī","ĭ":"ĭ","ǐ":"ǐ","î":"î","ǰ":"ǰ","ĵ":"ĵ","ḱ":"ḱ","ǩ":"ǩ","ĺ":"ĺ","ľ":"ľ","ḿ":"ḿ","ṁ":"ṁ","ń":"ń","ǹ":"ǹ","ñ":"ñ","ň":"ň","ṅ":"ṅ","ó":"ó","ò":"ò","ö":"ö","ȫ":"ȫ","õ":"õ","ṍ":"ṍ","ṏ":"ṏ","ȭ":"ȭ","ō":"ō","ṓ":"ṓ","ṑ":"ṑ","ŏ":"ŏ","ǒ":"ǒ","ô":"ô","ố":"ố","ồ":"ồ","ỗ":"ỗ","ȯ":"ȯ","ȱ":"ȱ","ő":"ő","ṕ":"ṕ","ṗ":"ṗ","ŕ":"ŕ","ř":"ř","ṙ":"ṙ","ś":"ś","ṥ":"ṥ","š":"š","ṧ":"ṧ","ŝ":"ŝ","ṡ":"ṡ","ẗ":"ẗ","ť":"ť","ṫ":"ṫ","ú":"ú","ù":"ù","ü":"ü","ǘ":"ǘ","ǜ":"ǜ","ǖ":"ǖ","ǚ":"ǚ","ũ":"ũ","ṹ":"ṹ","ū":"ū","ṻ":"ṻ","ŭ":"ŭ","ǔ":"ǔ","û":"û","ů":"ů","ű":"ű","ṽ":"ṽ","ẃ":"ẃ","ẁ":"ẁ","ẅ":"ẅ","ŵ":"ŵ","ẇ":"ẇ","ẘ":"ẘ","ẍ":"ẍ","ẋ":"ẋ","ý":"ý","ỳ":"ỳ","ÿ":"ÿ","ỹ":"ỹ","ȳ":"ȳ","ŷ":"ŷ","ẏ":"ẏ","ẙ":"ẙ","ź":"ź","ž":"ž","ẑ":"ẑ","ż":"ż","Á":"Á","À":"À","Ä":"Ä","Ǟ":"Ǟ","Ã":"Ã","Ā":"Ā","Ă":"Ă","Ắ":"Ắ","Ằ":"Ằ","Ẵ":"Ẵ","Ǎ":"Ǎ","Â":"Â","Ấ":"Ấ","Ầ":"Ầ","Ẫ":"Ẫ","Ȧ":"Ȧ","Ǡ":"Ǡ","Å":"Å","Ǻ":"Ǻ","Ḃ":"Ḃ","Ć":"Ć","Č":"Č","Ĉ":"Ĉ","Ċ":"Ċ","Ď":"Ď","Ḋ":"Ḋ","É":"É","È":"È","Ë":"Ë","Ẽ":"Ẽ","Ē":"Ē","Ḗ":"Ḗ","Ḕ":"Ḕ","Ĕ":"Ĕ","Ě":"Ě","Ê":"Ê","Ế":"Ế","Ề":"Ề","Ễ":"Ễ","Ė":"Ė","Ḟ":"Ḟ","Ǵ":"Ǵ","Ḡ":"Ḡ","Ğ":"Ğ","Ǧ":"Ǧ","Ĝ":"Ĝ","Ġ":"Ġ","Ḧ":"Ḧ","Ȟ":"Ȟ","Ĥ":"Ĥ","Ḣ":"Ḣ","Í":"Í","Ì":"Ì","Ï":"Ï","Ḯ":"Ḯ","Ĩ":"Ĩ","Ī":"Ī","Ĭ":"Ĭ","Ǐ":"Ǐ","Î":"Î","İ":"İ","Ĵ":"Ĵ","Ḱ":"Ḱ","Ǩ":"Ǩ","Ĺ":"Ĺ","Ľ":"Ľ","Ḿ":"Ḿ","Ṁ":"Ṁ","Ń":"Ń","Ǹ":"Ǹ","Ñ":"Ñ","Ň":"Ň","Ṅ":"Ṅ","Ó":"Ó","Ò":"Ò","Ö":"Ö","Ȫ":"Ȫ","Õ":"Õ","Ṍ":"Ṍ","Ṏ":"Ṏ","Ȭ":"Ȭ","Ō":"Ō","Ṓ":"Ṓ","Ṑ":"Ṑ","Ŏ":"Ŏ","Ǒ":"Ǒ","Ô":"Ô","Ố":"Ố","Ồ":"Ồ","Ỗ":"Ỗ","Ȯ":"Ȯ","Ȱ":"Ȱ","Ő":"Ő","Ṕ":"Ṕ","Ṗ":"Ṗ","Ŕ":"Ŕ","Ř":"Ř","Ṙ":"Ṙ","Ś":"Ś","Ṥ":"Ṥ","Š":"Š","Ṧ":"Ṧ","Ŝ":"Ŝ","Ṡ":"Ṡ","Ť":"Ť","Ṫ":"Ṫ","Ú":"Ú","Ù":"Ù","Ü":"Ü","Ǘ":"Ǘ","Ǜ":"Ǜ","Ǖ":"Ǖ","Ǚ":"Ǚ","Ũ":"Ũ","Ṹ":"Ṹ","Ū":"Ū","Ṻ":"Ṻ","Ŭ":"Ŭ","Ǔ":"Ǔ","Û":"Û","Ů":"Ů","Ű":"Ű","Ṽ":"Ṽ","Ẃ":"Ẃ","Ẁ":"Ẁ","Ẅ":"Ẅ","Ŵ":"Ŵ","Ẇ":"Ẇ","Ẍ":"Ẍ","Ẋ":"Ẋ","Ý":"Ý","Ỳ":"Ỳ","Ÿ":"Ÿ","Ỹ":"Ỹ","Ȳ":"Ȳ","Ŷ":"Ŷ","Ẏ":"Ẏ","Ź":"Ź","Ž":"Ž","Ẑ":"Ẑ","Ż":"Ż","ά":"ά","ὰ":"ὰ","ᾱ":"ᾱ","ᾰ":"ᾰ","έ":"έ","ὲ":"ὲ","ή":"ή","ὴ":"ὴ","ί":"ί","ὶ":"ὶ","ϊ":"ϊ","ΐ":"ΐ","ῒ":"ῒ","ῑ":"ῑ","ῐ":"ῐ","ό":"ό","ὸ":"ὸ","ύ":"ύ","ὺ":"ὺ","ϋ":"ϋ","ΰ":"ΰ","ῢ":"ῢ","ῡ":"ῡ","ῠ":"ῠ","ώ":"ώ","ὼ":"ὼ","Ύ":"Ύ","Ὺ":"Ὺ","Ϋ":"Ϋ","Ῡ":"Ῡ","Ῠ":"Ῠ","Ώ":"Ώ","Ὼ":"Ὼ"};const Rr=["bin","op","open","punct","rel"];class jr{constructor(e,t,r=!1){this.mode="math",this.gullet=new $r(e,t,this.mode),this.settings=t,this.isPreamble=r,this.leftrightDepth=0,this.prevAtomType=""}expect(t,r=!0){if(this.fetch().text!==t)throw new e(`Expected '${t}', got '${this.fetch().text}'`,this.fetch());r&&this.consume()}consume(){this.nextToken=null}fetch(){return null==this.nextToken&&(this.nextToken=this.gullet.expandNextToken()),this.nextToken}switchMode(e){this.mode=e,this.gullet.switchMode(e)}parse(){this.gullet.beginGroup(),this.settings.colorIsTextColor&&this.gullet.macros.set("\\color","\\textcolor");const e=this.parseExpression(!1);if(this.expect("EOF"),this.isPreamble){const e=Object.create(null);return Object.entries(this.gullet.macros.current).forEach((([t,r])=>{e[t]=r})),this.gullet.endGroup(),e}const t=this.gullet.macros.get("\\df@tag");return this.gullet.endGroup(),t&&(this.gullet.macros.current["\\df@tag"]=t),e}static get endOfExpression(){return["}","\\endgroup","\\end","\\right","\\endtoggle","&"]}subparse(e){const t=this.nextToken;this.consume(),this.gullet.pushToken(new br("}")),this.gullet.pushTokens(e);const r=this.parseExpression(!1);return this.expect("}"),this.nextToken=t,r}parseExpression(e,t,r){const n=[];for(;;){"math"===this.mode&&this.consumeSpaces();const o=this.fetch();if(-1!==jr.endOfExpression.indexOf(o.text))break;if(t&&o.text===t)break;if(r&&"\\middle"===o.text)break;if(e&&gr[o.text]&&gr[o.text].infix)break;const s=this.parseAtom(t);if(!s)break;"internal"!==s.type&&(n.push(s),this.prevAtomType="atom"===s.type?s.family:s.type)}return"text"===this.mode&&this.formLigatures(n),this.handleInfixNodes(n)}handleInfixNodes(t){let r,n=-1;for(let o=0;o=128))return null;if(this.settings.strict&&"math"===this.mode)throw new e(`Unicode text character "${r[0]}" used in math mode`,t);o={type:"textord",mode:"text",loc:fr.range(t),text:r}}if(this.consume(),n)for(let r=0;r0&&o[0].type&&"array"===o[0].type&&o[0].addEqnNum)&&n.gullet.macros.get("\\df@tag")){if(!r.displayMode)throw new e("\\tag works only in display mode");n.gullet.feed("\\df@tag"),o=[{type:"tag",mode:"text",body:o,tag:n.parse()}]}return o},Hr=[2,2,3,3];class Vr{constructor(e){this.level=e.level,this.color=e.color,this.font=e.font||"",this.fontFamily=e.fontFamily||"",this.fontSize=e.fontSize||1,this.fontWeight=e.fontWeight||"",this.fontShape=e.fontShape||"",this.maxSize=e.maxSize}extend(e){const t={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 r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return new Vr(t)}withLevel(e){return this.extend({level:e})}incrementLevel(){return this.extend({level:Math.min(this.level+1,3)})}inSubOrSup(){return this.extend({level:Hr[this.level]})}withColor(e){return this.extend({color:e})}withFont(e){return this.extend({font:e})}withTextFontFamily(e){return this.extend({fontFamily:e,font:""})}withFontSize(e){return this.extend({fontSize:e})}withTextFontWeight(e){return this.extend({fontWeight:e,font:""})}withTextFontShape(e){return this.extend({fontShape:e,font:""})}getColor(){return this.color}}let _r=function(e,t,r={}){t.textContent="";const n="math"===t.tagName.toLowerCase();n&&(r.wrap="none");const o=Wr(e,r);n||o.children.length>1?(t.textContent="",o.children.forEach((e=>{t.appendChild(e.toNode())}))):t.appendChild(o.toNode())};"undefined"!=typeof document&&"CSS1Compat"!==document.compatMode&&("undefined"!=typeof console&&console.warn("Warning: Temml doesn't work in quirks mode. Make sure your website has a suitable doctype."),_r=function(){throw new e("Temml doesn't work in quirks mode.")});const Wr=function(t,r){const n=new a(r);try{const e=Ur(t,n);return ue(e,t,new Vr({level:n.displayMode?nt:ot,maxSize:n.maxSize}),n)}catch(r){return function(t,r,n){if(n.throwOnError||!(t instanceof e))throw t;const o=new y(["temml-error"],[new x(r+"\n"+t.toString())]);return o.style.color=n.errorColor,o.style.whiteSpace="pre-line",o}(r,t,n)}};return{version:"0.10.24",render:_r,renderToString:function(e,t){return Wr(e,t).toMarkup()},postProcess:function(e){const t={};let r=0;const n=e.getElementsByClassName("tml-tageqn");for(const e of n){const n=e.getElementsByClassName("tml-eqn");n.length>0&&(r+=1,n[0].id="tml-eqn-"+r);const o=e.getElementsByClassName("tml-label");if(0!==o.length)if(n.length>0)t[o[0].id]=String(r);else{const r=e.getElementsByClassName("tml-tag");r.length>0&&(t[o[0].id]=r[0].textContent)}}[...e.getElementsByClassName("tml-ref")].forEach((e=>{let r=t[e.getAttribute("href").slice(1)];-1===e.className.indexOf("tml-eqref")&&(r=r.replace(/^\(/,""),r=r.replace(/\($/,"")),"("!==r.charAt(0)&&(r="("+r),")"!==r.slice(-1)&&(r+=")"),e.textContent=r}))},ParseError:e,definePreamble:function(e,t){const r=new a(t);if(r.macros={},!("string"==typeof e||e instanceof String))throw new TypeError("Temml can only parse string typed expression");const n=new jr(e,r,!0);delete n.gullet.macros.current["\\df@tag"];return n.parse()},__parse:function(e,t){const r=new a(t);return Ur(e,r)},__renderToMathMLTree:Wr,__defineSymbol:I,__defineMacro:Pt}}(); \ No newline at end of file diff --git a/dist/temml.mjs b/dist/temml.mjs index b0de360..374b91c 100644 --- a/dist/temml.mjs +++ b/dist/temml.mjs @@ -144,11 +144,29 @@ const assert = function(value) { /** * Return the protocol of a URL, or "_relative" if the URL does not specify a - * protocol (and thus is relative). + * protocol (and thus is relative), or `null` if URL has invalid protocol + * (so should be outright rejected). */ const protocolFromUrl = function(url) { - const protocol = /^\s*([^\\/#]*?)(?::|�*58|�*3a)/i.exec(url); - return protocol != null ? protocol[1] : "_relative"; + // Check for possible leading protocol. + // https://url.spec.whatwg.org/#url-parsing strips leading whitespace + // (\x00) or C0 control (\x00-\x1F) characters. + // eslint-disable-next-line no-control-regex + const protocol = /^[\x00-\x20]*([^\\/#?]*?)(:|�*58|�*3a|&colon)/i.exec(url); + if (!protocol) { + return "_relative"; + } + // Reject weird colons + if (protocol[2] !== ":") { + return null; + } + // Reject invalid characters in scheme according to + // https://datatracker.ietf.org/doc/html/rfc3986#section-3.1 + if (!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(protocol[1])) { + return null; + } + // Lowercase the protocol + return protocol[1].toLowerCase(); }; /** @@ -213,7 +231,11 @@ class Settings { */ isTrusted(context) { if (context.url && !context.protocol) { - context.protocol = utils.protocolFromUrl(context.url); + const protocol = utils.protocolFromUrl(context.url); + if (protocol == null) { + return false + } + context.protocol = protocol; } const trust = typeof this.trust === "function" ? this.trust(context) : this.trust; return Boolean(trust); @@ -1252,7 +1274,72 @@ defineSymbol(math, bin, "\u27d5", "\\leftouterjoin", true); defineSymbol(math, bin, "\u27d6", "\\rightouterjoin", true); defineSymbol(math, bin, "\u27d7", "\\fullouterjoin", true); -defineSymbol(math, bin, "\u2238", "\\dotminus", true); // stix +// stix Binary Operators +defineSymbol(math, bin, "\u2238", "\\dotminus", true); +defineSymbol(math, bin, "\u27D1", "\\wedgedot", true); +defineSymbol(math, bin, "\u27C7", "\\veedot", true); +defineSymbol(math, bin, "\u2A62", "\\doublebarvee", true); +defineSymbol(math, bin, "\u2A63", "\\veedoublebar", true); +defineSymbol(math, bin, "\u2A5F", "\\wedgebar", true); +defineSymbol(math, bin, "\u2A60", "\\wedgedoublebar", true); +defineSymbol(math, bin, "\u2A54", "\\Vee", true); +defineSymbol(math, bin, "\u2A53", "\\Wedge", true); +defineSymbol(math, bin, "\u2A43", "\\barcap", true); +defineSymbol(math, bin, "\u2A42", "\\barcup", true); +defineSymbol(math, bin, "\u2A48", "\\capbarcup", true); +defineSymbol(math, bin, "\u2A40", "\\capdot", true); +defineSymbol(math, bin, "\u2A47", "\\capovercup", true); +defineSymbol(math, bin, "\u2A46", "\\cupovercap", true); +defineSymbol(math, bin, "\u2A4D", "\\closedvarcap", true); +defineSymbol(math, bin, "\u2A4C", "\\closedvarcup", true); +defineSymbol(math, bin, "\u2A2A", "\\minusdot", true); +defineSymbol(math, bin, "\u2A2B", "\\minusfdots", true); +defineSymbol(math, bin, "\u2A2C", "\\minusrdots", true); +defineSymbol(math, bin, "\u22BB", "\\Xor", true); +defineSymbol(math, bin, "\u22BC", "\\Nand", true); +defineSymbol(math, bin, "\u22BD", "\\Nor", true); +defineSymbol(math, bin, "\u22BD", "\\barvee"); +defineSymbol(math, bin, "\u2AF4", "\\interleave", true); +defineSymbol(math, bin, "\u29E2", "\\shuffle", true); +defineSymbol(math, bin, "\u2AF6", "\\threedotcolon", true); +defineSymbol(math, bin, "\u2982", "\\typecolon", true); +defineSymbol(math, bin, "\u223E", "\\invlazys", true); +defineSymbol(math, bin, "\u2A4B", "\\twocaps", true); +defineSymbol(math, bin, "\u2A4A", "\\twocups", true); +defineSymbol(math, bin, "\u2A4E", "\\Sqcap", true); +defineSymbol(math, bin, "\u2A4F", "\\Sqcup", true); +defineSymbol(math, bin, "\u2A56", "\\veeonvee", true); +defineSymbol(math, bin, "\u2A55", "\\wedgeonwedge", true); +defineSymbol(math, bin, "\u29D7", "\\blackhourglass", true); +defineSymbol(math, bin, "\u29C6", "\\boxast", true); +defineSymbol(math, bin, "\u29C8", "\\boxbox", true); +defineSymbol(math, bin, "\u29C7", "\\boxcircle", true); +defineSymbol(math, bin, "\u229C", "\\circledequal", true); +defineSymbol(math, bin, "\u29B7", "\\circledparallel", true); +defineSymbol(math, bin, "\u29B6", "\\circledvert", true); +defineSymbol(math, bin, "\u29B5", "\\circlehbar", true); +defineSymbol(math, bin, "\u27E1", "\\concavediamond", true); +defineSymbol(math, bin, "\u27E2", "\\concavediamondtickleft", true); +defineSymbol(math, bin, "\u27E3", "\\concavediamondtickright", true); +defineSymbol(math, bin, "\u22C4", "\\diamond", true); +defineSymbol(math, bin, "\u29D6", "\\hourglass", true); +defineSymbol(math, bin, "\u27E0", "\\lozengeminus", true); +defineSymbol(math, bin, "\u233D", "\\obar", true); +defineSymbol(math, bin, "\u29B8", "\\obslash", true); +defineSymbol(math, bin, "\u2A38", "\\odiv", true); +defineSymbol(math, bin, "\u29C1", "\\ogreaterthan", true); +defineSymbol(math, bin, "\u29C0", "\\olessthan", true); +defineSymbol(math, bin, "\u29B9", "\\operp", true); +defineSymbol(math, bin, "\u2A37", "\\Otimes", true); +defineSymbol(math, bin, "\u2A36", "\\otimeshat", true); +defineSymbol(math, bin, "\u22C6", "\\star", true); +defineSymbol(math, bin, "\u25B3", "\\triangle", true); +defineSymbol(math, bin, "\u2A3A", "\\triangleminus", true); +defineSymbol(math, bin, "\u2A39", "\\triangleplus", true); +defineSymbol(math, bin, "\u2A3B", "\\triangletimes", true); +defineSymbol(math, bin, "\u27E4", "\\whitesquaretickleft", true); +defineSymbol(math, bin, "\u27E5", "\\whitesquaretickright", true); +defineSymbol(math, bin, "\u2A33", "\\smashtimes", true); // AMS Arrows // Note: unicode-math maps \u21e2 to their own function \rightdasharrow. @@ -1494,8 +1581,8 @@ defineSymbol(math, spacing, null, "\\allowbreak"); defineSymbol(math, punct, ",", ","); defineSymbol(text, punct, ":", ":"); defineSymbol(math, punct, ";", ";"); -defineSymbol(math, bin, "\u22bc", "\\barwedge", true); -defineSymbol(math, bin, "\u22bb", "\\veebar", true); +defineSymbol(math, bin, "\u22bc", "\\barwedge"); +defineSymbol(math, bin, "\u22bb", "\\veebar"); defineSymbol(math, bin, "\u2299", "\\odot", true); // Firefox turns ⊕ into an emoji. So append \uFE0E. Define Unicode character in macros, not here. defineSymbol(math, bin, "\u2295\uFE0E", "\\oplus"); @@ -1508,7 +1595,6 @@ defineSymbol(math, bin, "\u25b3", "\\bigtriangleup"); defineSymbol(math, bin, "\u25bd", "\\bigtriangledown"); defineSymbol(math, bin, "\u2020", "\\dagger"); defineSymbol(math, bin, "\u22c4", "\\diamond"); -defineSymbol(math, bin, "\u22c6", "\\star"); defineSymbol(math, bin, "\u25c3", "\\triangleleft"); defineSymbol(math, bin, "\u25b9", "\\triangleright"); defineSymbol(math, open, "{", "\\{"); @@ -3483,6 +3569,9 @@ defineFunction({ if (funcName === "\\edef" || funcName === "\\xdef") { tokens = parser.gullet.expandTokens(tokens); + if (tokens.length > parser.gullet.settings.maxExpand) { + throw new ParseError("Too many expansions in an " + funcName); + } tokens.reverse(); // to fit in with stack order } // Final arg is the expansion of the macro @@ -13221,7 +13310,7 @@ class Style { * https://mit-license.org/ */ -const version = "0.10.23"; +const version = "0.10.24"; function postProcess(block) { const labelMap = {}; diff --git a/dist/temmlPostProcess.js b/dist/temmlPostProcess.js index 0cedf9a..be7ef50 100644 --- a/dist/temmlPostProcess.js +++ b/dist/temmlPostProcess.js @@ -14,7 +14,7 @@ * https://mit-license.org/ */ - const version = "0.10.23"; + const version = "0.10.24"; function postProcess(block) { const labelMap = {}; diff --git a/docs/administration.md b/docs/administration.md index 39577d1..0249ff1 100644 --- a/docs/administration.md +++ b/docs/administration.md @@ -443,7 +443,7 @@ You can suggest revisions to this page at the Temml [issues page](https://github