@cortex-js/compute-engine 0.4.3 → 0.4.4

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 (80) hide show
  1. package/README.md +2 -3
  2. package/dist/compute-engine.esm.js +63 -44
  3. package/dist/compute-engine.min.esm.js +2 -2
  4. package/dist/compute-engine.min.js +2 -2
  5. package/dist/math-json.esm.js +23 -16
  6. package/dist/math-json.min.esm.js +2 -2
  7. package/dist/math-json.min.js +2 -2
  8. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  9. package/dist/types/common/signals.d.ts +1 -1
  10. package/dist/types/compute-engine/assume.d.ts +1 -1
  11. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +3 -3
  12. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  13. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  14. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +1 -1
  15. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
  16. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  17. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  18. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  19. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  20. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +2 -2
  21. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +3 -3
  22. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  23. package/dist/types/compute-engine/boxed-expression/order.d.ts +2 -1
  24. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  25. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  26. package/dist/types/compute-engine/compute-engine.d.ts +12 -7
  27. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  28. package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +1 -1
  29. package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +1 -1
  30. package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +1 -1
  31. package/dist/types/compute-engine/dictionary/arithmetic-power.d.ts +1 -1
  32. package/dist/types/compute-engine/dictionary/arithmetic.d.ts +1 -1
  33. package/dist/types/compute-engine/dictionary/collections.d.ts +1 -1
  34. package/dist/types/compute-engine/dictionary/core.d.ts +1 -1
  35. package/dist/types/compute-engine/dictionary/dictionary.d.ts +1 -1
  36. package/dist/types/compute-engine/dictionary/logic.d.ts +1 -1
  37. package/dist/types/compute-engine/dictionary/polynomials.d.ts +1 -1
  38. package/dist/types/compute-engine/dictionary/relational-operator.d.ts +1 -1
  39. package/dist/types/compute-engine/dictionary/sets.d.ts +1 -1
  40. package/dist/types/compute-engine/dictionary/trigonometry.d.ts +1 -1
  41. package/dist/types/compute-engine/domain-utils.d.ts +1 -1
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  48. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  49. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  50. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  51. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  52. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  53. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +2 -2
  54. package/dist/types/compute-engine/latex-syntax/parse.d.ts +5 -5
  55. package/dist/types/compute-engine/latex-syntax/public.d.ts +2 -2
  56. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +3 -3
  57. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  58. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +3 -3
  59. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  60. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  61. package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +1 -1
  62. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  63. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  64. package/dist/types/compute-engine/public.d.ts +68 -35
  65. package/dist/types/compute-engine/rules.d.ts +1 -1
  66. package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
  67. package/dist/types/compute-engine/symbolic/expand.d.ts +1 -1
  68. package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
  69. package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
  70. package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
  71. package/dist/types/compute-engine/symbolic/product.d.ts +1 -1
  72. package/dist/types/compute-engine/symbolic/sum.d.ts +1 -1
  73. package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
  74. package/dist/types/compute-engine.d.ts +2 -2
  75. package/dist/types/math-json/math-json-format.d.ts +1 -1
  76. package/dist/types/math-json/utils.d.ts +1 -1
  77. package/dist/types/math-json.d.ts +2 -2
  78. package/package.json +3 -3
  79. package/dist/compute-engine.js +0 -23523
  80. package/dist/math-json.js +0 -6339
@@ -1,4 +1,4 @@
1
- /** MathJSON 0.4.3 */
1
+ /** MathJSON 0.4.4 */
2
2
  function stringToCodepoints(string) {
3
3
  const result = [];
4
4
  for (let i = 0; i < string.length; i++) {
@@ -874,17 +874,17 @@ function numeratorDenominator(expr) {
874
874
  for (const arg of args) {
875
875
  if (head(arg) === 'Power') {
876
876
  if (head(op(arg, 2)) === 'Negate') {
877
- const a = op(arg, 1) ?? 'Nothing';
878
- const b = op(op(arg, 2), 1) ?? 'Nothing';
877
+ const a = op(arg, 1) ?? 'Missing';
878
+ const b = op(op(arg, 2), 1) ?? 'Missing';
879
879
  denominator.push([POWER, a, b]);
880
880
  }
881
881
  else {
882
882
  const exponentVal = machineValue(op(arg, 2)) ?? NaN;
883
883
  if (exponentVal === -1) {
884
- denominator.push(op(arg, 1) ?? 'Nothing');
884
+ denominator.push(op(arg, 1) ?? 'Missing');
885
885
  }
886
886
  else if (exponentVal < 0) {
887
- denominator.push([POWER, op(arg, 1) ?? 'Nothing', -exponentVal]);
887
+ denominator.push([POWER, op(arg, 1) ?? 'Missing', -exponentVal]);
888
888
  }
889
889
  else {
890
890
  numerator.push(arg);
@@ -902,8 +902,8 @@ function parseRoot(parser) {
902
902
  const base = parser.matchRequiredLatexArgument();
903
903
  if (base === null) {
904
904
  if (degree !== null)
905
- return [ROOT, 'Nothing', degree];
906
- return [SQRT, 'Nothing'];
905
+ return [ROOT, 'Missing', degree];
906
+ return [SQRT, 'Missing'];
907
907
  }
908
908
  if (degree !== null)
909
909
  return [ROOT, base, degree];
@@ -1134,11 +1134,11 @@ function parseFraction(parser) {
1134
1134
  head(op(denom, 1)) === 'PartialDerivative'))) {
1135
1135
  // It's a Leibniz notation partial derivative
1136
1136
  // `∂f(x)/∂x` or `∂^2f(x)/∂x∂y` or `∂/∂x f(x)`
1137
- const degree = op(numer, 3) ?? 'Nothing';
1137
+ const degree = op(numer, 3) ?? 'Missing';
1138
1138
  // Expect: getArg(numer, 2) === 'Nothing' -- no args
1139
1139
  let fn = op(numer, 1);
1140
1140
  if (fn === null || fn === 'Missing') {
1141
- fn = parser.matchExpression() ?? 'Nothing';
1141
+ fn = parser.matchExpression() ?? 'Missing';
1142
1142
  }
1143
1143
  let vars = [];
1144
1144
  if (head(denom) === 'Multiply') {
@@ -1370,7 +1370,7 @@ const DEFINITIONS_ARITHMETIC = [
1370
1370
  name: 'Exp',
1371
1371
  serialize: (serializer, expr) => joinLatex([
1372
1372
  '\\exponentialE^{',
1373
- serializer.serialize(op(expr, 1) ?? 'Nothing'),
1373
+ serializer.serialize(op(expr, 1) ?? 'Missing'),
1374
1374
  '}',
1375
1375
  ]),
1376
1376
  },
@@ -4965,10 +4965,10 @@ class _Parser {
4965
4965
  if (sub)
4966
4966
  this.match('<}>');
4967
4967
  }
4968
- subscripts.push(sub ?? 'Nothing');
4968
+ subscripts.push(sub ?? 'Missing');
4969
4969
  }
4970
4970
  else if (this.match('^'))
4971
- superscripts.push(this.matchRequiredLatexArgument() ?? 'Nothing');
4971
+ superscripts.push(this.matchRequiredLatexArgument() ?? 'Missing');
4972
4972
  this.skipSpace();
4973
4973
  }
4974
4974
  if (superscripts.length === 0 && subscripts.length === 0) {
@@ -5236,13 +5236,13 @@ class _Parser {
5236
5236
  if (tokens.length === 0)
5237
5237
  return [
5238
5238
  'Error',
5239
- 'Nothing',
5239
+ 'Missing',
5240
5240
  { str: 'syntax-error' },
5241
5241
  ['LatexForm', { str: command }],
5242
5242
  ];
5243
5243
  return [
5244
5244
  'Error',
5245
- 'Nothing',
5245
+ 'Missing',
5246
5246
  { str: 'unknown-command' },
5247
5247
  ['LatexForm', { str: `${command}{${tokensToString(tokens)}}` }],
5248
5248
  ];
@@ -5282,7 +5282,7 @@ class _Parser {
5282
5282
  }
5283
5283
  return [
5284
5284
  'Error',
5285
- 'Nothing',
5285
+ 'Missing',
5286
5286
  { str: 'unknown-command' },
5287
5287
  ['LatexForm', { str: `${command}${tokensToString(tokens)}` }],
5288
5288
  ];
@@ -5542,6 +5542,13 @@ function serializeNumber(expr, options) {
5542
5542
  // remove it (legacy format)
5543
5543
  if (/[0-9][nd]$/.test(num))
5544
5544
  num = num.slice(0, -1);
5545
+ // Remove any whitespace
5546
+ num = num.replace(/[\u0009-\u000d\u0020\u00a0]/g, '');
5547
+ // Do we have repeating digits?
5548
+ if (/\([0-9]+\)$/.test(num)) {
5549
+ const [_, body, repeat] = num.match(/(.+)\(([0-9]+)\)$/) ?? [];
5550
+ num = body + repeat.repeat(Math.ceil(options.precision / repeat.length));
5551
+ }
5545
5552
  let sign = '';
5546
5553
  if (num[0] === '-') {
5547
5554
  sign = '-';
@@ -6307,6 +6314,6 @@ class LatexSyntax {
6307
6314
  }
6308
6315
 
6309
6316
  // This is the root of the `math-json` package (i.e. `math-json.js` and
6310
- const version = '0.4.3';
6317
+ const version = '0.4.4';
6311
6318
 
6312
6319
  export { LatexSyntax, applyRecursively, asValidJSONNumber, dictionary as getDictionary, stringValue as getStringValue, head, headName, isAtomic, isDictionaryObject, isFunctionObject, isStringObject, isSymbolObject, mapArgs, nops, op, symbol, tail, version };
@@ -1,2 +1,2 @@
1
- /** MathJSON 0.4.3 */
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{if(0===o.length)if(/^#[0-9?]$/.test(e.peek())){o=n(i?.[e.get().slice(1)]??i?.["?"]??"\\placeholder{}",i),r=o[0]}else 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 w(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 L(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 _(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 C(e,i){return i>2?"solidus":"radical"}function $(e,i){return i>3?"inline-solidus":"quotient"}function M(e,i,t,r){if(null===t)return"\\sqrt{}";if(r=r??2,"solidus"===i)return e.wrapShort(t)+"^{1\\/"+e.serialize(r)+"}";if("quotient"===i)return e.wrapShort(t)+"^{\\frac{1}{"+e.serialize(r)+"}}";return 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}}`}if("reciprocal"===n)return e.wrap(t)+e.wrap(r)+"^{-1}";if("factor"===n)return"\\frac{1}{"+e.serialize(r)+"}"+e.wrap(t);return`\\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 M(e,C(0,e.level),r,2);if("Root"===t)return M(e,C(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 M(e,C(0,e.level),r,b(n,2))}}else if("Power"===k(n)&&-1===A(b(n,2))){return M(e,C(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:L("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)??"Nothing";let n=b(i,1);null!==n&&"Missing"!==n||(n=e.matchExpression()??"Nothing");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)??"Nothing"),"}"])},{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)??"Nothing",r=b(b(e,2),1)??"Nothing";t.push(["Power",i,r])}else{const r=A(b(e,2))??NaN;-1===r?t.push(b(e,1)??"Nothing"):r<0?t.push(["Power",b(e,1)??"Nothing",-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+=M(i,C(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:L("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","Nothing",i]:["Sqrt","Nothing"]: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 U(e,i);if("LatexTokens"===t)return j(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=W(y(b(e,1)));if(i)return`${r??""}\\texttt{\\textcolor{red}{${i}}}`}}return r??""}},{name:"FromLatex",serialize:(e,i)=>`\\texttt{${W(y(b(i,1)))}}`},{name:"LatexForm",serialize:U},{name:"LatexTokens",serialize:j},{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:(B=20,(e,i,t)=>{if(i.minPrec>=B)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:B});r.push(t??"Nothing"),n=null===t}n||(e.skipSpace(),n=!e.match(","))}return r}),serialize:T()},{trigger:[";"],kind:"infix",precedence:19,parse:function(e){return(i,t,r)=>{if(t.minPrec>=e)return null;"Missing"===r&&(r="Nothing");const n=["Sequence",..._(r)??["Sequence",r]];for(;;){for(i.skipSpace();i.match(",");)n.push("Nothing"),i.skipSpace();if(i.atEnd){n.push("Nothing");break}const r=i.matchExpression({...t,minPrec:e});if(null===r){n.push("Nothing");break}if(n.push(..._(r)??["Sequence",r]),i.skipSpace(),!i.match(","))break}return n}}(19)},{name:"String",trigger:["\\text"],parse:e=>G(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}"}}];var B;function G(e,i){if(!e.match("<{>"))return"Nothing";const t=[];let r="",n=null;for(;!e.atEnd&&!e.match("<}>");)if("<{>"===e.peek)t.push(G(e));else if(e.match("\\textbf")&&e.match("<{>"))t.push(G(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 j(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 U(e,i){return null===i?"":s(P(i,(i=>y(i)??e.serialize(i))))}function W(e){return null===e?"":e.replace(/[{}\[\]\\:\-\$%]/g,(e=>({"{":"\\lbrace ","}":"\\rbrace ","[":"\\lbrack ","]":"\\rbrack ",":":"\\colon ","\\":"\\backslash "}[e]??"\\"+e)))}const V=[{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=_(r);if(n&&(r=["List",...n]),!r||!t)return null;let s=e.matchRequiredLatexArgument()??"Nothing";if("Nothing"!==s){s=[s,...e.matchArguments("group")??"Nothing"]}return["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 H(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 K=[{name:"Arcsin",trigger:["\\arcsin"],arguments:"implicit",parse:H("Arcsin")},{name:"Arccos",trigger:["\\arccos"],arguments:"implicit",parse:H("Arccos")},{name:"Arctan",trigger:["\\arctan"],arguments:"implicit",parse:H("Arctan")},{trigger:["\\arctg"],arguments:"implicit",parse:H("Arctan")},{name:"Arccot",trigger:["\\arcctg"],arguments:"implicit",parse:H("Arccot")},{name:"Arcsec",trigger:["\\arcsec"],arguments:"implicit",parse:H("Arcsec")},{name:"Arccsc",trigger:["\\arccsc"],arguments:"implicit",parse:H("Arccsc")},{name:"Arsinh",trigger:["\\arsinh"],arguments:"implicit",parse:H("Arsinh")},{name:"Arcosh",trigger:["\\arcosh"],arguments:"implicit",parse:H("Arcosh")},{name:"Artanh",trigger:["\\artanh"],arguments:"implicit",parse:H("Artanh")},{name:"Arsech",trigger:["\\arsech"],arguments:"implicit",parse:H("Arsech")},{name:"Arcsch",trigger:["\\arcsch"],arguments:"implicit",parse:H("Arcsch")},{trigger:["\\ch"],arguments:"implicit",parse:H("Cosh")},{name:"Cosec",trigger:["\\cosec"],arguments:"implicit",parse:H("Cosec")},{name:"Cosh",trigger:["\\cosh"],arguments:"implicit",parse:H("Cosh")},{name:"Cot",trigger:["\\cot"],arguments:"implicit",parse:H("Cot")},{trigger:["\\cotg"],arguments:"implicit",parse:H("Cot")},{name:"Coth",trigger:["\\coth"],arguments:"implicit",parse:H("Coth")},{name:"Csc",trigger:["\\csc"],arguments:"implicit",parse:H("Csc")},{trigger:["\\ctg"],arguments:"implicit",parse:H("Cot")},{trigger:["\\cth"],arguments:"implicit",parse:H("Cotanh")},{name:"Sec",trigger:["\\sec"],arguments:"implicit",parse:H("Sec")},{name:"Sinh",trigger:["\\sinh"],arguments:"implicit",parse:H("Sinh")},{trigger:["\\sh"],arguments:"implicit",parse:H("Sinh")},{name:"Tan",trigger:["\\tan"],arguments:"implicit",parse:H("Tan")},{trigger:["\\tg"],arguments:"implicit",parse:H("Tan")},{name:"Tanh",trigger:["\\tanh"],arguments:"implicit",parse:H("Tanh")},{trigger:["\\th"],arguments:"implicit",parse:H("Tanh")},{name:"Cos",trigger:["\\cos"],arguments:"implicit",parse:H("Cos")},{name:"Sin",trigger:["\\sin"],arguments:"implicit",parse:H("Sin")}],Q=[{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:X},{name:"Multiple",serialize:X},{name:"Union",trigger:["\\cup"],kind:"infix",precedence:350},{name:"Range",serialize:X},{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 X(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 J=[{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""}}],Y=[["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]],ee=[...Y.map((([e,i,t])=>({name:e,trigger:[i],parse:e}))),...Y.map((([e,i,t])=>({trigger:[String.fromCodePoint(t)],parse:e})))],ie={"(":"(",")":")","[":"\\lbrack","]":"\\rbrack","{":"\\lbrace","}":"\\rbrace","<":"\\langle",">":"\\rangle","|":"\\vert","||":"\\Vert","\\lceil":"\\lceil","\\lfloor":"\\lfloor","\\rceil":"\\rceil","\\rfloor":"\\rfloor"};function te(e){return Array.isArray(e)?e.length:1}function re(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;if(!o(e)&&(void 0!==e.optionalLatexArg||void 0!==e.requiredLatexArg))return i({severity:"warning",message:["invalid-dictionary-entry",t,'Unexpected "optionalLatexArg" or "requiredLatexArg" for non-symbol']}),!1;if(!l(e)&&!e.trigger&&!e.name)return i({severity:"warning",message:["invalid-dictionary-entry",t,"Expected at least a 'trigger' or a 'name'"]}),!1;if(void 0===e.parse&&void 0===e.name)return i({severity:"warning",message:["invalid-dictionary-entry",t,"Expected a 'parse' or 'name'"]}),!1;return!0}(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?ie[t.openDelimiter]:a(t.openDelimiter),i="string"==typeof t.closeDelimiter?ie[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"]:L(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 ne={algebra:[{name:"To",trigger:["\\to"],kind:"infix",precedence:270}],arithmetic:O,calculus:J,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:V,physics:[{name:"mu-0",trigger:"\\mu_0"}],sets:Q,symbols:ee,trigonometry:K},se={"(":["\\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"]},ae={":":[":","\\colon"],"|":["|","\\|","\\mid","\\mvert"]},oe={"\\left":"\\right","\\bigl":"\\bigr","\\Bigl":"\\Bigr","\\biggl":"\\biggr","\\Biggl":"\\Biggr","\\big":"\\big","\\Big":"\\Big","\\bigg":"\\bigg","\\Bigg":"\\Bigg"},le=["\\middle","\\bigm","\\Bigm","\\biggm","\\Biggm","\\big","\\Big","\\bigg","\\Bigg"],ce={"(":")","[":"]","\\{":"\\}","\\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"},ge={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]},ue={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 pe{constructor(e,i,t,r,n){this.index=0,this._lastPeek="",this._peekCounter=0,this.options={...ge,...ue,...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 pe(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)}}this.index=e;return 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=oe[this.peek];r&&this.next();const n=se[e]??[e],s=r?[r]:[];return n.includes("||")&&this.matchAll(["|","|"])?(s.push("|"),s.push("|"),s):n.includes(this.peek)?(ce[e]===i?s.push(ce[this.peek]):s.push(i),this.next(),s):(this.index=t,null)}matchMiddleDelimiter(e){const i=ae[e]??[e];if(le.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)}if(/^[0-9]$/.test(this.peek))return parseInt(this.next());if(/^[^\\#]$/.test(this.peek))return this.next();const i=this.matchSymbol();return i||(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??"Nothing")}else this.match("^")&&t.push(this.matchRequiredLatexArgument()??"Nothing");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){if(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?L("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","Nothing",{str:"syntax-error"},["LatexForm",{str:e}]]:["Error","Nothing",{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","Nothing",{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);if(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 he(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 me(e,i){return e?i.beginExponentMarker?i.beginExponentMarker+e+(i.endExponentMarker??""):"10^{"+e+"}":""}function fe(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=he(n.toExponential(),i));let o="";0!==r&&(o=me(r.toString(),i));return(e<0?"-":"")+s+o}(t,i):function(e,i){let t,r=e.match(/^(.*)[e|E]([-+]?[0-9]+)$/i);r?.[1]&&r[2]&&(t=me(r[2],i));let n=r?.[1]??e,s="";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=he(s,i));s&&(s=i.decimalMarker+s);return t?"1"!==n||s?n+s+i.exponentProduct+t:t:n+s}(t.toString(),i);/[0-9][nd]$/.test(t)&&(t=t.slice(0,-1));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+=he(t.substring(n.length),i);else if(e+1>=i.precision)n="0",r="";else{n=t[e];const r=he(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+me(""+(1-e),i))),t=n}else{t=s.replace(/\B(?=(\d{3})+(?!\d))/g,i.groupSeparator);const e=he(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=he(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+me(""+(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=me(n,i);return"1"===t&&s?r+s:(s&&(t=t+i.exponentProduct+s),r+t)}class de{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):ke(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?`${ke(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)}if("function"==typeof i.serialize)return i.serialize(this,e);return"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=fe(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)]}]),xe(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)]}]),xe(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=xe(t.serialize,[r,e.wrap(n,t.precedence)]))}}return r}(this,e,i)),t||"matchfix"!==i.kind||(t=function(e,i,t){return xe(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 xe(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 ye=["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 ke(e,i="italic."){if(null===e)return null;const t=e.match(/^(_+)(.*)/);if(t)return`\\text{${"\\_".repeat(t[1].length)+ve(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=ve(e);if(1===n.length&&!r)return n;r||(r=i);return({"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)}function ve(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('"')?`${ve(t)}_\\mathrm{${ve(r.substring(1,-1))}}`:`${ve(t)}_{${ve(r)}}`:ke(t)+"\\_"}const t=e.match(/([^0-9]+?)([0-9]+)$/);return t?0===t[1].length?e:`${ve(t[1])}_{${t[2]}}`:ye.includes(e)?"\\"+e:e=e.replace(/[{}\[\]\\:\-\$%]/g,(e=>({"{":"\\lbrace ","}":"\\rbrace ","[":"\\lbrack ","]":"\\rbrack ",":":"\\colon ","\\":"\\backslash ","-":'\\unicode{"2013}'}[e]??"\\"+e)))}const be={invisibleMultiply:"",invisiblePlus:"",multiply:"\\times",missingSymbol:"\\placeholder{}",applyFunctionStyle:function(e,i){return"paren"},groupStyle:function(e,i){return"paren"},rootStyle:C,fractionStyle:$,logicStyle:function(e,i){return"boolean"},powerStyle:function(e,i){return"solidus"},numericSetStyle:function(e,i){return"compact"}};class Se{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={...ge,...be,...ue,...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]=re(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=te(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??Se.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(ne))ne[i]&&(e=[...e,...ne[i]]);return e}return ne[e]?[...ne[e]]:[]}parse(e){const i=new pe(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 de(this.options,this.dictionary,this.computeEngine,this.onError)),this._serializer}}const Ne="0.4.3";export{Se as LatexSyntax,z as applyRecursively,w 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,Ne as version};
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};