@cortex-js/compute-engine 0.32.0 → 0.32.1

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 (153) hide show
  1. package/dist/compute-engine.esm.js +42905 -0
  2. package/dist/compute-engine.min.esm.js +125 -0
  3. package/dist/compute-engine.min.umd.js +127 -0
  4. package/dist/compute-engine.umd.js +42930 -0
  5. package/dist/math-json.esm.js +130 -0
  6. package/dist/math-json.min.esm.js +130 -0
  7. package/dist/math-json.min.umd.js +4 -0
  8. package/dist/math-json.umd.js +155 -0
  9. package/dist/types/common/ansi-codes.d.ts +41 -0
  10. package/dist/types/common/configuration-change.d.ts +28 -0
  11. package/dist/types/common/fuzzy-string-match.d.ts +2 -0
  12. package/dist/types/common/grapheme-splitter.d.ts +15 -0
  13. package/dist/types/common/interruptible.d.ts +20 -0
  14. package/dist/types/common/one-of.d.ts +10 -0
  15. package/dist/types/common/signals.d.ts +96 -0
  16. package/dist/types/common/type/ast-nodes.d.ts +146 -0
  17. package/dist/types/common/type/boxed-type.d.ts +30 -0
  18. package/dist/types/common/type/lexer.d.ts +51 -0
  19. package/dist/types/common/type/parse.d.ts +211 -0
  20. package/dist/types/common/type/parser.d.ts +45 -0
  21. package/dist/types/common/type/primitive.d.ts +10 -0
  22. package/dist/types/common/type/serialize.d.ts +2 -0
  23. package/dist/types/common/type/subtype.d.ts +6 -0
  24. package/dist/types/common/type/type-builder.d.ts +32 -0
  25. package/dist/types/common/type/types.d.ts +300 -0
  26. package/dist/types/common/type/utils.d.ts +36 -0
  27. package/dist/types/common/utils.d.ts +23 -0
  28. package/dist/types/compute-engine/assume.d.ts +26 -0
  29. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +165 -0
  30. package/dist/types/compute-engine/boxed-expression/apply.d.ts +5 -0
  31. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +16 -0
  32. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +27 -0
  33. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +38 -0
  34. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +11 -0
  35. package/dist/types/compute-engine/boxed-expression/box.d.ts +47 -0
  36. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +44 -0
  37. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +136 -0
  38. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +103 -0
  39. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +53 -0
  40. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +107 -0
  41. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +27 -0
  42. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +170 -0
  43. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +83 -0
  44. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +46 -0
  45. package/dist/types/compute-engine/boxed-expression/cache.d.ts +7 -0
  46. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +5 -0
  47. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +2 -0
  48. package/dist/types/compute-engine/boxed-expression/compare.d.ts +13 -0
  49. package/dist/types/compute-engine/boxed-expression/expand.d.ts +20 -0
  50. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +12 -0
  51. package/dist/types/compute-engine/boxed-expression/factor.d.ts +10 -0
  52. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +25 -0
  53. package/dist/types/compute-engine/boxed-expression/hold.d.ts +10 -0
  54. package/dist/types/compute-engine/boxed-expression/match.d.ts +41 -0
  55. package/dist/types/compute-engine/boxed-expression/negate.d.ts +11 -0
  56. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +34 -0
  57. package/dist/types/compute-engine/boxed-expression/order.d.ts +71 -0
  58. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +105 -0
  59. package/dist/types/compute-engine/boxed-expression/product.d.ts +66 -0
  60. package/dist/types/compute-engine/boxed-expression/rules.d.ts +129 -0
  61. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +3 -0
  62. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +46 -0
  63. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +6 -0
  64. package/dist/types/compute-engine/boxed-expression/solve.d.ts +20 -0
  65. package/dist/types/compute-engine/boxed-expression/terms.d.ts +10 -0
  66. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +9 -0
  67. package/dist/types/compute-engine/boxed-expression/utils.d.ts +64 -0
  68. package/dist/types/compute-engine/boxed-expression/validate.d.ts +58 -0
  69. package/dist/types/compute-engine/collection-utils.d.ts +35 -0
  70. package/dist/types/compute-engine/compilation/base-compiler.d.ts +31 -0
  71. package/dist/types/compute-engine/compilation/javascript-target.d.ts +68 -0
  72. package/dist/types/compute-engine/compilation/types.d.ts +83 -0
  73. package/dist/types/compute-engine/cost-function.d.ts +13 -0
  74. package/dist/types/compute-engine/function-utils.d.ts +120 -0
  75. package/dist/types/compute-engine/global-types.d.ts +2930 -0
  76. package/dist/types/compute-engine/index.d.ts +660 -0
  77. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +2 -0
  78. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +2 -0
  79. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +2 -0
  80. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +2 -0
  81. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +27 -0
  82. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +2 -0
  83. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +2 -0
  84. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +2 -0
  85. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +2 -0
  86. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +2 -0
  87. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +2 -0
  88. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +3 -0
  89. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +2 -0
  90. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +88 -0
  91. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +21 -0
  92. package/dist/types/compute-engine/latex-syntax/parse.d.ts +316 -0
  93. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +29 -0
  94. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +10 -0
  95. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +37 -0
  96. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +18 -0
  97. package/dist/types/compute-engine/latex-syntax/types.d.ts +896 -0
  98. package/dist/types/compute-engine/latex-syntax/utils.d.ts +5 -0
  99. package/dist/types/compute-engine/library/arithmetic.d.ts +4 -0
  100. package/dist/types/compute-engine/library/calculus.d.ts +2 -0
  101. package/dist/types/compute-engine/library/collections.d.ts +27 -0
  102. package/dist/types/compute-engine/library/combinatorics.d.ts +2 -0
  103. package/dist/types/compute-engine/library/complex.d.ts +2 -0
  104. package/dist/types/compute-engine/library/control-structures.d.ts +2 -0
  105. package/dist/types/compute-engine/library/core.d.ts +2 -0
  106. package/dist/types/compute-engine/library/invisible-operator.d.ts +4 -0
  107. package/dist/types/compute-engine/library/library.d.ts +17 -0
  108. package/dist/types/compute-engine/library/linear-algebra.d.ts +2 -0
  109. package/dist/types/compute-engine/library/logic-analysis.d.ts +64 -0
  110. package/dist/types/compute-engine/library/logic-utils.d.ts +58 -0
  111. package/dist/types/compute-engine/library/logic.d.ts +7 -0
  112. package/dist/types/compute-engine/library/number-theory.d.ts +2 -0
  113. package/dist/types/compute-engine/library/polynomials.d.ts +2 -0
  114. package/dist/types/compute-engine/library/random-expression.d.ts +2 -0
  115. package/dist/types/compute-engine/library/relational-operator.d.ts +2 -0
  116. package/dist/types/compute-engine/library/sets.d.ts +2 -0
  117. package/dist/types/compute-engine/library/statistics.d.ts +2 -0
  118. package/dist/types/compute-engine/library/trigonometry.d.ts +2 -0
  119. package/dist/types/compute-engine/library/utils.d.ts +77 -0
  120. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +57 -0
  121. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +75 -0
  122. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +56 -0
  123. package/dist/types/compute-engine/numeric-value/types.d.ts +116 -0
  124. package/dist/types/compute-engine/numerics/bigint.d.ts +2 -0
  125. package/dist/types/compute-engine/numerics/expression.d.ts +4 -0
  126. package/dist/types/compute-engine/numerics/interval.d.ts +12 -0
  127. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +4 -0
  128. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +18 -0
  129. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +9 -0
  130. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +3 -0
  131. package/dist/types/compute-engine/numerics/numeric.d.ts +60 -0
  132. package/dist/types/compute-engine/numerics/primes.d.ts +7 -0
  133. package/dist/types/compute-engine/numerics/rationals.d.ts +43 -0
  134. package/dist/types/compute-engine/numerics/richardson.d.ts +80 -0
  135. package/dist/types/compute-engine/numerics/special-functions.d.ts +28 -0
  136. package/dist/types/compute-engine/numerics/statistics.d.ts +24 -0
  137. package/dist/types/compute-engine/numerics/strings.d.ts +2 -0
  138. package/dist/types/compute-engine/numerics/types.d.ts +30 -0
  139. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +3 -0
  140. package/dist/types/compute-engine/symbolic/derivative.d.ts +18 -0
  141. package/dist/types/compute-engine/symbolic/distribute.d.ts +5 -0
  142. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +6 -0
  143. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +27 -0
  144. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +6 -0
  145. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +128 -0
  146. package/dist/types/compute-engine/tensor/tensors.d.ts +93 -0
  147. package/dist/types/compute-engine/types.d.ts +8 -0
  148. package/dist/types/compute-engine.d.ts +3 -0
  149. package/dist/types/math-json/symbols.d.ts +11 -0
  150. package/dist/types/math-json/types.d.ts +122 -0
  151. package/dist/types/math-json/utils.d.ts +87 -0
  152. package/dist/types/math-json.d.ts +3 -0
  153. package/package.json +1 -1
@@ -0,0 +1,896 @@
1
+ /* 0.32.1 */
2
+ import type { Expression, MathJsonSymbol } from '../../math-json/types';
3
+ import { BoxedType, TypeString } from '../types';
4
+ import type { IndexedLatexDictionary, IndexedLatexDictionaryEntry } from './dictionary/definitions';
5
+ export type SymbolTable = {
6
+ parent: SymbolTable | null;
7
+ ids: {
8
+ [id: MathJsonSymbol]: BoxedType;
9
+ };
10
+ };
11
+ /**
12
+ * A `LatexToken` is a token as returned by `Parser.peek`.
13
+ *
14
+ * It can be one of the indicated tokens, or a string that starts with a
15
+ * `\` for LaTeX commands, or a LaTeX character which includes digits,
16
+ * letters and punctuation.
17
+ *
18
+ * @category Latex Parsing and Serialization
19
+ */
20
+ export type LatexToken = string | '<{>' | '<}>' | '<space>' | '<$>' | '<$$>';
21
+ /** A LatexString is a regular string of LaTeX, for example:
22
+ * `\frac{\pi}{2}`
23
+ *
24
+ * @category Latex Parsing and Serialization
25
+ */
26
+ export type LatexString = string;
27
+ /**
28
+ * Open and close delimiters that can be used with {@linkcode MatchfixEntry}
29
+ * record to define new LaTeX dictionary entries.
30
+ *
31
+ * @category Latex Parsing and Serialization
32
+ */
33
+ export type Delimiter = '.' | ')' | '(' | ']' | '[' | '{' /** \lbrace */ | '}' /** \rbrace */ | '<' /** \langle */ | '>' /** \rangle */ | '|' | '||' | '\\lceil' | '\\rceil' | '\\lfloor' | '\\rfloor' | '\\llbracket' | '\\rrbracket';
34
+ /** @category Latex Parsing and Serialization */
35
+ export type DelimiterScale = 'normal' | 'scaled' | 'big' | 'none';
36
+ /**
37
+ * @category Latex Parsing and Serialization
38
+ */
39
+ export type LibraryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'collections' | 'control-structures' | 'combinatorics' | 'complex' | 'core' | 'data-structures' | 'dimensions' | 'domains' | 'linear-algebra' | 'logic' | 'number-theory' | 'numeric' | 'other' | 'physics' | 'polynomials' | 'relop' | 'sets' | 'statistics' | 'styling' | 'symbols' | 'trigonometry' | 'units';
40
+ /**
41
+ *
42
+ * :::info[THEORY OF OPERATIONS]
43
+ *
44
+ * The precedence of an operator is a number that indicates the order in which
45
+ * operators are applied.
46
+ *
47
+ * For example, in `1 + 2 * 3`, the `*` operator has a **higher** precedence
48
+ * than the `+` operator, so it is applied first.
49
+ *
50
+ * The precedence ranges from 0 to 1000. The larger the number, the higher the
51
+ * precedence, the more "binding" the operator is.
52
+ *
53
+ * ## Operator Precedence Table
54
+ *
55
+ * | Precedence | Operators | Description |
56
+ * |------------|-----------|-------------|
57
+ * | **880** | `\lnot` `\neg` `++` `--` `+` `-` (prefix) | Prefix/postfix unary |
58
+ * | **810** | `!` `'` `!!` `'''` | Factorial, prime (postfix) |
59
+ * | **800** | `_` (subscript) | Subscript |
60
+ * | **780** | `\degree` `\prime` | Degree, prime symbols |
61
+ * | **740** | `\%` | Percent |
62
+ * | **720** | `\/` (inline division) | Inline division |
63
+ * | **700** | `^` `\overset` `\underset` | Exponentiation, over/underscript |
64
+ * | **650** | (invisible multiply) `\cdot` | Implicit multiplication |
65
+ * | **600** | `\div` `\frac` | Division |
66
+ * | **390** | `\times` `*` `/` | Multiplication |
67
+ * | **350** | `\cup` `\cap` | Set union/intersection |
68
+ * | **275** | `+` `-` (infix) | Addition, subtraction |
69
+ * | **270** | `\to` `\rightarrow` `\mapsto` | Arrows |
70
+ * | **265** | `\setminus` `\smallsetminus` `:` (range) | Set difference, range |
71
+ * | **260** | `:=` | Assignment |
72
+ * | **255** | `\ne` | Not equal |
73
+ * | **250** | `\not\approxeq` | Not approximately equal |
74
+ * | **247** | `\approx` | Approximately |
75
+ * | **245-246** | `=` `<` `>` `\lt` `\gt` `\nless` `\ngtr` | Equality, comparison |
76
+ * | **241-244** | `\le` `\leq` `\ge` `\geq` `>=` | Less/greater or equal |
77
+ * | **240** | `\in` `\notin` `\subset` `\supset` ... | Set membership/relations |
78
+ * | **235** | `\land` `\wedge` `\&` | Logical AND |
79
+ * | **232** | `\veebar` `\barwedge` (Xor, Nand, Nor) | Logical XOR, NAND, NOR |
80
+ * | **230** | `\lor` `\vee` `\parallel` | Logical OR |
81
+ * | **220** | `\implies` `\Rightarrow` `\vdash` `\models` | Implication, entailment |
82
+ * | **219** | `\iff` `\Leftrightarrow` `\equiv` | Equivalence |
83
+ * | **200** | `\forall` `\exists` `\exists!` | Quantifiers |
84
+ * | **160** | `\mid` `\vert` (set builder) | Set builder notation |
85
+ * | **19-20** | `,` `;` `\ldots` | Sequence separators |
86
+ *
87
+ * ## Key Relationships
88
+ *
89
+ * - **Comparisons bind tighter than logic**: `x = 1 \lor y = 2` parses as
90
+ * `(x = 1) \lor (y = 2)`, not `x = (1 \lor y) = 2`
91
+ * - **AND binds tighter than OR**: `a \land b \lor c` parses as
92
+ * `(a \land b) \lor c`
93
+ * - **Logic operators bind tighter than implication**: `a \lor b \implies c`
94
+ * parses as `(a \lor b) \implies c`
95
+ *
96
+ * Some constants are defined below for common precedence values.
97
+ *
98
+ * **Note**: MathML defines
99
+ * [some operator precedence](https://www.w3.org/TR/2009/WD-MathML3-20090924/appendixc.html),
100
+ * but it has some issues and inconsistencies. However,
101
+ * whenever possible we adopted the MathML precedence.
102
+ *
103
+ * The JavaScript operator precedence is documented
104
+ * [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence).
105
+ *
106
+ * :::
107
+ *
108
+ * @category Latex Parsing and Serialization
109
+ */
110
+ export type Precedence = number;
111
+ /** @hidden */
112
+ export declare const COMPARISON_PRECEDENCE: Precedence;
113
+ /** @hidden */
114
+ export declare const ASSIGNMENT_PRECEDENCE: Precedence;
115
+ /** @hidden */
116
+ export declare const ARROW_PRECEDENCE: Precedence;
117
+ /** @hidden */
118
+ export declare const ADDITION_PRECEDENCE: Precedence;
119
+ /** @hidden */
120
+ export declare const MULTIPLICATION_PRECEDENCE: Precedence;
121
+ /** @hidden */
122
+ export declare const DIVISION_PRECEDENCE: Precedence;
123
+ /** @hidden */
124
+ export declare const INVISIBLE_OP_PRECEDENCE: Precedence;
125
+ /** @hidden */
126
+ export declare const EXPONENTIATION_PRECEDENCE: Precedence;
127
+ /** @hidden */
128
+ export declare const POSTFIX_PRECEDENCE: Precedence;
129
+ /**
130
+ * This indicates a condition under which parsing should stop:
131
+ * - an operator of a precedence higher than specified has been encountered
132
+ * - the last token has been reached
133
+ * - or if a condition is provided, the condition returns true
134
+ *
135
+ * @category Latex Parsing and Serialization
136
+ */
137
+ export type Terminator = {
138
+ minPrec: Precedence;
139
+ condition?: (parser: Parser) => boolean;
140
+ };
141
+ /**
142
+ * **Custom parsing handler.**
143
+ *
144
+ * When this handler is invoked the parser points right after the LaTeX
145
+ * fragment that triggered it.
146
+ *
147
+ * Tokens can be consumed with `parser.nextToken()` and other parser methods
148
+ * such as `parser.parseGroup()`, `parser.parseOptionalGroup()`, etc...
149
+ *
150
+ * If it was in an infix or postfix context, `lhs` will represent the
151
+ * left-hand side argument. In a prefix or matchfix context, `lhs` is `null`.
152
+ *
153
+ * In a superfix (`^`) or subfix (`_`) context (that is if the first token of
154
+ * the trigger is `^` or `_`), `lhs` is `["Superscript", lhs, rhs]`
155
+ * and `["Subscript", lhs, rhs]`, respectively.
156
+ *
157
+ * The handler should return `null` if the tokens could not be parsed
158
+ * (didn't match the syntax that was expected), or the matching expression
159
+ * otherwise.
160
+ *
161
+ * If the tokens were parsed but should be ignored, the handler should
162
+ * return `Nothing`.
163
+ *
164
+ * @category Latex Parsing and Serialization
165
+ */
166
+ export type ParseHandler = ExpressionParseHandler | SymbolParseHandler | FunctionParseHandler | EnvironmentParseHandler | PostfixParseHandler | InfixParseHandler | MatchfixParseHandler;
167
+ /**
168
+ * @category Latex Parsing and Serialization
169
+ */
170
+ export type ExpressionParseHandler = (parser: Parser, until?: Readonly<Terminator>) => Expression | null;
171
+ /**
172
+ * @category Latex Parsing and Serialization
173
+ */
174
+ export type PrefixParseHandler = (parser: Parser, until?: Readonly<Terminator>) => Expression | null;
175
+ /**
176
+ * @category Latex Parsing and Serialization
177
+ */
178
+ export type SymbolParseHandler = (parser: Parser, until?: Readonly<Terminator>) => Expression | null;
179
+ /**
180
+ * @category Latex Parsing and Serialization
181
+ */
182
+ export type FunctionParseHandler = (parser: Parser, until?: Readonly<Terminator>) => Expression | null;
183
+ /**
184
+ * @category Latex Parsing and Serialization
185
+ */
186
+ export type EnvironmentParseHandler = (parser: Parser, until?: Readonly<Terminator>) => Expression | null;
187
+ /**
188
+ * @category Latex Parsing and Serialization
189
+ */
190
+ export type PostfixParseHandler = (parser: Parser, lhs: Expression, until?: Readonly<Terminator>) => Expression | null;
191
+ /**
192
+ * @category Latex Parsing and Serialization
193
+ */
194
+ export type InfixParseHandler = (parser: Parser, lhs: Expression, until: Readonly<Terminator>) => Expression | null;
195
+ /**
196
+ * @category Latex Parsing and Serialization
197
+ */
198
+ export type MatchfixParseHandler = (parser: Parser, body: Expression) => Expression | null;
199
+ /**
200
+ * @category Latex Parsing and Serialization
201
+ */
202
+ export type LatexArgumentType = '{expression}' /** A required math mode expression */ | '[expression]' /** An optional math mode expression */ | '{text}' /** A required expression in text mode */ | '[text]' /** An optional expression in text mode */ | '{unit}' /** A required unit expression, e.g. `3em` */ | '[unit]' /** An optional unit expression, e.g. `3em` */ | '{glue}' /** A required glue expression, e.g. `25 mu plus 3em ` */ | '[glue]' /** An optional glue expression, e.g. `25 mu plus 3em ` */ | '{string}' /** A required text string, terminated by a non-literal token */ | '[string]' /** An optional text string, terminated by a non-literal token */ | '{color}' /** A required color expression, e.g. `red` or `#00ff00` */ | '[color]'; /** An optional color expression, e.g. `red` or `#00ff00` */
203
+ /**
204
+ * A trigger is the set of tokens that will make an entry in the
205
+ * LaTeX dictionary eligible to parse the stream and generate an expression.
206
+ * If the trigger matches, the `parse` handler is called, if available.
207
+ *
208
+ * The trigger can be specified either as a LaTeX string (`latexTrigger`) or
209
+ * as an symbol (`symbolTrigger`). A symbol match several
210
+ * LaTeX expressions that are equivalent, for example `\operatorname{gcd}` or
211
+ * `\mathbin{gcd}`, match the `"gcd"` symbol
212
+ *
213
+ * `matchfix` operators use `openTrigger` and `closeTrigger` instead.
214
+ *
215
+ * @category Latex Parsing and Serialization
216
+ */
217
+ export type Trigger = {
218
+ latexTrigger?: LatexString | LatexToken[];
219
+ symbolTrigger?: MathJsonSymbol;
220
+ };
221
+ /**
222
+ * Maps a string of LaTeX tokens to a function or symbol and vice-versa.
223
+ * @category Latex Parsing and Serialization
224
+ */
225
+ export type BaseEntry = {
226
+ /**
227
+ * Map a MathJSON symbol to this entry.
228
+ *
229
+ * Each entry should have at least a `name` or a `parse` handler.
230
+ *
231
+ * An entry with no `name` cannot be serialized: the `name` is used to map
232
+ * a MathJSON function or symbol name to the appropriate entry for
233
+ * serializing.
234
+ *
235
+ * However, an entry with no `name` can be used to define a synonym (for
236
+ * example for the symbol `\varnothing` which is a synonym for `\emptyset`).
237
+ *
238
+ * If no `parse` handler is provided, only the trigger is used to select this
239
+ * entry. Otherwise, if the trigger of the entry matches the current
240
+ * token, the `parse` handler is invoked.
241
+ */
242
+ name?: MathJsonSymbol;
243
+ /**
244
+ * Transform an expression into a LaTeX string.
245
+ * If no `serialize` handler is provided, the trigger is used.
246
+ */
247
+ serialize?: LatexString | SerializeHandler;
248
+ };
249
+ /**
250
+ * @category Latex Parsing and Serialization
251
+ */
252
+ export type DefaultEntry = BaseEntry & Trigger & {
253
+ parse?: Expression | ExpressionParseHandler;
254
+ };
255
+ /**
256
+ * @category Latex Parsing and Serialization
257
+ */
258
+ export type ExpressionEntry = BaseEntry & Trigger & {
259
+ kind: 'expression';
260
+ parse?: Expression | ExpressionParseHandler;
261
+ precedence?: Precedence;
262
+ };
263
+ /**
264
+ * @category Latex Parsing and Serialization
265
+ */
266
+ export type MatchfixEntry = BaseEntry & {
267
+ kind: 'matchfix';
268
+ /**
269
+ * If `kind` is `'matchfix'`: the `openTrigger` and `closeTrigger`
270
+ * properties are required.
271
+ */
272
+ openTrigger: Delimiter | LatexToken[];
273
+ closeTrigger: Delimiter | LatexToken[];
274
+ /** When invoked, the parser is pointing after the close delimiter.
275
+ * The argument of the handler is the body, i.e. the content between
276
+ * the open delimiter and the close delimiter.
277
+ */
278
+ parse?: MatchfixParseHandler;
279
+ };
280
+ /**
281
+ * @category Latex Parsing and Serialization
282
+ */
283
+ export type InfixEntry = BaseEntry & Trigger & {
284
+ /**
285
+ * Infix position, with an operand before and an operand after: `a ⊛ b`.
286
+ *
287
+ * Example: `+`, `\times`.
288
+ */
289
+ kind: 'infix';
290
+ /**
291
+ * - **`none`**: a ? b ? c -> syntax error
292
+ * - **`any`**: a + b + c -> +(a, b, c)
293
+ * - **`left`**: a / b / c -> /(/(a, b), c)
294
+ * - **`right`**: a = b = c -> =(a, =(b, c))
295
+ *
296
+ * - `any`-associative operators have an unlimited number of arguments
297
+ * - `left`, `right` or `none` associative operators have two arguments
298
+ *
299
+ */
300
+ associativity?: 'right' | 'left' | 'none' | 'any';
301
+ precedence?: Precedence;
302
+ parse?: string | InfixParseHandler;
303
+ };
304
+ /**
305
+ * @category Latex Parsing and Serialization
306
+ */
307
+ export type PostfixEntry = BaseEntry & Trigger & {
308
+ /**
309
+ * Postfix position, with an operand before: `a ⊛`
310
+ *
311
+ * Example: `!`.
312
+ */
313
+ kind: 'postfix';
314
+ precedence?: Precedence;
315
+ parse?: string | PostfixParseHandler;
316
+ };
317
+ /**
318
+ * @category Latex Parsing and Serialization
319
+ */
320
+ export type PrefixEntry = BaseEntry & Trigger & {
321
+ /**
322
+ * Prefix position, with an operand after: `⊛ a`
323
+ *
324
+ * Example: `-`, `\not`.
325
+ */
326
+ kind: 'prefix';
327
+ precedence: Precedence;
328
+ parse?: string | PrefixParseHandler;
329
+ };
330
+ /**
331
+ * A LaTeX dictionary entry for an environment, that is a LaTeX
332
+ * construct using `\begin{...}...\end{...}`.
333
+ * @category Latex Parsing and Serialization
334
+ */
335
+ export type EnvironmentEntry = BaseEntry & {
336
+ kind: 'environment';
337
+ parse: EnvironmentParseHandler;
338
+ symbolTrigger: MathJsonSymbol;
339
+ };
340
+ /**
341
+ * @category Latex Parsing and Serialization
342
+ */
343
+ export type SymbolEntry = BaseEntry & Trigger & {
344
+ kind: 'symbol';
345
+ /** Used for appropriate wrapping (i.e. when to surround it with parens) */
346
+ precedence?: Precedence;
347
+ parse: Expression | SymbolParseHandler;
348
+ };
349
+ /**
350
+ * A function is a symbol followed by:
351
+ * - some postfix operators such as `\prime`
352
+ * - an optional list of arguments in an enclosure (parentheses)
353
+ *
354
+ * For more complex situations, for example implicit arguments or
355
+ * inverse functions postfix (i.e. ^{-1}), use a custom parse handler with a
356
+ * entry of kind `expression`.
357
+ * @category Latex Parsing and Serialization
358
+ */
359
+ export type FunctionEntry = BaseEntry & Trigger & {
360
+ kind: 'function';
361
+ parse?: Expression | FunctionParseHandler;
362
+ };
363
+ /**
364
+ *
365
+ * A dictionary entry is a record that maps a LaTeX token or string of tokens
366
+ * ( a trigger) to a MathJSON expression or to a parsing handler.
367
+ *
368
+ * Set the {@linkcode ComputeEngine.latexDictionary} property to an array of
369
+ * dictionary entries to define custom LaTeX parsing and serialization.
370
+ *
371
+ * @category Latex Parsing and Serialization
372
+ *
373
+ */
374
+ export type LatexDictionaryEntry = OneOf<[
375
+ ExpressionEntry | MatchfixEntry | InfixEntry | PostfixEntry | PrefixEntry | SymbolEntry | FunctionEntry | EnvironmentEntry | DefaultEntry
376
+ ]>;
377
+ /** @internal */
378
+ export declare function isExpressionEntry(entry: LatexDictionaryEntry): entry is ExpressionEntry;
379
+ /** @internal */
380
+ export declare function isSymbolEntry(entry: LatexDictionaryEntry): entry is SymbolEntry;
381
+ /** @internal */
382
+ export declare function isFunctionEntry(entry: LatexDictionaryEntry): entry is FunctionEntry;
383
+ /** @internal */
384
+ export declare function isMatchfixEntry(entry: LatexDictionaryEntry): entry is MatchfixEntry;
385
+ /** @internal */
386
+ export declare function isInfixEntry(entry: LatexDictionaryEntry): entry is InfixEntry;
387
+ /** @internal */
388
+ export declare function isPrefixEntry(entry: LatexDictionaryEntry): entry is PrefixEntry;
389
+ /** @internal */
390
+ export declare function isPostfixEntry(entry: LatexDictionaryEntry): entry is PostfixEntry;
391
+ /** @internal */
392
+ export declare function isEnvironmentEntry(entry: LatexDictionaryEntry): entry is EnvironmentEntry;
393
+ /**
394
+ * A LaTeX dictionary is a collection of LaTeX dictionary entries.
395
+ *
396
+ * Each entry in the dictionary indicates how to parse and serialize a
397
+ * particular LaTeX token or string of tokens.
398
+ *
399
+ * @category Latex Parsing and Serialization
400
+ * @internal
401
+ */
402
+ export type LatexDictionary = ReadonlyArray<Partial<LatexDictionaryEntry>>;
403
+ /**
404
+ * These options control how numbers are parsed and serialized.
405
+ * @category Serialization
406
+ */
407
+ export type NumberFormat = {
408
+ positiveInfinity: LatexString;
409
+ negativeInfinity: LatexString;
410
+ notANumber: LatexString;
411
+ imaginaryUnit: LatexString;
412
+ /**
413
+ * A string representing the decimal separator, the string separating
414
+ * the whole portion of a number from the fractional portion, i.e.
415
+ * the "." in "3.1415".
416
+ *
417
+ * Some countries use a comma rather than a dot. In this case it is
418
+ * recommended to use `"{,}"` as the separator: the surrounding brackets
419
+ * ensure there is no additional gap after the comma.
420
+ *
421
+ * **Default**: `"."`
422
+ */
423
+ decimalSeparator: LatexString;
424
+ /**
425
+ * A string representing the separator between groups of digits,
426
+ * to make numbers with many digits easier to read.
427
+ *
428
+ * If a single string is provided, it is used to group digits in the
429
+ * whole and the fractional part of the number. If two strings are provided,
430
+ * the first is used for the whole part and the second for the fractional
431
+ * part.
432
+ *
433
+ * Caution: some values may lead to unexpected results.
434
+ *
435
+ * For example, if the `digitGroupSeparator` is `,` (comma) the expression
436
+ * `\operatorname{Hypot}(1,2)` will parse as `["Hypot", 1.2]` rather than
437
+ * `["Hypot", 1, 2]`. You can however use `{,}` which will avoid this issue
438
+ * and display with correct spacing.
439
+ *
440
+ * **Default**: `"\\,"` (thin space, 3/18mu) (Resolution 7 of the 1948 CGPM)
441
+ */
442
+ digitGroupSeparator: LatexString | [LatexString, LatexString];
443
+ /**
444
+ * Maximum length of digits between digit group separators.
445
+ *
446
+ * If a single number is provided, it is used for the whole and the fractional
447
+ * part of the number. If two numbers are provided, the first is used for the
448
+ * whole part and the second for the fractional part.
449
+ *
450
+ * If '`"lakh"`' is provided, the number is grouped in groups of 2 digits,
451
+ * except for the last group which has 3 digits. For example: `1,00,00,000`.
452
+ *
453
+ *
454
+ * **Default**: `3`
455
+ */
456
+ digitGroup: 'lakh' | number | [number | 'lakh', number];
457
+ exponentProduct: LatexString;
458
+ beginExponentMarker: LatexString;
459
+ endExponentMarker: LatexString;
460
+ truncationMarker: LatexString;
461
+ repeatingDecimal: 'auto' | 'vinculum' | 'dots' | 'parentheses' | 'arc' | 'none';
462
+ };
463
+ /** @category Serialization */
464
+ export type NumberSerializationFormat = NumberFormat & {
465
+ /**
466
+ * The maximum number of significant digits in serialized numbers.
467
+ * - `"max"`: all availabe digits are serialized.
468
+ * - `"auto"`: use the same precision as the compute engine.
469
+ *
470
+ * Default: `"auto"`
471
+ */
472
+ fractionalDigits: 'auto' | 'max' | number;
473
+ notation: 'auto' | 'engineering' | 'scientific' | 'adaptiveScientific';
474
+ avoidExponentsInRange: undefined | null | [negativeExponent: number, positiveExponent: number];
475
+ };
476
+ /**
477
+ *
478
+ * The LaTeX parsing options can be used with the `ce.parse()` method.
479
+ *
480
+ * @category Latex Parsing and Serialization
481
+ */
482
+ export type ParseLatexOptions = NumberFormat & {
483
+ /**
484
+ * If true, ignore space characters in math mode.
485
+ *
486
+ * **Default**: `true`
487
+ *
488
+ */
489
+ skipSpace: boolean;
490
+ /**
491
+ * When parsing a decimal number, e.g. `3.1415`:
492
+ *
493
+ * - `"auto"` or `"decimal"`: if a decimal number, parse it as an approximate
494
+ * decimal number with a whole part and a fractional part
495
+ * - `"rational"`: if a decimal number, parse it as an exact rational number
496
+ * with a numerator and a denominator. If not a decimal number, parse
497
+ * it as a regular number.
498
+ * - `"never"`: do not parse numbers, instead return each token making up
499
+ * the number (minus sign, digits, decimal marker, etc...).
500
+ *
501
+ * Note: if the number includes repeating digits (e.g. `1.33(333)`),
502
+ * it will be parsed as a decimal number even if this setting is `"rational"`.
503
+ *
504
+ * **Default**: `"auto"`
505
+ *
506
+ */
507
+ parseNumbers: 'auto' | 'rational' | 'decimal' | 'never';
508
+ /**
509
+ * This handler is invoked when the parser encounters a
510
+ * that has not yet been declared.
511
+ *
512
+ * The `symbol` argument is a [valid symbol](/math-json/#symbols).
513
+ *
514
+ */
515
+ getSymbolType: (symbol: MathJsonSymbol) => BoxedType;
516
+ /** This handler is invoked when the parser encounters an unexpected token.
517
+ *
518
+ * The `lhs` argument is the left-hand side of the token, if any.
519
+ *
520
+ * The handler can access the unexpected token with `parser.peek`. If
521
+ * it is a token that should be recognized, the handler can consume it
522
+ * by calling `parser.nextToken()`.
523
+ *
524
+ * The handler should return an expression or `null` if the token is not
525
+ * recognized.
526
+ */
527
+ parseUnexpectedToken: (lhs: Expression | null, parser: Parser) => Expression | null;
528
+ /**
529
+ * If true, the expression will be decorated with the LaTeX
530
+ * fragments corresponding to each elements of the expression.
531
+ *
532
+ * The top-level expression, that is the one returned by `parse()`, will
533
+ * include the verbatim LaTeX input that was parsed. The sub-expressions
534
+ * may contain a slightly different LaTeX, for example with consecutive spaces
535
+ * replaced by one, with comments removed and with some low-level LaTeX
536
+ * commands replaced, for example `\egroup` and `\bgroup`.
537
+ *
538
+ * **Default:** `false`
539
+ */
540
+ preserveLatex: boolean;
541
+ /**
542
+ * Controls how quantifier scope is determined when parsing expressions
543
+ * like `\forall x. P(x) \rightarrow Q(x)`.
544
+ *
545
+ * - `"tight"`: The quantifier binds only to the immediately following
546
+ * well-formed formula, stopping at logical connectives (`\rightarrow`,
547
+ * `\implies`, `\land`, `\lor`, etc.). This follows standard First-Order
548
+ * Logic conventions. Use explicit parentheses for wider scope:
549
+ * `\forall x. (P(x) \rightarrow Q(x))`.
550
+ *
551
+ * - `"loose"`: The quantifier scope extends to the end of the expression
552
+ * or until a lower-precedence operator is encountered.
553
+ *
554
+ * **Default:** `"tight"`
555
+ *
556
+ * @example
557
+ * // With "tight" (default):
558
+ * // \forall x. P(x) \rightarrow Q(x)
559
+ * // parses as: (∀x. P(x)) → Q(x)
560
+ *
561
+ * // With "loose":
562
+ * // \forall x. P(x) \rightarrow Q(x)
563
+ * // parses as: ∀x. (P(x) → Q(x))
564
+ */
565
+ quantifierScope: 'tight' | 'loose';
566
+ };
567
+ /**
568
+ *
569
+ * The expected format of numbers in the LaTeX string can be specified with
570
+ * the `ce.parse()` method.
571
+ *
572
+ * @category Latex Parsing and Serialization
573
+ */
574
+ /**
575
+ * An instance of `Parser` is provided to the `parse` handlers of custom
576
+ * LaTeX dictionary entries.
577
+ *
578
+ * @category Latex Parsing and Serialization
579
+ */
580
+ export interface Parser {
581
+ readonly options: Required<ParseLatexOptions>;
582
+ getSymbolType(id: MathJsonSymbol): BoxedType;
583
+ pushSymbolTable(): void;
584
+ popSymbolTable(): void;
585
+ addSymbol(id: MathJsonSymbol, type: BoxedType | TypeString): void;
586
+ /** True if currently parsing inside a quantifier body (ForAll, Exists, etc.) */
587
+ readonly inQuantifierScope: boolean;
588
+ /** Enter a quantifier scope for parsing the body of ForAll, Exists, etc. */
589
+ enterQuantifierScope(): void;
590
+ /** Exit the current quantifier scope */
591
+ exitQuantifierScope(): void;
592
+ /** The index of the current token */
593
+ index: number;
594
+ /** True if the last token has been reached.
595
+ * Consider also `atTerminator()`.
596
+ */
597
+ readonly atEnd: boolean;
598
+ /** Return true if the terminator condition is met or if the last token
599
+ * has been reached.
600
+ */
601
+ atTerminator(t: Terminator | undefined): boolean;
602
+ /** Return the next token, without advancing the index */
603
+ readonly peek: LatexToken;
604
+ /** Return the next token and advance the index */
605
+ nextToken(): LatexToken;
606
+ /** Return a string representation of the expression
607
+ * between `start` and `end` (default: the whole expression)
608
+ *
609
+ *
610
+ */
611
+ latex(start: number, end?: number): string;
612
+ /** Return an error expression with the specified code and arguments */
613
+ error(code: string | [string, ...Expression[]], fromToken: number): Expression;
614
+ /** If there are any space, advance the index until a non-space is encountered */
615
+ skipSpace(): boolean;
616
+ /** Skip over "visual space" which
617
+ includes space tokens, empty groups `{}`, and commands such as `\,` and `\!` */
618
+ skipVisualSpace(): void;
619
+ /** If the next token matches the target advance and return true. Otherwise
620
+ * return false
621
+ */
622
+ match(token: LatexToken): boolean;
623
+ /** Return true if the next tokens match the argument, an array of tokens, or null otherwise
624
+ */
625
+ matchAll(tokens: LatexToken[]): boolean;
626
+ /** Return the next token if it matches any of the token in the argument or null otherwise
627
+ */
628
+ matchAny(tokens: LatexToken[]): LatexToken;
629
+ /** If the next token is a character, return it and advance the index
630
+ * This includes plain characters (e.g. 'a', '+'...), characters
631
+ * defined in hex (^^ and ^^^^), the `\char` and `\unicode` command.
632
+ */
633
+ parseChar(): string | null;
634
+ /**
635
+ * Parse an expression in a LaTeX group enclosed in curly brackets `{}`.
636
+ * These are often used as arguments to LaTeX commands, for example
637
+ * `\frac{1}{2}`.
638
+ *
639
+ * Return `null` if none was found
640
+ * Return `Nothing` if an empty group `{}` was found
641
+ */
642
+ parseGroup(): Expression | null;
643
+ /**
644
+ * Some LaTeX commands (but not all) can accept arguments as single
645
+ * tokens (i.e. without braces), for example `^2`, `\sqrt3` or `\frac12`
646
+ *
647
+ * This argument will usually be a single token, but can be a sequence of
648
+ * tokens (e.g. `\sqrt\frac12` or `\sqrt\operatorname{speed}`).
649
+ *
650
+ * The following tokens are excluded from consideration in order to fail
651
+ * early when encountering a likely syntax error, for example `x^(2)`
652
+ * instead of `x^{2}`. With `(` in the list of excluded tokens, the
653
+ * match will fail and the error can be recovered.
654
+ *
655
+ * The excluded tokens include `!"#$%&(),/;:?@[]`|~", `\left`, `\bigl`, etc...
656
+ */
657
+ parseToken(): Expression | null;
658
+ /**
659
+ * Parse an expression enclosed in a LaTeX optional group enclosed in square brackets `[]`.
660
+ *
661
+ * Return `null` if none was found.
662
+ */
663
+ parseOptionalGroup(): Expression | null;
664
+ /** Parse an enclosure (open paren/close paren, etc..) and return the expression inside the enclosure */
665
+ parseEnclosure(): Expression | null;
666
+ /**
667
+ * Some LaTeX commands have arguments that are not interpreted as
668
+ * expressions, but as strings. For example, `\begin{array}{ccc}` (both
669
+ * `array` and `ccc` are strings), `\color{red}` or `\operatorname{lim sup}`.
670
+ *
671
+ * If the next token is the start of a group (`{`), return the content
672
+ * of the group as a string. This may include white space, and it may need
673
+ * to be trimmed at the start and end of the string.
674
+ *
675
+ * LaTeX commands are typically not allowed inside a string group (for example,
676
+ * `\alpha` would result in an error), but we do not enforce this.
677
+ *
678
+ * If `optional` is true, this should be an optional group in square brackets
679
+ * otherwise it is a regular group in braces.
680
+ */
681
+ parseStringGroup(optional?: boolean): string | null;
682
+ /**
683
+ * A symbol can be:
684
+ * - a single-letter symbol: `x`
685
+ * - a single LaTeX command: `\pi`
686
+ * - a multi-letter symbol: `\operatorname{speed}`
687
+ */
688
+ parseSymbol(until?: Partial<Terminator>): Expression | null;
689
+ /**
690
+ * Parse an expression in a tabular format, where rows are separated by `\\`
691
+ * and columns by `&`.
692
+ *
693
+ * Return rows of sparse columns: empty rows are indicated with `Nothing`,
694
+ * and empty cells are also indicated with `Nothing`.
695
+ */
696
+ parseTabular(): null | Expression[][];
697
+ /**
698
+ * Parse an argument list, for example: `(12, x+1)` or `\left(x\right)`
699
+ *
700
+ * - 'enclosure' : will look for arguments inside an enclosure
701
+ * (an open/close fence) (**default**)
702
+ * - 'implicit': either an expression inside a pair of `()`, or just a primary
703
+ * (i.e. we interpret `\cos x + 1` as `\cos(x) + 1`)
704
+ *
705
+ * Return an array of expressions, one for each argument, or `null` if no
706
+ * argument was found.
707
+ */
708
+ parseArguments(kind?: 'implicit' | 'enclosure', until?: Terminator): ReadonlyArray<Expression> | null;
709
+ /**
710
+ * Parse a postfix operator, such as `'` or `!`.
711
+ *
712
+ * Prefix, infix and matchfix operators are handled by `parseExpression()`
713
+ *
714
+ */
715
+ parsePostfixOperator(lhs: Expression | null, until?: Partial<Terminator>): Expression | null;
716
+ /**
717
+ * Parse an expression:
718
+ *
719
+ * ```
720
+ * <expression> ::=
721
+ * | <primary> ( <infix-op> <expression> )?
722
+ * | <prefix-op> <expression>
723
+ *
724
+ * <primary> :=
725
+ * (<number> | <symbol> | <function-call> | <matchfix-expr>)
726
+ * (<subsup> | <postfix-operator>)*
727
+ *
728
+ * <matchfix-expr> :=
729
+ * <matchfix-op-open> <expression> <matchfix-op-close>
730
+ *
731
+ * <function-call> ::=
732
+ * | <function><matchfix-op-group-open><expression>[',' <expression>]<matchfix-op-group-close>
733
+ * ```
734
+ *
735
+ * This is the top-level parsing entry point.
736
+ *
737
+ * Stop when an operator of precedence less than `until.minPrec`
738
+ * or the sequence of tokens `until.tokens` is encountered
739
+ *
740
+ * `until` is `{ minPrec:0 }` by default.
741
+ */
742
+ parseExpression(until?: Partial<Terminator>): Expression | null;
743
+ /**
744
+ * Parse a number.
745
+ */
746
+ parseNumber(): Expression | null;
747
+ /**
748
+ * Boundaries are used to detect the end of an expression.
749
+ *
750
+ * They are used for unusual syntactic constructs, for example
751
+ * `\int \sin x dx` where the `dx` is not an argument to the `\sin`
752
+ * function, but a boundary of the integral.
753
+ *
754
+ * They are also useful when handling syntax errors and recovery.
755
+ *
756
+ * For example, `\begin{bmatrix} 1 & 2 { \end{bmatrix}` has an
757
+ * extraneous `{`, but the parser will attempt to recover and continue
758
+ * parsing when it encounters the `\end{bmatrix}` boundary.
759
+ */
760
+ addBoundary(boundary: LatexToken[]): void;
761
+ removeBoundary(): void;
762
+ get atBoundary(): boolean;
763
+ matchBoundary(): boolean;
764
+ boundaryError(msg: string | [string, ...Expression[]]): Expression;
765
+ }
766
+ /**
767
+ *
768
+ * The LaTeX serialization options can used with the `expr.toLatex()` method.
769
+ *
770
+ * @category Latex Parsing and Serialization
771
+ */
772
+ export type SerializeLatexOptions = NumberSerializationFormat & {
773
+ /**
774
+ * If true, prettify the LaTeX output.
775
+ *
776
+ * For example, render `\frac{a}{b}\frac{c}{d}` as `\frac{ac}{bd}`
777
+ *
778
+ */
779
+ prettify: boolean;
780
+ /**
781
+ * Controls the materialization of the lazy collections.
782
+ *
783
+ * - If `true`, lazy collections are materialized, i.e. it is rendered as a
784
+ * LaTeX expression with all its elements.
785
+ * - If `false`, the expression is not materialized, i.e. it is
786
+ * rendered as a LaTeX command with its arguments.
787
+ * - If a number is provided, it is the maximum number of elements
788
+ * that will be materialized.
789
+ * - If a pair of numbers is provided, it is the number of elements
790
+ * of the head and the tail that will be materialized, respectively.
791
+ */
792
+ materialization: boolean | number | [number, number];
793
+ /**
794
+ * LaTeX string used to render an invisible multiply, e.g. in '2x'.
795
+ *
796
+ * If empty, both operands are concatenated, i.e. `2x`.
797
+ *
798
+ * Use `\cdot` to insert a `\cdot` operator between them, i.e. `2 \cdot x`.
799
+ *
800
+ * Empty by default.
801
+ */
802
+ invisibleMultiply: LatexString;
803
+ /**
804
+ * LaTeX string used to render [mixed numbers](https://en.wikipedia.org/wiki/Fraction#Mixed_numbers) e.g. '1 3/4'.
805
+ *
806
+ * Leave it empty to join the main number and the fraction, i.e. render it
807
+ * as `1\frac{3}{4}`.
808
+ *
809
+ * Use `+` to insert an explicit `+` operator between them,
810
+ * i.e. `1+\frac{3}{4}`
811
+ *
812
+ * Empty by default.
813
+ */
814
+ invisiblePlus: LatexString;
815
+ /**
816
+ * LaTeX string used to render an explicit multiply operator.
817
+ *
818
+ * For example, `\times`, `\cdot`, etc...
819
+ *
820
+ * Default: `\times`
821
+ */
822
+ multiply: LatexString;
823
+ /**
824
+ * Serialize the expression `["Error", "'missing'"]`, with this LaTeX string
825
+ *
826
+ */
827
+ missingSymbol: LatexString;
828
+ applyFunctionStyle: (expr: Expression, level: number) => DelimiterScale;
829
+ groupStyle: (expr: Expression, level: number) => DelimiterScale;
830
+ rootStyle: (expr: Expression, level: number) => 'radical' | 'quotient' | 'solidus';
831
+ fractionStyle: (expr: Expression, level: number) => 'quotient' | 'block-quotient' | 'inline-quotient' | 'inline-solidus' | 'nice-solidus' | 'reciprocal' | 'factor';
832
+ logicStyle: (expr: Expression, level: number) => 'word' | 'boolean' | 'uppercase-word' | 'punctuation';
833
+ powerStyle: (expr: Expression, level: number) => 'root' | 'solidus' | 'quotient';
834
+ numericSetStyle: (expr: Expression, level: number) => 'compact' | 'regular' | 'interval' | 'set-builder';
835
+ };
836
+ /**
837
+ *
838
+ * An instance of `Serializer` is provided to the `serialize` handlers of custom
839
+ * LaTeX dictionary entries.
840
+ *
841
+ * @category Latex Parsing and Serialization
842
+ *
843
+ */
844
+ export interface Serializer {
845
+ readonly options: Required<SerializeLatexOptions>;
846
+ readonly dictionary: IndexedLatexDictionary;
847
+ /** "depth" of the expression:
848
+ * - 0 for the root
849
+ * - 1 for a subexpression of the root
850
+ * - 2 for subexpressions of the subexpressions of the root
851
+ * - etc...
852
+ *
853
+ * This allows the serialized LaTeX to vary depending on the depth of the
854
+ * expression.
855
+ *
856
+ * For example use `\Bigl(` for the top level, and `\bigl(` or `(` for others.
857
+ */
858
+ level: number;
859
+ /** Output a LaTeX string representing the expression */
860
+ serialize: (expr: Expression | null | undefined) => string;
861
+ serializeFunction(expr: Expression, def?: IndexedLatexDictionaryEntry): LatexString;
862
+ serializeSymbol(expr: Expression): LatexString;
863
+ /** Output `s` surrounded by delimiters.
864
+ *
865
+ * If `delimiters` is not specified, use `()`
866
+ *
867
+ */
868
+ wrapString(s: LatexString, style: DelimiterScale, delimiters?: string): LatexString;
869
+ /** A string with the arguments of expr fenced appropriately and separated by
870
+ * commas.
871
+ */
872
+ wrapArguments(expr: Expression): LatexString;
873
+ /** Add a group fence around the expression if it is
874
+ * an operator of precedence less than or equal to `prec`.
875
+ */
876
+ wrap: (expr: Expression | null | undefined, prec?: number) => LatexString;
877
+ /** Add a group fence around the expression if it is
878
+ * short (not a function)
879
+ */
880
+ wrapShort(expr: Expression | null | undefined): LatexString;
881
+ /** Styles */
882
+ applyFunctionStyle: (expr: Expression, level: number) => DelimiterScale;
883
+ groupStyle: (expr: Expression, level: number) => DelimiterScale;
884
+ rootStyle: (expr: Expression, level: number) => 'radical' | 'quotient' | 'solidus';
885
+ fractionStyle: (expr: Expression, level: number) => 'quotient' | 'block-quotient' | 'inline-quotient' | 'inline-solidus' | 'nice-solidus' | 'reciprocal' | 'factor';
886
+ logicStyle: (expr: Expression, level: number) => 'word' | 'boolean' | 'uppercase-word' | 'punctuation';
887
+ powerStyle: (expr: Expression, level: number) => 'root' | 'solidus' | 'quotient';
888
+ numericSetStyle: (expr: Expression, level: number) => 'compact' | 'regular' | 'interval' | 'set-builder';
889
+ }
890
+ /** The `serialize` handler of a custom LaTeX dictionary entry can be
891
+ * a function of this type.
892
+ *
893
+ * @category Latex Parsing and Serialization
894
+ *
895
+ */
896
+ export type SerializeHandler = (serializer: Serializer, expr: Expression) => string;