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