@cortex-js/compute-engine 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/README.md +4 -5
  2. package/dist/compute-engine.esm.js +16755 -10484
  3. package/dist/compute-engine.min.esm.js +2 -7
  4. package/dist/compute-engine.min.js +2 -7
  5. package/dist/math-json.esm.js +148 -12472
  6. package/dist/math-json.min.esm.js +2 -7
  7. package/dist/math-json.min.js +2 -7
  8. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  9. package/dist/types/common/signals.d.ts +90 -0
  10. package/dist/types/compute-engine/assume.d.ts +21 -6
  11. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +107 -0
  12. package/dist/types/compute-engine/boxed-expression/box.d.ts +56 -0
  13. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +39 -0
  14. package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +8 -0
  15. package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +2 -0
  16. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +95 -0
  17. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +83 -0
  18. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +21 -0
  19. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +23 -0
  20. package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +98 -0
  21. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +74 -0
  22. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +12 -0
  23. package/dist/types/compute-engine/boxed-expression/order.d.ts +53 -0
  24. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +15 -0
  25. package/dist/types/compute-engine/boxed-expression/utils.d.ts +37 -0
  26. package/dist/types/compute-engine/compute-engine.d.ts +284 -99
  27. package/dist/types/compute-engine/cost-function.d.ts +3 -0
  28. package/dist/types/compute-engine/dictionary/arithmetic-add.d.ts +11 -0
  29. package/dist/types/compute-engine/dictionary/arithmetic-divide.d.ts +9 -0
  30. package/dist/types/compute-engine/dictionary/arithmetic-multiply.d.ts +17 -0
  31. package/dist/types/compute-engine/dictionary/arithmetic-power.d.ts +9 -0
  32. package/dist/types/compute-engine/dictionary/arithmetic.d.ts +2 -12
  33. package/dist/types/compute-engine/dictionary/collections.d.ts +1 -1
  34. package/dist/types/compute-engine/dictionary/core.d.ts +2 -2
  35. package/dist/types/compute-engine/dictionary/dictionary.d.ts +18 -11
  36. package/dist/types/compute-engine/dictionary/logic.d.ts +1 -1
  37. package/dist/types/compute-engine/dictionary/polynomials.d.ts +2 -0
  38. package/dist/types/compute-engine/dictionary/relational-operator.d.ts +2 -0
  39. package/dist/types/compute-engine/dictionary/sets.d.ts +1 -1
  40. package/dist/types/compute-engine/dictionary/trigonometry.d.ts +2 -2
  41. package/dist/types/compute-engine/domain-utils.d.ts +30 -0
  42. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +2 -0
  43. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +2 -0
  44. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +2 -0
  45. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +4 -0
  46. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +2 -0
  47. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +2 -0
  48. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +2 -0
  49. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +2 -0
  50. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +2 -0
  51. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +2 -0
  52. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +57 -0
  53. package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +23 -0
  54. package/dist/types/compute-engine/latex-syntax/parse.d.ts +198 -0
  55. package/dist/types/compute-engine/latex-syntax/public.d.ts +576 -0
  56. package/dist/types/{common → compute-engine/latex-syntax}/serialize-number.d.ts +4 -5
  57. package/dist/types/{latex-syntax → compute-engine/latex-syntax}/serializer-style.d.ts +2 -1
  58. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +41 -0
  59. package/dist/types/{latex-syntax/core → compute-engine/latex-syntax}/tokenizer.d.ts +2 -2
  60. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +3 -0
  61. package/dist/types/compute-engine/numerics/numeric-decimal.d.ts +12 -0
  62. package/dist/types/compute-engine/numerics/numeric.d.ts +35 -0
  63. package/dist/types/compute-engine/numerics/primes.d.ts +2 -0
  64. package/dist/types/compute-engine/public.d.ts +1416 -447
  65. package/dist/types/compute-engine/rules.d.ts +16 -6
  66. package/dist/types/compute-engine/simplify-rules.d.ts +17 -0
  67. package/dist/types/compute-engine/symbolic/expand.d.ts +11 -0
  68. package/dist/types/compute-engine/symbolic/flatten.d.ts +7 -0
  69. package/dist/types/compute-engine/symbolic/negate.d.ts +12 -0
  70. package/dist/types/compute-engine/symbolic/polynomials.d.ts +52 -0
  71. package/dist/types/compute-engine/symbolic/product.d.ts +45 -0
  72. package/dist/types/compute-engine/symbolic/sum.d.ts +25 -0
  73. package/dist/types/compute-engine/symbolic/utils.d.ts +47 -0
  74. package/dist/types/compute-engine.d.ts +3 -5
  75. package/dist/types/math-json/math-json-format.d.ts +101 -0
  76. package/dist/types/math-json/utils.d.ts +97 -0
  77. package/dist/types/math-json.d.ts +4 -3
  78. package/package.json +29 -28
  79. package/dist/compute-engine.js +0 -17296
  80. package/dist/cortex.esm.js +0 -20989
  81. package/dist/cortex.js +0 -21011
  82. package/dist/cortex.min.esm.js +0 -7
  83. package/dist/cortex.min.js +0 -7
  84. package/dist/math-json.js +0 -12517
  85. package/dist/types/common/debug.d.ts +0 -28
  86. package/dist/types/common/utils.d.ts +0 -153
  87. package/dist/types/compute-engine/canonical-forms.d.ts +0 -74
  88. package/dist/types/compute-engine/dictionary/domains.d.ts +0 -26
  89. package/dist/types/compute-engine/dictionary/utils.d.ts +0 -5
  90. package/dist/types/compute-engine/domains.d.ts +0 -4
  91. package/dist/types/compute-engine/evaluate.d.ts +0 -13
  92. package/dist/types/compute-engine/expression-map.d.ts +0 -11
  93. package/dist/types/compute-engine/internal-compute-engine.d.ts +0 -108
  94. package/dist/types/compute-engine/numeric-complex.d.ts +0 -2
  95. package/dist/types/compute-engine/numeric-decimal.d.ts +0 -12
  96. package/dist/types/compute-engine/numeric.d.ts +0 -21
  97. package/dist/types/compute-engine/numerical-eval.d.ts +0 -5
  98. package/dist/types/compute-engine/order.d.ts +0 -18
  99. package/dist/types/compute-engine/patterns.d.ts +0 -22
  100. package/dist/types/compute-engine/predicates.d.ts +0 -42
  101. package/dist/types/compute-engine/simplify.d.ts +0 -6
  102. package/dist/types/compute-engine/utils.d.ts +0 -15
  103. package/dist/types/cortex/formatter.d.ts +0 -165
  104. package/dist/types/cortex/parse-cortex.d.ts +0 -5
  105. package/dist/types/cortex/reserved-words.d.ts +0 -1
  106. package/dist/types/cortex/serialize-cortex.d.ts +0 -14
  107. package/dist/types/cortex.d.ts +0 -8
  108. package/dist/types/latex-syntax/definitions-algebra.d.ts +0 -2
  109. package/dist/types/latex-syntax/definitions-arithmetic.d.ts +0 -3
  110. package/dist/types/latex-syntax/definitions-calculus.d.ts +0 -2
  111. package/dist/types/latex-syntax/definitions-core.d.ts +0 -3
  112. package/dist/types/latex-syntax/definitions-inequalities.d.ts +0 -2
  113. package/dist/types/latex-syntax/definitions-other.d.ts +0 -3
  114. package/dist/types/latex-syntax/definitions-sets.d.ts +0 -2
  115. package/dist/types/latex-syntax/definitions-symbols.d.ts +0 -3
  116. package/dist/types/latex-syntax/definitions-trigonometry.d.ts +0 -3
  117. package/dist/types/latex-syntax/definitions.d.ts +0 -40
  118. package/dist/types/latex-syntax/latex-syntax.d.ts +0 -27
  119. package/dist/types/latex-syntax/parse.d.ts +0 -138
  120. package/dist/types/latex-syntax/public.d.ts +0 -456
  121. package/dist/types/latex-syntax/serializer.d.ts +0 -26
  122. package/dist/types/latex-syntax/utils.d.ts +0 -10
  123. package/dist/types/point-free-parser/characters.d.ts +0 -25
  124. package/dist/types/point-free-parser/combinators.d.ts +0 -46
  125. package/dist/types/point-free-parser/core-combinators.d.ts +0 -78
  126. package/dist/types/point-free-parser/grammar.d.ts +0 -12
  127. package/dist/types/point-free-parser/identifier-parsers.d.ts +0 -7
  128. package/dist/types/point-free-parser/numeric-parsers.d.ts +0 -8
  129. package/dist/types/point-free-parser/parsers.d.ts +0 -130
  130. package/dist/types/point-free-parser/string-parsers.d.ts +0 -29
  131. package/dist/types/point-free-parser/whitespace-parsers.d.ts +0 -17
  132. package/dist/types/public.d.ts +0 -163
@@ -0,0 +1,576 @@
1
+ /* 0.5.0 */
2
+ import { Expression } from '../../math-json/math-json-format';
3
+ import type { IComputeEngine } from '../public';
4
+ /**
5
+ * A `LatexToken` is a token as returned by `Scanner.peek`.
6
+ *
7
+ * It can be one of the indicated tokens, or a string that starts with a
8
+ * `\` for LaTeX commands, or a LaTeX character which includes digits,
9
+ * letters and punctuation.
10
+ */
11
+ export declare type LatexToken = string | '<{>' | '<}>' | '<space>' | '<$>' | '<$$>';
12
+ /** A LatexString is a regular string of LaTeX, for example:
13
+ * `\frac{\pi}{2}`
14
+ */
15
+ export declare type LatexString = string;
16
+ /**
17
+ * Open and close delimiters that can be used with {@link MatchfixEntry}
18
+ * record to define new LaTeX dictionary entries.
19
+ */
20
+ export declare type Delimiter = ')' | '(' | ']' | '[' | '{' /** \lbrace */ | '}' /** \rbrace */ | '<' /** \langle */ | '>' /** \rangle */ | '|' | '||' | '\\lceil' | '\\rceil' | '\\lfloor' | '\\rfloor';
21
+ export declare type DictionaryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'collections' | 'combinatorics' | 'core' | 'dimensions' | 'domains' | 'linear-algebra' | 'logic' | 'numeric' | 'other' | 'physics' | 'polynomials' | 'relop' | 'sets' | 'statistics' | 'symbols' | 'trigonometry' | 'units';
22
+ /**
23
+ * This indicates a condition under which parsing should stop:
24
+ * - a specific string of tokens has been encountered
25
+ * - an operator of a precedence higher than specified has been encountered
26
+ * - the last token has been reached
27
+ * - or if a function is provided, the function returns true;
28
+ */
29
+ export declare type Terminator = {
30
+ minPrec: number;
31
+ tokens?: LatexToken[];
32
+ condition?: (parser: Parser) => boolean;
33
+ };
34
+ /**
35
+ * Custom parsing handler.
36
+ *
37
+ * When invoked the scanner points right after the LaTeX fragment that triggered
38
+ * this parsing handler.
39
+ *
40
+ * The scanner should be moved, by calling `scanner.next()` for every consumed
41
+ * token.
42
+ *
43
+ * If it was in an infix or postfix context, `lhs` will represent the
44
+ * left-hand side argument. In a prefix or matchfix context, `lhs` is `null`.
45
+ *
46
+ * In a superfix (^) or subfix (_) context (that is if the first token of the
47
+ * trigger is `^` or `_`), lhs is `["Superscript", lhs, rhs]`
48
+ * and `["Subscript", lhs, rhs]`, respectively.
49
+ *
50
+ * The handler should return `null` if the expression could not be parsed
51
+ * (didn't match the syntax that was expected). The matching expression
52
+ * otherwise.
53
+ *
54
+ */
55
+ export declare type EnvironmentParseHandler = (parser: Parser, reqArgs: Expression[], optArgs: Expression[]) => Expression | null;
56
+ export declare type SymbolParseHandler = (parser: Parser) => Expression | null;
57
+ export declare type PostfixParseHandler = (parser: Parser, lhs: Expression) => Expression | null;
58
+ export declare type PrefixParseHandler = (parser: Parser, until: Terminator) => Expression | null;
59
+ export declare type InfixParseHandler = (parser: Parser, until: Terminator, lhs: Expression) => Expression | null;
60
+ export declare type MatchfixParseHandler = (parser: Parser, body: Expression) => Expression | null;
61
+ export declare type ParseHandler = SymbolParseHandler | EnvironmentParseHandler | PostfixParseHandler | PrefixParseHandler | InfixParseHandler | MatchfixParseHandler;
62
+ /**
63
+ * Maps a string of LaTeX tokens to a function or symbol and vice-versa.
64
+ *
65
+ */
66
+ export declare type BaseEntry = {
67
+ /**
68
+ * Map a MathJSON function or symbol name to this entry.
69
+ *
70
+ * Each entry should have at least a `name` or a `parse` handler.
71
+ *
72
+ * An entry with no `name` cannot be serialized: the `name` is used to map
73
+ * a MathJSON function or symbol name to the appropriate entry for serializing.
74
+ * However, an entry with no `name` can be used to define a synonym (for example
75
+ * for the symbol `\varnothing` which is a synonym for `\emptyset`).
76
+ *
77
+ * If not `parse` handler is provided, only the trigger is used to select this
78
+ * entry. Otherwise, if the trigger of the entry matches the current
79
+ * token, the `parse` handler is invoked.
80
+ */
81
+ name?: string;
82
+ /**
83
+ * The trigger is the set of tokens that will make this record eligible for
84
+ * attempting to parse the stream and generate an expression. After the
85
+ * trigger matches, the `parse` handler is called, if available.
86
+ *
87
+ * `matchfix` operators use `openDelimiter` and `closeDelimiter` instead.
88
+ *
89
+ */
90
+ trigger?: LatexString | LatexToken[];
91
+ /**
92
+ * Transform an expression into a LaTeX string.
93
+ * If no `serialize` handler is provided, the `trigger` property is used
94
+ */
95
+ serialize?: LatexString | SerializeHandler;
96
+ };
97
+ export declare type MatchfixEntry = BaseEntry & {
98
+ kind: 'matchfix';
99
+ /**
100
+ * If `kind` is `'matchfix'`: the `closeDelimiter` and `openDelimiter`
101
+ * property are required
102
+ */
103
+ openDelimiter?: Delimiter | LatexToken[];
104
+ closeDelimiter?: Delimiter | LatexToken[];
105
+ /** When invoked, the parser is pointing after the close delimiter.
106
+ * The argument of the handler is the body, i.e. the content between
107
+ * the open delimiter and the close delimiter.
108
+ */
109
+ parse: MatchfixParseHandler;
110
+ };
111
+ export declare type InfixEntry = BaseEntry & {
112
+ /**
113
+ * Infix position, with an operand before and an operand after: `a ⊛ b`.
114
+ *
115
+ * Example: `+`, `\times`.
116
+ */
117
+ kind: 'infix';
118
+ /**
119
+ * - **`both`**: a + b + c +(a, b, c)
120
+ * - **`left`**: a / b / c -> /(/(a, b), c)
121
+ * - **`right`**: a = b = c -> =(a, =(b, c))
122
+ * - **`non`**: a < b < c -> syntax error
123
+ *
124
+ * - a `both`-associative operator has an unlimited number of arguments
125
+ * - a `left`, `right` or `non` associative operator has at most two arguments
126
+ *
127
+ */
128
+ associativity?: 'right' | 'left' | 'non' | 'both';
129
+ precedence?: number;
130
+ /**
131
+ */
132
+ parse: string | InfixParseHandler;
133
+ };
134
+ export declare type PostfixEntry = BaseEntry & {
135
+ /**
136
+ * Postfix position, with an operand before: `a ⊛`
137
+ *
138
+ * Example: `!`.
139
+ */
140
+ kind: 'postfix';
141
+ precedence?: number;
142
+ parse: PostfixParseHandler;
143
+ };
144
+ export declare type PrefixEntry = BaseEntry & {
145
+ /**
146
+ * Prefix position, with an operand after: `⊛ a`
147
+ *
148
+ * Example: `-`, `\not`.
149
+ */
150
+ kind: 'prefix';
151
+ precedence: number;
152
+ parse: PrefixParseHandler;
153
+ };
154
+ /**
155
+ * A LaTeX dictionary entry for an environment, that is a LaTeX
156
+ * construct using `\begin{...}...\end{...}`.
157
+ */
158
+ export declare type EnvironmentEntry = BaseEntry & {
159
+ kind: 'environment';
160
+ parse: EnvironmentParseHandler;
161
+ };
162
+ export declare type SymbolEntry = BaseEntry & {
163
+ kind: 'symbol';
164
+ /** Used for appropriate wrapping (i.e. when to surround it with parens) */
165
+ precedence?: number;
166
+ /**
167
+ * Indicate if this symbol can be followed by arguments.
168
+ * The presence of arguments will indicate that the arguments should be
169
+ * applied to the symbol. Otherwise, the invisible operator is applied
170
+ * to the symbol and the arguments.
171
+ *
172
+ * If `arguments` is `"group"`:
173
+ *
174
+ * "f(x)" -> `["f", "x"]`
175
+ * "f x" -> `["multiply", "f", "x"]`
176
+ *
177
+ * If `arguments` is `""`:
178
+ *
179
+ * "f(x)" -> `["multiply", "f", ["group", "x"]]`
180
+ * "f x" -> `["multiply", "f", "x"]`
181
+ *
182
+ * If `arguments` is `"group/primary"` and the symbol is followed either
183
+ * by a group or by a primary (prefix + symbol + subsupfix + postfix).
184
+ * Used for trig functions. i.e. `\sin x` vs `\sin(x)`:
185
+ *
186
+ * "f(x)" -> `["f", "x"]`
187
+ * "f x" -> `["f", "x"]`
188
+ *
189
+ */
190
+ arguments?: 'group' | 'implicit' | '';
191
+ /**
192
+ * Applicable when `kind` is `"symbol"`.
193
+ *
194
+ * If a LaTeX command (i.e. the trigger starts with `\`, e.g. `\sqrt`)
195
+ * indicates the number of optional arguments expected (indicate with
196
+ * square brackets).
197
+ *
198
+ * For example, for the `\sqrt` command, 1: `\sqrt[3]{x}`
199
+ *
200
+ */
201
+ optionalLatexArg?: number;
202
+ /**
203
+ * Applicable when `kind` is `"symbol"`.
204
+ *
205
+ * If a LaTeX command (i.e. the trigger starts with `\`, e.g. `\frac`)
206
+ * indicates the number of required arguments expected (indicated with
207
+ * curly braces).
208
+ *
209
+ * For example, for the `\frac` command, 2: `\frac{1}{n}`
210
+ *
211
+ */
212
+ requiredLatexArg?: number;
213
+ parse: Expression | SymbolParseHandler;
214
+ };
215
+ /**
216
+ * A simple LaTeX dictionary entry, for example for a command like `\pi`.
217
+ */
218
+ export declare type DefaultEntry = BaseEntry & {
219
+ precedence?: number;
220
+ arguments?: 'group' | 'implicit' | '';
221
+ optionalLatexArg?: number;
222
+ requiredLatexArg?: number;
223
+ parse?: Expression | SymbolParseHandler;
224
+ };
225
+ export declare type LatexDictionaryEntry = DefaultEntry | MatchfixEntry | InfixEntry | PostfixEntry | PrefixEntry | SymbolEntry | EnvironmentEntry;
226
+ /** @internal */
227
+ export declare function isSymbolEntry(entry: LatexDictionaryEntry): entry is SymbolEntry;
228
+ /** @internal */
229
+ export declare function isMatchfixEntry(entry: LatexDictionaryEntry): entry is MatchfixEntry;
230
+ /** @internal */
231
+ export declare function isInfixEntry(entry: LatexDictionaryEntry): entry is InfixEntry;
232
+ /** @internal */
233
+ export declare function isPrefixEntry(entry: LatexDictionaryEntry): entry is PrefixEntry;
234
+ /** @internal */
235
+ export declare function isPostfixEntry(entry: LatexDictionaryEntry): entry is PostfixEntry;
236
+ /** @internal */
237
+ export declare function isEnvironmentEntry(entry: LatexDictionaryEntry): entry is EnvironmentEntry;
238
+ export declare type LatexDictionary = LatexDictionaryEntry[];
239
+ export declare type ParseLatexOptions = {
240
+ /**
241
+ * This function is invoked when a number is followed by a symbol,
242
+ * an open delimiter or a function.
243
+ *
244
+ * If this function is set to `null`, the lhs and rhs are joined as a `Sequence`.
245
+ *
246
+ * If this function is set to `undefined` it behaves in the following way:
247
+ * - a number followed by a numeric expression is considered as separated
248
+ * with an invisible multiplication sign, and the two are joined as
249
+ * ['Multiply', lhs, rhs].
250
+ * - a number followed by a rational number is considered to be separated
251
+ * with an invisible plus, and the two are joined as ['Add', lhs,
252
+ *
253
+ * For example with `2\frac{3}{4}`: `["Add", 2, ["Divide", 3, 4]]`
254
+ *
255
+ */
256
+ applyInvisibleOperator: 'auto' | null | ((parser: Parser, lhs: Expression, rhs: Expression) => Expression | null);
257
+ /**
258
+ * If true, ignore space characters.
259
+ *
260
+ * Default: `true`
261
+ *
262
+ */
263
+ skipSpace: boolean;
264
+ /**
265
+ * When an unknown LaTeX command is encountered, attempt to parse
266
+ * any arguments it may have.
267
+ *
268
+ * For example, `\foo{x+1}` would produce `['\foo', ['Add', 'x', 1]]` if
269
+ * this property is true, `['LatexSymbols', '\foo', '<{>', 'x', '+', 1, '<{>']`
270
+ * otherwise.
271
+ */
272
+ parseArgumentsOfUnknownLatexCommands: boolean;
273
+ /**
274
+ * When a number is encountered, parse it.
275
+ *
276
+ * Otherwise, return each token making up the number (minus sign, digits,
277
+ * decimal separator, etc...).
278
+ *
279
+ * Default: `true`
280
+ */
281
+ parseNumbers: boolean;
282
+ /**
283
+ * The `parseUnknownToken` function is invoked when a token (`a`,
284
+ * `\alpha`...) is encountered at a position where a symbol or a function
285
+ * could be parsed.
286
+ *
287
+ * If it returns `symbol` or `function`, the token is interpreted as a symbol
288
+ * or function, respectively.
289
+ *
290
+ * If a `function` and the token is followed by an apply function operator
291
+ * (typically, parentheses), parse them as arguments to the function.
292
+ *
293
+ * If `skip`, the token is skipped as if it was not present. This is
294
+ * convenient for purely presentational commands, such as `\displaystyle`.
295
+ *
296
+ * If `error`, an error condition is raised.
297
+ */
298
+ parseUnknownToken: (token: LatexToken, parser: Parser) => 'symbol' | 'function' | 'skip' | 'error';
299
+ /**
300
+ * If true, the expression will be decorated with the LaTeX
301
+ * fragments corresponding to each elements of the expression.
302
+ *
303
+ * The top-level expression, that is the one returned by `parse()`, will
304
+ * include the verbatim LaTeX input that was parsed. The sub-expressions
305
+ * may contain a slightly different LaTeX, for example with consecutive spaces
306
+ * replaced by one, with comments removed and with some low-level LaTeX
307
+ * commands replaced, for example `\egroup` and `\bgroup`.
308
+ */
309
+ preserveLatex: boolean;
310
+ };
311
+ export declare type SerializeLatexOptions = {
312
+ /**
313
+ * LaTeX string used to render an invisible multiply, e.g. in '2x'.
314
+ * Leave it empty to join the adjacent terms, or use `\cdot` to insert
315
+ * a `\cdot` operator between them, i.e. `2\cdot x`.
316
+ *
317
+ * Empty by default.
318
+ */
319
+ invisibleMultiply: LatexString;
320
+ /**
321
+ * LaTeX string used for an invisible plus, e.g. in '1 3/4'.
322
+ * Leave it empty to join the main number and the fraction, i.e. render it
323
+ * as `1\frac{3}{4}`, or use `+` to insert a `+` operator between them, i.e.
324
+ * `1+\frac{3}{4}`
325
+ *
326
+ * Empty by default.
327
+ */
328
+ invisiblePlus: LatexString;
329
+ /**
330
+ * LaTeX string used for an explicit multiply operator,
331
+ *
332
+ * Default: `\times`
333
+ */
334
+ multiply: LatexString;
335
+ /**
336
+ * When an expression contains the symbol `Missing`, serialize it
337
+ * with this LaTeX string
338
+ */
339
+ missingSymbol: LatexString;
340
+ applyFunctionStyle: (expr: Expression, level: number) => 'paren' | 'leftright' | 'big' | 'none';
341
+ groupStyle: (expr: Expression, level: number) => 'paren' | 'leftright' | 'big' | 'none';
342
+ rootStyle: (expr: Expression, level: number) => 'radical' | 'quotient' | 'solidus';
343
+ fractionStyle: (expr: Expression, level: number) => 'quotient' | 'inline-solidus' | 'nice-solidus' | 'reciprocal' | 'factor';
344
+ logicStyle: (expr: Expression, level: number) => 'word' | 'boolean' | 'uppercase-word' | 'punctuation';
345
+ powerStyle: (expr: Expression, level: number) => 'root' | 'solidus' | 'quotient';
346
+ numericSetStyle: (expr: Expression, level: number) => 'compact' | 'regular' | 'interval' | 'set-builder';
347
+ };
348
+ export declare type NumberFormattingOptions = {
349
+ precision: number;
350
+ positiveInfinity: LatexString;
351
+ negativeInfinity: LatexString;
352
+ notANumber: LatexString;
353
+ /**
354
+ * A string representing the decimal marker, the string separating
355
+ * the whole portion of a number from the fractional portion, i.e.
356
+ * the '.' in '3.1415'.
357
+ *
358
+ * Some countries use a comma rather than a dot. In this case it is
359
+ * recommended to use `"{,}"` as the marker: the surrounding bracket ensure
360
+ * there is no additional gap after the comma.
361
+ *
362
+ * Default: `"."`
363
+ */
364
+ decimalMarker: LatexString;
365
+ /**
366
+ * A string representing the separator between groups of digits,
367
+ * used to improve readability of numbers with lots of digits.
368
+ *
369
+ * If you change it to another value, be aware that this may lead to
370
+ * unexpected results. For example, if changing it to `,` the expression
371
+ * `x_{1,2}` will parse as `x` with a subscript of `1.2`, rather than `x`
372
+ * with two subscripts, `1` and `2`.
373
+ *
374
+ * Default: `"\\,"` (thin space, 3/18mu) (Resolution 7 of the 1948 CGPM)
375
+ */
376
+ groupSeparator: LatexString;
377
+ exponentProduct: LatexString;
378
+ beginExponentMarker: LatexString;
379
+ endExponentMarker: LatexString;
380
+ notation: 'engineering' | 'auto' | 'scientific';
381
+ truncationMarker: LatexString;
382
+ beginRepeatingDigits: LatexString;
383
+ endRepeatingDigits: LatexString;
384
+ imaginaryNumber: LatexString;
385
+ avoidExponentsInRange: [negativeExponent: number, positiveExponent: number];
386
+ };
387
+ /**
388
+ * To customize the parsing and serializing of LaTeX syntax, create a `LatexSyntax`
389
+ * instance.
390
+ */
391
+ export declare class LatexSyntax {
392
+ /**
393
+ *
394
+ * @param onError - Called when a non-fatal error is encountered. When parsing,
395
+ * the parser will attempt to recover and continue.
396
+ *
397
+ */
398
+ constructor(options?: NumberFormattingOptions & ParseLatexOptions & SerializeLatexOptions & {
399
+ onError?: WarningSignalHandler;
400
+ dictionary?: LatexDictionary;
401
+ });
402
+ /**
403
+ * Return a LaTeX dictionary suitable for the specified category, or `"all"`
404
+ * for all categories (`"arithmetic"`, `"algebra"`, etc...).
405
+ *
406
+ * A LaTeX dictionary is needed to translate between LaTeX and MathJSON.
407
+ *
408
+ * Each entry in the dictionary indicate how a LaTeX token (or string of
409
+ * tokens) should be parsed into a MathJSON expression.
410
+ *
411
+ * For example an entry can define that the `\pi` LaTeX token should map to the
412
+ * symbol `"Pi"`, or that the token `-` should map to the function
413
+ * `["Negate",...]` when in a prefix position and to the function
414
+ * `["Subtract", ...]` when in an infix position.
415
+ *
416
+ * Furthermore, the information in each dictionary entry is used to serialize
417
+ * the LaTeX string corresponding to a MathJSON expression.
418
+ *
419
+ * Use the value returned by this function to the `options` argument of the
420
+ * constructor.
421
+ */
422
+ static getDictionary(domain?: DictionaryCategory | 'all'): Readonly<LatexDictionary>;
423
+ parse(latex: LatexString): Expression;
424
+ serialize(expr: Expression): LatexString;
425
+ }
426
+ export interface Serializer {
427
+ readonly onError: WarningSignalHandler;
428
+ readonly options: Required<SerializeLatexOptions>;
429
+ /** "depth" of the expression:
430
+ * - 0 for the root
431
+ * - 1 for the arguments of the root
432
+ * - 2 for the arguments of the arguments of the root
433
+ * - etc...
434
+ *
435
+ * This allows for variation of the LaTeX serialized based
436
+ * on the depth of the expression, for example using `\Bigl(`
437
+ * for the top level, and `\bigl(` or `(` for others.
438
+ */
439
+ level: number;
440
+ /** Output a LaTeX string representing the expression */
441
+ serialize: (expr: Expression | null) => string;
442
+ wrapString(s: string, style: 'paren' | 'leftright' | 'big' | 'none'): string;
443
+ /** Add a group fence around the expression if it is
444
+ * an operator of precedence less than or equal to `prec`.
445
+ */
446
+ wrap: (expr: Expression | null, prec?: number) => string;
447
+ /** Add a group fence around the expression if it is
448
+ * short (not a function)
449
+ */
450
+ wrapShort(expr: Expression | null): string;
451
+ /** Styles */
452
+ applyFunctionStyle: (expr: Expression, level: number) => 'paren' | 'leftright' | 'big' | 'none';
453
+ groupStyle: (expr: Expression, level: number) => 'paren' | 'leftright' | 'big' | 'none';
454
+ rootStyle: (expr: Expression, level: number) => 'radical' | 'quotient' | 'solidus';
455
+ fractionStyle: (expr: Expression, level: number) => 'quotient' | 'inline-solidus' | 'nice-solidus' | 'reciprocal' | 'factor';
456
+ logicStyle: (expr: Expression, level: number) => 'word' | 'boolean' | 'uppercase-word' | 'punctuation';
457
+ powerStyle: (expr: Expression, level: number) => 'root' | 'solidus' | 'quotient';
458
+ numericSetStyle: (expr: Expression, level: number) => 'compact' | 'regular' | 'interval' | 'set-builder';
459
+ }
460
+ export declare type SerializeHandler = (serializer: Serializer, expr: Expression) => string;
461
+ export interface Parser {
462
+ readonly onError: WarningSignalHandler;
463
+ readonly options: Required<ParseLatexOptions>;
464
+ readonly computeEngine?: IComputeEngine;
465
+ index: number;
466
+ /** True if the last token has been reached */
467
+ readonly atEnd: boolean;
468
+ /** Return the next token, without advancing the index */
469
+ readonly peek: LatexToken;
470
+ /** Return true if the terminator condition is met */
471
+ atTerminator(t: Terminator): boolean;
472
+ /** Return an array of string corresponding to tokens ahead.
473
+ * The index is unchanged.
474
+ */
475
+ lookAhead(): string[];
476
+ /** Return the next token and advance the index */
477
+ next(): LatexToken;
478
+ /** Return a LaTeX string before the index */
479
+ latexBefore(): string;
480
+ /** Return a LaTeX string after the index */
481
+ latexAfter(): string;
482
+ /** If there are any space, advance the index until a non-space is encountered */
483
+ skipSpace(): boolean;
484
+ /** If the next token is a character, return it and advance the index
485
+ * This includes plain characters (e.g. 'a', '+'...), characters
486
+ * defined in hex (^^ and ^^^^), the `\char` and `\unicode` command.
487
+ */
488
+ matchChar(): string | null;
489
+ /** Return a CSS color. Handle the various color formats supported by the
490
+ * `xcolor` package.
491
+ */
492
+ matchColor(background?: boolean): string | null;
493
+ /**
494
+ * Return a LaTeX dimension.
495
+ *
496
+ */
497
+ matchLatexDimension(): string | null;
498
+ /** If the next token matches the target advance and return true. Otherwise
499
+ * return false */
500
+ match(tokens: LatexToken): boolean;
501
+ matchAll(tokens: LatexToken | LatexToken[]): boolean;
502
+ matchAny(tokens: LatexToken[]): LatexToken;
503
+ matchWhile(tokens: LatexToken[]): LatexToken[];
504
+ /** If the next token matches a `+` or `-` sign, return it and advance the index.
505
+ * Otherwise return `''` and do not advance */
506
+ matchSign(): string;
507
+ matchDecimalDigits(): string;
508
+ matchSignedInteger(): string;
509
+ matchExponent(): string;
510
+ matchNumber(): string;
511
+ /** Parse a tabular environment, until `\end{endName}`
512
+ */
513
+ matchTabular(endName: string): null | Expression;
514
+ applyInvisibleOperator(terminator: Terminator, lhs: Expression | null): Expression | null;
515
+ /** If the next tokens correspond to an optional LaTeX argument,
516
+ * enclosed with `[` and `]` return the content of the argument
517
+ * as an expression and advance the index past the closing `]`.
518
+ * Otherwise, return `null`.
519
+ */
520
+ matchOptionalLatexArgument(): Expression | null;
521
+ matchRequiredLatexArgument(): Expression | null;
522
+ /**
523
+ * 'group' : will look for an argument inside a pair of `()`
524
+ * 'implicit': either an expression inside a pair of `()`, or just a primary
525
+ * (i.e. we interpret `\cos x + 1` as `\cos(x) + 1`)
526
+ */
527
+ matchArguments(kind: '' | 'group' | 'implicit'): Expression[] | null;
528
+ /** If matches the normalized open delimiter, returns the
529
+ * expected closing delimiter.
530
+ *
531
+ * For example, if `openDelim` is `(`, and `closeDelim` is `)` it would match
532
+ * `\left\lparen` and return `['\right', '\rparen']`, which can be matched
533
+ * with `matchAll()`
534
+ */
535
+ matchOpenDelimiter(openDelim: Delimiter, closeDelim: Delimiter): LatexToken[] | null;
536
+ matchMiddleDelimiter(delimiter: '|' | ':' | LatexToken): boolean;
537
+ matchSupsub(lhs: Expression | null): Expression | null;
538
+ /**
539
+ *
540
+ * ```
541
+ * <primary> :=
542
+ * (<number> | <symbol> | <latex-command> | <function-call> | <matchfix-expr>)
543
+ * (<subsup> | <postfix-operator>)*
544
+ * ```
545
+ *
546
+ * ```
547
+ * <matchfix-expr> :=
548
+ * <matchfix-op-open> <expression> <matchfix-op-close>
549
+ *```
550
+ *
551
+ *```
552
+ * <function-call> ::=
553
+ * | <function><matchfix-op-group-open><expression>[',' <expression>]<matchfix-op-group-close>
554
+ *```
555
+ * If not a primary, return `null` and do not advance the index.
556
+ */
557
+ matchPrimary(): Expression | null;
558
+ /**
559
+ * Parse an expression:
560
+ *
561
+ * ```
562
+ * <expression> ::=
563
+ * | <prefix-op> <expression>
564
+ * | <primary>
565
+ * | <primary> <infix-op> <expression>
566
+ * ```
567
+ *
568
+ * This is the top-level parsing entry point.
569
+ *
570
+ * Stop when an operator of precedence less than `until.minPrec`
571
+ * or the sequence of tokens `until.tokens` is encountered
572
+ *
573
+ * `until` is `{ minPrec:0 }` by default.
574
+ */
575
+ matchExpression(until?: Partial<Terminator>): Expression | null;
576
+ }
@@ -1,8 +1,7 @@
1
- /* 0.4.2 */
2
- import { NumberFormattingOptions } from '../latex-syntax/public';
3
- export declare function serializeNumber(expr: Expression | null, options: Required<NumberFormattingOptions>): string;
4
- export declare function serializeEngineeringNotationNumber(value: number, options: Required<NumberFormattingOptions>): string;
5
- export declare function serializeAutoNotationNumber(valString: string, options: Required<NumberFormattingOptions>): string;
1
+ /* 0.5.0 */
2
+ import { NumberFormattingOptions } from './public';
3
+ export declare function serializeNumber(expr: Expression | null, options: NumberFormattingOptions): string;
4
+ export declare function serializeEngineeringNotationNumber(value: number, options: NumberFormattingOptions): string;
6
5
  /**
7
6
  * `value` is a base-10 number, possibly a floating point number with an
8
7
  * exponent, i.e. "0.31415e1"
@@ -1,7 +1,8 @@
1
- /* 0.4.2 */
1
+ /* 0.5.0 */
2
2
  export declare function getApplyFunctionStyle(_expr: Expression, _level: number): 'paren' | 'leftright' | 'big' | 'none';
3
3
  export declare function getGroupStyle(_expr: Expression, _level: number): 'paren' | 'leftright' | 'big' | 'none';
4
4
  export declare function getRootStyle(_expr: Expression | null, level: number): 'radical' | 'quotient' | 'solidus';
5
5
  export declare function getFractionStyle(_expr: Expression, level: number): 'quotient' | 'inline-solidus' | 'nice-solidus' | 'reciprocal' | 'factor';
6
6
  export declare function getLogicStyle(_expr: Expression, _level: number): 'word' | 'boolean' | 'uppercase-word' | 'punctuation';
7
7
  export declare function getPowerStyle(_expr: Expression, _level: number): 'root' | 'solidus' | 'quotient';
8
+ export declare function getNumericSetStyle(_expr: Expression, _level: number): 'compact' | 'regular' | 'interval' | 'set-builder';
@@ -0,0 +1,41 @@
1
+ /* 0.5.0 */
2
+ import { NumberFormattingOptions, LatexString, SerializeLatexOptions } from './public';
3
+ import { IndexedLatexDictionary, SymbolEntry } from './dictionary/definitions';
4
+ import { WarningSignalHandler } from '../../common/signals';
5
+ export declare class Serializer {
6
+ readonly onError: WarningSignalHandler;
7
+ options: NumberFormattingOptions & SerializeLatexOptions;
8
+ readonly dictionary: IndexedLatexDictionary;
9
+ level: number;
10
+ constructor(options: NumberFormattingOptions & SerializeLatexOptions, dictionary: IndexedLatexDictionary, onError: WarningSignalHandler);
11
+ updateOptions(opt: Partial<NumberFormattingOptions> & Partial<SerializeLatexOptions>): void;
12
+ /**
13
+ * Serialize the expression, and if the expression is an operator
14
+ * of precedence less than or equal to prec, wrap it in some paren.
15
+ * @todo: don't wrap Abs, Floor, Ceil, Delimiter
16
+ */
17
+ wrap(expr: Expression | null, prec?: number): string;
18
+ /** If this is a "short" expression (atomic), wrap it.
19
+ *
20
+ */
21
+ wrapShort(expr: Expression | null): string;
22
+ wrapString(s: string, style: 'paren' | 'leftright' | 'big' | 'none'): string;
23
+ serializeSymbol(expr: Expression, def?: SymbolEntry): string;
24
+ serializeDictionary(dict: {
25
+ [key: string]: Expression;
26
+ }): string;
27
+ serialize(expr: Expression | null): LatexString;
28
+ applyFunctionStyle(expr: Expression, level: number): 'paren' | 'leftright' | 'big' | 'none';
29
+ groupStyle(expr: Expression, level: number): 'paren' | 'leftright' | 'big' | 'none';
30
+ rootStyle(expr: Expression, level: number): 'radical' | 'quotient' | 'solidus';
31
+ fractionStyle(expr: Expression, level: number): 'quotient' | 'inline-solidus' | 'nice-solidus' | 'reciprocal' | 'factor';
32
+ logicStyle(expr: Expression, level: number): 'word' | 'boolean' | 'uppercase-word' | 'punctuation';
33
+ powerStyle(expr: Expression, level: number): 'root' | 'solidus' | 'quotient';
34
+ numericSetStyle(expr: Expression, level: number): 'compact' | 'regular' | 'interval' | 'set-builder';
35
+ }
36
+ export declare function appendLatex(src: string, s: string): string;
37
+ /**
38
+ * Replace '#1', '#2' in the LaTeX template stings with the corresponding
39
+ * values from `replacement`, in a LaTeX syntax safe manner (i.e. inserting spaces when needed)
40
+ */
41
+ export declare function replaceLatex(template: string, replacement: string[]): string;
@@ -1,4 +1,4 @@
1
- /* 0.4.2 */
1
+ /* 0.5.0 */
2
2
  * ## Reference
3
3
  * TeX source code:
4
4
  * {@link http://tug.org/texlive/devsrc/Build/source/texk/web2c/tex.web | Tex.web}
@@ -12,5 +12,5 @@ export declare type Token = string;
12
12
  * marker) and multiple lines.
13
13
  */
14
14
  export declare function tokenize(s: string, args: string[]): Token[];
15
- export declare function joinLatex(segments: string[]): string;
15
+ export declare function joinLatex(segments: Iterable<string>): string;
16
16
  export declare function tokensToString(tokens: Token | Token[] | [Token[] | Token][]): string;
@@ -0,0 +1,3 @@
1
+ /* 0.5.0 */
2
+ export declare function gamma(c: Complex): Complex;
3
+ export declare function lngamma(c: Complex): Complex;
@@ -0,0 +1,12 @@
1
+ /* 0.5.0 */
2
+ import { IComputeEngine } from '../public';
3
+ export declare function gcd(a: Decimal, b: Decimal): Decimal;
4
+ export declare function lcm(a: Decimal, b: Decimal): Decimal;
5
+ export declare function factorial(ce: IComputeEngine, n: Decimal): Decimal;
6
+ export declare function lngamma(ce: IComputeEngine, z: Decimal): Decimal;
7
+ export declare function gamma(ce: IComputeEngine, z: Decimal): Decimal;
8
+ /**
9
+ * If the exponent of the decimal number is in the range of the exponents
10
+ * for machine numbers,return true.
11
+ */
12
+ export declare function isInMachineRange(d: Decimal): boolean;