@cortex-js/compute-engine 0.4.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/compute-engine.esm.js +7057 -7037
  2. package/dist/compute-engine.min.esm.js +2 -2
  3. package/dist/compute-engine.min.js +2 -2
  4. package/dist/math-json.esm.js +3 -6142
  5. package/dist/math-json.min.esm.js +2 -2
  6. package/dist/math-json.min.js +2 -2
  7. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  8. package/dist/types/common/signals.d.ts +1 -1
  9. package/dist/types/compute-engine/assume.d.ts +1 -1
  10. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  11. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  12. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  13. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
  14. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +3 -1
  16. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  17. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  18. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  19. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
  20. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  21. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  22. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  24. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  25. package/dist/types/compute-engine/compute-engine.d.ts +87 -43
  26. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  27. package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +1 -1
  28. package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +1 -1
  29. package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +1 -1
  30. package/dist/types/compute-engine/dictionary/arithmetic-power.d.ts +1 -1
  31. package/dist/types/compute-engine/dictionary/arithmetic.d.ts +1 -1
  32. package/dist/types/compute-engine/dictionary/collections.d.ts +1 -1
  33. package/dist/types/compute-engine/dictionary/core.d.ts +1 -1
  34. package/dist/types/compute-engine/dictionary/dictionary.d.ts +1 -1
  35. package/dist/types/compute-engine/dictionary/logic.d.ts +1 -1
  36. package/dist/types/compute-engine/dictionary/polynomials.d.ts +1 -1
  37. package/dist/types/compute-engine/dictionary/relational-operator.d.ts +1 -1
  38. package/dist/types/compute-engine/dictionary/sets.d.ts +1 -1
  39. package/dist/types/compute-engine/dictionary/trigonometry.d.ts +1 -1
  40. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  41. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  48. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  49. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  50. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  51. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  52. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
  53. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  54. package/dist/types/compute-engine/latex-syntax/public.d.ts +46 -20
  55. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  56. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  57. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +2 -4
  58. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  59. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  60. package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +1 -1
  61. package/dist/types/compute-engine/numerics/numeric.d.ts +2 -2
  62. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  63. package/dist/types/compute-engine/public.d.ts +432 -138
  64. package/dist/types/compute-engine/rules.d.ts +1 -1
  65. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  66. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  67. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  68. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  69. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  70. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  71. package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
  72. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  73. package/dist/types/compute-engine.d.ts +2 -2
  74. package/dist/types/math-json/math-json-format.d.ts +1 -1
  75. package/dist/types/math-json/utils.d.ts +1 -1
  76. package/dist/types/math-json.d.ts +3 -4
  77. package/package.json +16 -16
@@ -1,2 +1,2 @@
1
- /** MathJSON 0.4.4 */
2
- function e(e){return 8205===e||65038===e||65039===e||e>=127995&&e<=128e3||e>=129456&&e<=129460||e>=917536&&e<=917632}function i(e){return e>=127462&&e<=127487}class t{constructor(t){this.obeyspaces=!1,this.s=function(t){if(/^[\u0020-\u00FF]*$/.test(t))return t;const r=[],n=function(e){const i=[];for(let t=0;t<e.length;t++){let r=e.charCodeAt(t);if(r>=55296&&r<=56319){const i=e.charCodeAt(t+1);i>=56320&&i<=57343&&(r=65536+1024*(r-55296)+(i-56320),t++)}i.push(r)}return i}(t);let s=0;for(;s<n.length;){const t=n[s++],a=n[s];if(8205===a){const e=s-1;for(s+=2;8205===n[s];)s+=2;r.push(String.fromCodePoint(...n.slice(e,2*s-e+1)))}else if(e(a)){const i=s-1;for(;e(n[s]);)s+=8205===n[s]?2:1;r.push(String.fromCodePoint(...n.slice(i,2*s-i-1)))}else i(t)?(s+=1,r.push(String.fromCodePoint(...n.slice(s-2,2)))):r.push(String.fromCodePoint(t))}return r}(t),this.pos=0}end(){return this.pos>=this.s.length}get(){return this.pos<this.s.length?this.s[this.pos++]:""}peek(){return this.s[this.pos]}match(e){let i;return i="string"==typeof this.s?e.exec(this.s.slice(this.pos)):e.exec(this.s.slice(this.pos).join("")),i?.[0]?(this.pos+=i[0].length,i[0]):null}next(){if(this.end())return null;if(!this.obeyspaces&&this.match(/^[ \f\n\r\t\v\xA0\u2028\u2029]+/))return"<space>";if(this.obeyspaces&&this.match(/^[ \f\n\r\t\v\xA0\u2028\u2029]/))return"<space>";const e=this.get();if("\\"===e){if(!this.end()){let e=this.match(/^[a-zA-Z*]+/);if(e)this.match(/^[ \f\n\r\t\v\xA0\u2028\u2029]*/);else if(e=this.get()," "===e)return"<space>";return"\\"+e}}else{if("{"===e)return"<{>";if("}"===e)return"<}>";if("^"===e){if("^"===this.peek()){this.get();const e=this.match(/^(\^(\^(\^(\^[0-9a-f])?[0-9a-f])?[0-9a-f])?[0-9a-f])?[0-9a-f][0-9a-f]/);if(e)return String.fromCodePoint(parseInt(e.slice(e.lastIndexOf("^")+1),16))}return e}if("#"===e){if(!this.end()){let e=!1;if(/[0-9?]/.test(this.peek())&&(e=!0,this.pos+1<this.s.length)){const i=this.s[this.pos+1];e=/[^0-9A-Za-z]/.test(i)}return e?"#"+this.get():"#"}}else if("$"===e)return"$"===this.peek()?(this.get(),"<$$>"):"<$>"}return e}}function r(e,i){let t=[],r=e.next();if(r)if("\\relax"===r);else if("\\noexpand"===r)r=e.next(),r&&t.push(r);else if("\\obeyspaces"===r)e.obeyspaces=!0;else if("\\space"===r||"~"===r)t.push("<space>");else if("\\bgroup"===r)t.push("<{>");else if("\\egroup"===r)t.push("<}>");else if("\\string"===r)r=e.next(),r&&("\\"===r[0]?Array.from(r).forEach((e=>t.push("\\"===e?"\\backslash":e))):"<{>"===r?t.push("\\{"):"<space>"===r?t.push("~"):"<}>"===r&&t.push("\\}"));else if("\\csname"===r){for(;"<space>"===e.peek();)e.next();let s="",a=!1,o=[];do{0===o.length&&(/^#[0-9?]$/.test(e.peek())?(o=n(i?.[e.get().slice(1)]??i?.["?"]??"\\placeholder{}",i),r=o[0]):(r=e.next(),o=r?[r]:[])),a=0===o.length,a||"\\endcsname"!==r||(a=!0,o.shift()),a||(a="<$>"===r||"<$$>"===r||"<{>"===r||"<}>"===r||!!r&&r.length>1&&"\\"===r[0]),a||(s+=o.shift())}while(!a);s&&t.push("\\"+s),t=t.concat(o)}else if("\\endcsname"===r);else if(r.length>1&&"#"===r[0]){const e=r.slice(1);t=t.concat(n(i?.[e]??i?.["?"]??"\\placeholder{}",i))}else t.push(r);return t}function n(e,i){const n=e.toString().split(/\r?\n/);let s="",a="";for(const e of n){s+=a,a=" ";const i=e.match(/((?:\\%)|[^%])*/);null!==i&&(s+=i[0])}const o=new t(s);let l=[];do{l=l.concat(r(o,i))}while(!o.end());return l}function s(e){let i="",t="";for(const r of e)r&&(/[a-zA-Z*]/.test(r[0])&&(t+=i),i=/\\[a-zA-Z]+\*?$/.test(r)?" ":"",t+=r);return t}function a(e){let i=[];if(Array.isArray(e))for(const t of e)Array.isArray(t)?i=[...i,...t]:i.push(t);else i=[e];return s(i.map((e=>({"<space>":" ","<$$>":"$$","<$>":"$","<{>":"{","<}>":"}"}[e]??e))))}function o(e){return!("kind"in e)||"symbol"===e.kind}function l(e){return"kind"in e&&"matchfix"===e.kind}function c(e){return"kind"in e&&"infix"===e.kind}function g(e){return"kind"in e&&"prefix"===e.kind}function u(e){return"kind"in e&&"postfix"===e.kind}function p(e){return null!==e&&"object"==typeof e&&"num"in e}function h(e){return null!==e&&"object"==typeof e&&"sym"in e}function m(e){return null!==e&&"object"==typeof e&&"str"in e}function f(e){return null!==e&&"object"==typeof e&&"fn"in e}function d(e){return null!==e&&"object"==typeof e&&"dict"in e}function x(e){return null===e||!Array.isArray(e)&&("object"!=typeof e||!("fn"in e||"dic"in e))}function y(e){return null===e?null:"object"==typeof e&&"str"in e?e.str:"string"!=typeof e||e.length<2||"'"!==e[0]||"'"!==e[e.length-1]?null:e.substring(1,e.length-1)}function k(e){return null===e?null:Array.isArray(e)?e[0]:f(e)?e.fn[0]:null}function v(e){const i=k(e);return"string"==typeof i?i:""}function b(e,i){return null===e?null:Array.isArray(e)?e[i]??null:f(e)?e.fn[i]??null:null}function S(e){return Array.isArray(e)?Math.max(0,e.length-1):f(e)?Math.max(0,e.fn.length-1):0}function N(e){return null===e?null:"string"==typeof e?e.length>=2&&"'"===e[0]&&"'"===e[e.length-1]?null:e:h(e)?e.sym:null}function A(e){if(null===e)return null;if("number"==typeof e)return e;if(p(e))return parseFloat(e.num);const i=N(e);return"NaN"===i?NaN:"+Infinity"===i?1/0:"-Infinity"===i?-1/0:null}function E(e){if(x(e))return[null,null];const i=k(e);if(!i)return[null,null];let t=null,r=null;if("Negate"===i&&([t,r]=E(b(e,1)??"Missing"),null!==t&&null!==r))return[-t,r];if("Rational"===i)return[A(b(e,1)??NaN)??NaN,A(b(e,2)??NaN)??NaN];if("Power"===i){const i=A(b(e,2));1===i?(t=A(b(e,1))??null,r=1):-1===i&&(t=1,r=A(b(e,1))??null)}return"Divide"===i&&(t=A(b(e,1))??null,r=A(b(e,2))??null),"Multiply"===i&&"Power"===k(b(e,2))&&-1===A(b(b(e,2),2))&&(t=A(b(e,1))??null,r=A(b(b(e,2),1))??null),null===t||null===r?[null,null]:Number.isInteger(t)&&Number.isInteger(r)?[t,r]:[null,null]}function q(e){return Array.isArray(e)?e.slice(1):f(e)?e.fn.slice(1):[]}function z(e,i){const t=k(e);if(null!==t)return[i(t),...q(e).map(i)];const r=D(e);if(null!==r){const e=Object.keys(r),t={};for(const n of e)t[n]=i(r[n]);return{dict:t}}return i(e)}function P(e,i){let t=null;if(Array.isArray(e)&&(t=e),f(e)&&(t=e.fn),null===t)return[];let r=1;const n=[];for(;r<t.length;)n.push(i(t[r])),r+=1;return n}function D(e){return"object"==typeof e&&"dict"in e?e.dict:null}function M(e){if("string"==typeof e){const i=Number(e);if("+"===e[0]&&(e=e.slice(1)),i.toString()===e)return isNaN(i)||!isFinite(i)?i.toString():i}return e}function w(e,i,t,r="both"){if("non"===r)return[e,i,t];const n=k(i),s=k(t);return"left"===r?n===e?[e,...q(i)??[],t]:[e,i,t]:"right"===r?s===e?[e,i,...q(t)??[]]:[e,i,t]:n===e&&s===e?[e,...q(i)??[],...q(t)??[]]:n===e?[e,...q(i)??[],t]:s===e?[e,i,...q(t)??[]]:[e,i,t]}function L(e){const i=k(e);return null===e?null:("Delimiter"===i&&(e=b(e,1)??null),null===e?null:"Sequence"===i?q(e)??[]:null)}function _(e,i){return i>2?"solidus":"radical"}function $(e,i){return i>3?"inline-solidus":"quotient"}function C(e,i,t,r){return null===t?"\\sqrt{}":(r=r??2,"solidus"===i?e.wrapShort(t)+"^{1\\/"+e.serialize(r)+"}":"quotient"===i?e.wrapShort(t)+"^{\\frac{1}{"+e.serialize(r)+"}}":2===A(r)?"\\sqrt{"+e.serialize(t)+"}":"\\sqrt["+e.serialize(r)+"]{"+e.serialize(t)+"}")}function I(e,i){if(null===i)return"";const t=b(i,1)??"Missing",r=b(i,2)??"Missing";if(1===S(i))return e.serialize(t);const n=$(0,e.level);if("inline-solidus"===n||"nice-solidus"===n){const i=e.wrapShort(t),s=e.wrapShort(r);return"inline-solidus"===n?`${i}\\/${s}`:`^{${i}}\\!\\!/\\!_{${s}}`}return"reciprocal"===n?e.wrap(t)+e.wrap(r)+"^{-1}":"factor"===n?"\\frac{1}{"+e.serialize(r)+"}"+e.wrap(t):`\\frac{${e.serialize(t)}}{${e.serialize(r)}}`}function R(e,i){const t=k(i),r=b(i,1)??"Missing",n=b(i,2)??"Missing";if("Sqrt"===t)return C(e,_(0,e.level),r,2);if("Root"===t)return C(e,_(0,e.level),r,n);const s=A(n)??1;if(-1===s)return e.serialize(["Divide","1",r]);if(s<0)return e.serialize(["Divide","1",["Power",r,-s]]);if("Divide"===k(n)||"Rational"===k(n)){if(1===A(b(n,1)))return C(e,_(0,e.level),r,b(n,2))}else if("Power"===k(n)&&-1===A(b(n,2)))return C(e,_(0,e.level),r,b(n,1));return e.wrapShort(r)+"^{"+e.serialize(n)+"}"}const O=[{name:"CatalanConstant",serialize:"G"},{name:"GoldenRatio",serialize:"\\varphi"},{name:"EulerGamma",serialize:"\\gamma"},{name:"Degrees",serialize:"\\frac{\\pi}{180}"},{trigger:["\\infty"],parse:{num:"+Infinity"}},{name:"ComplexInfinity",trigger:["\\tilde","\\infty"],serialize:"\\tilde\\infty"},{trigger:["\\tilde","<{>","\\infty","<}>"],parse:"ComplexInfinity"},{name:"Pi",trigger:["\\pi"]},{trigger:["\u03c0"],parse:"Pi"},{name:"ExponentialE",trigger:["e"],serialize:"e"},{trigger:["\\mathrm","<{>","e","<}>"],parse:"ExponentialE"},{trigger:["\\exponentialE"],parse:"ExponentialE"},{name:"ImaginaryUnit",trigger:["\\imaginaryI"]},{trigger:["i"],parse:"ImaginaryUnit"},{trigger:["\\mathrm","<{>","i","<}>"],parse:"ImaginaryUnit"},{name:"Add",trigger:["+"],kind:"infix",associativity:"both",precedence:275,parse:(e,i,t)=>{if(275<i.minPrec)return null;const r=e.matchExpression({...i,minPrec:275});return null===r?null:w("Add",t,r)},serialize:function(e,i){e.level-=1;const t=k(i);let r="",n=b(i,1),s=!Number.isNaN(A(n)??NaN);if("Negate"===t)r="-"+e.wrap(n,276);else if("Add"===t){r=e.serialize(n);const t=S(i)+1;for(let a=2;a<t;a++){n=b(i,a);const t=A(n)??NaN,o=!Number.isNaN(t);let l=!1;if(null!==n&&s){const[i,t]=E(n);null!==i&&null!==t&&isFinite(i)&&isFinite(t)&&1!==t&&(r+=e.options.invisiblePlus+e.serialize(n),l=!0)}if(!l)if(t<0)r+=e.serialize(n);else if("Negate"===k(n))r+=e.wrap(n,275);else{const i=e.wrap(n,275);"-"===i[0]||"+"===i[0]?r+=i:r=r+"+"+i}s=o}}else if("Subtract"===t){const t=b(i,2);r=null!==t?e.wrap(n,275)+"-"+e.wrap(t,275):e.wrap(n,275)}return e.level+=1,r}},{kind:"prefix",trigger:["+"],precedence:275,parse:(e,i)=>275<i.minPrec?null:e.matchExpression({...i,minPrec:400})},{name:"Complex",precedence:274,serialize:(e,i)=>{const t=A(b(i,1)),r=A(b(i,2));if(0===r)return e.serialize(b(i,1));const n=1===r?"\\imaginaryI":-1===r?"-\\imaginaryI":s([e.serialize(b(i,2)),"\\imaginaryI"]);return 0===t?n:s(null!==r&&r<0?[e.serialize(b(i,1)),n]:[e.serialize(b(i,1)),"+",n])}},{name:"Divide",trigger:["\\frac"],requiredLatexArg:2,precedence:660,parse:function(e){const i=e.matchRequiredLatexArgument()??"Missing",t=e.matchRequiredLatexArgument()??"Missing";if("PartialDerivative"===k(i)&&("PartialDerivative"===k(t)||"Multiply"===k(t)&&"PartialDerivative"===k(b(t,1)))){const r=b(i,3)??"Missing";let n=b(i,1);null!==n&&"Missing"!==n||(n=e.matchExpression()??"Missing");let s=[];if("Multiply"===k(t)){for(const e of q(t))if("PartialDerivative"===k(e)){const i=b(e,2);i&&s.push(i)}}else{const e=b(t,2);e&&s.push(e)}return s.length>1&&(s=["List",...s]),["PartialDerivative",n,...s,"Missing"===r?1:r]}return["Divide",i,t]},serialize:I},{trigger:["\\/"],kind:"infix",associativity:"non",precedence:660,parse:"Divide"},{trigger:["/"],kind:"infix",associativity:"non",precedence:660,parse:"Divide"},{trigger:["\\div"],kind:"infix",associativity:"non",precedence:660,parse:"Divide"},{name:"Exp",serialize:(e,i)=>s(["\\exponentialE^{",e.serialize(b(i,1)??"Missing"),"}"])},{name:"Factorial",trigger:["!"],kind:"postfix",precedence:810},{name:"Factorial2",trigger:["!","!"],kind:"postfix",precedence:810},{trigger:"\\operatorname{floor}",parse:e=>{const i=e.matchArguments("group");return null===i?null:["Floor",...i]}},{name:"Gcd",trigger:"\\operatorname{gcd}",parse:e=>{const i=e.matchArguments("group");return null===i?null:["Gcd",...i]},serialize:(e,i)=>s(["\\operatorname{gcd}","\\left(",e.serialize(i),"\\right)"])},{name:"Half",serialize:"\\frac12"},{name:"Lcm",trigger:"\\operatorname{lcm}"},{name:"MinusPlus",trigger:["\\mp"],kind:"infix",associativity:"both",precedence:270},{name:"Multiply",trigger:["\\times"],kind:"infix",associativity:"both",precedence:390,serialize:function e(i,t){if(null===t)return"";i.level-=1;let r="";const[n,a]=function(e){if("Multiply"!==k(e))return[[],[]];const i=[],t=[],r=q(e);for(const e of r)if("Power"===k(e))if("Negate"===k(b(e,2))){const i=b(e,1)??"Missing",r=b(b(e,2),1)??"Missing";t.push(["Power",i,r])}else{const r=A(b(e,2))??NaN;-1===r?t.push(b(e,1)??"Missing"):r<0?t.push(["Power",b(e,1)??"Missing",-r]):i.push(e)}else i.push(e);return[i,t]}(t);if(a.length>0&&(r=1===a.length&&1===a[0]?0===n.length?"1":1===n.length?i.serialize(n[0]):e(i,["Multiply",...n]):i.serialize(["Divide",1===n.length?n[0]:["Multiply",...n],1===a.length?a[0]:["Multiply",...a]])),r)return i.level+=1,r;let o=!1,l=null;const c=S(t)+1;let g=!1;for(let e=1;e<c;e++){if(l=b(t,e),null===l)continue;let n;if("number"==typeof l||p(l))n=i.serialize(l),"-1"!==n||r?("-"===n[0]&&(n=n.slice(1),o=!o),r=r?s([r,i.options.multiply,n]):n):r="-",g=!0;else{if("Power"===k(l)){const[e,t]=E(b(l,2)??NaN);if(1===e&&null!==t){r+=C(i,_(0,i.level),b(l,1),t),g=!1;continue}}if("Power"!==k(l)||isNaN(A(b(l,1))??NaN)){if("Negate"===k(l)&&(l=b(l,1),o=!o),n=i.wrap(l,390),r){const e=k(l);r=!g||"Divide"!==e&&"Rational"!==e?i.options.invisibleMultiply?s([r,i.options.invisibleMultiply,n]):s([r,n]):s([r,i.options.multiply,n])}else r=n;g=!1}else n=i.serialize(l),r=r?s([r,i.options.multiply,n]):n,g=!0}}return i.level+=1,o?"-"+r:r}},{trigger:["\\cdot"],kind:"infix",associativity:"both",precedence:390,parse:(e,i,t)=>{if(391<i.minPrec)return null;const r=e.matchExpression({...i,minPrec:392});return null===r?null:w("Multiply",t,r)}},{trigger:["*"],kind:"infix",associativity:"both",precedence:390,parse:(e,i,t)=>{if(391<i.minPrec)return null;const r=e.matchExpression({...i,minPrec:392});return null===r?null:["Multiply",t,r]}},{name:"Negate",trigger:["-"],kind:"prefix",parse:(e,i)=>{if(276<i.minPrec)return null;const t=e.matchExpression({...i,minPrec:400});return null===t?null:["Negate",t]},precedence:275},{name:"PlusMinus",trigger:["\\pm"],kind:"infix",associativity:"both",precedence:270},{name:"Power",trigger:["^"],kind:"infix",serialize:R},{name:"Rational",precedence:660,serialize:I},{name:"Root",serialize:R},{name:"Round",trigger:"\\operatorname{round}"},{name:"Square",precedence:720,serialize:(e,i)=>e.wrapShort(b(i,1))+"^2"},{name:"Sign",trigger:"\\operatorname{sgn}"},{name:"Sqrt",trigger:["\\sqrt"],optionalLatexArg:1,requiredLatexArg:1,parse:function(e){const i=e.matchOptionalLatexArgument(),t=e.matchRequiredLatexArgument();return null===t?null!==i?["Root","Missing",i]:["Sqrt","Missing"]:null!==i?["Root",t,i]:["Sqrt",t]},serialize:R},{name:"Subtract",trigger:["-"],kind:"infix",associativity:"both",precedence:275,parse:(e,i,t)=>{if(276<i.minPrec)return null;const r=e.matchExpression({...i,minPrec:277});return null===r?null:["Subtract",t,r]}}];function T(e=""){return(i,t)=>q(t).map((e=>i.serialize(e))).join(e)}function F(e,i){if(null===i)return"";const t=k(i);if("LatexString"===t)return j(e,i);if("LatexTokens"===t)return G(e,i);const r=y(i);if(null!==r)return`\\text{${r}}`;const n=A(i);return null!==n?n.toString():`\\text{${JSON.stringify(i)}}`}const Z=[{name:"Missing",trigger:["\\placeholder"],requiredLatexArg:1,serialize:e=>e.options.missingSymbol??"\\placeholder{}"},{name:"BaseForm",serialize:(e,i)=>{const t=A(b(i,2))??NaN;if(isFinite(t)&&t>=2&&t<=36){const e=A(b(i,1))??NaN;if(isFinite(e)){let i=Number(e).toString(t),r=0;if(2===t||10===t?r=4:16===t?r=2:t>16&&(r=4),r>0){const e=i;i="";for(let t=0;t<e.length;t++)t>0&&t%r==0&&(i="\\, "+i),i=e[e.length-t-1]+i}return`(\\text{${i}}_{${t}}`}}return"\\operatorname{BaseForm}("+e.serialize(b(i,1))+", "+e.serialize(b(i,2))+")"}},{name:"Delimiter",serialize:(e,i)=>{const t=S(i);if(0===t)return"";if(1===t)return`\\left( ${e.serialize(b(i,1))} \\right)`;let r="",n="\\left(",s="\\left)";2===t?r=F(e,b(i,2))??"":3===t?(n=F(e,b(i,2))??"",s=F(e,b(i,3))??""):(n=F(e,b(i,2))??"",r=F(e,b(i,3))??"",s=F(e,b(i,4))??"");const a=b(i,1);return r&&"Sequence"===k(a)?`${n} ${T(r)(e,a)} ${s}`:`${n} ${e.serialize(a)} ${s}`}},{name:"Error",serialize:(e,i)=>{const t=b(i,1),r="Nothing"===N(t)?"":e.serialize(t);if(S(i)>=3){const e=b(i,3);if(e&&"LatexForm"===k(e)){const i=U(y(b(e,1)));if(i)return`${r??""}\\texttt{\\textcolor{red}{${i}}}`}}return r??""}},{name:"FromLatex",serialize:(e,i)=>`\\texttt{${U(y(b(i,1)))}}`},{name:"LatexForm",serialize:j},{name:"LatexTokens",serialize:G},{kind:"matchfix",openDelimiter:"(",closeDelimiter:")",parse:(e,i)=>null===i?null:"Sequence"===k(i)?0===S(i)?["Delimiter","Nothing"]:["Delimiter",...q(i)]:["Delimiter",i]},{name:"Sequence",trigger:[","],kind:"infix",precedence:20,parse:(e,i,t)=>{if(i.minPrec>=20)return null;"Missing"===t&&(t="Nothing");const r=["Sequence",t];let n=!1;for(;!n;){for(n=!0,e.skipSpace();e.match(",");)r.push("Nothing"),e.skipSpace();if(e.atTerminator(i))r.push("Nothing");else{const t=e.matchExpression({...i,minPrec:20});r.push(t??"Nothing"),n=null===t}n||(e.skipSpace(),n=!e.match(","))}return r},serialize:T()},{trigger:[";"],kind:"infix",precedence:19,parse:(e,i,t)=>{if(i.minPrec>=19)return null;"Missing"===t&&(t="Nothing");const r=["Sequence",...L(t)??["Sequence",t]];for(;;){for(e.skipSpace();e.match(",");)r.push("Nothing"),e.skipSpace();if(e.atEnd){r.push("Nothing");break}const t=e.matchExpression({...i,minPrec:19});if(null===t){r.push("Nothing");break}if(r.push(...L(t)??["Sequence",t]),e.skipSpace(),!e.match(","))break}return r}},{name:"String",trigger:["\\text"],parse:e=>B(e),serialize:(e,i)=>{const t=q(i);return null===t||0===t.length?"\\text{}":"\\text{"+t.map((i=>e.serialize(i))).join("")+"}"}},{name:"Subscript",trigger:["_"],kind:"infix",serialize:(e,i)=>2===S(i)?e.serialize(b(i,1))+"_{"+e.serialize(b(i,2))+"}":"_{"+e.serialize(b(i,1))+"}"},{name:"Superplus",trigger:["^","+"],kind:"postfix"},{name:"Subplus",trigger:["_","+"],kind:"postfix"},{name:"Superminus",trigger:["^","-"],kind:"postfix"},{name:"Subminus",trigger:["_","-"],kind:"postfix"},{trigger:["^","*"],kind:"postfix",parse:(e,i)=>["Superstar",i]},{name:"Superstar",trigger:["^","\\star"],kind:"postfix"},{trigger:["_","*"],kind:"postfix",parse:(e,i)=>["Substar",i]},{name:"Substar",trigger:["_","\\star"],kind:"postfix"},{name:"Superdagger",trigger:["^","\\dagger"],kind:"postfix"},{trigger:["^","\\dag"],kind:"postfix",parse:(e,i)=>["Superdagger",i]},{name:"Prime",trigger:["^","\\prime"],kind:"postfix"},{trigger:["^","\\doubleprime"],kind:"postfix",parse:(e,i)=>["Prime",i??"Nothing",2]},{name:"Derivative",serialize:(e,i)=>{const t=A(b(i,1))??NaN;if(!isFinite(t))return"";const r=e.serialize(b(i,2));return 1===t?r+"^{\\prime}":2===t?r+"^{\\doubleprime}":r+"^{("+Number(t).toString()+")}"}},{name:"Piecewise",trigger:"cases",kind:"environment",parse:e=>["Piecewise",e.matchTabular("cases")??"Nothing"],serialize:(e,i)=>{if("List"!==k(b(i,1)))return"";const t=q(b(i,1));let r="",n="";for(const i of t){r+=n;const t=b(i,1);if(null!==t){r+=e.serialize(t);const n=b(i,2);null!==n&&(r+="&"+e.serialize(n))}n="\\\\"}return"\\begin{cases}"+r+"\\end{cases}"}}];function B(e,i){if(!e.match("<{>"))return"Nothing";const t=[];let r="",n=null;for(;!e.atEnd&&!e.match("<}>");)if("<{>"===e.peek)t.push(B(e));else if(e.match("\\textbf")&&e.match("<{>"))t.push(B(e,{"font-weight":"bold"}));else if(e.match("\\color")&&e.match("<{>")){const i=e.matchColor();i&&e.match("<}>")&&(null!==n&&r?t.push(["Style",r,{dict:n}]):r&&t.push(["String",r]),r="",n={color:i})}else if(e.match("<space>"))r+=" ";else if(e.match("<$>")){const i=e.index,n=e.matchExpression()??"Nothing";e.skipSpace(),e.match("<$>")?t.push(n):(r+="$",e.index=i)}else if(e.match("<$$>")){const i=e.index,n=e.matchExpression()??"Nothing";e.skipSpace(),e.match("<$$>")?t.push(n):(r+="$$",e.index=i)}else r+=e.matchChar()??"";return null!==n&&r?t.push(["Style",r,{dict:n}]):r&&t.push(["String",r]),i?["Style",["String",...t],{dict:i}]:["String",...t]}function G(e,i){return null===i?"":s(P(i,(i=>{const t=y(i);return null===t?e.serialize(i):"<{>"===t?"{":"<}>"===t?"}":"<$>"===t?"$":"<$$>"===t?"$$":"<space>"===t?" ":t})))}function j(e,i){return null===i?"":s(P(i,(i=>y(i)??e.serialize(i))))}function U(e){return null===e?"":e.replace(/[{}\[\]\\:\-\$%]/g,(e=>({"{":"\\lbrace ","}":"\\rbrace ","[":"\\lbrack ","]":"\\rbrack ",":":"\\colon ","\\":"\\backslash "}[e]??"\\"+e)))}const W=[{name:"Overscript",trigger:["\\overset"],kind:"infix",precedence:700},{name:"Underscript",trigger:["\\underset"],kind:"infix",precedence:700},{name:"Increment",trigger:["+","+"],kind:"postfix",precedence:880},{name:"Decrement",trigger:["-","-"],kind:"postfix",precedence:880},{name:"PreIncrement",trigger:["+","+"],kind:"prefix",precedence:880},{name:"PreDecrement",trigger:["-","-"],kind:"prefix",precedence:880},{name:"Ring",trigger:["\\circ"],kind:"infix",precedence:265},{name:"Transpose",trigger:["^","T"],kind:"infix"},{name:"ConjugateTranspose",trigger:["^","H"],kind:"infix"},{name:"StringJoin",trigger:["\\lt","\\gt"],kind:"infix",precedence:780},{name:"Starstar",trigger:["\\star","\\star"],kind:"infix",precedence:780},{name:"PartialDerivative",trigger:["\\partial"],kind:"prefix",parse:e=>{let i=!1,t="Nothing",r="Nothing";for(;!i;)e.skipSpace(),e.match("_")?r=e.matchRequiredLatexArgument():e.match("^")?t=e.matchRequiredLatexArgument():i=!0;const n=L(r);if(n&&(r=["List",...n]),!r||!t)return null;let s=e.matchRequiredLatexArgument()??"Nothing";return"Nothing"!==s&&(s=[s,...e.matchArguments("group")??"Nothing"]),["PartialDerivative",s,r,t]},serialize:(e,i)=>{let t="\\partial";const r=b(i,1),n=b(i,2),s=b(i,3);return null!==n&&"Nothing"!==n&&("List"===k(n)?t+="_{"+e.serialize(["Sequence",...q(n)])+"}":t+="_{"+e.serialize(n)+"}"),null!==s&&"Nothing"!==s&&(t+="^{"+e.serialize(s)+"}"),null!==r&&"Nothing"!==r&&(t+=e.serialize(r)),t},precedence:740},{name:"OverBar",trigger:["\\overline"],requiredLatexArg:1},{name:"UnderBar",trigger:["\\underline"],requiredLatexArg:1},{name:"OverVector",trigger:["\\vec"],requiredLatexArg:1},{name:"OverTilde",trigger:["\\tilde"],requiredLatexArg:1},{name:"OverHat",trigger:["\\hat"],requiredLatexArg:1},{name:"OverRightArrow",trigger:["\\overrightarrow"],requiredLatexArg:1},{name:"OverLeftArrow",trigger:["\\overleftarrow"],requiredLatexArg:1},{name:"OverRightDoubleArrow",trigger:["\\Overrightarrow"],requiredLatexArg:1},{name:"OverLeftHarpoon",trigger:["\\overleftharpoon"],requiredLatexArg:1},{name:"OverRightHarpoon",trigger:["\\overrightharpoon"],requiredLatexArg:1},{name:"OverLeftRightArrow",trigger:["\\overleftrightarrow"],requiredLatexArg:1},{name:"OverBrace",trigger:["\\overbrace"],requiredLatexArg:1},{name:"OverLineSegment",trigger:["\\overlinesegment"],requiredLatexArg:1},{name:"OverGroup",trigger:["\\overgroup"],requiredLatexArg:1}];function V(e){return i=>{let t=!1,r=0;if(i.skipSpace(),i.match("^")){if(i.skipSpace(),i.match("<{>")){i.skipSpace(),i.match("-")&&i.match("1")&&(t=!0);do{i.match("\\doubleprime")&&(r+=2),i.match("\\prime")&&(r+=1),i.match("'")&&(r+=1)}while(!i.match("<}>")&&!i.atEnd)}let e=!1;for(;!e;)i.skipSpace(),i.match("\\doubleprime")?r+=2:i.match("\\prime")||i.match("'")?r+=1:e=!0}let n={"\\arcsin":"Arcsin","\\arccos":"Arccos","\\arctan":"Arctan","\\arctg":"Arctan","\\arcctg":"Arctan","\\arcsec":"Arcsec","\\arccsc":" Arccsc","\\arsinh":"Arsinh","\\arcosh":"Arcosh","\\artanh":"Artanh","\\arcsech":"Arcsech","\\arccsch":"Arcsch","\\ch":"Cosh","\\cos":"Cos","\\cosec":"Csc","\\cosh":"Csch","\\cot":"Cot","\\cotg":"Cot","\\coth":"Coth","\\csc":"Csc","\\ctg":"Cot","\\cth":"Coth","\\sec":"Sec","\\sin":"Sin","\\sinh":"Sinh","\\sh":"Sinh","\\tan":"Tan","\\tanh":"Tanh","\\tg":"Tan","\\th":"Tanh"}[e??""]??e??"";t&&(n=["InverseFunction",n]),r>=1&&(n=["Derivative",r,n]);const s=i.matchArguments("implicit");return null===s?[n,"Nothing"]:[n,...s]}}const H=[{name:"Arcsin",trigger:["\\arcsin"],arguments:"implicit",parse:V("Arcsin")},{name:"Arccos",trigger:["\\arccos"],arguments:"implicit",parse:V("Arccos")},{name:"Arctan",trigger:["\\arctan"],arguments:"implicit",parse:V("Arctan")},{trigger:["\\arctg"],arguments:"implicit",parse:V("Arctan")},{name:"Arccot",trigger:["\\arcctg"],arguments:"implicit",parse:V("Arccot")},{name:"Arcsec",trigger:["\\arcsec"],arguments:"implicit",parse:V("Arcsec")},{name:"Arccsc",trigger:["\\arccsc"],arguments:"implicit",parse:V("Arccsc")},{name:"Arsinh",trigger:["\\arsinh"],arguments:"implicit",parse:V("Arsinh")},{name:"Arcosh",trigger:["\\arcosh"],arguments:"implicit",parse:V("Arcosh")},{name:"Artanh",trigger:["\\artanh"],arguments:"implicit",parse:V("Artanh")},{name:"Arsech",trigger:["\\arsech"],arguments:"implicit",parse:V("Arsech")},{name:"Arcsch",trigger:["\\arcsch"],arguments:"implicit",parse:V("Arcsch")},{trigger:["\\ch"],arguments:"implicit",parse:V("Cosh")},{name:"Cosec",trigger:["\\cosec"],arguments:"implicit",parse:V("Cosec")},{name:"Cosh",trigger:["\\cosh"],arguments:"implicit",parse:V("Cosh")},{name:"Cot",trigger:["\\cot"],arguments:"implicit",parse:V("Cot")},{trigger:["\\cotg"],arguments:"implicit",parse:V("Cot")},{name:"Coth",trigger:["\\coth"],arguments:"implicit",parse:V("Coth")},{name:"Csc",trigger:["\\csc"],arguments:"implicit",parse:V("Csc")},{trigger:["\\ctg"],arguments:"implicit",parse:V("Cot")},{trigger:["\\cth"],arguments:"implicit",parse:V("Cotanh")},{name:"Sec",trigger:["\\sec"],arguments:"implicit",parse:V("Sec")},{name:"Sinh",trigger:["\\sinh"],arguments:"implicit",parse:V("Sinh")},{trigger:["\\sh"],arguments:"implicit",parse:V("Sinh")},{name:"Tan",trigger:["\\tan"],arguments:"implicit",parse:V("Tan")},{trigger:["\\tg"],arguments:"implicit",parse:V("Tan")},{name:"Tanh",trigger:["\\tanh"],arguments:"implicit",parse:V("Tanh")},{trigger:["\\th"],arguments:"implicit",parse:V("Tanh")},{name:"Cos",trigger:["\\cos"],arguments:"implicit",parse:V("Cos")},{name:"Sin",trigger:["\\sin"],arguments:"implicit",parse:V("Sin")}],K=[{name:"AlgebraicNumber",trigger:"\\bar\\Q"},{name:"ComplexNumber",trigger:["\\C"]},{trigger:"\\mathbb{C}",parse:"ComplexNumber"},{name:"ImaginaryNumber",trigger:["\\imaginaryI\\R"]},{name:"ExtendedComplexNumber",trigger:["\\bar\\C"]},{name:"EmptySet",trigger:["\\emptyset"]},{trigger:["\\varnothing"],parse:"EmptySet"},{name:"Integer",trigger:["\\Z"]},{trigger:"\\mathbb{Z}",parse:"Integer"},{name:"RationalNumber",trigger:["\\Q"]},{name:"RealNumber",trigger:["\\R"]},{name:"ExtendedRealNumber",trigger:["\\bar\\R"]},{name:"TranscendentalNumber",trigger:"\\R-\\bar\\Q"},{trigger:"\\R\\backslash\\bar\\Q",parse:"TranscendentalNumber"},{name:"NegativeNumber",trigger:"\\R^-"},{trigger:"\\R^{-}",parse:"NegativeNumber"},{trigger:"\\R_-",parse:"NegativeNumber"},{trigger:"\\R_{-}",parse:"NegativeNumber"},{trigger:"\\R^{\\lt}",parse:"NegativeNumber"},{name:"PositiveNumber",trigger:"\\R^+"},{trigger:"\\R^{+}",parse:"PositiveNumber"},{trigger:"\\R_+",parse:"PositiveNumber"},{trigger:"\\R_{+}",parse:"PositiveNumber"},{trigger:"\\R^{\\gt}",parse:"PositiveNumber"},{name:"NonPositiveNumber",trigger:"\\R^{0-}"},{trigger:"\\R^{-0}",parse:"NonPositiveNumber"},{trigger:"\\R^{\\leq}",parse:"NonPositiveNumber"},{name:"NegativeInteger",trigger:"\\Z^-"},{trigger:"\\Z^-",parse:"NegativeInteger"},{trigger:"\\Z^{-}",parse:"NegativeInteger"},{trigger:"\\Z_-",parse:"NegativeInteger"},{trigger:"\\Z_{-}",parse:"NegativeInteger"},{trigger:"\\Z^{\\lt}",parse:"NegativeInteger"},{name:"PositiveInteger",trigger:"\\Z^+"},{trigger:"\\Z^{+}",parse:"PositiveInteger"},{trigger:"\\Z_+",parse:"PositiveInteger"},{trigger:"\\Z_{+}",parse:"PositiveInteger"},{trigger:"\\Z^{\\gt}",parse:"PositiveInteger"},{trigger:"\\Z^{\\gt0}",parse:"PositiveInteger"},{trigger:"\\N^+",parse:"PositiveInteger"},{trigger:"\\N^{+}",parse:"PositiveInteger"},{trigger:"\\N^*",parse:"PositiveInteger"},{trigger:"\\N^{*}",parse:"PositiveInteger"},{trigger:"\\N^\\star",parse:"PositiveInteger"},{trigger:"\\N^{\\star}",parse:"PositiveInteger"},{trigger:"\\N_1",parse:"PositiveInteger"},{trigger:"\\N_{1}",parse:"PositiveInteger"},{name:"NonNegativeInteger",trigger:["\\N"]},{trigger:"\\Z^{+0}",parse:"NonNegativeInteger"},{trigger:"\\Z^{\\geq}",parse:"NonNegativeInteger"},{trigger:"\\Z^{\\geq0}",parse:"NonNegativeInteger"},{trigger:"\\Z^{0+}",parse:"NonNegativeInteger"},{trigger:"\\mathbb{N}",parse:"NonNegativeInteger"},{trigger:"\\N_0",parse:"NonNegativeInteger"},{trigger:"\\N_{0}",parse:"NonNegativeInteger"},{name:"CartesianProduct",trigger:["\\times"],kind:"infix",associativity:"right",precedence:390,parse:(e,i,t)=>{if(390<i.minPrec)return null;const r=e.computeEngine;if(!r||!r.box(t).domain.isSubsetOf("Set"))return null;const n=e.index,s=e.matchExpression({...i,minPrec:390});return null===s||!0!==r.box(t).domain.isSubsetOf("Set")?(e.index=n,null):["CartesianProduct",t,s]}},{name:"Complement",trigger:["^","\\complement"],kind:"infix"},{name:"Intersection",trigger:["\\cap"],kind:"infix",precedence:350},{name:"Interval",serialize:Q},{name:"Multiple",serialize:Q},{name:"Union",trigger:["\\cup"],kind:"infix",precedence:350},{name:"Range",serialize:Q},{name:"SetMinus",trigger:["\\setminus"],kind:"infix",precedence:650},{name:"SymmetricDifference",trigger:["\\triangle"],kind:"infix",precedence:260},{trigger:["\\ni"],kind:"infix",associativity:"right",precedence:160,parse:(e,i,t)=>{const r=e.matchExpression(i);return null===r?null:["Element",r,t]}},{name:"Element",trigger:["\\in"],kind:"infix",precedence:240},{name:"NotElement",trigger:["\\notin"],kind:"infix",precedence:240},{name:"NotSubset",trigger:["\\nsubset"],kind:"infix",associativity:"right",precedence:240},{name:"NotSuperset",trigger:["\\nsupset"],kind:"infix",associativity:"right",precedence:240},{name:"NotSubsetNotEqual",trigger:["\\nsubseteq"],kind:"infix",associativity:"right",precedence:240},{name:"NotSupersetNotEqual",trigger:["\\nsupseteq"],kind:"infix",associativity:"right",precedence:240},{name:"SquareSubset",trigger:["\\sqsubset"],kind:"infix",associativity:"right",precedence:265},{name:"SquareSubsetEqual",trigger:["\\sqsubseteq"],kind:"infix",associativity:"right",precedence:265},{name:"SquareSuperset",trigger:["\\sqsupset"],kind:"infix",associativity:"right",precedence:265},{name:"SquareSupersetEqual",trigger:["\\sqsupseteq"],kind:"infix",associativity:"right",precedence:265},{name:"Subset",trigger:["\\subset"],kind:"infix",associativity:"right",precedence:240},{trigger:["\\subsetneq"],kind:"infix",associativity:"right",precedence:240,parse:"Subset"},{trigger:["\\varsubsetneqq"],kind:"infix",associativity:"right",precedence:240,parse:"Subset"},{name:"SubsetEqual",trigger:["\\subseteq"],kind:"infix",precedence:240},{name:"Superset",trigger:["\\supset"],kind:"infix",associativity:"right",precedence:240},{trigger:["\\supsetneq"],kind:"infix",associativity:"right",precedence:240,parse:"Superset"},{trigger:["\\varsupsetneq"],kind:"infix",associativity:"right",precedence:240,parse:"Superset"},{name:"SupersetEqual",trigger:["\\supseteq"],kind:"infix",associativity:"right",precedence:240}];function Q(e,i){if(null===i)return"";const t=k(i);return null===t?"":"Set"===t?0===S(i)?"\\emptyset":2===S(i)&&"Condition"===k(b(i,2))?s(["\\left\\lbrace",e.serialize(b(i,1)),"\\middle\\mid",e.serialize(b(i,2)),"\\right\\rbrace"]):s(["\\left\\lbrace",...q(i).map((i=>e.serialize(i)+" ,")),"\\right\\rbrace"]):(e.numericSetStyle(i,e.level),"")}const X=[["Alpha","\\alpha",945],["Beta","\\beta",946],["Delta","\\delta",948],["Epsilon","\\epsilon",949],["EpsilonSymbol","\\varepsilon",1013],["Zeta","\\zeta",950],["Eta","\\eta",951],["Theta","\\theta",952],["ThetaSymbol","\\vartheta",977],["Iota","\\iota",953],["Kappa","\\kappa",954],["KappaSymbol","\\varkappa",1008],["Lambda","\\lambda",955],["Mu","\\mu",956],["Nu","\\nu",957],["Xi","\\xi",958],["Omicron","\\omicron",959],["PiSymbol","\\varpi",982],["Rho","\\rho",961],["RhoSymbol","\\varrho",1009],["Sigma","\\sigma",963],["FinalSigma","\\varsigma",962],["Tau","\\tau",964],["Phi","\\phi",981],["PhiLetter","\\varphi",966],["Upsilon","\\upsilon",965],["Chi","\\chi",967],["Psi","\\psi",968],["Omega","\\omega",969],["CapitalAlpha","\\Alpha",913],["CapitalBeta","\\Beta",914],["CapitalGamma","\\Gamma",915],["CapitalDelta","\\Delta",916],["CapitalEpsilon","\\Epsilon",917],["CapitalZeta","\\Zeta",918],["CapitalEta","\\Eta",919],["CapitalTheta","\\Theta",920],["CapitaIota","\\Iota",921],["CapitalKappa","\\Kappa",922],["CapitalLambda","\\Lambda",923],["CapitalMu","\\Mu",924],["CapitalNu","\\Nu",925],["CapitalXi","\\Xi",926],["CapitalOmicron","\\Omicron",927],["CapitalPi","\\Pi",928],["CapitalRho","\\Rho",929],["CapitalSigma","\\Sigma",931],["CapitalTau","\\Tau",932],["CapitalPhi","\\Phi",934],["CapitalUpsilon","\\Upsilon",933],["CapitalChi","\\Chi",935],["CapitalPsi","\\Psi",936],["CapitalOmega","\\Omega",937],["Digamma","\\digamma",989],["Alef","\\aleph",8501],["Bet","\\beth",8502],["Gimel","\\gimel",8503],["Dalet","\\daleth",8504],["TurnedCapitalF","\\Finv",8498],["TurnedCapitalG","\\Game",8513],["Weierstrass","\\wp",8472],["Eth","\\eth",240],["InvertedOhm","\\mho",8487],["BlackClubSuit","\\clubsuit",9827],["WhiteHeartSuit","\\heartsuit",9825],["BlackSpadeSuit","\\spadesuit",9824],["WhiteDiamondSuit","\\diamondsuit",9826],["Sharp","\\sharp",9839],["Flat","\\flat",9837],["Natural","\\natural",9838]],J=[...X.map((([e,i,t])=>({name:e,trigger:[i],parse:e}))),...X.map((([e,i,t])=>({trigger:[String.fromCodePoint(t)],parse:e})))],Y={"(":"(",")":")","[":"\\lbrack","]":"\\rbrack","{":"\\lbrace","}":"\\rbrace","<":"\\langle",">":"\\rangle","|":"\\vert","||":"\\Vert","\\lceil":"\\lceil","\\lfloor":"\\lfloor","\\rceil":"\\rceil","\\rfloor":"\\rfloor"};function ee(e){return Array.isArray(e)?e.length:1}function ie(e,i){if(!function(e,i){const t=e.name??e.trigger??e.openDelimiter;if(void 0!==e.serialize&&!e.name)return i({severity:"warning",message:["invalid-dictionary-entry",t,"Unexpected serialize property without a name property"]}),!1;if(l(e)){if(e.trigger)return i({severity:"warning",message:["invalid-dictionary-entry",t,`Unexpected 'trigger' "${e.trigger}". 'matchfix' operators use a 'openDelimiter' and 'closeDelimiter' instead of a trigger. `]}),!1;if(!e.openDelimiter||!e.closeDelimiter)return i({severity:"warning",message:["invalid-dictionary-entry",t,"Expected `openDelimiter` and a `closeDelimiter` for matchfix operator"]}),!1;if(typeof e.openDelimiter!=typeof e.closeDelimiter)return i({severity:"warning",message:["invalid-dictionary-entry",t,"Expected `openDelimiter` and `closeDelimiter` to both be strings or array of LatexToken"]}),!1}if(c(e)||u(e)||g(e)){if(Array.isArray(e.trigger)&&("_"===e.trigger[0]||"^"===e.trigger[0])||"string"==typeof e.trigger&&(e.trigger.startsWith("^")||e.trigger.startsWith("_"))){if(void 0!==e.precedence||void 0!==e.associativity)return i({severity:"warning",message:["invalid-dictionary-entry",t,'Unexpected "precedence" or "associativity" for superscript/subscript operator']}),!1}else if(void 0===e.precedence)return i({severity:"warning",message:["invalid-dictionary-entry",t,`Expected a "precedence" for ${e.kind} operator`]}),!1}else if(void 0!==e.associativity)return i({severity:"warning",message:["invalid-dictionary-entry",t,'Unexpected "associativity" operator']}),!1;return o(e)||void 0===e.optionalLatexArg&&void 0===e.requiredLatexArg?l(e)||e.trigger||e.name?void 0!==e.parse||void 0!==e.name||(i({severity:"warning",message:["invalid-dictionary-entry",t,"Expected a 'parse' or 'name'"]}),!1):(i({severity:"warning",message:["invalid-dictionary-entry",t,"Expected at least a 'trigger' or a 'name'"]}),!1):(i({severity:"warning",message:["invalid-dictionary-entry",t,'Unexpected "optionalLatexArg" or "requiredLatexArg" for non-symbol']}),!1)}(e,i))return[null,null];const t={name:e.name,kind:"kind"in e?e.kind:"symbol"};if("matchfix"===t.kind&&l(e)){if(t.openDelimiter=e.openDelimiter,t.closeDelimiter=e.closeDelimiter,"function"==typeof e.serialize)t.serialize=e.serialize;else{const e="string"==typeof t.openDelimiter?Y[t.openDelimiter]:a(t.openDelimiter),i="string"==typeof t.closeDelimiter?Y[t.closeDelimiter]:a(t.closeDelimiter);t.serialize=(t,r)=>s([e,t.serialize(r),i])}if("function"==typeof e.parse)t.parse=e.parse;else{const i=e.parse??e.name;t.parse=(e,t)=>[i,t]}return[null,t]}if("environment"===t.kind&&function(e){return"kind"in e&&"environment"===e.kind}(e)){const i=e.trigger;return t.serialize=(e,t)=>`\\begin{${i}${e.serialize(b(t,1))}\\end{${i}`,t.parse=e.parse??(()=>null),[i,t]}const r="string"==typeof e.trigger?n(e.trigger,[]):e.trigger,p=r?a(r):"";if(e.trigger,"symbol"===t.kind&&o(e)&&(t.arguments=e.arguments??"",t.precedence=e.precedence??0,t.optionalLatexArg=e.optionalLatexArg??0,t.requiredLatexArg=e.requiredLatexArg??0),"infix"!==t.kind&&"prefix"!==t.kind&&"postfix"!==t.kind||!(c(e)||g(e)||u(e))||(!r||"^"!==r[0]&&"_"!==r[0]?t.precedence=e.precedence??0:t.precedence=720),"infix"===t.kind&&c(e))if(t.associativity=e.associativity??"non","function"==typeof e.parse)t.parse=e.parse;else if(!r||"^"!==r[0]&&"_"!==r[0]){const i=e.parse??e.name,r=t.precedence,n=t.associativity;t.parse=(e,t,s)=>{if(r<t.minPrec)return null;const a=e.matchExpression({...t,minPrec:r});return"string"!=typeof i?[i,s,a??"Missing"]:w(i,s,a??"Missing",n)}}else{const i=e.parse??e.name;t.parse=(e,t,r)=>[i,b(r,1)??"Missing",b(r,2)??"Missing"]}else if("function"==typeof e.parse)t.parse=e.parse;else if(void 0!==e.parse)t.parse=()=>e.parse;else if(void 0===e.parse&&void 0!==e.name)if("postfix"===t.kind)t.parse=(i,t)=>t?[e.name,t]:null;else if("prefix"===t.kind){const i=t.precedence,r=e.name;t.parse=(e,t)=>{if(i<t.minPrec)return null;const n=e.matchExpression({...t,minPrec:i});return null===n?null:[r,n]}}else t.parse=()=>e.name;return"function"==typeof e.serialize||"string"==typeof e.serialize?t.serialize=e.serialize:r&&("postfix"===t.kind?t.serialize="#1"+p:"prefix"===t.kind?t.serialize=p+"#1":"infix"===t.kind?t.serialize="#1"+p+"#2":"symbol"===t.kind?t.serialize=p:t.serialize=""),[r??null,t]}const te={algebra:[{name:"To",trigger:["\\to"],kind:"infix",precedence:270}],arithmetic:O,calculus:[{name:"Integral",trigger:["\\int"],parse:function(e){let i="Nothing",t="Nothing",r=!1;for(;!r;)e.skipSpace(),e.match("_")?t=e.matchRequiredLatexArgument():e.match("^")?i=e.matchRequiredLatexArgument():r=!0;return["Integral",e.matchExpression({tokens:["d"]})??"",i??"Nothing",t??"Nothing"]},serialize:function(e,i){return""}}],core:Z,logic:[{name:"True",trigger:["\\mathrm","<{>","T","r","u","e","<}>"],serialize:"\\mathrm{True}"},{name:"False",trigger:["\\mathrm","<{>","F","a","l","s","e","<}>"],serialize:"\\mathrm{False}"},{name:"Maybe",trigger:["\\mathrm","<{>","M","a","y","b","e","<}>"],serialize:"\\mathrm{Maybe}"}],relop:[{trigger:["!","<"],kind:"infix",associativity:"right",precedence:246,parse:"NotLess"},{name:"NotLess",trigger:["\\nless"],kind:"infix",associativity:"right",precedence:246},{trigger:["<"],kind:"infix",associativity:"right",precedence:245,parse:"Less"},{name:"Less",trigger:["\\lt"],kind:"infix",associativity:"right",precedence:245},{trigger:["<","="],kind:"infix",associativity:"right",precedence:241,parse:"LessEqual"},{name:"LessEqual",trigger:["\\le"],kind:"infix",associativity:"right",precedence:241},{trigger:["\\leq"],kind:"infix",associativity:"right",precedence:241,parse:"Equal"},{trigger:["\\leqslant"],kind:"infix",associativity:"right",precedence:265,parse:"LessEqual"},{name:"LessNotEqual",trigger:["\\lneqq"],kind:"infix",associativity:"right",precedence:260},{name:"NotLessNotEqual",trigger:["\\nleqq"],kind:"infix",associativity:"right",precedence:260},{name:"LessOverEqual",trigger:["\\leqq"],kind:"infix",associativity:"right",precedence:265},{name:"GreaterOverEqual",trigger:["\\geqq"],kind:"infix",associativity:"right",precedence:265,parse:"GreaterEqual"},{name:"Equal",trigger:["="],kind:"infix",associativity:"right",precedence:260},{trigger:["*","="],kind:"infix",associativity:"right",precedence:260,parse:"StarEqual"},{name:"StarEqual",trigger:["\\star","="],kind:"infix",associativity:"right",precedence:260},{name:"PlusEqual",trigger:["+","="],kind:"infix",associativity:"right",precedence:260},{name:"MinusEqual",trigger:["-","="],kind:"infix",associativity:"right",precedence:260},{name:"SlashEqual",trigger:["/","="],kind:"infix",associativity:"right",precedence:260},{name:"EqualEqual",trigger:["=","="],kind:"infix",associativity:"right",precedence:260},{name:"EqualEqualEqual",trigger:["=","=","="],kind:"infix",associativity:"right",precedence:265},{name:"TildeFullEqual",trigger:["\\cong"],kind:"infix",associativity:"right",precedence:260},{name:"NotTildeFullEqual",trigger:["\\ncong"],kind:"infix",associativity:"right",precedence:260},{trigger:[":","="],kind:"infix",associativity:"right",precedence:260,parse:"Assign"},{name:"Assign",trigger:["\\coloneq"],kind:"infix",associativity:"right",precedence:260},{name:"Approx",trigger:["\\approx"],kind:"infix",associativity:"right",precedence:247},{name:"NotApprox",trigger:["\\approx"],kind:"infix",associativity:"right",precedence:247},{name:"ApproxEqual",trigger:["\\approxeq"],kind:"infix",associativity:"right",precedence:260},{name:"NotApproxEqual",trigger:["!","\\approxeq"],kind:"infix",associativity:"right",precedence:250},{name:"NotEqual",trigger:["\\ne"],kind:"infix",associativity:"right",precedence:255},{name:"Unequal",trigger:["!","="],kind:"infix",associativity:"right",precedence:260},{name:"GreaterEqual",trigger:["\\ge"],kind:"infix",associativity:"right",precedence:242},{trigger:["\\geq"],kind:"infix",associativity:"right",precedence:242,parse:"GreaterEqual"},{trigger:[">","="],kind:"infix",associativity:"right",precedence:243,parse:"GreaterEqual"},{trigger:["\\geqslant"],kind:"infix",associativity:"right",precedence:265,parse:"GreaterEqual"},{name:"GreaterNotEqual",trigger:["\\gneqq"],kind:"infix",associativity:"right",precedence:260},{name:"NotGreaterNotEqual",trigger:["\\ngeqq"],kind:"infix",associativity:"right",precedence:260},{trigger:[">"],kind:"infix",associativity:"right",precedence:245,parse:"Greater"},{name:"Greater",trigger:["\\gt"],kind:"infix",associativity:"right",precedence:245},{name:"NotGreater",trigger:["\\ngtr"],kind:"infix",associativity:"right",precedence:244},{trigger:["!",">"],kind:"infix",associativity:"right",precedence:244,parse:"NotGreater"},{name:"RingEqual",trigger:["\\circeq"],kind:"infix",associativity:"right",precedence:260},{name:"TriangleEqual",trigger:["\\triangleq"],kind:"infix",associativity:"right",precedence:260},{name:"DotEqual",trigger:["\\doteq"],kind:"infix",associativity:"right",precedence:265},{name:"DotEqualDot",trigger:["\\doteqdot"],kind:"infix",associativity:"right",precedence:265},{name:"FallingDotEqual",trigger:["\\fallingdotseq"],kind:"infix",associativity:"right",precedence:265},{name:"RisingDotEqual",trigger:["\\fallingdotseq"],kind:"infix",associativity:"right",precedence:265},{name:"QuestionEqual",trigger:["\\questeq"],kind:"infix",associativity:"right",precedence:260},{name:"Equivalent",trigger:["\\equiv"],kind:"infix",associativity:"right",precedence:260},{name:"MuchLess",trigger:["\\ll"],kind:"infix",associativity:"right",precedence:260},{name:"MuchGreater",trigger:["\\gg"],kind:"infix",associativity:"right",precedence:260},{name:"Precedes",trigger:["\\prec"],kind:"infix",associativity:"right",precedence:260},{name:"Succeeds",trigger:["\\succ"],kind:"infix",associativity:"right",precedence:260},{name:"PrecedesEqual",trigger:["\\preccurlyeq"],kind:"infix",associativity:"right",precedence:260},{name:"SucceedsEqual",trigger:["\\curlyeqprec"],kind:"infix",associativity:"right",precedence:260},{name:"NotPrecedes",trigger:["\\nprec"],kind:"infix",associativity:"right",precedence:260},{name:"NotSucceeds",trigger:["\\nsucc"],kind:"infix",associativity:"right",precedence:260},{name:"Between",trigger:["\\between"],kind:"infix",associativity:"right",precedence:265}],other:W,physics:[{name:"mu-0",trigger:"\\mu_0"}],sets:K,symbols:J,trigonometry:H},re={"(":["\\lparen","("],")":["\\rparen",")"],"[":["\\lbrack"],"]":["\\rbrack"],"<":["<","\\langle"],">":[">","\\rangle"],"{":["\\{","\\lbrace"],"}":["\\}","\\rbrace"],":":[":","\\colon"],"|":["|","\\|","\\lvert","\\rvert"],"||":["||","\\Vert","\\lVert","\\rVert"],"\\lfloor":["\\lfloor"],"\\rfloor":["\\rfloor"],"\\lceil":["\\lceil"],"\\rceil":["\\rceil"],"\\ulcorner":["\\ulcorner"],"\\urcorner":["\\urcorner"],"\\llcorner":["\\llcorner"],"\\lrcorner":["\\lrcorner"],"\\lgroup":["\\lgroup"],"\\rgroup":["\\rgroup"],"\\lmoustache":["\\lmoustache"],"\\rmoustache":["\\rmoustache"]},ne={":":[":","\\colon"],"|":["|","\\|","\\mid","\\mvert"]},se={"\\left":"\\right","\\bigl":"\\bigr","\\Bigl":"\\Bigr","\\biggl":"\\biggr","\\Biggl":"\\Biggr","\\big":"\\big","\\Big":"\\Big","\\bigg":"\\bigg","\\Bigg":"\\Bigg"},ae=["\\middle","\\bigm","\\Bigm","\\biggm","\\Biggm","\\big","\\Big","\\bigg","\\Bigg"],oe={"(":")","[":"]","\\{":"\\}","\\lbrace":"\\rbrace","\\lparen":"\\rparen","\\langle":"\\rangle","\\lfloor":"\\rfloor","\\lceil":"\\rceil","\\vert":"\\vert","\\lvert":"\\rvert","\\Vert":"\\Vert","\\lVert":"\\rVert","\\lbrack":"\\rbrack","\\ulcorner":"\\urcorner","\\llcorner":"\\lrcorner","\\lgroup":"\\rgroup","\\lmoustache":"\\rmoustache"},le={precision:6,positiveInfinity:"\\infty",negativeInfinity:"-\\infty",notANumber:"\\operatorname{NaN}",decimalMarker:".",groupSeparator:"\\,",exponentProduct:"\\cdot",beginExponentMarker:"10^{",endExponentMarker:"}",notation:"auto",truncationMarker:"\\ldots",beginRepeatingDigits:"\\overline{",endRepeatingDigits:"}",imaginaryNumber:"\\imaginaryI",avoidExponentsInRange:[-7,20]},ce={applyInvisibleOperator:"auto",skipSpace:!0,parseArgumentsOfUnknownLatexCommands:!0,parseNumbers:!0,parseUnknownToken:e=>["\\displaystyle","\\!","\\:","\\enskip","\\quad","\\,","\\;","\\enspace","\\qquad","\\selectfont","\\tiny","\\scriptsize","\\footnotesize","\\small","\\normalsize","\\large","\\Large","\\LARGE","\\huge","\\Huge"].includes(e)?"skip":/^[fg]$/.test(e)?"function":/^[a-zA-Z]$/.test(e)?"symbol":"error",preserveLatex:!0};class ge{constructor(e,i,t,r,n){this.index=0,this._lastPeek="",this._peekCounter=0,this.options={...le,...ce,...i},this.engine=r,this._tokens=e,this.onError=n,this._dictionary=t}updateOptions(e){for(const[i,t]of Object.entries(e))this.options[i]=t}clone(e,i){return new ge(this._tokens.slice(e,i),this.options,this._dictionary,this.engine,this.onError)}get atEnd(){return this.index>=this._tokens.length}get peek(){if(this._tokens[this.index]===this._lastPeek?this._peekCounter+=1:this._peekCounter=0,this._peekCounter>=1024)throw Error("Infinite loop");return this._lastPeek=this._tokens[this.index],this._tokens[this.index]}atTerminator(e){const i=this.index;return!!this.atEnd||!!e&&(!(!e.condition||!e.condition(this))||!!(e.tokens&&e.tokens.length>0&&this.matchAll(e.tokens))&&(this.index=i,!0))}latex(e,i){return a(this._tokens.slice(e,i))}latexAhead(e){return a(this._tokens.slice(this.index,this.index+e))}latexBefore(){return this.latex(0,this.index)}latexAfter(){return this.latex(this.index)}lookAhead(){let e=Math.min(this._dictionary.lookahead,this._tokens.length-this.index);const i=[];for(;e>0;)i[e]=this.latexAhead(e--);return i}peekDefinitions(e){let i;i="operator"===e?this.lookAhead().map(((e,i)=>this._dictionary.infix[i]?.get(e)??this._dictionary.postfix[i]?.get(e)??this._dictionary.prefix[i]?.get(e))):this.lookAhead().map(((i,t)=>this._dictionary[e][t]?.get(i)));const t=[];for(let e=i.length;e>0;e--)if(void 0!==i[e])for(const r of i[e])t.push([r,e]);return 0===t.length?null:t}next(){return this._tokens[this.index++]}skipSpace(){if(!this.atEnd&&"<{>"===this.peek&&"<}>"===this._tokens[this.index+1])return this.index+=2,this.skipSpace(),!0;let e=!1;for(;!this.atEnd&&"skip"===this.options.parseUnknownToken?.(this.peek,this);)this.index+=1,this.skipSpace(),e=!0;if(!this.options.skipSpace)return!1;for(;this.match("<space>");)e=!0;return e&&this.skipSpace(),e}matchChar(){const e=this.index;let i=0;for(;this.match("^");)i+=1;if(i>=2){let e="",t=0;for(;t!=i;){const i=this.matchAny(["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]);if(!i)break;e+=i,t+=1}if(e.length===i)return String.fromCodePoint(Number.parseInt(e,16))}else{if(this.match("\\char")){let e=Math.floor(this.matchLatexNumber()??NaN);return(!Number.isFinite(e)||e<0||e>1114111)&&(e=10067),String.fromCodePoint(e)}if(this.match("\\unicode"))if("<{>"===this.peek){const e=this.matchLatexNumber();if(this.match("<}>")&&null!==e&&e>=0&&e<=1114111)return String.fromCodePoint(e)}else{const e=this.matchLatexNumber();if(null!==e&&e>=0&&e<=1114111)return String.fromCodePoint(e)}}return this.index=e,this.next()}matchColor(e=!1){let i="";for(;!this.atEnd&&"}"!==this.peek;)i+=this.next();return i}matchLatexDimension(){return null}match(e){return this._tokens[this.index]===e&&(this.index++,!0)}matchAll(e){"string"==typeof e&&(e=[e]);let i=!0,t=0;do{i=this._tokens[this.index+t]===e[t++]}while(i&&t<e.length);return i&&(this.index+=t),i}matchAny(e){return e.includes(this._tokens[this.index])?this._tokens[this.index++]:""}matchWhile(e){const i=[];for(;e.includes(this._tokens[this.index]);)i.push(this._tokens[this.index++]);return i}matchSign(){let e=!1,i=!1;for(;!i;)this.skipSpace()?i=!1:this.matchAny(["-","\u2212"])?(e=!e,i=!1):i=!this.matchAny(["+","\ufe62"]);return e?"-":"+"}matchDecimalDigits(){let e="",i=!1;for(;!i;)if(e+=this.matchWhile(["0","1","2","3","4","5","6","7","8","9"]).join(""),i=!0,this.options.groupSeparator){const e=this.index;this.skipSpace(),this.match(this.options.groupSeparator)&&(this.skipSpace(),/[0-9]/.test(this.peek)?i=!1:this.index=e)}return e}matchSignedInteger(){const e=this.index,i=this.matchSign(),t=this.matchDecimalDigits();return t?("-"===i?"-":"")+t:(this.index=e,"")}matchExponent(){const e=this.index;let i="";if(this.matchAny(["e","E"])){const e=this.matchSignedInteger();e&&(i="e"+e)}if(i)return i;if(this.match("\\times")&&(this.skipSpace(),this.match("1")&&this.match("0")&&this.match("^"))){if(/[0-9]/.test(this.peek))return"e"+this.next();if(this.match("<{>")){this.skipSpace();const e=this.matchSignedInteger();if(this.skipSpace(),this.match("<}>")&&e)return"e"+e}}return this.index=e,""}matchNumber(){if(!this.options.parseNumbers)return"";const e=this.index;this.skipSpace(),this.match("+");let i=!1;if(this.match(this.options.decimalMarker)){const t=this.index;if(!this.matchAny(["0","1","2","3","4","5","6","7","8","9"]))return this.index=e,"";this.index=t,i=!0}let t=this.matchDecimalDigits();return t?(!i&&this.match(this.options.decimalMarker??"")&&(t+="."+(this.matchDecimalDigits()??"0")),(i?"0.":"")+t+this.matchExponent()):(this.index=e,"")}matchLatexNumber(e=!0){let i=!1,t=this.peek;for(;"<space>"===t||"+"===t||"-"===t;)"-"===t&&(i=!i),this.next(),t=this.peek;let r=10,n=["0","1","2","3","4","5","6","7","8","9"];if(this.match("'"))r=8,n=["0","1","2","3","4","5","6","7"],e=!0;else if(this.match('"')||this.match("x"))r=16,n=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"],e=!0;else if(this.match("`"))return t=this.next(),t?t.startsWith("\\")&&2===t.length?(i?-1:1)*(t.codePointAt(1)??0):(i?-1:1)*(t.codePointAt(0)??0):null;let s="";for(;n.includes(this.peek);)s+=this.next();if(!e&&this.match("."))for(s+=".";n.includes(this.peek);)s+=this.next();const a=e?Number.parseInt(s,r):Number.parseFloat(s);return Number.isNaN(a)?null:i?-a:a}matchPrefixOperator(e){e||(e={minPrec:0}),e.minPrec||(e={...e,minPrec:0});const i=this.peekDefinitions("prefix");if(null===i)return null;const t=this.index;for(const[r,n]of i){this.index=t+n;const i=r.parse(this,e);if(i)return i}return this.index=t,null}matchInfixOperator(e,i){i||(i={minPrec:0}),i.minPrec||(i={...i,minPrec:0});const t=this.peekDefinitions("infix");if(null===t)return null;const r=this.index;for(const[n,s]of t)if(n.precedence>=i.minPrec){this.index=r+s;const t=n.parse(this,i,e);if(t)return t}return this.index=r,null}matchArguments(e){if(!e)return null;const i=this.index;let t=null;const r=this.matchEnclosure();if("group"===e&&"Delimiter"===k(r))t=q(r);else if("implicit"===e)if("Delimiter"===k(r))t=q(r);else if(null!==r)t=[r];else{const e=this.matchPrimary();null!==e&&(t=[e])}else this.index=i;return t}matchOpenDelimiter(e,i){const t=this.index,r=se[this.peek];r&&this.next();const n=re[e]??[e],s=r?[r]:[];return n.includes("||")&&this.matchAll(["|","|"])?(s.push("|"),s.push("|"),s):n.includes(this.peek)?(oe[e]===i?s.push(oe[this.peek]):s.push(i),this.next(),s):(this.index=t,null)}matchMiddleDelimiter(e){const i=ne[e]??[e];if(ae.includes(this.peek)){const e=this.index;return this.next(),i.includes(this.peek)?(this.next(),!0):(this.index=e,!1)}return!!i.include(this.peek)&&(this.next(),!0)}matchEnclosure(){const e=this._dictionary.matchfix;if(0===e.length)return null;const i=this.index;for(const t of e){if(this.index=i,Array.isArray(t.openDelimiter)){if(!this.matchAll(t.openDelimiter))continue;const e=this.matchExpression({tokens:t.closeDelimiter,minPrec:0});if(this.skipSpace(),!this.matchAll(t.closeDelimiter))continue;if("function"==typeof t.parse){const i=t.parse(this,e??"Nothing");if(null===i)continue;return i}return[t.name,e??"Nothing"]}const e=this.matchOpenDelimiter(t.openDelimiter,t.closeDelimiter);if(null===e)continue;const r=this.matchExpression({minPrec:0,tokens:e});if(r&&this.matchAll(e)){if("function"==typeof t.parse){const e=t.parse(this,r??"Nothing");if(null===e)continue;return e}return[t.name,r]}}return this.index=i,null}matchSymbol(){const e=this.index,i=this.peekDefinitions("symbol");if(i)for(const[t,r]of i){let i=null;if(this.index=e+r,"function"!=typeof t.parse)return t.name;if(i=t.parse(this),i)return i}this.index=e;const t=this.options.parseUnknownToken?.(this.peek,this);if("function"===t){const e=this.next(),i=this.matchEnclosure();return null===i?e:"Delimiter"!==k(i)?null:[e,...q(i)]}return"symbol"===t?this.next():this.matchUnknownLatexCommand()}matchOptionalLatexArgument(){const e=this.index;if(this.skipSpace(),this.match("[")){const e=this.matchExpression();if(this.skipSpace(),this.match("]"))return e}return this.index=e,null}matchRequiredLatexArgument(){const e=this.index;if(this.skipSpace(),this.match("<{>")){const i=this.matchExpression({tokens:["<}>"]});return this.skipSpace(),this.match("<}>")?i:(this.index=e,null)}return/^[0-9]$/.test(this.peek)?parseInt(this.next()):/^[^\\#]$/.test(this.peek)?this.next():this.matchSymbol()||(this.index=e,null)}matchSupsub(e){if(null===e)return null;const i=this.index;this.skipSpace();const t=[],r=[];for(;"_"===this.peek||"^"===this.peek;){if(this.match("_")){let e=this.matchRequiredLatexArgument();!e&&this.match("<{>")&&(e=this.matchString({tokens:["<}>"]}),e&&this.match("<}>")),r.push(e??"Missing")}else this.match("^")&&t.push(this.matchRequiredLatexArgument()??"Missing");this.skipSpace()}if(0===t.length&&0===r.length)return this.index=i,e;let n=e;if(r.length>0){const e=this._dictionary.infix[1]?.get("_");if(e){const i=["Subscript",n,1===r.length?r[0]:["Sequence",...r]];for(const t of e)if(n="function"==typeof t.parse?t.parse(this,{minPrec:0},i):i,n)break}}if(t.length>0){const e=this._dictionary.infix[1]?.get("^");if(e){const i=["Superscript",n,1===t.length?t[0]:["Sequence",...t]];for(const t of e)if(n="function"==typeof t.parse?t.parse(this,{minPrec:0},i):i,n)break}}return null===n&&(this.index=i),n}matchPostfix(e){if(null===e)return null;const i=this.peekDefinitions("postfix");if(null===i)return null;const t=this.index;for(const[r,n]of i){this.index=t+n;const i=r.parse(this,e);if(null!==i)return i}return this.index=t,null}matchString(e){e.minPrec||(e={...e,minPrec:0});let i="",t=this.atEnd;for(;!t;){const r=this.peek;"<space>"===r?i+=" ":"\\"===r[0]?(this.onError([{severity:"warning",message:"unexpected-command"}]),i+=this.next()):/^<(\$|\$\$)>$/.test(r)?t=!0:i+=this.next(),t=t||this.atTerminator(e)}return i}matchEnvironmentName(e,i){if(!this.match(e))return!1;const t=this.index;if(this.match("<{>")){const e=this.matchString({tokens:["<}>"]});if(this.match("<}>")&&e===i)return!0}return this.index=t,!1}matchTabular(e){const i=["List"],t={minPrec:0,tokens:["\\end","<{>",...e.split(""),"<}>"]};let r=["List"],n=null;for(;!this.atTerminator(t);)this.match("&")?(r.push(n??"Nothing"),n=null):(this.match("\\\\")||this.match("\\cr"))&&(this.skipSpace(),this.matchOptionalLatexArgument(),null!==n&&r.push(n),i.push(r),r=["List"],n=null);return r.length>1&&i.push(r),i}matchEnvironment(){if(!this.match("\\begin"))return null;const e=this.index;if(this.match("<{>")){const e=this.matchString({tokens:["<}>"]});if(this.match("<}>")){const i=this._dictionary.environment.get(e);if(i)return i.parse(this,[],[]);const t=this.matchTabular(e);if(null!==t)return t}}return this.index=e,null}applyInvisibleOperator(e,i){if(null===i||this.atTerminator(e))return null;if(null===this.options.applyInvisibleOperator)return null;const t=this.index,r=this.matchExpression({...e,minPrec:390});if(null===r)return this.index=t,null;if("function"==typeof this.options.applyInvisibleOperator)return this.options.applyInvisibleOperator(this,i,r);const n=this.engine.box(r),s=N(i);if(s&&this.engine.getFunctionDefinition(s)){let e=[];return e="Delimiter"===n.head?"Sequence"===n.op1.head?[...n.op1.ops]:[n.op1]:[n],[s,...e.map((e=>e.json))]}const a=this.engine.box(i);if(a.isLiteral&&a.isInteger&&n.isLiteral){const[e,t]=n.rationalValue;if(null!==e&&null!==t)return["Add",i,r]}return a.isNumber&&n.isNumber?w("Multiply",i,r):(this.index=t,null)}matchUnknownLatexCommand(){const e=this.peek;if(!e||"\\"!==e[0])return null;this.next();const i=[];if("\\operatorname"===e){if(this.match("<{>")){for(;!this.atEnd&&"<}>"!==this.peek;)i.push(this.next());this.match("<}>")}else i.push(this.next());return 0===i.length?["Error","Missing",{str:"syntax-error"},["LatexForm",{str:e}]]:["Error","Missing",{str:"unknown-command"},["LatexForm",{str:`${e}{${a(i)}}`}]]}for(;this.match("[");){i.push("[");let e=0;for(;!this.atEnd&&0===e&&"]"!==this.peek;)"["===this.peek&&(e+=1),"]"===this.peek&&(e-=1),i.push(this.next());this.match("]")&&i.push("]")}for(;this.match("<{>");){i.push("<{>");let e=0;for(;!this.atEnd&&0===e&&"<}>"!==this.peek;)"<{>"===this.peek&&(e+=1),"<}>"===this.peek&&(e-=1),i.push(this.next());this.match("<}>")&&i.push("<}>")}return["Error","Missing",{str:"unknown-command"},["LatexForm",{str:`${e}${a(i)}`}]]}matchPrimary(){let e=null;const i=this.index,t=this.matchNumber();if(t&&(e={num:t}),null===e&&(e=this.matchEnclosure()),null===e&&(e=this.matchEnvironment()),null===e&&(e=this.matchSymbol()),null!==e){e=this.decorate(e,i);let t=null,r=this.index;do{if(t=this.matchPostfix(e),e=t??e,this.index===r&&null!==t)break;r=this.index}while(null!==t)}return null!==e&&(e=this.matchSupsub(e)),this.decorate(e,i)}matchExpression(e){const i=this.index;e||(e={minPrec:0}),e.minPrec||(e={...e,minPrec:0}),this.skipSpace();let t=this.matchPrefixOperator({...e,minPrec:0});if(null===t&&(t=this.matchPrimary()),t){let i=!1;for(;!this.atTerminator(e)&&!i;){this.skipSpace();let r=this.matchInfixOperator(t,e);null===r&&null===this.peekDefinitions("operator")&&(r=this.applyInvisibleOperator(e,t)),null!==r?t=r:i=!0}}return this.decorate(t,i)}decorate(e,i){if(null===e)return null;if(!this.options.preserveLatex)return e;const t=this.latex(i,this.index);return Array.isArray(e)?e={latex:t,fn:e}:"number"==typeof e?e={latex:t,num:Number(e).toString()}:"string"==typeof e?e={latex:t,sym:e}:"object"==typeof e&&null!==e&&(e.latex=t),e}}function ue(e,i){const t=e.length,r=e;e=e.slice(0,-1);for(let t=0;t<e.length-16;t++){const r=e.substring(0,t);for(let n=0;n<17;n++){const s=e.substring(t,t+n+1),a=Math.floor((e.length-r.length)/s.length);if(a>1&&(r+s.repeat(a+1)).startsWith(e))return"0"===s?r.replace(/(\d{3})/g,"$1"+i.groupSeparator):r.replace(/(\d{3})/g,"$1"+i.groupSeparator)+i.beginRepeatingDigits+s+i.endRepeatingDigits}}const n=t>i.precision-1;return e=r,n&&(e=e.substring(0,i.precision-1)),i.groupSeparator&&(e=e.replace(/(\d{3})/g,"$1"+i.groupSeparator)).endsWith(i.groupSeparator)&&(e=e.slice(0,-i.groupSeparator.length)),n?e+i.truncationMarker:e}function pe(e,i){return e?i.beginExponentMarker?i.beginExponentMarker+e+(i.endExponentMarker??""):"10^{"+e+"}":""}class he{constructor(e,i,t,r){this.level=-1,this.options=e,this.computeEngine=t,e.invisibleMultiply&&(/#1/.test(e.invisibleMultiply)&&/#2/.test(e.invisibleMultiply)||r([{severity:"warning",message:["expected-argument","invisibleMultiply"]}])),this.onError=r,this.dictionary=i}updateOptions(e){for(const i of Object.keys(this.options))i in e&&(this.options[i]=e[i])}wrap(e,i){if(null===e)return"";if(void 0===i)return"("+this.serialize(e)+")";if("number"==typeof e||p(e)||"string"==typeof e||h(e))return this.serialize(e);const t=k(e);if("string"==typeof t&&"Delimiter"!==t){const r=this.dictionary.name.get(t);if(r&&("symbol"===r.kind||"prefix"===r.kind||"infix"===r.kind||"postfix"===r.kind)&&r.precedence<i)return this.wrapString(this.serialize(e),this.options.applyFunctionStyle(e,this.level))}return this.serialize(e)}wrapShort(e){if(null===e)return"";const i=this.serialize(e);return"Delimiter"===k(e)||"number"==typeof e||p(e)||/(^(.|\\[a-zA-Z*]+))$/.test(i)?i:this.wrapString(i,this.options.groupStyle(e,this.level+1))}wrapString(e,i){return"none"===i?e:"("+e+")"}serializeSymbol(e,i){const t=k(e);if(!t)return"string"==typeof i?.serialize?i.serialize:"function"==typeof i?.serialize?i.serialize(this,e):de(N(e),"upright.")??"";const r=q(e);if(!i){if("string"==typeof t&&t.length>0&&"\\"===t[0]){let e=t;for(const i of r)e+="{"+this.serialize(i)+"}";return e}return"string"==typeof t?`${de(t,"upright.")}(${r.map((e=>this.serialize(e))).join(", ")})`:`\\operatorname{Apply}(${this.serialize(t)}, ${this.serialize(["List",...r])})`}if(i.requiredLatexArg>0){let e="",t="",n=0;for(;n<i.requiredLatexArg;)t+="{"+this.serialize(r[n++])+"}";for(;n<Math.min(r.length,i.optionalLatexArg+i.requiredLatexArg);){const i=this.serialize(r[1+n++]);i&&(e+="["+i+"]")}return i.serialize+(e+t)}return"function"==typeof i.serialize?i.serialize(this,e):"none"===this.options.applyFunctionStyle(e,this.level)?i.serialize+s(r.map((e=>this.serialize(e)))):i.serialize+this.serialize(["Delimiter",...r])}serializeDictionary(e){return`\\left[\\begin{array}{lll}${Object.keys(e).map((i=>`\\textbf{${i}} & \\rightarrow & ${this.serialize(e[i])}`)).join("\\\\")}\\end{array}\\right]`}serialize(e){if(null===e)return"";this.level+=1;const i=(()=>{const i=function(e,i){if(null===e)return"";let t;if("number"==typeof e)t=e;else{if("object"!=typeof e||!("num"in e))return"";t=e.num}if(t===1/0||"Infinity"===t||"+Infinity"===t)return i.positiveInfinity;if(t===-1/0||"-Infinity"===t)return i.negativeInfinity;if("NaN"===t||"number"==typeof t&&Number.isNaN(t))return i.notANumber;if("number"==typeof t)return"engineering"===i.notation?function(e,i){if(0===e)return"0";const t=Math.abs(e);let r=Math.round(Math.log10(t));r-=r%3,t>Math.pow(10,i.avoidExponentsInRange[0])&&t<Math.pow(10,i.avoidExponentsInRange[1])&&(r=0);const n=t/Math.pow(10,r);let s="";const a=n.toString().match(/^(.*)\.(.*)$/);a?.[1]&&a[2]&&(s=a[1]+i.decimalMarker+a[2]),i.groupSeparator&&(s=ue(n.toExponential(),i));let o="";return 0!==r&&(o=pe(r.toString(),i)),(e<0?"-":"")+s+o}(t,i):function(e,i){let t,r=e.match(/^(.*)[e|E]([-+]?[0-9]+)$/i);r?.[1]&&r[2]&&(t=pe(r[2],i));let n=r?.[1]??e,s="";return r=(t?r[1]:e).match(/^(.*)\.(.*)$/),r?.[1]&&r[2]&&(n=r[1],s=r[2]),i.groupSeparator&&(n=n.replace(/\B(?=(\d{3})+(?!\d))/g,i.groupSeparator),s=ue(s,i)),s&&(s=i.decimalMarker+s),t?"1"!==n||s?n+s+i.exponentProduct+t:t:n+s}(t.toString(),i);if(/[0-9][nd]$/.test(t)&&(t=t.slice(0,-1)),t=t.replace(/[\u0009-\u000d\u0020\u00a0]/g,""),/\([0-9]+\)$/.test(t)){const[e,r,n]=t.match(/(.+)\(([0-9]+)\)$/)??[];t=r+n.repeat(Math.ceil(i.precision/n.length))}let r="";for("-"===t[0]?(r="-",t=t.substring(1)):"+"===t[0]&&(t=t.substring(1));"0"===t[0];)t=t.substring(1);if(0===t.length)return r+"0";"."===t[0]&&(t="0"+t);let n="";if(t.indexOf(".")>=0){const e=t.match(/(\d*)\.(\d*)([e|E]([-+]?[0-9]*))?/);if(!e)return"";const s=e[1],a=e[2];if(n=e[4]??"","0"===s){let e=0;for(;"0"===a[e]&&e<a.length;)e+=1;let n="";if(e<=4)n="0"+i.decimalMarker,n+=a.substring(0,e),n+=ue(t.substring(n.length),i);else if(e+1>=i.precision)n="0",r="";else{n=t[e];const r=ue(t.substring(e+1),i);r&&(n+=i.decimalMarker+r)}"0"!==n&&(!(t.length-1>i.precision)||i.endRepeatingDigits&&n.endsWith(i.endRepeatingDigits)||!i.truncationMarker||n.endsWith(i.truncationMarker)||(n+=i.truncationMarker),e>4&&(n+=i.exponentProduct+pe(""+(1-e),i))),t=n}else{t=s.replace(/\B(?=(\d{3})+(?!\d))/g,i.groupSeparator);const e=ue(a,i);e&&(t+=i.decimalMarker+e)}}else if(t.length>i.precision){const e=t.length;if(e>i.avoidExponentsInRange[1]){let r=t[0];const n=ue(t.substring(1),i);n&&(r+=i.decimalMarker+n,i.truncationMarker&&!r.endsWith(i.truncationMarker)&&i.endRepeatingDigits&&!r.endsWith(i.endRepeatingDigits)&&(r+=i.truncationMarker)),"1"!==r?r+=i.exponentProduct:r="",t=r+pe(""+(e-1),i)}}else{const e=t.match(/([0-9]*)\.?([0-9]*)([e|E]([-+]?[0-9]+))?/);e&&(t=e[1],e[2]&&(t+=i.decimalMarker+e[2]),n=e[4]??""),t=t.replace(/\B(?=(\d{3})+(?!\d))/g,i.groupSeparator)}const s=pe(n,i);return"1"===t&&s?r+s:(s&&(t=t+i.exponentProduct+s),r+t)}(e,this.options);if(i)return i;const t=y(e);if(null!==t)return`\\text{${t}}`;const r=N(e);if(null!==r){const i=this.dictionary.name.get(r);if("symbol"===i?.kind)return this.serializeSymbol(e,i)}const n=D(e);if(null!==n)return this.serializeDictionary(n);const s=v(e);if(s){if("\\"===s[0]){const i=q(e);return 0===i.length?s:s+"{"+i.map((e=>this.serialize(e))).filter((e=>!!e)).join("}{")+"}"}const i=this.dictionary.name.get(s);if(i){let t="";return"function"==typeof i.serialize&&(t=i.serialize(this,e)),t||"infix"!==i.kind&&"postfix"!==i.kind&&"prefix"!==i.kind||(t=function(e,i,t){let r="";const n=S(i),s=v(i);if("postfix"===t.kind)return 1!==n&&e.onError([{severity:"warning",message:["postfix-operator-requires-one-operand",e.serializeSymbol(s)]}]),me(t.serialize,[e.wrap(b(i,1),t.precedence)]);if("prefix"===t.kind)return 1!==n&&e.onError([{severity:"warning",message:["prefix-operator-requires-one-operand",e.serializeSymbol(s)]}]),me(t.serialize,[e.wrap(b(i,1),t.precedence+1)]);if("infix"===t.kind){r=e.wrap(b(i,1),t.precedence);for(let s=2;s<n+1;s++){const n=b(i,s);null!==n&&(r=me(t.serialize,[r,e.wrap(n,t.precedence)]))}}return r}(this,e,i)),t||"matchfix"!==i.kind||(t=function(e,i,t){return me(t.serialize,[e.serialize(b(i,1)??"Nothing")])}(this,e,i)),t||"symbol"!==i.kind||(t=this.serializeSymbol(e,i)),t}}if(Array.isArray(e)||f(e)||null!==N(e))return this.serializeSymbol(e);this.onError([{severity:"warning",message:["syntax-error",JSON.stringify(e)]}])})();return this.level-=1,i??""}applyFunctionStyle(e,i){return this.options.applyFunctionStyle(e,i)}groupStyle(e,i){return this.options.groupStyle(e,i)}rootStyle(e,i){return this.options.rootStyle(e,i)}fractionStyle(e,i){return this.options.fractionStyle(e,i)}logicStyle(e,i){return this.options.logicStyle(e,i)}powerStyle(e,i){return this.options.powerStyle(e,i)}numericSetStyle(e,i){return this.options.numericSetStyle(e,i)}}function me(e,i){let t=e;for(let e=0;e<i.length;e++){let r=i[e]??"";if(/[a-zA-Z*]/.test(r[0])){const i=t.match(RegExp("(.*)#"+Number(e+1).toString()));i&&/\\[a-zA-Z*]+/.test(i[1])&&(r=" "+r)}t=t.replace("#"+Number(e+1).toString(),r)}return t}const fe=["alpha","beta","gamma","Gamma","delta","Delta","epsilon","zeta","eta","theta","Theta","iota","kappa","lambda","Lambda","mu","nu","xi","Xi","pi","Pi","rho","sigma","Sigma","tau","upsilon","phi","Phi","varphi","chi","psi","Psi","omega","Omega","aleph","ast","blacksquare","bot","bullet","circ","diamond","times","top","square","star"];function de(e,i="italic."){if(null===e)return null;const t=e.match(/^(_+)(.*)/);if(t)return`\\text{${"\\_".repeat(t[1].length)+xe(t[2])}}`;let r;[r,e]=function(e){const i=e.match(/^([a-zA-Z-]+\.)(.*)/);return i?[i[1],i[2]]:["",e]}(e);const n=xe(e);return 1!==n.length||r?(r||(r=i),({"upright.":"\\mathrm{_}","italic.":"\\mathit{_}","bold-italic.":"\\mathbf{\\mathit{_}}","script.":"\\mathscr{_}","calligraphic.":"\\mathcal{_}","bold-script.":"\\mathbf{\\mathscr{_}}","bold-calligraphic.":"\\mathbf{\\mathcal{_}}","fraktur.":"\\mathfrak{_}","gothic.":"\\mathfrak{_}","bold-gothic.":"\\mathbf{\\mathfrak{_}}","bold-fraktur.":"\\mathbf{\\mathfrak{_}}","sans-serif.":"\\mathsf{_}","bold-sans-serif.":"\\mathbf{\\mathsf{_}}","italic-sans-serif.":"\\mathit{\\mathsf{_}}","monospace.":"\\mathtt{_}","blackboard.":"\\mathbb{_}","double-struck.":"\\mathbb{_}"}[r]??"\\mathit{_}").replace("_",n)):n}function xe(e){const i=e.indexOf("_");if(i>0){const t=e.substring(0,i),r=e.substring(i+1);return r?r.startsWith('"')&&r.endsWith('"')?`${xe(t)}_\\mathrm{${xe(r.substring(1,-1))}}`:`${xe(t)}_{${xe(r)}}`:de(t)+"\\_"}const t=e.match(/([^0-9]+?)([0-9]+)$/);return t?0===t[1].length?e:`${xe(t[1])}_{${t[2]}}`:fe.includes(e)?"\\"+e:e=e.replace(/[{}\[\]\\:\-\$%]/g,(e=>({"{":"\\lbrace ","}":"\\rbrace ","[":"\\lbrack ","]":"\\rbrack ",":":"\\colon ","\\":"\\backslash ","-":'\\unicode{"2013}'}[e]??"\\"+e)))}const ye={invisibleMultiply:"",invisiblePlus:"",multiply:"\\times",missingSymbol:"\\placeholder{}",applyFunctionStyle:function(e,i){return"paren"},groupStyle:function(e,i){return"paren"},rootStyle:_,fractionStyle:$,logicStyle:function(e,i){return"boolean"},powerStyle:function(e,i){return"solidus"},numericSetStyle:function(e,i){return"compact"}};class ke{constructor(e){this.onError=e.onError??(e=>{if("undefined"!=typeof window)for(const i of e);}),this.computeEngine=e.computeEngine;const i={...e};delete i.dictionary,delete i.onError,this.options={...le,...ye,...ce,...i},this.dictionary=function(e,i){const t={lookahead:1,name:new Map,symbol:[],infix:[],prefix:[],postfix:[],environment:new Map,matchfix:[]};for(const r of e){const[e,n]=ie(r,i);if(null!==n)if(void 0!==n.name&&(t.name.has(n.name)&&i({severity:"warning",message:["invalid-dictionary-entry",n.name,"Duplicate definition"]}),t.name.set(n.name,n)),"matchfix"===n.kind)t.matchfix.push(n);else if("environment"===n.kind){const e=a(r.trigger??"");t.environment.has(e)&&i({severity:"warning",message:["invalid-dictionary-entry",e,"Duplicate environment definition"]}),t.environment.set(e,n)}else if(e){const i=a(r.trigger??""),s=ee(e);if(t.lookahead=Math.max(t.lookahead,s),"symbol"===n.kind){void 0===t.symbol[s]&&(t.symbol[s]=new Map);const e=t.symbol[s];e.has(i)?e.get(i).push(n):e.set(i,[n])}else if("prefix"===n.kind){void 0===t.prefix[s]&&(t.prefix[s]=new Map);const e=t.prefix[s];e.has(i)?e.get(i).push(n):e.set(i,[n])}else if("infix"===n.kind){void 0===t.infix[s]&&(t.infix[s]=new Map);const e=t.infix[s];e.has(i)?e.get(i).push(n):e.set(i,[n])}else if("postfix"===n.kind){void 0===t.postfix[s]&&(t.postfix[s]=new Map);const e=t.postfix[s];e.has(i)?e.get(i).push(n):e.set(i,[n])}}}return t}(e.dictionary??ke.getDictionary(),(e=>this.onError([e])))}updateOptions(e){for(const i of Object.keys(this.options))i in e&&(this.options[i]=e[i]);this.serializer.updateOptions(e)}static getDictionary(e="all"){if("all"===e){let e=[];for(const i of Object.keys(te))te[i]&&(e=[...e,...te[i]]);return e}return te[e]?[...te[e]]:[]}parse(e){const i=new ge(n(e,[]),this.options,this.dictionary,this.computeEngine,this.onError);let t=i.matchExpression();if(!i.atEnd){const e=[];for(;!i.atEnd;)e.push(i.next());t=["Error",t??"Nothing",{str:"syntax-error"},["LatexForm",{str:a(e)}]]}return t??"Nothing"}serialize(e){return this.serializer.serialize(e)}get serializer(){return this._serializer||(this._serializer=new he(this.options,this.dictionary,this.computeEngine,this.onError)),this._serializer}}const ve="0.4.4";export{ke as LatexSyntax,z as applyRecursively,M as asValidJSONNumber,D as getDictionary,y as getStringValue,k as head,v as headName,x as isAtomic,d as isDictionaryObject,f as isFunctionObject,m as isStringObject,h as isSymbolObject,P as mapArgs,S as nops,b as op,N as symbol,q as tail,ve as version};
1
+ /** MathJSON 0.5.0 */
2
+ function n(n){return null!==n&&"object"==typeof n&&"sym"in n}function t(n){return null!==n&&"object"==typeof n&&"str"in n}function r(n){return null!==n&&"object"==typeof n&&"fn"in n}function u(n){return null!==n&&"object"==typeof n&&"dict"in n}function l(n){return null===n||!Array.isArray(n)&&("object"!=typeof n||!("fn"in n||"dic"in n))}function e(n){return null===n?null:"object"==typeof n&&"str"in n?n.str:"string"!=typeof n||n.length<2||"'"!==n[0]||"'"!==n[n.length-1]?null:n.substring(1,n.length-1)}function i(n){return null===n?null:Array.isArray(n)?n[0]:r(n)?n.fn[0]:null}function o(n){const t=i(n);return"string"==typeof t?t:""}function f(n,t){return null===n?null:Array.isArray(n)?n[t]??null:r(n)?n.fn[t]??null:null}function c(n){return Array.isArray(n)?Math.max(0,n.length-1):r(n)?Math.max(0,n.fn.length-1):0}function s(t){return null===t?null:"string"==typeof t?t.length>=2&&"'"===t[0]&&"'"===t[t.length-1]?null:t:n(t)?t.sym:null}function y(n){return Array.isArray(n)?n.slice(1):r(n)?n.fn.slice(1):[]}function a(n,t){const r=i(n);if(null!==r)return[t(r),...y(n).map(t)];const u=p(n);if(null!==u){const n=Object.keys(u),r={};for(const l of n)r[l]=t(u[l]);return{dict:r}}return t(n)}function g(n,t){let u=null;if(Array.isArray(n)&&(u=n),r(n)&&(u=n.fn),null===u)return[];let l=1;const e=[];for(;l<u.length;)e.push(t(u[l])),l+=1;return e}function p(n){return"object"==typeof n&&"dict"in n?n.dict:null}function A(n){if("string"==typeof n){const t=Number(n);if("+"===n[0]&&(n=n.slice(1)),t.toString()===n)return isNaN(t)||!isFinite(t)?t.toString():t}return n}const h="0.5.0";export{a as applyRecursively,A as asValidJSONNumber,p as getDictionary,e as getStringValue,i as head,o as headName,l as isAtomic,u as isDictionaryObject,r as isFunctionObject,t as isStringObject,n as isSymbolObject,g as mapArgs,c as nops,f as op,s as symbol,y as tail,h as version};
@@ -1,2 +1,2 @@
1
- /** MathJSON 0.4.4 */
2
- var global,factory;global=this,factory=function(e){const i=8205;function t(e){return e===i||65038===e||65039===e||e>=127995&&e<=128e3||e>=129456&&e<=129460||e>=917536&&e<=917632}function r(e){return e>=127462&&e<=127487}class n{constructor(e){this.obeyspaces=!1,this.s=function(e){if(/^[\u0020-\u00FF]*$/.test(e))return e;const n=[],s=function(e){const i=[];for(let t=0;t<e.length;t++){let r=e.charCodeAt(t);if(r>=55296&&r<=56319){const i=e.charCodeAt(t+1);i>=56320&&i<=57343&&(r=65536+1024*(r-55296)+(i-56320),t++)}i.push(r)}return i}(e);let a=0;for(;a<s.length;){const e=s[a++],l=s[a];if(l===i){const e=a-1;for(a+=2;s[a]===i;)a+=2;n.push(String.fromCodePoint(...s.slice(e,2*a-e+1)))}else if(t(l)){const e=a-1;for(;t(s[a]);)a+=s[a]===i?2:1;n.push(String.fromCodePoint(...s.slice(e,2*a-e-1)))}else r(e)?(a+=1,n.push(String.fromCodePoint(...s.slice(a-2,2)))):n.push(String.fromCodePoint(e))}return n}(e),this.pos=0}end(){return this.pos>=this.s.length}get(){return this.pos<this.s.length?this.s[this.pos++]:""}peek(){return this.s[this.pos]}match(e){let i;return i="string"==typeof this.s?e.exec(this.s.slice(this.pos)):e.exec(this.s.slice(this.pos).join("")),(null==i?void 0:i[0])?(this.pos+=i[0].length,i[0]):null}next(){if(this.end())return null;if(!this.obeyspaces&&this.match(/^[ \f\n\r\t\v\xA0\u2028\u2029]+/))return"<space>";if(this.obeyspaces&&this.match(/^[ \f\n\r\t\v\xA0\u2028\u2029]/))return"<space>";const e=this.get();if("\\"===e){if(!this.end()){let e=this.match(/^[a-zA-Z*]+/);if(e)this.match(/^[ \f\n\r\t\v\xA0\u2028\u2029]*/);else if(e=this.get()," "===e)return"<space>";return"\\"+e}}else{if("{"===e)return"<{>";if("}"===e)return"<}>";if("^"===e){if("^"===this.peek()){this.get();const e=this.match(/^(\^(\^(\^(\^[0-9a-f])?[0-9a-f])?[0-9a-f])?[0-9a-f])?[0-9a-f][0-9a-f]/);if(e)return String.fromCodePoint(parseInt(e.slice(e.lastIndexOf("^")+1),16))}return e}if("#"===e){if(!this.end()){let e=!1;if(/[0-9?]/.test(this.peek())&&(e=!0,this.pos+1<this.s.length)){const i=this.s[this.pos+1];e=/[^0-9A-Za-z]/.test(i)}return e?"#"+this.get():"#"}}else if("$"===e)return"$"===this.peek()?(this.get(),"<$$>"):"<$>"}return e}}function s(e,i){var t,r,n,s;let l=[],o=e.next();if(o)if("\\relax"===o);else if("\\noexpand"===o)o=e.next(),o&&l.push(o);else if("\\obeyspaces"===o)e.obeyspaces=!0;else if("\\space"===o||"~"===o)l.push("<space>");else if("\\bgroup"===o)l.push("<{>");else if("\\egroup"===o)l.push("<}>");else if("\\string"===o)o=e.next(),o&&("\\"===o[0]?Array.from(o).forEach((e=>l.push("\\"===e?"\\backslash":e))):"<{>"===o?l.push("\\{"):"<space>"===o?l.push("~"):"<}>"===o&&l.push("\\}"));else if("\\csname"===o){for(;"<space>"===e.peek();)e.next();let n="",s=!1,c=[];do{if(0===c.length)if(/^#[0-9?]$/.test(e.peek())){const n=e.get().slice(1);c=a(null!==(r=null!==(t=null==i?void 0:i[n])&&void 0!==t?t:null==i?void 0:i["?"])&&void 0!==r?r:"\\placeholder{}",i),o=c[0]}else o=e.next(),c=o?[o]:[];s=0===c.length,s||"\\endcsname"!==o||(s=!0,c.shift()),s||(s="<$>"===o||"<$$>"===o||"<{>"===o||"<}>"===o||!!o&&o.length>1&&"\\"===o[0]),s||(n+=c.shift())}while(!s);n&&l.push("\\"+n),l=l.concat(c)}else if("\\endcsname"===o);else if(o.length>1&&"#"===o[0]){const e=o.slice(1);l=l.concat(a(null!==(s=null!==(n=null==i?void 0:i[e])&&void 0!==n?n:null==i?void 0:i["?"])&&void 0!==s?s:"\\placeholder{}",i))}else l.push(o);return l}function a(e,i){const t=e.toString().split(/\r?\n/);let r="",a="";for(const e of t){r+=a,a=" ";const i=e.match(/((?:\\%)|[^%])*/);null!==i&&(r+=i[0])}const l=new n(r);let o=[];do{o=o.concat(s(l,i))}while(!l.end());return o}function l(e){let i="",t="";for(const r of e)r&&(/[a-zA-Z*]/.test(r[0])&&(t+=i),i=/\\[a-zA-Z]+\*?$/.test(r)?" ":"",t+=r);return t}function o(e){let i=[];if(Array.isArray(e))for(const t of e)Array.isArray(t)?i=[...i,...t]:i.push(t);else i=[e];return l(i.map((e=>{var i;return null!==(i={"<space>":" ","<$$>":"$$","<$>":"$","<{>":"{","<}>":"}"}[e])&&void 0!==i?i:e})))}function c(e){return!("kind"in e)||"symbol"===e.kind}function u(e){return"kind"in e&&"matchfix"===e.kind}function g(e){return"kind"in e&&"infix"===e.kind}function p(e){return"kind"in e&&"prefix"===e.kind}function h(e){return"kind"in e&&"postfix"===e.kind}const m="List",d="Divide",f="Multiply",v="Negate",x="Power",y="Prime",k="Root",b="Sqrt",S="Subtract",N="ComplexInfinity",A="ExponentialE",z="ImaginaryUnit";function q(e){return null!==e&&"object"==typeof e&&"num"in e}function E(e){return null!==e&&"object"==typeof e&&"sym"in e}function P(e){return null!==e&&"object"==typeof e&&"fn"in e}function D(e){return null===e||!Array.isArray(e)&&("object"!=typeof e||!("fn"in e||"dic"in e))}function O(e){return null===e?null:"object"==typeof e&&"str"in e?e.str:"string"!=typeof e||e.length<2||"'"!==e[0]||"'"!==e[e.length-1]?null:e.substring(1,e.length-1)}function M(e){return null===e?null:Array.isArray(e)?e[0]:P(e)?e.fn[0]:null}function _(e){const i=M(e);return"string"==typeof i?i:""}function $(e,i){var t,r;return null===e?null:Array.isArray(e)?null!==(t=e[i])&&void 0!==t?t:null:P(e)&&null!==(r=e.fn[i])&&void 0!==r?r:null}function L(e){return Array.isArray(e)?Math.max(0,e.length-1):P(e)?Math.max(0,e.fn.length-1):0}function w(e){return null===e?null:"string"==typeof e?e.length>=2&&"'"===e[0]&&"'"===e[e.length-1]?null:e:E(e)?e.sym:null}function C(e){if(null===e)return null;if("number"==typeof e)return e;if(q(e))return parseFloat(e.num);const i=w(e);return"NaN"===i?NaN:"+Infinity"===i?1/0:"-Infinity"===i?-1/0:null}function I(e){var i,t,r,n,s,a,l,o,c,u,g;if(D(e))return[null,null];const p=M(e);if(!p)return[null,null];let h=null,m=null;if("Negate"===p&&([h,m]=I(null!==(i=$(e,1))&&void 0!==i?i:"Missing"),null!==h&&null!==m))return[-h,m];if("Rational"===p)return[null!==(r=C(null!==(t=$(e,1))&&void 0!==t?t:NaN))&&void 0!==r?r:NaN,null!==(s=C(null!==(n=$(e,2))&&void 0!==n?n:NaN))&&void 0!==s?s:NaN];if("Power"===p){const i=C($(e,2));1===i?(h=null!==(a=C($(e,1)))&&void 0!==a?a:null,m=1):-1===i&&(h=1,m=null!==(l=C($(e,1)))&&void 0!==l?l:null)}return"Divide"===p&&(h=null!==(o=C($(e,1)))&&void 0!==o?o:null,m=null!==(c=C($(e,2)))&&void 0!==c?c:null),"Multiply"===p&&M($(e,2))===x&&-1===C($($(e,2),2))&&(h=null!==(u=C($(e,1)))&&void 0!==u?u:null,m=null!==(g=C($($(e,2),1)))&&void 0!==g?g:null),null===h||null===m?[null,null]:Number.isInteger(h)&&Number.isInteger(m)?[h,m]:[null,null]}function j(e){return Array.isArray(e)?e.slice(1):P(e)?e.fn.slice(1):[]}function R(e,i){let t=null;if(Array.isArray(e)&&(t=e),P(e)&&(t=e.fn),null===t)return[];let r=1;const n=[];for(;r<t.length;)n.push(i(t[r])),r+=1;return n}function T(e){return"object"==typeof e&&"dict"in e?e.dict:null}function F(e,i,t,r="both"){var n,s,a,l,o,c;if("non"===r)return[e,i,t];const u=M(i),g=M(t);return"left"===r?u===e?[e,...null!==(n=j(i))&&void 0!==n?n:[],t]:[e,i,t]:"right"===r?g===e?[e,i,...null!==(s=j(t))&&void 0!==s?s:[]]:[e,i,t]:u===e&&g===e?[e,...null!==(a=j(i))&&void 0!==a?a:[],...null!==(l=j(t))&&void 0!==l?l:[]]:u===e?[e,...null!==(o=j(i))&&void 0!==o?o:[],t]:g===e?[e,i,...null!==(c=j(t))&&void 0!==c?c:[]]:[e,i,t]}function Z(e){var i,t;const r=M(e);return null===e?null:("Delimiter"===r&&(e=null!==(i=$(e,1))&&void 0!==i?i:null),null===e?null:"Sequence"===r?null!==(t=j(e))&&void 0!==t?t:[]:null)}function B(e,i){return i>2?"solidus":"radical"}function G(e,i){return i>3?"inline-solidus":"quotient"}function U(e,i,t,r){return null===t?"\\sqrt{}":(r=null!=r?r:2,"solidus"===i?e.wrapShort(t)+"^{1\\/"+e.serialize(r)+"}":"quotient"===i?e.wrapShort(t)+"^{\\frac{1}{"+e.serialize(r)+"}}":2===C(r)?"\\sqrt{"+e.serialize(t)+"}":"\\sqrt["+e.serialize(r)+"]{"+e.serialize(t)+"}")}function W(e,i){var t,r;if(null===i)return"";const n=null!==(t=$(i,1))&&void 0!==t?t:"Missing",s=null!==(r=$(i,2))&&void 0!==r?r:"Missing";if(1===L(i))return e.serialize(n);const a=G(0,e.level);if("inline-solidus"===a||"nice-solidus"===a){const i=e.wrapShort(n),t=e.wrapShort(s);return"inline-solidus"===a?`${i}\\/${t}`:`^{${i}}\\!\\!/\\!_{${t}}`}return"reciprocal"===a?e.wrap(n)+e.wrap(s)+"^{-1}":"factor"===a?"\\frac{1}{"+e.serialize(s)+"}"+e.wrap(n):`\\frac{${e.serialize(n)}}{${e.serialize(s)}}`}function V(e,i){var t,r,n;const s=M(i),a=null!==(t=$(i,1))&&void 0!==t?t:"Missing",l=null!==(r=$(i,2))&&void 0!==r?r:"Missing";if("Sqrt"===s)return U(e,B(0,e.level),a,2);if("Root"===s)return U(e,B(0,e.level),a,l);const o=null!==(n=C(l))&&void 0!==n?n:1;if(-1===o)return e.serialize([d,"1",a]);if(o<0)return e.serialize([d,"1",[x,a,-o]]);if("Divide"===M(l)||"Rational"===M(l)){if(1===C($(l,1)))return U(e,B(0,e.level),a,$(l,2))}else if(M(l)===x&&-1===C($(l,2)))return U(e,B(0,e.level),a,$(l,1));return e.wrapShort(a)+"^{"+e.serialize(l)+"}"}const H=[{name:"CatalanConstant",serialize:"G"},{name:"GoldenRatio",serialize:"\\varphi"},{name:"EulerGamma",serialize:"\\gamma"},{name:"Degrees",serialize:"\\frac{\\pi}{180}"},{trigger:["\\infty"],parse:{num:"+Infinity"}},{name:N,trigger:["\\tilde","\\infty"],serialize:"\\tilde\\infty"},{trigger:["\\tilde","<{>","\\infty","<}>"],parse:N},{name:"Pi",trigger:["\\pi"]},{trigger:["\u03c0"],parse:"Pi"},{name:A,trigger:["e"],serialize:"e"},{trigger:["\\mathrm","<{>","e","<}>"],parse:A},{trigger:["\\exponentialE"],parse:A},{name:z,trigger:["\\imaginaryI"]},{trigger:["i"],parse:z},{trigger:["\\mathrm","<{>","i","<}>"],parse:z},{name:"Add",trigger:["+"],kind:"infix",associativity:"both",precedence:275,parse:(e,i,t)=>{if(275<i.minPrec)return null;const r=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:275}));return null===r?null:F("Add",t,r)},serialize:function(e,i){var t,r;e.level-=1;const n=M(i);let s="",a=$(i,1),l=!Number.isNaN(null!==(t=C(a))&&void 0!==t?t:NaN);if(n===v)s="-"+e.wrap(a,276);else if("Add"===n){s=e.serialize(a);const t=L(i)+1;for(let n=2;n<t;n++){a=$(i,n);const t=null!==(r=C(a))&&void 0!==r?r:NaN,o=!Number.isNaN(t);let c=!1;if(null!==a&&l){const[i,t]=I(a);null!==i&&null!==t&&isFinite(i)&&isFinite(t)&&1!==t&&(s+=e.options.invisiblePlus+e.serialize(a),c=!0)}if(!c)if(t<0)s+=e.serialize(a);else if("Negate"===M(a))s+=e.wrap(a,275);else{const i=e.wrap(a,275);"-"===i[0]||"+"===i[0]?s+=i:s=s+"+"+i}l=o}}else if(n===S){const t=$(i,2);s=null!==t?e.wrap(a,275)+"-"+e.wrap(t,275):e.wrap(a,275)}return e.level+=1,s}},{kind:"prefix",trigger:["+"],precedence:275,parse:(e,i)=>275<i.minPrec?null:e.matchExpression(Object.assign(Object.assign({},i),{minPrec:400}))},{name:"Complex",precedence:274,serialize:(e,i)=>{const t=C($(i,1)),r=C($(i,2));if(0===r)return e.serialize($(i,1));const n=1===r?"\\imaginaryI":-1===r?"-\\imaginaryI":l([e.serialize($(i,2)),"\\imaginaryI"]);return 0===t?n:l(null!==r&&r<0?[e.serialize($(i,1)),n]:[e.serialize($(i,1)),"+",n])}},{name:"Divide",trigger:["\\frac"],requiredLatexArg:2,precedence:660,parse:function(e){var i,t,r,n;const s=null!==(i=e.matchRequiredLatexArgument())&&void 0!==i?i:"Missing",a=null!==(t=e.matchRequiredLatexArgument())&&void 0!==t?t:"Missing";if("PartialDerivative"===M(s)&&("PartialDerivative"===M(a)||"Multiply"===M(a)&&"PartialDerivative"===M($(a,1)))){const i=null!==(r=$(s,3))&&void 0!==r?r:"Missing";let t=$(s,1);null!==t&&"Missing"!==t||(t=null!==(n=e.matchExpression())&&void 0!==n?n:"Missing");let l=[];if("Multiply"===M(a)){for(const e of j(a))if("PartialDerivative"===M(e)){const i=$(e,2);i&&l.push(i)}}else{const e=$(a,2);e&&l.push(e)}return l.length>1&&(l=[m,...l]),["PartialDerivative",t,...l,"Missing"===i?1:i]}return[d,s,a]},serialize:W},{trigger:["\\/"],kind:"infix",associativity:"non",precedence:660,parse:"Divide"},{trigger:["/"],kind:"infix",associativity:"non",precedence:660,parse:"Divide"},{trigger:["\\div"],kind:"infix",associativity:"non",precedence:660,parse:"Divide"},{name:"Exp",serialize:(e,i)=>{var t;return l(["\\exponentialE^{",e.serialize(null!==(t=$(i,1))&&void 0!==t?t:"Missing"),"}"])}},{name:"Factorial",trigger:["!"],kind:"postfix",precedence:810},{name:"Factorial2",trigger:["!","!"],kind:"postfix",precedence:810},{trigger:"\\operatorname{floor}",parse:e=>{const i=e.matchArguments("group");return null===i?null:["Floor",...i]}},{name:"Gcd",trigger:"\\operatorname{gcd}",parse:e=>{const i=e.matchArguments("group");return null===i?null:["Gcd",...i]},serialize:(e,i)=>l(["\\operatorname{gcd}","\\left(",e.serialize(i),"\\right)"])},{name:"Half",serialize:"\\frac12"},{name:"Lcm",trigger:"\\operatorname{lcm}"},{name:"MinusPlus",trigger:["\\mp"],kind:"infix",associativity:"both",precedence:270},{name:f,trigger:["\\times"],kind:"infix",associativity:"both",precedence:390,serialize:function e(i,t){var r,n;if(null===t)return"";i.level-=1;let s="";const[a,o]=function(e){var i,t,r,n,s;if("Multiply"!==M(e))return[[],[]];const a=[],l=[],o=j(e);for(const e of o)if("Power"===M(e))if("Negate"===M($(e,2))){const r=null!==(i=$(e,1))&&void 0!==i?i:"Missing",n=null!==(t=$($(e,2),1))&&void 0!==t?t:"Missing";l.push([x,r,n])}else{const i=null!==(r=C($(e,2)))&&void 0!==r?r:NaN;-1===i?l.push(null!==(n=$(e,1))&&void 0!==n?n:"Missing"):i<0?l.push([x,null!==(s=$(e,1))&&void 0!==s?s:"Missing",-i]):a.push(e)}else a.push(e);return[a,l]}(t);if(o.length>0&&(s=1===o.length&&1===o[0]?0===a.length?"1":1===a.length?i.serialize(a[0]):e(i,[f,...a]):i.serialize([d,1===a.length?a[0]:[f,...a],1===o.length?o[0]:[f,...o]])),s)return i.level+=1,s;let c=!1,u=null;const g=L(t)+1;let p=!1;for(let e=1;e<g;e++){if(u=$(t,e),null===u)continue;let a;if("number"==typeof u||q(u))a=i.serialize(u),"-1"!==a||s?("-"===a[0]&&(a=a.slice(1),c=!c),s=s?l([s,i.options.multiply,a]):a):s="-",p=!0;else{if("Power"===M(u)){const[e,t]=I(null!==(r=$(u,2))&&void 0!==r?r:NaN);if(1===e&&null!==t){s+=U(i,B(0,i.level),$(u,1),t),p=!1;continue}}if("Power"!==M(u)||isNaN(null!==(n=C($(u,1)))&&void 0!==n?n:NaN)){if("Negate"===M(u)&&(u=$(u,1),c=!c),a=i.wrap(u,390),s){const e=M(u);s=!p||"Divide"!==e&&"Rational"!==e?i.options.invisibleMultiply?l([s,i.options.invisibleMultiply,a]):l([s,a]):l([s,i.options.multiply,a])}else s=a;p=!1}else a=i.serialize(u),s=s?l([s,i.options.multiply,a]):a,p=!0}}return i.level+=1,c?"-"+s:s}},{trigger:["\\cdot"],kind:"infix",associativity:"both",precedence:390,parse:(e,i,t)=>{if(391<i.minPrec)return null;const r=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:392}));return null===r?null:F("Multiply",t,r)}},{trigger:["*"],kind:"infix",associativity:"both",precedence:390,parse:(e,i,t)=>{if(391<i.minPrec)return null;const r=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:392}));return null===r?null:["Multiply",t,r]}},{name:v,trigger:["-"],kind:"prefix",parse:(e,i)=>{if(276<i.minPrec)return null;const t=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:400}));return null===t?null:[v,t]},precedence:275},{name:"PlusMinus",trigger:["\\pm"],kind:"infix",associativity:"both",precedence:270},{name:x,trigger:["^"],kind:"infix",serialize:V},{name:"Rational",precedence:660,serialize:W},{name:k,serialize:V},{name:"Round",trigger:"\\operatorname{round}"},{name:"Square",precedence:720,serialize:(e,i)=>e.wrapShort($(i,1))+"^2"},{name:"Sign",trigger:"\\operatorname{sgn}"},{name:b,trigger:["\\sqrt"],optionalLatexArg:1,requiredLatexArg:1,parse:function(e){const i=e.matchOptionalLatexArgument(),t=e.matchRequiredLatexArgument();return null===t?null!==i?[k,"Missing",i]:[b,"Missing"]:null!==i?[k,t,i]:[b,t]},serialize:V},{name:S,trigger:["-"],kind:"infix",associativity:"both",precedence:275,parse:(e,i,t)=>{if(276<i.minPrec)return null;const r=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:277}));return null===r?null:[S,t,r]}}];function J(e=""){return(i,t)=>j(t).map((e=>i.serialize(e))).join(e)}function K(e,i){if(null===i)return"";const t=M(i);if("LatexString"===t)return ee(e,i);if("LatexTokens"===t)return Y(e,i);const r=O(i);if(null!==r)return`\\text{${r}}`;const n=C(i);return null!==n?n.toString():`\\text{${JSON.stringify(i)}}`}const Q=[{name:"Missing",trigger:["\\placeholder"],requiredLatexArg:1,serialize:e=>{var i;return null!==(i=e.options.missingSymbol)&&void 0!==i?i:"\\placeholder{}"}},{name:"BaseForm",serialize:(e,i)=>{var t,r;const n=null!==(t=C($(i,2)))&&void 0!==t?t:NaN;if(isFinite(n)&&n>=2&&n<=36){const e=null!==(r=C($(i,1)))&&void 0!==r?r:NaN;if(isFinite(e)){let i=Number(e).toString(n),t=0;if(2===n||10===n?t=4:16===n?t=2:n>16&&(t=4),t>0){const e=i;i="";for(let r=0;r<e.length;r++)r>0&&r%t==0&&(i="\\, "+i),i=e[e.length-r-1]+i}return`(\\text{${i}}_{${n}}`}}return"\\operatorname{BaseForm}("+e.serialize($(i,1))+", "+e.serialize($(i,2))+")"}},{name:"Delimiter",serialize:(e,i)=>{var t,r,n,s,a,l;const o=L(i);if(0===o)return"";if(1===o)return`\\left( ${e.serialize($(i,1))} \\right)`;let c="",u="\\left(",g="\\left)";2===o?c=null!==(t=K(e,$(i,2)))&&void 0!==t?t:"":3===o?(u=null!==(r=K(e,$(i,2)))&&void 0!==r?r:"",g=null!==(n=K(e,$(i,3)))&&void 0!==n?n:""):(u=null!==(s=K(e,$(i,2)))&&void 0!==s?s:"",c=null!==(a=K(e,$(i,3)))&&void 0!==a?a:"",g=null!==(l=K(e,$(i,4)))&&void 0!==l?l:"");const p=$(i,1);return c&&"Sequence"===M(p)?`${u} ${J(c)(e,p)} ${g}`:`${u} ${e.serialize(p)} ${g}`}},{name:"Error",serialize:(e,i)=>{const t=$(i,1),r="Nothing"===w(t)?"":e.serialize(t);if(L(i)>=3){const e=$(i,3);if(e&&"LatexForm"===M(e)){const i=ie(O($(e,1)));if(i)return`${null!=r?r:""}\\texttt{\\textcolor{red}{${i}}}`}}return null!=r?r:""}},{name:"FromLatex",serialize:(e,i)=>`\\texttt{${ie(O($(i,1)))}}`},{name:"LatexForm",serialize:ee},{name:"LatexTokens",serialize:Y},{kind:"matchfix",openDelimiter:"(",closeDelimiter:")",parse:(e,i)=>null===i?null:"Sequence"===M(i)?0===L(i)?["Delimiter","Nothing"]:["Delimiter",...j(i)]:["Delimiter",i]},{name:"Sequence",trigger:[","],kind:"infix",precedence:20,parse:(e,i,t)=>{if(i.minPrec>=20)return null;"Missing"===t&&(t="Nothing");const r=["Sequence",t];let n=!1;for(;!n;){for(n=!0,e.skipSpace();e.match(",");)r.push("Nothing"),e.skipSpace();if(e.atTerminator(i))r.push("Nothing");else{const t=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:20}));r.push(null!=t?t:"Nothing"),n=null===t}n||(e.skipSpace(),n=!e.match(","))}return r},serialize:J()},{trigger:[";"],kind:"infix",precedence:19,parse:(e,i,t)=>{var r,n;if(i.minPrec>=19)return null;"Missing"===t&&(t="Nothing");const s=["Sequence",...null!==(r=Z(t))&&void 0!==r?r:["Sequence",t]];for(;;){for(e.skipSpace();e.match(",");)s.push("Nothing"),e.skipSpace();if(e.atEnd){s.push("Nothing");break}const t=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:19}));if(null===t){s.push("Nothing");break}if(s.push(...null!==(n=Z(t))&&void 0!==n?n:["Sequence",t]),e.skipSpace(),!e.match(","))break}return s}},{name:"String",trigger:["\\text"],parse:e=>X(e),serialize:(e,i)=>{const t=j(i);return null===t||0===t.length?"\\text{}":"\\text{"+t.map((i=>e.serialize(i))).join("")+"}"}},{name:"Subscript",trigger:["_"],kind:"infix",serialize:(e,i)=>2===L(i)?e.serialize($(i,1))+"_{"+e.serialize($(i,2))+"}":"_{"+e.serialize($(i,1))+"}"},{name:"Superplus",trigger:["^","+"],kind:"postfix"},{name:"Subplus",trigger:["_","+"],kind:"postfix"},{name:"Superminus",trigger:["^","-"],kind:"postfix"},{name:"Subminus",trigger:["_","-"],kind:"postfix"},{trigger:["^","*"],kind:"postfix",parse:(e,i)=>["Superstar",i]},{name:"Superstar",trigger:["^","\\star"],kind:"postfix"},{trigger:["_","*"],kind:"postfix",parse:(e,i)=>["Substar",i]},{name:"Substar",trigger:["_","\\star"],kind:"postfix"},{name:"Superdagger",trigger:["^","\\dagger"],kind:"postfix"},{trigger:["^","\\dag"],kind:"postfix",parse:(e,i)=>["Superdagger",i]},{name:y,trigger:["^","\\prime"],kind:"postfix"},{trigger:["^","\\doubleprime"],kind:"postfix",parse:(e,i)=>[y,null!=i?i:"Nothing",2]},{name:"Derivative",serialize:(e,i)=>{var t;const r=null!==(t=C($(i,1)))&&void 0!==t?t:NaN;if(!isFinite(r))return"";const n=e.serialize($(i,2));return 1===r?n+"^{\\prime}":2===r?n+"^{\\doubleprime}":n+"^{("+Number(r).toString()+")}"}},{name:"Piecewise",trigger:"cases",kind:"environment",parse:e=>{var i;return["Piecewise",null!==(i=e.matchTabular("cases"))&&void 0!==i?i:"Nothing"]},serialize:(e,i)=>{if(M($(i,1))!==m)return"";const t=j($(i,1));let r="",n="";for(const i of t){r+=n;const t=$(i,1);if(null!==t){r+=e.serialize(t);const n=$(i,2);null!==n&&(r+="&"+e.serialize(n))}n="\\\\"}return"\\begin{cases}"+r+"\\end{cases}"}}];function X(e,i){var t,r,n;if(!e.match("<{>"))return"Nothing";const s=[];let a="",l=null;for(;!e.atEnd&&!e.match("<}>");)if("<{>"===e.peek)s.push(X(e));else if(e.match("\\textbf")&&e.match("<{>"))s.push(X(e,{"font-weight":"bold"}));else if(e.match("\\color")&&e.match("<{>")){const i=e.matchColor();i&&e.match("<}>")&&(null!==l&&a?s.push(["Style",a,{dict:l}]):a&&s.push(["String",a]),a="",l={color:i})}else if(e.match("<space>"))a+=" ";else if(e.match("<$>")){const i=e.index,r=null!==(t=e.matchExpression())&&void 0!==t?t:"Nothing";e.skipSpace(),e.match("<$>")?s.push(r):(a+="$",e.index=i)}else if(e.match("<$$>")){const i=e.index,t=null!==(r=e.matchExpression())&&void 0!==r?r:"Nothing";e.skipSpace(),e.match("<$$>")?s.push(t):(a+="$$",e.index=i)}else a+=null!==(n=e.matchChar())&&void 0!==n?n:"";return null!==l&&a?s.push(["Style",a,{dict:l}]):a&&s.push(["String",a]),i?["Style",["String",...s],{dict:i}]:["String",...s]}function Y(e,i){return null===i?"":l(R(i,(i=>{const t=O(i);return null===t?e.serialize(i):"<{>"===t?"{":"<}>"===t?"}":"<$>"===t?"$":"<$$>"===t?"$$":"<space>"===t?" ":t})))}function ee(e,i){return null===i?"":l(R(i,(i=>{var t;return null!==(t=O(i))&&void 0!==t?t:e.serialize(i)})))}function ie(e){return null===e?"":e.replace(/[{}\[\]\\:\-\$%]/g,(e=>{var i;return null!==(i={"{":"\\lbrace ","}":"\\rbrace ","[":"\\lbrack ","]":"\\rbrack ",":":"\\colon ","\\":"\\backslash "}[e])&&void 0!==i?i:"\\"+e}))}const te=[{name:"Overscript",trigger:["\\overset"],kind:"infix",precedence:700},{name:"Underscript",trigger:["\\underset"],kind:"infix",precedence:700},{name:"Increment",trigger:["+","+"],kind:"postfix",precedence:880},{name:"Decrement",trigger:["-","-"],kind:"postfix",precedence:880},{name:"PreIncrement",trigger:["+","+"],kind:"prefix",precedence:880},{name:"PreDecrement",trigger:["-","-"],kind:"prefix",precedence:880},{name:"Ring",trigger:["\\circ"],kind:"infix",precedence:265},{name:"Transpose",trigger:["^","T"],kind:"infix"},{name:"ConjugateTranspose",trigger:["^","H"],kind:"infix"},{name:"StringJoin",trigger:["\\lt","\\gt"],kind:"infix",precedence:780},{name:"Starstar",trigger:["\\star","\\star"],kind:"infix",precedence:780},{name:"PartialDerivative",trigger:["\\partial"],kind:"prefix",parse:e=>{var i,t;let r=!1,n="Nothing",s="Nothing";for(;!r;)e.skipSpace(),e.match("_")?s=e.matchRequiredLatexArgument():e.match("^")?n=e.matchRequiredLatexArgument():r=!0;const a=Z(s);if(a&&(s=[m,...a]),!s||!n)return null;let l=null!==(i=e.matchRequiredLatexArgument())&&void 0!==i?i:"Nothing";return"Nothing"!==l&&(l=[l,...null!==(t=e.matchArguments("group"))&&void 0!==t?t:"Nothing"]),["PartialDerivative",l,s,n]},serialize:(e,i)=>{let t="\\partial";const r=$(i,1),n=$(i,2),s=$(i,3);return null!==n&&"Nothing"!==n&&(M(n)===m?t+="_{"+e.serialize(["Sequence",...j(n)])+"}":t+="_{"+e.serialize(n)+"}"),null!==s&&"Nothing"!==s&&(t+="^{"+e.serialize(s)+"}"),null!==r&&"Nothing"!==r&&(t+=e.serialize(r)),t},precedence:740},{name:"OverBar",trigger:["\\overline"],requiredLatexArg:1},{name:"UnderBar",trigger:["\\underline"],requiredLatexArg:1},{name:"OverVector",trigger:["\\vec"],requiredLatexArg:1},{name:"OverTilde",trigger:["\\tilde"],requiredLatexArg:1},{name:"OverHat",trigger:["\\hat"],requiredLatexArg:1},{name:"OverRightArrow",trigger:["\\overrightarrow"],requiredLatexArg:1},{name:"OverLeftArrow",trigger:["\\overleftarrow"],requiredLatexArg:1},{name:"OverRightDoubleArrow",trigger:["\\Overrightarrow"],requiredLatexArg:1},{name:"OverLeftHarpoon",trigger:["\\overleftharpoon"],requiredLatexArg:1},{name:"OverRightHarpoon",trigger:["\\overrightharpoon"],requiredLatexArg:1},{name:"OverLeftRightArrow",trigger:["\\overleftrightarrow"],requiredLatexArg:1},{name:"OverBrace",trigger:["\\overbrace"],requiredLatexArg:1},{name:"OverLineSegment",trigger:["\\overlinesegment"],requiredLatexArg:1},{name:"OverGroup",trigger:["\\overgroup"],requiredLatexArg:1}];function re(e){return i=>{var t,r;let n=!1,s=0;if(i.skipSpace(),i.match("^")){if(i.skipSpace(),i.match("<{>")){i.skipSpace(),i.match("-")&&i.match("1")&&(n=!0);do{i.match("\\doubleprime")&&(s+=2),i.match("\\prime")&&(s+=1),i.match("'")&&(s+=1)}while(!i.match("<}>")&&!i.atEnd)}let e=!1;for(;!e;)i.skipSpace(),i.match("\\doubleprime")?s+=2:i.match("\\prime")||i.match("'")?s+=1:e=!0}let a=null!==(r=null!==(t={"\\arcsin":"Arcsin","\\arccos":"Arccos","\\arctan":"Arctan","\\arctg":"Arctan","\\arcctg":"Arctan","\\arcsec":"Arcsec","\\arccsc":" Arccsc","\\arsinh":"Arsinh","\\arcosh":"Arcosh","\\artanh":"Artanh","\\arcsech":"Arcsech","\\arccsch":"Arcsch","\\ch":"Cosh","\\cos":"Cos","\\cosec":"Csc","\\cosh":"Csch","\\cot":"Cot","\\cotg":"Cot","\\coth":"Coth","\\csc":"Csc","\\ctg":"Cot","\\cth":"Coth","\\sec":"Sec","\\sin":"Sin","\\sinh":"Sinh","\\sh":"Sinh","\\tan":"Tan","\\tanh":"Tanh","\\tg":"Tan","\\th":"Tanh"}[null!=e?e:""])&&void 0!==t?t:e)&&void 0!==r?r:"";n&&(a=["InverseFunction",a]),s>=1&&(a=["Derivative",s,a]);const l=i.matchArguments("implicit");return null===l?[a,"Nothing"]:[a,...l]}}const ne=[{name:"Arcsin",trigger:["\\arcsin"],arguments:"implicit",parse:re("Arcsin")},{name:"Arccos",trigger:["\\arccos"],arguments:"implicit",parse:re("Arccos")},{name:"Arctan",trigger:["\\arctan"],arguments:"implicit",parse:re("Arctan")},{trigger:["\\arctg"],arguments:"implicit",parse:re("Arctan")},{name:"Arccot",trigger:["\\arcctg"],arguments:"implicit",parse:re("Arccot")},{name:"Arcsec",trigger:["\\arcsec"],arguments:"implicit",parse:re("Arcsec")},{name:"Arccsc",trigger:["\\arccsc"],arguments:"implicit",parse:re("Arccsc")},{name:"Arsinh",trigger:["\\arsinh"],arguments:"implicit",parse:re("Arsinh")},{name:"Arcosh",trigger:["\\arcosh"],arguments:"implicit",parse:re("Arcosh")},{name:"Artanh",trigger:["\\artanh"],arguments:"implicit",parse:re("Artanh")},{name:"Arsech",trigger:["\\arsech"],arguments:"implicit",parse:re("Arsech")},{name:"Arcsch",trigger:["\\arcsch"],arguments:"implicit",parse:re("Arcsch")},{trigger:["\\ch"],arguments:"implicit",parse:re("Cosh")},{name:"Cosec",trigger:["\\cosec"],arguments:"implicit",parse:re("Cosec")},{name:"Cosh",trigger:["\\cosh"],arguments:"implicit",parse:re("Cosh")},{name:"Cot",trigger:["\\cot"],arguments:"implicit",parse:re("Cot")},{trigger:["\\cotg"],arguments:"implicit",parse:re("Cot")},{name:"Coth",trigger:["\\coth"],arguments:"implicit",parse:re("Coth")},{name:"Csc",trigger:["\\csc"],arguments:"implicit",parse:re("Csc")},{trigger:["\\ctg"],arguments:"implicit",parse:re("Cot")},{trigger:["\\cth"],arguments:"implicit",parse:re("Cotanh")},{name:"Sec",trigger:["\\sec"],arguments:"implicit",parse:re("Sec")},{name:"Sinh",trigger:["\\sinh"],arguments:"implicit",parse:re("Sinh")},{trigger:["\\sh"],arguments:"implicit",parse:re("Sinh")},{name:"Tan",trigger:["\\tan"],arguments:"implicit",parse:re("Tan")},{trigger:["\\tg"],arguments:"implicit",parse:re("Tan")},{name:"Tanh",trigger:["\\tanh"],arguments:"implicit",parse:re("Tanh")},{trigger:["\\th"],arguments:"implicit",parse:re("Tanh")},{name:"Cos",trigger:["\\cos"],arguments:"implicit",parse:re("Cos")},{name:"Sin",trigger:["\\sin"],arguments:"implicit",parse:re("Sin")}],se=[{name:"AlgebraicNumber",trigger:"\\bar\\Q"},{name:"ComplexNumber",trigger:["\\C"]},{trigger:"\\mathbb{C}",parse:"ComplexNumber"},{name:"ImaginaryNumber",trigger:["\\imaginaryI\\R"]},{name:"ExtendedComplexNumber",trigger:["\\bar\\C"]},{name:"EmptySet",trigger:["\\emptyset"]},{trigger:["\\varnothing"],parse:"EmptySet"},{name:"Integer",trigger:["\\Z"]},{trigger:"\\mathbb{Z}",parse:"Integer"},{name:"RationalNumber",trigger:["\\Q"]},{name:"RealNumber",trigger:["\\R"]},{name:"ExtendedRealNumber",trigger:["\\bar\\R"]},{name:"TranscendentalNumber",trigger:"\\R-\\bar\\Q"},{trigger:"\\R\\backslash\\bar\\Q",parse:"TranscendentalNumber"},{name:"NegativeNumber",trigger:"\\R^-"},{trigger:"\\R^{-}",parse:"NegativeNumber"},{trigger:"\\R_-",parse:"NegativeNumber"},{trigger:"\\R_{-}",parse:"NegativeNumber"},{trigger:"\\R^{\\lt}",parse:"NegativeNumber"},{name:"PositiveNumber",trigger:"\\R^+"},{trigger:"\\R^{+}",parse:"PositiveNumber"},{trigger:"\\R_+",parse:"PositiveNumber"},{trigger:"\\R_{+}",parse:"PositiveNumber"},{trigger:"\\R^{\\gt}",parse:"PositiveNumber"},{name:"NonPositiveNumber",trigger:"\\R^{0-}"},{trigger:"\\R^{-0}",parse:"NonPositiveNumber"},{trigger:"\\R^{\\leq}",parse:"NonPositiveNumber"},{name:"NegativeInteger",trigger:"\\Z^-"},{trigger:"\\Z^-",parse:"NegativeInteger"},{trigger:"\\Z^{-}",parse:"NegativeInteger"},{trigger:"\\Z_-",parse:"NegativeInteger"},{trigger:"\\Z_{-}",parse:"NegativeInteger"},{trigger:"\\Z^{\\lt}",parse:"NegativeInteger"},{name:"PositiveInteger",trigger:"\\Z^+"},{trigger:"\\Z^{+}",parse:"PositiveInteger"},{trigger:"\\Z_+",parse:"PositiveInteger"},{trigger:"\\Z_{+}",parse:"PositiveInteger"},{trigger:"\\Z^{\\gt}",parse:"PositiveInteger"},{trigger:"\\Z^{\\gt0}",parse:"PositiveInteger"},{trigger:"\\N^+",parse:"PositiveInteger"},{trigger:"\\N^{+}",parse:"PositiveInteger"},{trigger:"\\N^*",parse:"PositiveInteger"},{trigger:"\\N^{*}",parse:"PositiveInteger"},{trigger:"\\N^\\star",parse:"PositiveInteger"},{trigger:"\\N^{\\star}",parse:"PositiveInteger"},{trigger:"\\N_1",parse:"PositiveInteger"},{trigger:"\\N_{1}",parse:"PositiveInteger"},{name:"NonNegativeInteger",trigger:["\\N"]},{trigger:"\\Z^{+0}",parse:"NonNegativeInteger"},{trigger:"\\Z^{\\geq}",parse:"NonNegativeInteger"},{trigger:"\\Z^{\\geq0}",parse:"NonNegativeInteger"},{trigger:"\\Z^{0+}",parse:"NonNegativeInteger"},{trigger:"\\mathbb{N}",parse:"NonNegativeInteger"},{trigger:"\\N_0",parse:"NonNegativeInteger"},{trigger:"\\N_{0}",parse:"NonNegativeInteger"},{name:"CartesianProduct",trigger:["\\times"],kind:"infix",associativity:"right",precedence:390,parse:(e,i,t)=>{if(390<i.minPrec)return null;const r=e.computeEngine;if(!r||!r.box(t).domain.isSubsetOf("Set"))return null;const n=e.index,s=e.matchExpression(Object.assign(Object.assign({},i),{minPrec:390}));return null===s||!0!==r.box(t).domain.isSubsetOf("Set")?(e.index=n,null):["CartesianProduct",t,s]}},{name:"Complement",trigger:["^","\\complement"],kind:"infix"},{name:"Intersection",trigger:["\\cap"],kind:"infix",precedence:350},{name:"Interval",serialize:ae},{name:"Multiple",serialize:ae},{name:"Union",trigger:["\\cup"],kind:"infix",precedence:350},{name:"Range",serialize:ae},{name:"SetMinus",trigger:["\\setminus"],kind:"infix",precedence:650},{name:"SymmetricDifference",trigger:["\\triangle"],kind:"infix",precedence:260},{trigger:["\\ni"],kind:"infix",associativity:"right",precedence:160,parse:(e,i,t)=>{const r=e.matchExpression(i);return null===r?null:["Element",r,t]}},{name:"Element",trigger:["\\in"],kind:"infix",precedence:240},{name:"NotElement",trigger:["\\notin"],kind:"infix",precedence:240},{name:"NotSubset",trigger:["\\nsubset"],kind:"infix",associativity:"right",precedence:240},{name:"NotSuperset",trigger:["\\nsupset"],kind:"infix",associativity:"right",precedence:240},{name:"NotSubsetNotEqual",trigger:["\\nsubseteq"],kind:"infix",associativity:"right",precedence:240},{name:"NotSupersetNotEqual",trigger:["\\nsupseteq"],kind:"infix",associativity:"right",precedence:240},{name:"SquareSubset",trigger:["\\sqsubset"],kind:"infix",associativity:"right",precedence:265},{name:"SquareSubsetEqual",trigger:["\\sqsubseteq"],kind:"infix",associativity:"right",precedence:265},{name:"SquareSuperset",trigger:["\\sqsupset"],kind:"infix",associativity:"right",precedence:265},{name:"SquareSupersetEqual",trigger:["\\sqsupseteq"],kind:"infix",associativity:"right",precedence:265},{name:"Subset",trigger:["\\subset"],kind:"infix",associativity:"right",precedence:240},{trigger:["\\subsetneq"],kind:"infix",associativity:"right",precedence:240,parse:"Subset"},{trigger:["\\varsubsetneqq"],kind:"infix",associativity:"right",precedence:240,parse:"Subset"},{name:"SubsetEqual",trigger:["\\subseteq"],kind:"infix",precedence:240},{name:"Superset",trigger:["\\supset"],kind:"infix",associativity:"right",precedence:240},{trigger:["\\supsetneq"],kind:"infix",associativity:"right",precedence:240,parse:"Superset"},{trigger:["\\varsupsetneq"],kind:"infix",associativity:"right",precedence:240,parse:"Superset"},{name:"SupersetEqual",trigger:["\\supseteq"],kind:"infix",associativity:"right",precedence:240}];function ae(e,i){if(null===i)return"";const t=M(i);return null===t?"":"Set"===t?0===L(i)?"\\emptyset":2===L(i)&&"Condition"===M($(i,2))?l(["\\left\\lbrace",e.serialize($(i,1)),"\\middle\\mid",e.serialize($(i,2)),"\\right\\rbrace"]):l(["\\left\\lbrace",...j(i).map((i=>e.serialize(i)+" ,")),"\\right\\rbrace"]):(e.numericSetStyle(i,e.level),"")}const le=[["Alpha","\\alpha",945],["Beta","\\beta",946],["Delta","\\delta",948],["Epsilon","\\epsilon",949],["EpsilonSymbol","\\varepsilon",1013],["Zeta","\\zeta",950],["Eta","\\eta",951],["Theta","\\theta",952],["ThetaSymbol","\\vartheta",977],["Iota","\\iota",953],["Kappa","\\kappa",954],["KappaSymbol","\\varkappa",1008],["Lambda","\\lambda",955],["Mu","\\mu",956],["Nu","\\nu",957],["Xi","\\xi",958],["Omicron","\\omicron",959],["PiSymbol","\\varpi",982],["Rho","\\rho",961],["RhoSymbol","\\varrho",1009],["Sigma","\\sigma",963],["FinalSigma","\\varsigma",962],["Tau","\\tau",964],["Phi","\\phi",981],["PhiLetter","\\varphi",966],["Upsilon","\\upsilon",965],["Chi","\\chi",967],["Psi","\\psi",968],["Omega","\\omega",969],["CapitalAlpha","\\Alpha",913],["CapitalBeta","\\Beta",914],["CapitalGamma","\\Gamma",915],["CapitalDelta","\\Delta",916],["CapitalEpsilon","\\Epsilon",917],["CapitalZeta","\\Zeta",918],["CapitalEta","\\Eta",919],["CapitalTheta","\\Theta",920],["CapitaIota","\\Iota",921],["CapitalKappa","\\Kappa",922],["CapitalLambda","\\Lambda",923],["CapitalMu","\\Mu",924],["CapitalNu","\\Nu",925],["CapitalXi","\\Xi",926],["CapitalOmicron","\\Omicron",927],["CapitalPi","\\Pi",928],["CapitalRho","\\Rho",929],["CapitalSigma","\\Sigma",931],["CapitalTau","\\Tau",932],["CapitalPhi","\\Phi",934],["CapitalUpsilon","\\Upsilon",933],["CapitalChi","\\Chi",935],["CapitalPsi","\\Psi",936],["CapitalOmega","\\Omega",937],["Digamma","\\digamma",989],["Alef","\\aleph",8501],["Bet","\\beth",8502],["Gimel","\\gimel",8503],["Dalet","\\daleth",8504],["TurnedCapitalF","\\Finv",8498],["TurnedCapitalG","\\Game",8513],["Weierstrass","\\wp",8472],["Eth","\\eth",240],["InvertedOhm","\\mho",8487],["BlackClubSuit","\\clubsuit",9827],["WhiteHeartSuit","\\heartsuit",9825],["BlackSpadeSuit","\\spadesuit",9824],["WhiteDiamondSuit","\\diamondsuit",9826],["Sharp","\\sharp",9839],["Flat","\\flat",9837],["Natural","\\natural",9838]],oe=[...le.map((([e,i,t])=>({name:e,trigger:[i],parse:e}))),...le.map((([e,i,t])=>({trigger:[String.fromCodePoint(t)],parse:e})))],ce={"(":"(",")":")","[":"\\lbrack","]":"\\rbrack","{":"\\lbrace","}":"\\rbrace","<":"\\langle",">":"\\rangle","|":"\\vert","||":"\\Vert","\\lceil":"\\lceil","\\lfloor":"\\lfloor","\\rceil":"\\rceil","\\rfloor":"\\rfloor"};function ue(e){return Array.isArray(e)?e.length:1}function ge(e,i){var t,r,n,s,m,d,f,v,x,y;if(!function(e,i){var t,r;const n=null!==(r=null!==(t=e.name)&&void 0!==t?t:e.trigger)&&void 0!==r?r:e.openDelimiter;if(void 0!==e.serialize&&!e.name)return i({severity:"warning",message:["invalid-dictionary-entry",n,"Unexpected serialize property without a name property"]}),!1;if(u(e)){if(e.trigger)return i({severity:"warning",message:["invalid-dictionary-entry",n,`Unexpected 'trigger' "${e.trigger}". 'matchfix' operators use a 'openDelimiter' and 'closeDelimiter' instead of a trigger. `]}),!1;if(!e.openDelimiter||!e.closeDelimiter)return i({severity:"warning",message:["invalid-dictionary-entry",n,"Expected `openDelimiter` and a `closeDelimiter` for matchfix operator"]}),!1;if(typeof e.openDelimiter!=typeof e.closeDelimiter)return i({severity:"warning",message:["invalid-dictionary-entry",n,"Expected `openDelimiter` and `closeDelimiter` to both be strings or array of LatexToken"]}),!1}if(g(e)||h(e)||p(e)){if(Array.isArray(e.trigger)&&("_"===e.trigger[0]||"^"===e.trigger[0])||"string"==typeof e.trigger&&(e.trigger.startsWith("^")||e.trigger.startsWith("_"))){if(void 0!==e.precedence||void 0!==e.associativity)return i({severity:"warning",message:["invalid-dictionary-entry",n,'Unexpected "precedence" or "associativity" for superscript/subscript operator']}),!1}else if(void 0===e.precedence)return i({severity:"warning",message:["invalid-dictionary-entry",n,`Expected a "precedence" for ${e.kind} operator`]}),!1}else if(void 0!==e.associativity)return i({severity:"warning",message:["invalid-dictionary-entry",n,'Unexpected "associativity" operator']}),!1;return c(e)||void 0===e.optionalLatexArg&&void 0===e.requiredLatexArg?u(e)||e.trigger||e.name?void 0!==e.parse||void 0!==e.name||(i({severity:"warning",message:["invalid-dictionary-entry",n,"Expected a 'parse' or 'name'"]}),!1):(i({severity:"warning",message:["invalid-dictionary-entry",n,"Expected at least a 'trigger' or a 'name'"]}),!1):(i({severity:"warning",message:["invalid-dictionary-entry",n,'Unexpected "optionalLatexArg" or "requiredLatexArg" for non-symbol']}),!1)}(e,i))return[null,null];const k={name:e.name,kind:"kind"in e?e.kind:"symbol"};if("matchfix"===k.kind&&u(e)){if(k.openDelimiter=e.openDelimiter,k.closeDelimiter=e.closeDelimiter,"function"==typeof e.serialize)k.serialize=e.serialize;else{const e="string"==typeof k.openDelimiter?ce[k.openDelimiter]:o(k.openDelimiter),i="string"==typeof k.closeDelimiter?ce[k.closeDelimiter]:o(k.closeDelimiter);k.serialize=(t,r)=>l([e,t.serialize(r),i])}if("function"==typeof e.parse)k.parse=e.parse;else{const i=null!==(t=e.parse)&&void 0!==t?t:e.name;k.parse=(e,t)=>[i,t]}return[null,k]}if("environment"===k.kind&&function(e){return"kind"in e&&"environment"===e.kind}(e)){const i=e.trigger;return k.serialize=(e,t)=>`\\begin{${i}${e.serialize($(t,1))}\\end{${i}`,k.parse=null!==(r=e.parse)&&void 0!==r?r:()=>null,[i,k]}const b="string"==typeof e.trigger?a(e.trigger,[]):e.trigger,S=b?o(b):"";if(e.trigger,"symbol"===k.kind&&c(e)&&(k.arguments=null!==(n=e.arguments)&&void 0!==n?n:"",k.precedence=null!==(s=e.precedence)&&void 0!==s?s:0,k.optionalLatexArg=null!==(m=e.optionalLatexArg)&&void 0!==m?m:0,k.requiredLatexArg=null!==(d=e.requiredLatexArg)&&void 0!==d?d:0),"infix"!==k.kind&&"prefix"!==k.kind&&"postfix"!==k.kind||!(g(e)||p(e)||h(e))||(!b||"^"!==b[0]&&"_"!==b[0]?k.precedence=null!==(f=e.precedence)&&void 0!==f?f:0:k.precedence=720),"infix"===k.kind&&g(e))if(k.associativity=null!==(v=e.associativity)&&void 0!==v?v:"non","function"==typeof e.parse)k.parse=e.parse;else if(!b||"^"!==b[0]&&"_"!==b[0]){const i=null!==(y=e.parse)&&void 0!==y?y:e.name,t=k.precedence,r=k.associativity;k.parse=(e,n,s)=>{if(t<n.minPrec)return null;const a=e.matchExpression(Object.assign(Object.assign({},n),{minPrec:t}));return"string"!=typeof i?[i,s,null!=a?a:"Missing"]:F(i,s,null!=a?a:"Missing",r)}}else{const i=null!==(x=e.parse)&&void 0!==x?x:e.name;k.parse=(e,t,r)=>{var n,s;return[i,null!==(n=$(r,1))&&void 0!==n?n:"Missing",null!==(s=$(r,2))&&void 0!==s?s:"Missing"]}}else if("function"==typeof e.parse)k.parse=e.parse;else if(void 0!==e.parse)k.parse=()=>e.parse;else if(void 0===e.parse&&void 0!==e.name)if("postfix"===k.kind)k.parse=(i,t)=>t?[e.name,t]:null;else if("prefix"===k.kind){const i=k.precedence,t=e.name;k.parse=(e,r)=>{if(i<r.minPrec)return null;const n=e.matchExpression(Object.assign(Object.assign({},r),{minPrec:i}));return null===n?null:[t,n]}}else k.parse=()=>e.name;return"function"==typeof e.serialize||"string"==typeof e.serialize?k.serialize=e.serialize:b&&("postfix"===k.kind?k.serialize="#1"+S:"prefix"===k.kind?k.serialize=S+"#1":"infix"===k.kind?k.serialize="#1"+S+"#2":"symbol"===k.kind?k.serialize=S:k.serialize=""),[null!=b?b:null,k]}const pe={algebra:[{name:"To",trigger:["\\to"],kind:"infix",precedence:270}],arithmetic:H,calculus:[{name:"Integral",trigger:["\\int"],parse:function(e){let i="Nothing",t="Nothing",r=!1;for(;!r;)e.skipSpace(),e.match("_")?t=e.matchRequiredLatexArgument():e.match("^")?i=e.matchRequiredLatexArgument():r=!0;const n=e.matchExpression({tokens:["d"]});return["Integral",null!=n?n:"",null!=i?i:"Nothing",null!=t?t:"Nothing"]},serialize:function(e,i){return""}}],core:Q,logic:[{name:"True",trigger:["\\mathrm","<{>","T","r","u","e","<}>"],serialize:"\\mathrm{True}"},{name:"False",trigger:["\\mathrm","<{>","F","a","l","s","e","<}>"],serialize:"\\mathrm{False}"},{name:"Maybe",trigger:["\\mathrm","<{>","M","a","y","b","e","<}>"],serialize:"\\mathrm{Maybe}"}],relop:[{trigger:["!","<"],kind:"infix",associativity:"right",precedence:246,parse:"NotLess"},{name:"NotLess",trigger:["\\nless"],kind:"infix",associativity:"right",precedence:246},{trigger:["<"],kind:"infix",associativity:"right",precedence:245,parse:"Less"},{name:"Less",trigger:["\\lt"],kind:"infix",associativity:"right",precedence:245},{trigger:["<","="],kind:"infix",associativity:"right",precedence:241,parse:"LessEqual"},{name:"LessEqual",trigger:["\\le"],kind:"infix",associativity:"right",precedence:241},{trigger:["\\leq"],kind:"infix",associativity:"right",precedence:241,parse:"Equal"},{trigger:["\\leqslant"],kind:"infix",associativity:"right",precedence:265,parse:"LessEqual"},{name:"LessNotEqual",trigger:["\\lneqq"],kind:"infix",associativity:"right",precedence:260},{name:"NotLessNotEqual",trigger:["\\nleqq"],kind:"infix",associativity:"right",precedence:260},{name:"LessOverEqual",trigger:["\\leqq"],kind:"infix",associativity:"right",precedence:265},{name:"GreaterOverEqual",trigger:["\\geqq"],kind:"infix",associativity:"right",precedence:265,parse:"GreaterEqual"},{name:"Equal",trigger:["="],kind:"infix",associativity:"right",precedence:260},{trigger:["*","="],kind:"infix",associativity:"right",precedence:260,parse:"StarEqual"},{name:"StarEqual",trigger:["\\star","="],kind:"infix",associativity:"right",precedence:260},{name:"PlusEqual",trigger:["+","="],kind:"infix",associativity:"right",precedence:260},{name:"MinusEqual",trigger:["-","="],kind:"infix",associativity:"right",precedence:260},{name:"SlashEqual",trigger:["/","="],kind:"infix",associativity:"right",precedence:260},{name:"EqualEqual",trigger:["=","="],kind:"infix",associativity:"right",precedence:260},{name:"EqualEqualEqual",trigger:["=","=","="],kind:"infix",associativity:"right",precedence:265},{name:"TildeFullEqual",trigger:["\\cong"],kind:"infix",associativity:"right",precedence:260},{name:"NotTildeFullEqual",trigger:["\\ncong"],kind:"infix",associativity:"right",precedence:260},{trigger:[":","="],kind:"infix",associativity:"right",precedence:260,parse:"Assign"},{name:"Assign",trigger:["\\coloneq"],kind:"infix",associativity:"right",precedence:260},{name:"Approx",trigger:["\\approx"],kind:"infix",associativity:"right",precedence:247},{name:"NotApprox",trigger:["\\approx"],kind:"infix",associativity:"right",precedence:247},{name:"ApproxEqual",trigger:["\\approxeq"],kind:"infix",associativity:"right",precedence:260},{name:"NotApproxEqual",trigger:["!","\\approxeq"],kind:"infix",associativity:"right",precedence:250},{name:"NotEqual",trigger:["\\ne"],kind:"infix",associativity:"right",precedence:255},{name:"Unequal",trigger:["!","="],kind:"infix",associativity:"right",precedence:260},{name:"GreaterEqual",trigger:["\\ge"],kind:"infix",associativity:"right",precedence:242},{trigger:["\\geq"],kind:"infix",associativity:"right",precedence:242,parse:"GreaterEqual"},{trigger:[">","="],kind:"infix",associativity:"right",precedence:243,parse:"GreaterEqual"},{trigger:["\\geqslant"],kind:"infix",associativity:"right",precedence:265,parse:"GreaterEqual"},{name:"GreaterNotEqual",trigger:["\\gneqq"],kind:"infix",associativity:"right",precedence:260},{name:"NotGreaterNotEqual",trigger:["\\ngeqq"],kind:"infix",associativity:"right",precedence:260},{trigger:[">"],kind:"infix",associativity:"right",precedence:245,parse:"Greater"},{name:"Greater",trigger:["\\gt"],kind:"infix",associativity:"right",precedence:245},{name:"NotGreater",trigger:["\\ngtr"],kind:"infix",associativity:"right",precedence:244},{trigger:["!",">"],kind:"infix",associativity:"right",precedence:244,parse:"NotGreater"},{name:"RingEqual",trigger:["\\circeq"],kind:"infix",associativity:"right",precedence:260},{name:"TriangleEqual",trigger:["\\triangleq"],kind:"infix",associativity:"right",precedence:260},{name:"DotEqual",trigger:["\\doteq"],kind:"infix",associativity:"right",precedence:265},{name:"DotEqualDot",trigger:["\\doteqdot"],kind:"infix",associativity:"right",precedence:265},{name:"FallingDotEqual",trigger:["\\fallingdotseq"],kind:"infix",associativity:"right",precedence:265},{name:"RisingDotEqual",trigger:["\\fallingdotseq"],kind:"infix",associativity:"right",precedence:265},{name:"QuestionEqual",trigger:["\\questeq"],kind:"infix",associativity:"right",precedence:260},{name:"Equivalent",trigger:["\\equiv"],kind:"infix",associativity:"right",precedence:260},{name:"MuchLess",trigger:["\\ll"],kind:"infix",associativity:"right",precedence:260},{name:"MuchGreater",trigger:["\\gg"],kind:"infix",associativity:"right",precedence:260},{name:"Precedes",trigger:["\\prec"],kind:"infix",associativity:"right",precedence:260},{name:"Succeeds",trigger:["\\succ"],kind:"infix",associativity:"right",precedence:260},{name:"PrecedesEqual",trigger:["\\preccurlyeq"],kind:"infix",associativity:"right",precedence:260},{name:"SucceedsEqual",trigger:["\\curlyeqprec"],kind:"infix",associativity:"right",precedence:260},{name:"NotPrecedes",trigger:["\\nprec"],kind:"infix",associativity:"right",precedence:260},{name:"NotSucceeds",trigger:["\\nsucc"],kind:"infix",associativity:"right",precedence:260},{name:"Between",trigger:["\\between"],kind:"infix",associativity:"right",precedence:265}],other:te,physics:[{name:"mu-0",trigger:"\\mu_0"}],sets:se,symbols:oe,trigonometry:ne},he={"(":["\\lparen","("],")":["\\rparen",")"],"[":["\\lbrack"],"]":["\\rbrack"],"<":["<","\\langle"],">":[">","\\rangle"],"{":["\\{","\\lbrace"],"}":["\\}","\\rbrace"],":":[":","\\colon"],"|":["|","\\|","\\lvert","\\rvert"],"||":["||","\\Vert","\\lVert","\\rVert"],"\\lfloor":["\\lfloor"],"\\rfloor":["\\rfloor"],"\\lceil":["\\lceil"],"\\rceil":["\\rceil"],"\\ulcorner":["\\ulcorner"],"\\urcorner":["\\urcorner"],"\\llcorner":["\\llcorner"],"\\lrcorner":["\\lrcorner"],"\\lgroup":["\\lgroup"],"\\rgroup":["\\rgroup"],"\\lmoustache":["\\lmoustache"],"\\rmoustache":["\\rmoustache"]},me={":":[":","\\colon"],"|":["|","\\|","\\mid","\\mvert"]},de={"\\left":"\\right","\\bigl":"\\bigr","\\Bigl":"\\Bigr","\\biggl":"\\biggr","\\Biggl":"\\Biggr","\\big":"\\big","\\Big":"\\Big","\\bigg":"\\bigg","\\Bigg":"\\Bigg"},fe=["\\middle","\\bigm","\\Bigm","\\biggm","\\Biggm","\\big","\\Big","\\bigg","\\Bigg"],ve={"(":")","[":"]","\\{":"\\}","\\lbrace":"\\rbrace","\\lparen":"\\rparen","\\langle":"\\rangle","\\lfloor":"\\rfloor","\\lceil":"\\rceil","\\vert":"\\vert","\\lvert":"\\rvert","\\Vert":"\\Vert","\\lVert":"\\rVert","\\lbrack":"\\rbrack","\\ulcorner":"\\urcorner","\\llcorner":"\\lrcorner","\\lgroup":"\\rgroup","\\lmoustache":"\\rmoustache"},xe={precision:6,positiveInfinity:"\\infty",negativeInfinity:"-\\infty",notANumber:"\\operatorname{NaN}",decimalMarker:".",groupSeparator:"\\,",exponentProduct:"\\cdot",beginExponentMarker:"10^{",endExponentMarker:"}",notation:"auto",truncationMarker:"\\ldots",beginRepeatingDigits:"\\overline{",endRepeatingDigits:"}",imaginaryNumber:"\\imaginaryI",avoidExponentsInRange:[-7,20]},ye={applyInvisibleOperator:"auto",skipSpace:!0,parseArgumentsOfUnknownLatexCommands:!0,parseNumbers:!0,parseUnknownToken:e=>["\\displaystyle","\\!","\\:","\\enskip","\\quad","\\,","\\;","\\enspace","\\qquad","\\selectfont","\\tiny","\\scriptsize","\\footnotesize","\\small","\\normalsize","\\large","\\Large","\\LARGE","\\huge","\\Huge"].includes(e)?"skip":/^[fg]$/.test(e)?"function":/^[a-zA-Z]$/.test(e)?"symbol":"error",preserveLatex:!0};class ke{constructor(e,i,t,r,n){this.index=0,this._lastPeek="",this._peekCounter=0,this.options=Object.assign(Object.assign(Object.assign({},xe),ye),i),this.engine=r,this._tokens=e,this.onError=n,this._dictionary=t}updateOptions(e){for(const[i,t]of Object.entries(e))this.options[i]=t}clone(e,i){return new ke(this._tokens.slice(e,i),this.options,this._dictionary,this.engine,this.onError)}get atEnd(){return this.index>=this._tokens.length}get peek(){if(this._tokens[this.index]===this._lastPeek?this._peekCounter+=1:this._peekCounter=0,this._peekCounter>=1024)throw Error("Infinite loop");return this._lastPeek=this._tokens[this.index],this._tokens[this.index]}atTerminator(e){const i=this.index;return!!this.atEnd||!!e&&(!(!e.condition||!e.condition(this))||!!(e.tokens&&e.tokens.length>0&&this.matchAll(e.tokens))&&(this.index=i,!0))}latex(e,i){return o(this._tokens.slice(e,i))}latexAhead(e){return o(this._tokens.slice(this.index,this.index+e))}latexBefore(){return this.latex(0,this.index)}latexAfter(){return this.latex(this.index)}lookAhead(){let e=Math.min(this._dictionary.lookahead,this._tokens.length-this.index);const i=[];for(;e>0;)i[e]=this.latexAhead(e--);return i}peekDefinitions(e){let i;i="operator"===e?this.lookAhead().map(((e,i)=>{var t,r,n,s,a;return null!==(s=null!==(r=null===(t=this._dictionary.infix[i])||void 0===t?void 0:t.get(e))&&void 0!==r?r:null===(n=this._dictionary.postfix[i])||void 0===n?void 0:n.get(e))&&void 0!==s?s:null===(a=this._dictionary.prefix[i])||void 0===a?void 0:a.get(e)})):this.lookAhead().map(((i,t)=>{var r;return null===(r=this._dictionary[e][t])||void 0===r?void 0:r.get(i)}));const t=[];for(let e=i.length;e>0;e--)if(void 0!==i[e])for(const r of i[e])t.push([r,e]);return 0===t.length?null:t}next(){return this._tokens[this.index++]}skipSpace(){var e,i;if(!this.atEnd&&"<{>"===this.peek&&"<}>"===this._tokens[this.index+1])return this.index+=2,this.skipSpace(),!0;let t=!1;for(;!this.atEnd&&"skip"===(null===(i=(e=this.options).parseUnknownToken)||void 0===i?void 0:i.call(e,this.peek,this));)this.index+=1,this.skipSpace(),t=!0;if(!this.options.skipSpace)return!1;for(;this.match("<space>");)t=!0;return t&&this.skipSpace(),t}matchChar(){var e;const i=this.index;let t=0;for(;this.match("^");)t+=1;if(t>=2){let e="",i=0;for(;i!=t;){const t=this.matchAny(["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]);if(!t)break;e+=t,i+=1}if(e.length===t)return String.fromCodePoint(Number.parseInt(e,16))}else{if(this.match("\\char")){let i=Math.floor(null!==(e=this.matchLatexNumber())&&void 0!==e?e:NaN);return(!Number.isFinite(i)||i<0||i>1114111)&&(i=10067),String.fromCodePoint(i)}if(this.match("\\unicode"))if("<{>"===this.peek){const e=this.matchLatexNumber();if(this.match("<}>")&&null!==e&&e>=0&&e<=1114111)return String.fromCodePoint(e)}else{const e=this.matchLatexNumber();if(null!==e&&e>=0&&e<=1114111)return String.fromCodePoint(e)}}return this.index=i,this.next()}matchColor(e=!1){let i="";for(;!this.atEnd&&"}"!==this.peek;)i+=this.next();return i}matchLatexDimension(){return null}match(e){return this._tokens[this.index]===e&&(this.index++,!0)}matchAll(e){"string"==typeof e&&(e=[e]);let i=!0,t=0;do{i=this._tokens[this.index+t]===e[t++]}while(i&&t<e.length);return i&&(this.index+=t),i}matchAny(e){return e.includes(this._tokens[this.index])?this._tokens[this.index++]:""}matchWhile(e){const i=[];for(;e.includes(this._tokens[this.index]);)i.push(this._tokens[this.index++]);return i}matchSign(){let e=!1,i=!1;for(;!i;)this.skipSpace()?i=!1:this.matchAny(["-","\u2212"])?(e=!e,i=!1):i=!this.matchAny(["+","\ufe62"]);return e?"-":"+"}matchDecimalDigits(){let e="",i=!1;for(;!i;)if(e+=this.matchWhile(["0","1","2","3","4","5","6","7","8","9"]).join(""),i=!0,this.options.groupSeparator){const e=this.index;this.skipSpace(),this.match(this.options.groupSeparator)&&(this.skipSpace(),/[0-9]/.test(this.peek)?i=!1:this.index=e)}return e}matchSignedInteger(){const e=this.index,i=this.matchSign(),t=this.matchDecimalDigits();return t?("-"===i?"-":"")+t:(this.index=e,"")}matchExponent(){const e=this.index;let i="";if(this.matchAny(["e","E"])){const e=this.matchSignedInteger();e&&(i="e"+e)}if(i)return i;if(this.match("\\times")&&(this.skipSpace(),this.match("1")&&this.match("0")&&this.match("^"))){if(/[0-9]/.test(this.peek))return"e"+this.next();if(this.match("<{>")){this.skipSpace();const e=this.matchSignedInteger();if(this.skipSpace(),this.match("<}>")&&e)return"e"+e}}return this.index=e,""}matchNumber(){var e,i;if(!this.options.parseNumbers)return"";const t=this.index;this.skipSpace(),this.match("+");let r=!1;if(this.match(this.options.decimalMarker)){const e=this.index;if(!this.matchAny(["0","1","2","3","4","5","6","7","8","9"]))return this.index=t,"";this.index=e,r=!0}let n=this.matchDecimalDigits();return n?(!r&&this.match(null!==(e=this.options.decimalMarker)&&void 0!==e?e:"")&&(n+="."+(null!==(i=this.matchDecimalDigits())&&void 0!==i?i:"0")),(r?"0.":"")+n+this.matchExponent()):(this.index=t,"")}matchLatexNumber(e=!0){var i,t;let r=!1,n=this.peek;for(;"<space>"===n||"+"===n||"-"===n;)"-"===n&&(r=!r),this.next(),n=this.peek;let s=10,a=["0","1","2","3","4","5","6","7","8","9"];if(this.match("'"))s=8,a=["0","1","2","3","4","5","6","7"],e=!0;else if(this.match('"')||this.match("x"))s=16,a=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"],e=!0;else if(this.match("`"))return n=this.next(),n?n.startsWith("\\")&&2===n.length?(r?-1:1)*(null!==(i=n.codePointAt(1))&&void 0!==i?i:0):(r?-1:1)*(null!==(t=n.codePointAt(0))&&void 0!==t?t:0):null;let l="";for(;a.includes(this.peek);)l+=this.next();if(!e&&this.match("."))for(l+=".";a.includes(this.peek);)l+=this.next();const o=e?Number.parseInt(l,s):Number.parseFloat(l);return Number.isNaN(o)?null:r?-o:o}matchPrefixOperator(e){e||(e={minPrec:0}),e.minPrec||(e=Object.assign(Object.assign({},e),{minPrec:0}));const i=this.peekDefinitions("prefix");if(null===i)return null;const t=this.index;for(const[r,n]of i){this.index=t+n;const i=r.parse(this,e);if(i)return i}return this.index=t,null}matchInfixOperator(e,i){i||(i={minPrec:0}),i.minPrec||(i=Object.assign(Object.assign({},i),{minPrec:0}));const t=this.peekDefinitions("infix");if(null===t)return null;const r=this.index;for(const[n,s]of t)if(n.precedence>=i.minPrec){this.index=r+s;const t=n.parse(this,i,e);if(t)return t}return this.index=r,null}matchArguments(e){if(!e)return null;const i=this.index;let t=null;const r=this.matchEnclosure();if("group"===e&&"Delimiter"===M(r))t=j(r);else if("implicit"===e)if("Delimiter"===M(r))t=j(r);else if(null!==r)t=[r];else{const e=this.matchPrimary();null!==e&&(t=[e])}else this.index=i;return t}matchOpenDelimiter(e,i){var t;const r=this.index,n=de[this.peek];n&&this.next();const s=null!==(t=he[e])&&void 0!==t?t:[e],a=n?[n]:[];return s.includes("||")&&this.matchAll(["|","|"])?(a.push("|"),a.push("|"),a):s.includes(this.peek)?(ve[e]===i?a.push(ve[this.peek]):a.push(i),this.next(),a):(this.index=r,null)}matchMiddleDelimiter(e){var i;const t=null!==(i=me[e])&&void 0!==i?i:[e];if(fe.includes(this.peek)){const e=this.index;return this.next(),t.includes(this.peek)?(this.next(),!0):(this.index=e,!1)}return!!t.include(this.peek)&&(this.next(),!0)}matchEnclosure(){const e=this._dictionary.matchfix;if(0===e.length)return null;const i=this.index;for(const t of e){if(this.index=i,Array.isArray(t.openDelimiter)){if(!this.matchAll(t.openDelimiter))continue;const e=this.matchExpression({tokens:t.closeDelimiter,minPrec:0});if(this.skipSpace(),!this.matchAll(t.closeDelimiter))continue;if("function"==typeof t.parse){const i=t.parse(this,null!=e?e:"Nothing");if(null===i)continue;return i}return[t.name,null!=e?e:"Nothing"]}const e=this.matchOpenDelimiter(t.openDelimiter,t.closeDelimiter);if(null===e)continue;const r=this.matchExpression({minPrec:0,tokens:e});if(r&&this.matchAll(e)){if("function"==typeof t.parse){const e=t.parse(this,null!=r?r:"Nothing");if(null===e)continue;return e}return[t.name,r]}}return this.index=i,null}matchSymbol(){var e,i;const t=this.index,r=this.peekDefinitions("symbol");if(r)for(const[e,i]of r){let r=null;if(this.index=t+i,"function"!=typeof e.parse)return e.name;if(r=e.parse(this),r)return r}this.index=t;const n=null===(i=(e=this.options).parseUnknownToken)||void 0===i?void 0:i.call(e,this.peek,this);if("function"===n){const e=this.next(),i=this.matchEnclosure();return null===i?e:"Delimiter"!==M(i)?null:[e,...j(i)]}return"symbol"===n?this.next():this.matchUnknownLatexCommand()}matchOptionalLatexArgument(){const e=this.index;if(this.skipSpace(),this.match("[")){const e=this.matchExpression();if(this.skipSpace(),this.match("]"))return e}return this.index=e,null}matchRequiredLatexArgument(){const e=this.index;if(this.skipSpace(),this.match("<{>")){const i=this.matchExpression({tokens:["<}>"]});return this.skipSpace(),this.match("<}>")?i:(this.index=e,null)}return/^[0-9]$/.test(this.peek)?parseInt(this.next()):/^[^\\#]$/.test(this.peek)?this.next():this.matchSymbol()||(this.index=e,null)}matchSupsub(e){var i,t,r;if(null===e)return null;const n=this.index;this.skipSpace();const s=[],a=[];for(;"_"===this.peek||"^"===this.peek;){if(this.match("_")){let e=this.matchRequiredLatexArgument();!e&&this.match("<{>")&&(e=this.matchString({tokens:["<}>"]}),e&&this.match("<}>")),a.push(null!=e?e:"Missing")}else this.match("^")&&s.push(null!==(i=this.matchRequiredLatexArgument())&&void 0!==i?i:"Missing");this.skipSpace()}if(0===s.length&&0===a.length)return this.index=n,e;let l=e;if(a.length>0){const e=null===(t=this._dictionary.infix[1])||void 0===t?void 0:t.get("_");if(e){const i=["Subscript",l,1===a.length?a[0]:["Sequence",...a]];for(const t of e)if(l="function"==typeof t.parse?t.parse(this,{minPrec:0},i):i,l)break}}if(s.length>0){const e=null===(r=this._dictionary.infix[1])||void 0===r?void 0:r.get("^");if(e){const i=["Superscript",l,1===s.length?s[0]:["Sequence",...s]];for(const t of e)if(l="function"==typeof t.parse?t.parse(this,{minPrec:0},i):i,l)break}}return null===l&&(this.index=n),l}matchPostfix(e){if(null===e)return null;const i=this.peekDefinitions("postfix");if(null===i)return null;const t=this.index;for(const[r,n]of i){this.index=t+n;const i=r.parse(this,e);if(null!==i)return i}return this.index=t,null}matchString(e){e.minPrec||(e=Object.assign(Object.assign({},e),{minPrec:0}));let i="",t=this.atEnd;for(;!t;){const r=this.peek;"<space>"===r?i+=" ":"\\"===r[0]?(this.onError([{severity:"warning",message:"unexpected-command"}]),i+=this.next()):/^<(\$|\$\$)>$/.test(r)?t=!0:i+=this.next(),t=t||this.atTerminator(e)}return i}matchEnvironmentName(e,i){if(!this.match(e))return!1;const t=this.index;if(this.match("<{>")){const e=this.matchString({tokens:["<}>"]});if(this.match("<}>")&&e===i)return!0}return this.index=t,!1}matchTabular(e){const i=["List"],t={minPrec:0,tokens:["\\end","<{>",...e.split(""),"<}>"]};let r=["List"],n=null;for(;!this.atTerminator(t);)this.match("&")?(r.push(null!=n?n:"Nothing"),n=null):(this.match("\\\\")||this.match("\\cr"))&&(this.skipSpace(),this.matchOptionalLatexArgument(),null!==n&&r.push(n),i.push(r),r=["List"],n=null);return r.length>1&&i.push(r),i}matchEnvironment(){if(!this.match("\\begin"))return null;const e=this.index;if(this.match("<{>")){const e=this.matchString({tokens:["<}>"]});if(this.match("<}>")){const i=this._dictionary.environment.get(e);if(i)return i.parse(this,[],[]);const t=this.matchTabular(e);if(null!==t)return t}}return this.index=e,null}applyInvisibleOperator(e,i){if(null===i||this.atTerminator(e))return null;if(null===this.options.applyInvisibleOperator)return null;const t=this.index,r=this.matchExpression(Object.assign(Object.assign({},e),{minPrec:390}));if(null===r)return this.index=t,null;if("function"==typeof this.options.applyInvisibleOperator)return this.options.applyInvisibleOperator(this,i,r);const n=this.engine.box(r),s=w(i);if(s&&this.engine.getFunctionDefinition(s)){let e=[];return e="Delimiter"===n.head?"Sequence"===n.op1.head?[...n.op1.ops]:[n.op1]:[n],[s,...e.map((e=>e.json))]}const a=this.engine.box(i);if(a.isLiteral&&a.isInteger&&n.isLiteral){const[e,t]=n.rationalValue;if(null!==e&&null!==t)return["Add",i,r]}return a.isNumber&&n.isNumber?F("Multiply",i,r):(this.index=t,null)}matchUnknownLatexCommand(){const e=this.peek;if(!e||"\\"!==e[0])return null;this.next();const i=[];if("\\operatorname"===e){if(this.match("<{>")){for(;!this.atEnd&&"<}>"!==this.peek;)i.push(this.next());this.match("<}>")}else i.push(this.next());return 0===i.length?["Error","Missing",{str:"syntax-error"},["LatexForm",{str:e}]]:["Error","Missing",{str:"unknown-command"},["LatexForm",{str:`${e}{${o(i)}}`}]]}for(;this.match("[");){i.push("[");let e=0;for(;!this.atEnd&&0===e&&"]"!==this.peek;)"["===this.peek&&(e+=1),"]"===this.peek&&(e-=1),i.push(this.next());this.match("]")&&i.push("]")}for(;this.match("<{>");){i.push("<{>");let e=0;for(;!this.atEnd&&0===e&&"<}>"!==this.peek;)"<{>"===this.peek&&(e+=1),"<}>"===this.peek&&(e-=1),i.push(this.next());this.match("<}>")&&i.push("<}>")}return["Error","Missing",{str:"unknown-command"},["LatexForm",{str:`${e}${o(i)}`}]]}matchPrimary(){let e=null;const i=this.index,t=this.matchNumber();if(t&&(e={num:t}),null===e&&(e=this.matchEnclosure()),null===e&&(e=this.matchEnvironment()),null===e&&(e=this.matchSymbol()),null!==e){e=this.decorate(e,i);let t=null,r=this.index;do{if(t=this.matchPostfix(e),e=null!=t?t:e,this.index===r&&null!==t)break;r=this.index}while(null!==t)}return null!==e&&(e=this.matchSupsub(e)),this.decorate(e,i)}matchExpression(e){const i=this.index;e||(e={minPrec:0}),e.minPrec||(e=Object.assign(Object.assign({},e),{minPrec:0})),this.skipSpace();let t=this.matchPrefixOperator(Object.assign(Object.assign({},e),{minPrec:0}));if(null===t&&(t=this.matchPrimary()),t){let i=!1;for(;!this.atTerminator(e)&&!i;){this.skipSpace();let r=this.matchInfixOperator(t,e);null===r&&null===this.peekDefinitions("operator")&&(r=this.applyInvisibleOperator(e,t)),null!==r?t=r:i=!0}}return this.decorate(t,i)}decorate(e,i){if(null===e)return null;if(!this.options.preserveLatex)return e;const t=this.latex(i,this.index);return Array.isArray(e)?e={latex:t,fn:e}:"number"==typeof e?e={latex:t,num:Number(e).toString()}:"string"==typeof e?e={latex:t,sym:e}:"object"==typeof e&&null!==e&&(e.latex=t),e}}function be(e,i){const t=e.length,r=e;e=e.slice(0,-1);for(let t=0;t<e.length-16;t++){const r=e.substring(0,t);for(let n=0;n<17;n++){const s=e.substring(t,t+n+1),a=Math.floor((e.length-r.length)/s.length);if(a>1&&(r+s.repeat(a+1)).startsWith(e))return"0"===s?r.replace(/(\d{3})/g,"$1"+i.groupSeparator):r.replace(/(\d{3})/g,"$1"+i.groupSeparator)+i.beginRepeatingDigits+s+i.endRepeatingDigits}}const n=t>i.precision-1;return e=r,n&&(e=e.substring(0,i.precision-1)),i.groupSeparator&&(e=e.replace(/(\d{3})/g,"$1"+i.groupSeparator)).endsWith(i.groupSeparator)&&(e=e.slice(0,-i.groupSeparator.length)),n?e+i.truncationMarker:e}function Se(e,i){var t;return e?i.beginExponentMarker?i.beginExponentMarker+e+(null!==(t=i.endExponentMarker)&&void 0!==t?t:""):"10^{"+e+"}":""}class Ne{constructor(e,i,t,r){this.level=-1,this.options=e,this.computeEngine=t,e.invisibleMultiply&&(/#1/.test(e.invisibleMultiply)&&/#2/.test(e.invisibleMultiply)||r([{severity:"warning",message:["expected-argument","invisibleMultiply"]}])),this.onError=r,this.dictionary=i}updateOptions(e){for(const i of Object.keys(this.options))i in e&&(this.options[i]=e[i])}wrap(e,i){if(null===e)return"";if(void 0===i)return"("+this.serialize(e)+")";if("number"==typeof e||q(e)||"string"==typeof e||E(e))return this.serialize(e);const t=M(e);if("string"==typeof t&&"Delimiter"!==t){const r=this.dictionary.name.get(t);if(r&&("symbol"===r.kind||"prefix"===r.kind||"infix"===r.kind||"postfix"===r.kind)&&r.precedence<i)return this.wrapString(this.serialize(e),this.options.applyFunctionStyle(e,this.level))}return this.serialize(e)}wrapShort(e){if(null===e)return"";const i=this.serialize(e);return"Delimiter"===M(e)||"number"==typeof e||q(e)||/(^(.|\\[a-zA-Z*]+))$/.test(i)?i:this.wrapString(i,this.options.groupStyle(e,this.level+1))}wrapString(e,i){return"none"===i?e:"("+e+")"}serializeSymbol(e,i){var t;const r=M(e);if(!r)return"string"==typeof(null==i?void 0:i.serialize)?i.serialize:"function"==typeof(null==i?void 0:i.serialize)?i.serialize(this,e):null!==(t=qe(w(e),"upright."))&&void 0!==t?t:"";const n=j(e);if(!i){if("string"==typeof r&&r.length>0&&"\\"===r[0]){let e=r;for(const i of n)e+="{"+this.serialize(i)+"}";return e}return"string"==typeof r?`${qe(r,"upright.")}(${n.map((e=>this.serialize(e))).join(", ")})`:`\\operatorname{Apply}(${this.serialize(r)}, ${this.serialize(["List",...n])})`}if(i.requiredLatexArg>0){let e="",t="",r=0;for(;r<i.requiredLatexArg;)t+="{"+this.serialize(n[r++])+"}";for(;r<Math.min(n.length,i.optionalLatexArg+i.requiredLatexArg);){const i=this.serialize(n[1+r++]);i&&(e+="["+i+"]")}return i.serialize+(e+t)}return"function"==typeof i.serialize?i.serialize(this,e):"none"===this.options.applyFunctionStyle(e,this.level)?i.serialize+l(n.map((e=>this.serialize(e)))):i.serialize+this.serialize(["Delimiter",...n])}serializeDictionary(e){return`\\left[\\begin{array}{lll}${Object.keys(e).map((i=>`\\textbf{${i}} & \\rightarrow & ${this.serialize(e[i])}`)).join("\\\\")}\\end{array}\\right]`}serialize(e){if(null===e)return"";this.level+=1;const i=(()=>{const i=function(e,i){var t,r,n;if(null===e)return"";let s;if("number"==typeof e)s=e;else{if("object"!=typeof e||!("num"in e))return"";s=e.num}if(s===1/0||"Infinity"===s||"+Infinity"===s)return i.positiveInfinity;if(s===-1/0||"-Infinity"===s)return i.negativeInfinity;if("NaN"===s||"number"==typeof s&&Number.isNaN(s))return i.notANumber;if("number"==typeof s)return"engineering"===i.notation?function(e,i){if(0===e)return"0";const t=Math.abs(e);let r=Math.round(Math.log10(t));r-=r%3,t>Math.pow(10,i.avoidExponentsInRange[0])&&t<Math.pow(10,i.avoidExponentsInRange[1])&&(r=0);const n=t/Math.pow(10,r);let s="";const a=n.toString().match(/^(.*)\.(.*)$/);(null==a?void 0:a[1])&&a[2]&&(s=a[1]+i.decimalMarker+a[2]),i.groupSeparator&&(s=be(n.toExponential(),i));let l="";return 0!==r&&(l=Se(r.toString(),i)),(e<0?"-":"")+s+l}(s,i):function(e,i){var t;let r,n=e.match(/^(.*)[e|E]([-+]?[0-9]+)$/i);(null==n?void 0:n[1])&&n[2]&&(r=Se(n[2],i));let s=null!==(t=null==n?void 0:n[1])&&void 0!==t?t:e,a="";return n=(r?n[1]:e).match(/^(.*)\.(.*)$/),(null==n?void 0:n[1])&&n[2]&&(s=n[1],a=n[2]),i.groupSeparator&&(s=s.replace(/\B(?=(\d{3})+(?!\d))/g,i.groupSeparator),a=be(a,i)),a&&(a=i.decimalMarker+a),r?"1"!==s||a?s+a+i.exponentProduct+r:r:s+a}(s.toString(),i);if(/[0-9][nd]$/.test(s)&&(s=s.slice(0,-1)),s=s.replace(/[\u0009-\u000d\u0020\u00a0]/g,""),/\([0-9]+\)$/.test(s)){const[e,r,n]=null!==(t=s.match(/(.+)\(([0-9]+)\)$/))&&void 0!==t?t:[];s=r+n.repeat(Math.ceil(i.precision/n.length))}let a="";for("-"===s[0]?(a="-",s=s.substring(1)):"+"===s[0]&&(s=s.substring(1));"0"===s[0];)s=s.substring(1);if(0===s.length)return a+"0";"."===s[0]&&(s="0"+s);let l="";if(s.indexOf(".")>=0){const e=s.match(/(\d*)\.(\d*)([e|E]([-+]?[0-9]*))?/);if(!e)return"";const t=e[1],n=e[2];if(l=null!==(r=e[4])&&void 0!==r?r:"","0"===t){let e=0;for(;"0"===n[e]&&e<n.length;)e+=1;let t="";if(e<=4)t="0"+i.decimalMarker,t+=n.substring(0,e),t+=be(s.substring(t.length),i);else if(e+1>=i.precision)t="0",a="";else{t=s[e];const r=be(s.substring(e+1),i);r&&(t+=i.decimalMarker+r)}"0"!==t&&(!(s.length-1>i.precision)||i.endRepeatingDigits&&t.endsWith(i.endRepeatingDigits)||!i.truncationMarker||t.endsWith(i.truncationMarker)||(t+=i.truncationMarker),e>4&&(t+=i.exponentProduct+Se(""+(1-e),i))),s=t}else{s=t.replace(/\B(?=(\d{3})+(?!\d))/g,i.groupSeparator);const e=be(n,i);e&&(s+=i.decimalMarker+e)}}else if(s.length>i.precision){const e=s.length;if(e>i.avoidExponentsInRange[1]){let t=s[0];const r=be(s.substring(1),i);r&&(t+=i.decimalMarker+r,i.truncationMarker&&!t.endsWith(i.truncationMarker)&&i.endRepeatingDigits&&!t.endsWith(i.endRepeatingDigits)&&(t+=i.truncationMarker)),"1"!==t?t+=i.exponentProduct:t="",s=t+Se(""+(e-1),i)}}else{const e=s.match(/([0-9]*)\.?([0-9]*)([e|E]([-+]?[0-9]+))?/);e&&(s=e[1],e[2]&&(s+=i.decimalMarker+e[2]),l=null!==(n=e[4])&&void 0!==n?n:""),s=s.replace(/\B(?=(\d{3})+(?!\d))/g,i.groupSeparator)}const o=Se(l,i);return"1"===s&&o?a+o:(o&&(s=s+i.exponentProduct+o),a+s)}(e,this.options);if(i)return i;const t=O(e);if(null!==t)return`\\text{${t}}`;const r=w(e);if(null!==r){const i=this.dictionary.name.get(r);if("symbol"===(null==i?void 0:i.kind))return this.serializeSymbol(e,i)}const n=T(e);if(null!==n)return this.serializeDictionary(n);const s=_(e);if(s){if("\\"===s[0]){const i=j(e);return 0===i.length?s:s+"{"+i.map((e=>this.serialize(e))).filter((e=>!!e)).join("}{")+"}"}const i=this.dictionary.name.get(s);if(i){let t="";return"function"==typeof i.serialize&&(t=i.serialize(this,e)),t||"infix"!==i.kind&&"postfix"!==i.kind&&"prefix"!==i.kind||(t=function(e,i,t){let r="";const n=L(i),s=_(i);if("postfix"===t.kind)return 1!==n&&e.onError([{severity:"warning",message:["postfix-operator-requires-one-operand",e.serializeSymbol(s)]}]),Ae(t.serialize,[e.wrap($(i,1),t.precedence)]);if("prefix"===t.kind)return 1!==n&&e.onError([{severity:"warning",message:["prefix-operator-requires-one-operand",e.serializeSymbol(s)]}]),Ae(t.serialize,[e.wrap($(i,1),t.precedence+1)]);if("infix"===t.kind){r=e.wrap($(i,1),t.precedence);for(let s=2;s<n+1;s++){const n=$(i,s);null!==n&&(r=Ae(t.serialize,[r,e.wrap(n,t.precedence)]))}}return r}(this,e,i)),t||"matchfix"!==i.kind||(t=function(e,i,t){var r;return Ae(t.serialize,[e.serialize(null!==(r=$(i,1))&&void 0!==r?r:"Nothing")])}(this,e,i)),t||"symbol"!==i.kind||(t=this.serializeSymbol(e,i)),t}}if(Array.isArray(e)||P(e)||null!==w(e))return this.serializeSymbol(e);this.onError([{severity:"warning",message:["syntax-error",JSON.stringify(e)]}])})();return this.level-=1,null!=i?i:""}applyFunctionStyle(e,i){return this.options.applyFunctionStyle(e,i)}groupStyle(e,i){return this.options.groupStyle(e,i)}rootStyle(e,i){return this.options.rootStyle(e,i)}fractionStyle(e,i){return this.options.fractionStyle(e,i)}logicStyle(e,i){return this.options.logicStyle(e,i)}powerStyle(e,i){return this.options.powerStyle(e,i)}numericSetStyle(e,i){return this.options.numericSetStyle(e,i)}}function Ae(e,i){var t;let r=e;for(let e=0;e<i.length;e++){let n=null!==(t=i[e])&&void 0!==t?t:"";if(/[a-zA-Z*]/.test(n[0])){const i=r.match(RegExp("(.*)#"+Number(e+1).toString()));i&&/\\[a-zA-Z*]+/.test(i[1])&&(n=" "+n)}r=r.replace("#"+Number(e+1).toString(),n)}return r}const ze=["alpha","beta","gamma","Gamma","delta","Delta","epsilon","zeta","eta","theta","Theta","iota","kappa","lambda","Lambda","mu","nu","xi","Xi","pi","Pi","rho","sigma","Sigma","tau","upsilon","phi","Phi","varphi","chi","psi","Psi","omega","Omega","aleph","ast","blacksquare","bot","bullet","circ","diamond","times","top","square","star"];function qe(e,i="italic."){var t;if(null===e)return null;const r=e.match(/^(_+)(.*)/);if(r)return`\\text{${"\\_".repeat(r[1].length)+Ee(r[2])}}`;let n;[n,e]=function(e){const i=e.match(/^([a-zA-Z-]+\.)(.*)/);return i?[i[1],i[2]]:["",e]}(e);const s=Ee(e);return 1!==s.length||n?(n||(n=i),(null!==(t={"upright.":"\\mathrm{_}","italic.":"\\mathit{_}","bold-italic.":"\\mathbf{\\mathit{_}}","script.":"\\mathscr{_}","calligraphic.":"\\mathcal{_}","bold-script.":"\\mathbf{\\mathscr{_}}","bold-calligraphic.":"\\mathbf{\\mathcal{_}}","fraktur.":"\\mathfrak{_}","gothic.":"\\mathfrak{_}","bold-gothic.":"\\mathbf{\\mathfrak{_}}","bold-fraktur.":"\\mathbf{\\mathfrak{_}}","sans-serif.":"\\mathsf{_}","bold-sans-serif.":"\\mathbf{\\mathsf{_}}","italic-sans-serif.":"\\mathit{\\mathsf{_}}","monospace.":"\\mathtt{_}","blackboard.":"\\mathbb{_}","double-struck.":"\\mathbb{_}"}[n])&&void 0!==t?t:"\\mathit{_}").replace("_",s)):s}function Ee(e){const i=e.indexOf("_");if(i>0){const t=e.substring(0,i),r=e.substring(i+1);return r?r.startsWith('"')&&r.endsWith('"')?`${Ee(t)}_\\mathrm{${Ee(r.substring(1,-1))}}`:`${Ee(t)}_{${Ee(r)}}`:qe(t)+"\\_"}const t=e.match(/([^0-9]+?)([0-9]+)$/);return t?0===t[1].length?e:`${Ee(t[1])}_{${t[2]}}`:ze.includes(e)?"\\"+e:e=e.replace(/[{}\[\]\\:\-\$%]/g,(e=>{var i;return null!==(i={"{":"\\lbrace ","}":"\\rbrace ","[":"\\lbrack ","]":"\\rbrack ",":":"\\colon ","\\":"\\backslash ","-":'\\unicode{"2013}'}[e])&&void 0!==i?i:"\\"+e}))}const Pe={invisibleMultiply:"",invisiblePlus:"",multiply:"\\times",missingSymbol:"\\placeholder{}",applyFunctionStyle:function(e,i){return"paren"},groupStyle:function(e,i){return"paren"},rootStyle:B,fractionStyle:G,logicStyle:function(e,i){return"boolean"},powerStyle:function(e,i){return"solidus"},numericSetStyle:function(e,i){return"compact"}};class De{constructor(e){var i,t;this.onError=null!==(i=e.onError)&&void 0!==i?i:e=>{if("undefined"!=typeof window)for(const i of e);},this.computeEngine=e.computeEngine;const r=Object.assign({},e);delete r.dictionary,delete r.onError,this.options=Object.assign(Object.assign(Object.assign(Object.assign({},xe),Pe),ye),r),this.dictionary=function(e,i){var t,r;const n={lookahead:1,name:new Map,symbol:[],infix:[],prefix:[],postfix:[],environment:new Map,matchfix:[]};for(const s of e){const[e,a]=ge(s,i);if(null!==a)if(void 0!==a.name&&(n.name.has(a.name)&&i({severity:"warning",message:["invalid-dictionary-entry",a.name,"Duplicate definition"]}),n.name.set(a.name,a)),"matchfix"===a.kind)n.matchfix.push(a);else if("environment"===a.kind){const e=o(null!==(t=s.trigger)&&void 0!==t?t:"");n.environment.has(e)&&i({severity:"warning",message:["invalid-dictionary-entry",e,"Duplicate environment definition"]}),n.environment.set(e,a)}else if(e){const i=o(null!==(r=s.trigger)&&void 0!==r?r:""),t=ue(e);if(n.lookahead=Math.max(n.lookahead,t),"symbol"===a.kind){void 0===n.symbol[t]&&(n.symbol[t]=new Map);const e=n.symbol[t];e.has(i)?e.get(i).push(a):e.set(i,[a])}else if("prefix"===a.kind){void 0===n.prefix[t]&&(n.prefix[t]=new Map);const e=n.prefix[t];e.has(i)?e.get(i).push(a):e.set(i,[a])}else if("infix"===a.kind){void 0===n.infix[t]&&(n.infix[t]=new Map);const e=n.infix[t];e.has(i)?e.get(i).push(a):e.set(i,[a])}else if("postfix"===a.kind){void 0===n.postfix[t]&&(n.postfix[t]=new Map);const e=n.postfix[t];e.has(i)?e.get(i).push(a):e.set(i,[a])}}}return n}(null!==(t=e.dictionary)&&void 0!==t?t:De.getDictionary(),(e=>this.onError([e])))}updateOptions(e){for(const i of Object.keys(this.options))i in e&&(this.options[i]=e[i]);this.serializer.updateOptions(e)}static getDictionary(e="all"){if("all"===e){let e=[];for(const i of Object.keys(pe))pe[i]&&(e=[...e,...pe[i]]);return e}return pe[e]?[...pe[e]]:[]}parse(e){const i=new ke(a(e,[]),this.options,this.dictionary,this.computeEngine,this.onError);let t=i.matchExpression();if(!i.atEnd){const e=[];for(;!i.atEnd;)e.push(i.next());t=["Error",null!=t?t:"Nothing",{str:"syntax-error"},["LatexForm",{str:o(e)}]]}return null!=t?t:"Nothing"}serialize(e){return this.serializer.serialize(e)}get serializer(){return this._serializer||(this._serializer=new Ne(this.options,this.dictionary,this.computeEngine,this.onError)),this._serializer}}e.LatexSyntax=De,e.applyRecursively=function(e,i){const t=M(e);if(null!==t)return[i(t),...j(e).map(i)];const r=T(e);if(null!==r){const e=Object.keys(r),t={};for(const n of e)t[n]=i(r[n]);return{dict:t}}return i(e)},e.asValidJSONNumber=function(e){if("string"==typeof e){const i=Number(e);if("+"===e[0]&&(e=e.slice(1)),i.toString()===e)return isNaN(i)||!isFinite(i)?i.toString():i}return e},e.getDictionary=T,e.getStringValue=O,e.head=M,e.headName=_,e.isAtomic=D,e.isDictionaryObject=function(e){return null!==e&&"object"==typeof e&&"dict"in e},e.isFunctionObject=P,e.isStringObject=function(e){return null!==e&&"object"==typeof e&&"str"in e},e.isSymbolObject=E,e.mapArgs=R,e.nops=L,e.op=$,e.symbol=w,e.tail=j,e.version="0.4.4",Object.defineProperty(e,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory((global="undefined"!=typeof globalThis?globalThis:global||self).MathJson={});
1
+ /** MathJSON 0.5.0 */
2
+ var global,factory;global=this,factory=function(n){function t(n){return null!==n&&"object"==typeof n&&"sym"in n}function r(n){return null!==n&&"object"==typeof n&&"fn"in n}function e(n){return null===n?null:Array.isArray(n)?n[0]:r(n)?n.fn[0]:null}function l(n){return Array.isArray(n)?n.slice(1):r(n)?n.fn.slice(1):[]}function i(n){return"object"==typeof n&&"dict"in n?n.dict:null}n.applyRecursively=function(n,t){const r=e(n);if(null!==r)return[t(r),...l(n).map(t)];const o=i(n);if(null!==o){const n=Object.keys(o),r={};for(const e of n)r[e]=t(o[e]);return{dict:r}}return t(n)},n.asValidJSONNumber=function(n){if("string"==typeof n){const t=Number(n);if("+"===n[0]&&(n=n.slice(1)),t.toString()===n)return isNaN(t)||!isFinite(t)?t.toString():t}return n},n.getDictionary=i,n.getStringValue=function(n){return null===n?null:"object"==typeof n&&"str"in n?n.str:"string"!=typeof n||n.length<2||"'"!==n[0]||"'"!==n[n.length-1]?null:n.substring(1,n.length-1)},n.head=e,n.headName=function(n){const t=e(n);return"string"==typeof t?t:""},n.isAtomic=function(n){return null===n||!Array.isArray(n)&&("object"!=typeof n||!("fn"in n||"dic"in n))},n.isDictionaryObject=function(n){return null!==n&&"object"==typeof n&&"dict"in n},n.isFunctionObject=r,n.isStringObject=function(n){return null!==n&&"object"==typeof n&&"str"in n},n.isSymbolObject=t,n.mapArgs=function(n,t){let e=null;if(Array.isArray(n)&&(e=n),r(n)&&(e=n.fn),null===e)return[];let l=1;const i=[];for(;l<e.length;)i.push(t(e[l])),l+=1;return i},n.nops=function(n){return Array.isArray(n)?Math.max(0,n.length-1):r(n)?Math.max(0,n.fn.length-1):0},n.op=function(n,t){var e,l;return null===n?null:Array.isArray(n)?null!==(e=n[t])&&void 0!==e?e:null:r(n)&&null!==(l=n.fn[t])&&void 0!==l?l:null},n.symbol=function(n){return null===n?null:"string"==typeof n?n.length>=2&&"'"===n[0]&&"'"===n[n.length-1]?null:n:t(n)?n.sym:null},n.tail=l,n.version="0.5.0",Object.defineProperty(n,"__esModule",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory((global="undefined"!=typeof globalThis?globalThis:global||self).MathJson={});
@@ -1,4 +1,4 @@
1
- /* 0.4.4 */
1
+ /* 0.5.0 */
2
2
  /**
3
3
  * Return a string or an array of graphemes.
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.4.4 */
1
+ /* 0.5.0 */
2
2
  export declare type SignalCode = RuntimeSignalCode | ('invalid-name' | 'expected-predicate' | 'expected-symbol' | 'operator-requires-one-operand' | 'postfix-operator-requires-one-operand' | 'prefix-operator-requires-one-operand' | 'unbalanced-symbols' | 'expected-argument' | 'unexpected-command' | 'cyclic-definition' | 'invalid-supersets' | 'expected-supersets' | 'unknown-domain' | 'duplicate-wikidata' | 'invalid-dictionary-entry' | 'syntax-error');
3
3
  export declare type SignalMessage = SignalCode | [SignalCode, ...any[]];
4
4
  export declare type SignalOrigin = {
@@ -1,4 +1,4 @@
1
- /* 0.4.4 */
1
+ /* 0.5.0 */
2
2
  /**
3
3
  * Add an assumption, in the form of a predicate, for example:
4
4
  *
@@ -1,4 +1,4 @@
1
- /* 0.4.4 */
1
+ /* 0.5.0 */
2
2
  import type { Complex } from 'complex.js';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
4
  import { BoxedExpression, BoxedFunctionDefinition, BoxedRuleSet, BoxedSymbolDefinition, EvaluateOptions, IComputeEngine, LatexString, Metadata, NOptions, PatternMatchOption, SemiBoxedExpression, SimplifyOptions, Substitution } from '../public';
@@ -1,4 +1,4 @@
1
- /* 0.4.4 */
1
+ /* 0.5.0 */
2
2
  import { Decimal } from 'decimal.js';
3
3
  import { IComputeEngine, SemiBoxedExpression, BoxedExpression, Metadata } from '../public';
4
4
  import { Expression, MathJsonNumber } from '../../math-json/math-json-format';
@@ -1,4 +1,4 @@
1
- /* 0.4.4 */
1
+ /* 0.5.0 */
2
2
  import { BoxedExpression, IComputeEngine, EvaluateOptions, NOptions, BoxedRuleSet, SemiBoxedExpression, SimplifyOptions, ReplaceOptions, Substitution, Metadata, PatternMatchOption } from '../public';
3
3
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.4.4 */
1
+ /* 0.5.0 */
2
2
  import { BoxedExpression, IComputeEngine, Metadata } from '../public';
3
3
  export declare class Domain extends BoxedSymbol {
4
4
  constructor(ce: IComputeEngine, dom: string, metadata?: Metadata);
@@ -1,2 +1,2 @@
1
- /* 0.4.4 */
1
+ /* 0.5.0 */
2
2
  export declare function makeFunctionDefinition(engine: IComputeEngine, def: FunctionDefinition): BoxedFunctionDefinition;
@@ -1,4 +1,4 @@
1
- /* 0.4.4 */
1
+ /* 0.5.0 */
2
2
  import { Expression } from '../../math-json/math-json-format';
3
3
  import { BoxedExpression, BoxedFunctionDefinition, IComputeEngine, EvaluateOptions, NOptions, BoxedRuleSet, SemiBoxedExpression, SimplifyOptions, Substitution, ReplaceOptions, Metadata, PatternMatchOption } from '../public';
4
4
  /**
@@ -88,6 +88,8 @@ export declare function ungroup(expr: BoxedExpression): BoxedExpression;
88
88
  * - 'last': apply `f` to all elements except the last
89
89
  * - 'most': apply `f` to the last elements, skip the others
90
90
  *
91
+ * Account for `Hold`, `ReleaseHold` and `Nothing`.
92
+ *
91
93
  * If `f` returns `null`, the element is not added to the result
92
94
  */
93
95
  export declare function holdMap(xs: BoxedExpression[], skip: 'all' | 'none' | 'first' | 'rest' | 'last' | 'most', f: (BoxedExpression: any) => BoxedExpression | null): BoxedExpression[];
@@ -1,4 +1,4 @@
1
- /* 0.4.4 */
1
+ /* 0.5.0 */
2
2
  import { Complex } from 'complex.js';
3
3
  import { Expression } from '../../math-json/math-json-format';
4
4
  import { BoxedExpression, IComputeEngine, Metadata, NOptions, PatternMatchOption, SimplifyOptions, Substitution } from '../public';
@@ -1,4 +1,4 @@
1
- /* 0.4.4 */
1
+ /* 0.5.0 */
2
2
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
3
3
  import { BoxedExpression, IComputeEngine, LatexString, Metadata, Pattern, PatternMatchOption, SemiBoxedExpression, Substitution } from '../public';
4
4
  export declare class BoxedPattern extends AbstractBoxedExpression implements Pattern {
@@ -1,4 +1,4 @@
1
- /* 0.4.4 */
1
+ /* 0.5.0 */
2
2
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
3
3
  import { BoxedExpression, IComputeEngine, Metadata, PatternMatchOption, Substitution } from '../public';
4
4
  /**
@@ -1,4 +1,4 @@
1
- /* 0.4.4 */
1
+ /* 0.5.0 */
2
2
  export declare function domainToFlags(dom: BoxedExpression | undefined | null): Partial<SymbolFlags>;
3
3
  export declare class BoxedSymbolDefinitionImpl implements BoxedSymbolDefinition {
4
4
  private _engine;
@@ -1,4 +1,4 @@
1
- /* 0.4.4 */
1
+ /* 0.5.0 */
2
2
  import { AbstractBoxedExpression } from './abstract-boxed-expression';
3
3
  import { BoxedExpression, BoxedRuleSet, BoxedSymbolDefinition, IComputeEngine, EvaluateOptions, NOptions, ReplaceOptions, SimplifyOptions, Substitution, Metadata, PatternMatchOption } from '../public';
4
4
  /**