@cortex-js/compute-engine 0.12.3 → 0.12.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.
- package/dist/compute-engine.esm.js +24348 -28195
- package/dist/compute-engine.js +24523 -0
- package/dist/compute-engine.min.esm.js +24506 -2
- package/dist/compute-engine.min.js +24519 -2
- package/dist/math-json.esm.js +256 -185
- package/dist/math-json.js +283 -0
- package/dist/math-json.min.esm.js +258 -2
- package/dist/math-json.min.js +283 -2
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/signals.d.ts +1 -1
- package/dist/types/common/utils.d.ts +1 -1
- package/dist/types/compute-engine/assume.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +3 -1
- package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-domain.d.ts +3 -2
- package/dist/types/compute-engine/boxed-expression/boxed-function-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +3 -2
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +2 -2
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-symbol-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
- package/dist/types/compute-engine/compute-engine.d.ts +1 -2
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/domain-utils.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-inequalities.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +2 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +25 -16
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-identifier.d.ts +15 -0
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +28 -33
- package/dist/types/compute-engine/latex-syntax/public.d.ts +62 -65
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +10 -6
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +2 -1
- package/dist/types/compute-engine/library/arithmetic-add.d.ts +3 -2
- package/dist/types/compute-engine/library/arithmetic-divide.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic-multiply.d.ts +2 -2
- package/dist/types/compute-engine/library/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/library/calculus.d.ts +1 -1
- package/dist/types/compute-engine/library/collections.d.ts +1 -1
- package/dist/types/compute-engine/library/core.d.ts +1 -1
- package/dist/types/compute-engine/library/domains.d.ts +1 -1
- package/dist/types/compute-engine/library/library.d.ts +1 -1
- package/dist/types/compute-engine/library/logic.d.ts +1 -1
- package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/sets.d.ts +1 -1
- package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/library/utils.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
- package/dist/types/compute-engine/public.d.ts +13 -6
- package/dist/types/compute-engine/rules.d.ts +1 -1
- package/dist/types/compute-engine/simplify-rules.d.ts +1 -1
- package/dist/types/compute-engine/solve.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/expand.d.ts +18 -10
- package/dist/types/compute-engine/symbolic/flatten.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/negate.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/product.d.ts +4 -1
- package/dist/types/compute-engine/symbolic/sum.d.ts +2 -1
- package/dist/types/compute-engine/symbolic/utils.d.ts +1 -1
- package/dist/types/compute-engine.d.ts +2 -2
- package/dist/types/math-json/math-json-format.d.ts +1 -1
- package/dist/types/math-json/utils.d.ts +4 -1
- package/dist/types/math-json.d.ts +2 -2
- package/package.json +5 -14
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* 0.12.4 */
|
|
2
|
+
import { Parser } from './public';
|
|
3
|
+
/** For error handling, if we have a identifier prefix, assume
|
|
4
|
+
* the identifier is invalid (it would have been captured by
|
|
5
|
+
* `mathIdentifier()` otherwise) and return an error expression */
|
|
6
|
+
export declare function matchInvalidIdentifier(parser: Parser): Expression | null;
|
|
7
|
+
/**
|
|
8
|
+
* Match an identifier. It can be:
|
|
9
|
+
* - a sequence of emojis: `👍🏻👍🏻👍🏻`
|
|
10
|
+
* - a single-letter identifier: `a`
|
|
11
|
+
* - some LaTeX commands: `\alpha`
|
|
12
|
+
* - a multi-letter identifier with a prefix: `\mathrm{speed}`
|
|
13
|
+
* - an identifier with modifiers: `\mathrm{\alpha_{12}}` or `\mathit{speed\unicode{"2012}of\unicode{"2012}sound}`
|
|
14
|
+
*/
|
|
15
|
+
export declare function matchIdentifier(parser: Parser): string | null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/* 0.12.
|
|
2
|
-
import { IndexedLatexDictionary,
|
|
1
|
+
/* 0.12.4 */
|
|
2
|
+
import { IndexedLatexDictionary, IndexedInfixEntry, IndexedPostfixEntry, IndexedPrefixEntry, IndexedIdentifierEntry } from './dictionary/definitions';
|
|
3
3
|
import { IComputeEngine } from '../public';
|
|
4
4
|
import { Expression } from '../../math-json/math-json-format';
|
|
5
5
|
export declare const DEFAULT_LATEX_NUMBER_OPTIONS: NumberFormattingOptions;
|
|
@@ -33,11 +33,10 @@ export declare class _Parser implements Parser {
|
|
|
33
33
|
/**
|
|
34
34
|
* Return true if
|
|
35
35
|
* - at end of the token stream
|
|
36
|
-
* - the upcoming tokens match `t.tokens`
|
|
37
36
|
* - the `t.condition` function returns true
|
|
38
37
|
* Note: the `minPrec` condition is not checked. It should be checked separately.
|
|
39
38
|
*/
|
|
40
|
-
atTerminator(t?: Terminator): boolean;
|
|
39
|
+
atTerminator(t?: Partial<Terminator>): boolean;
|
|
41
40
|
/** True if the current token matches any of the boundaries we are waiting for */
|
|
42
41
|
get atBoundary(): boolean;
|
|
43
42
|
addBoundary(boundary: LatexToken[]): void;
|
|
@@ -62,11 +61,11 @@ export declare class _Parser implements Parser {
|
|
|
62
61
|
lookAhead(): string[];
|
|
63
62
|
/** Return all the definitions that potentially match the tokens ahead */
|
|
64
63
|
peekDefinitions(kind: 'function'): [FunctionEntry, number][] | null;
|
|
65
|
-
peekDefinitions(kind: '
|
|
66
|
-
peekDefinitions(kind: 'postfix'): [
|
|
67
|
-
peekDefinitions(kind: 'infix'): [
|
|
68
|
-
peekDefinitions(kind: 'prefix'): [
|
|
69
|
-
peekDefinitions(kind: 'operator'): [
|
|
64
|
+
peekDefinitions(kind: 'identifier'): [IndexedIdentifierEntry, number][] | null;
|
|
65
|
+
peekDefinitions(kind: 'postfix'): [IndexedPostfixEntry, number][] | null;
|
|
66
|
+
peekDefinitions(kind: 'infix'): [IndexedInfixEntry, number][] | null;
|
|
67
|
+
peekDefinitions(kind: 'prefix'): [IndexedPrefixEntry, number][] | null;
|
|
68
|
+
peekDefinitions(kind: 'operator'): [IndexedInfixEntry | IndexedPrefixEntry | IndexedPostfixEntry, number][] | null;
|
|
70
69
|
/** Skip strictly `<space>` tokens.
|
|
71
70
|
* To also skip `{}` see `skipSpace()`.
|
|
72
71
|
* To skip visual space (e.g. `\,`) see `skipVisualSpace()`.
|
|
@@ -114,14 +113,18 @@ export declare class _Parser implements Parser {
|
|
|
114
113
|
* - 'implicit': either an expression inside a pair of `()`, or just a product
|
|
115
114
|
* (i.e. we interpret `\cos 2x + 1` as `\cos(2x) + 1`)
|
|
116
115
|
*/
|
|
117
|
-
matchArguments(kind: undefined | '' | 'enclosure' | 'implicit'): Expression[] | null;
|
|
116
|
+
matchArguments(kind: undefined | '' | 'enclosure' | 'implicit', until?: Terminator): Expression[] | null;
|
|
118
117
|
/**
|
|
119
118
|
* A function can be followed by the following suffixes:
|
|
120
119
|
* - a `\prime`, `\doubleprime`, `'`, `(n)` to indicate a derivative
|
|
121
120
|
* - a subscript to indicate an argument
|
|
122
121
|
* - an argument, optionally inside an enclosure
|
|
123
122
|
*/
|
|
124
|
-
matchFunctionSuffix(): Expression
|
|
123
|
+
matchFunctionSuffix(id: string): Expression;
|
|
124
|
+
/** A prime suffix is a sequence of `'`, `\prime` or `\doubleprime`
|
|
125
|
+
* after a function or in a superscript.
|
|
126
|
+
*/
|
|
127
|
+
matchPrimeSuffix(): number;
|
|
125
128
|
/** If matches the normalized open delimiter, return the
|
|
126
129
|
* expected closing delimiter.
|
|
127
130
|
*
|
|
@@ -143,31 +146,23 @@ export declare class _Parser implements Parser {
|
|
|
143
146
|
* and finally a closing matching operator.
|
|
144
147
|
*/
|
|
145
148
|
matchEnclosure(): Expression | null;
|
|
149
|
+
matchIdentifier(): string | null;
|
|
146
150
|
/**
|
|
147
|
-
*
|
|
148
|
-
* - a
|
|
149
|
-
* - a
|
|
150
|
-
* -
|
|
151
|
-
* - a command: `\
|
|
152
|
-
*/
|
|
153
|
-
matchIdentifier(): string | Expression | null;
|
|
154
|
-
/**
|
|
155
|
-
* A function is a function identifier followed by arguments
|
|
156
|
-
* - a function with explicit arguments `f(x)`
|
|
157
|
-
* - a function with explicit arguments `\mathrm{floor}(x)`
|
|
158
|
-
* - a function name: `\mathrm{floor}`
|
|
159
|
-
* - a function with implicit arguments: `\cos x` (via a custom parser)
|
|
151
|
+
* A function is an identifier followed by arguments
|
|
152
|
+
* - a single letter identifier with explicit arguments `f(x)`
|
|
153
|
+
* - a multiletter identifier with explicit arguments `\mathrm{floor}(x)`
|
|
154
|
+
* - an identifier: `\mathrm{floor}`
|
|
155
|
+
* - a command with implicit arguments: `\cos x` (via a custom parser)
|
|
160
156
|
*
|
|
161
157
|
*/
|
|
162
|
-
matchFunction(): Expression | null;
|
|
158
|
+
matchFunction(until?: Partial<Terminator>): Expression | null;
|
|
163
159
|
/**
|
|
164
|
-
* A symbol
|
|
165
|
-
* - a single-letter variable: `x`
|
|
166
|
-
* - a single LaTeX command: `\pi`
|
|
160
|
+
* A symbol is an identifier or a custom definition
|
|
167
161
|
*/
|
|
168
|
-
matchSymbol(): Expression | null;
|
|
169
|
-
|
|
170
|
-
|
|
162
|
+
matchSymbol(until?: Partial<Terminator>): Expression | null;
|
|
163
|
+
matchLatexOptionalGroup(): Expression | null;
|
|
164
|
+
matchSingleAtomArgument(): Expression | null;
|
|
165
|
+
matchLatexGroup(): Expression | null;
|
|
171
166
|
matchSupsub(lhs: Expression | null): Expression | null;
|
|
172
167
|
matchPostfix(lhs: Expression | null): Expression | null;
|
|
173
168
|
/** Match a string used as a LaTeX identifier, for example an environment
|
|
@@ -208,7 +203,7 @@ export declare class _Parser implements Parser {
|
|
|
208
203
|
* - x2 -> no
|
|
209
204
|
* => lhs is a number, rhs is a number, but not a literal
|
|
210
205
|
*/
|
|
211
|
-
applyInvisibleOperator(
|
|
206
|
+
applyInvisibleOperator(until: Terminator, lhs: Expression | null): Expression | null;
|
|
212
207
|
matchUnexpectedLatexCommand(): Expression | null;
|
|
213
208
|
/**
|
|
214
209
|
* <primary> :=
|
|
@@ -220,7 +215,7 @@ export declare class _Parser implements Parser {
|
|
|
220
215
|
* <matchfix-op-open> <expression> [<matchfix-op-separator> <expression>] <matchfix-op-close>
|
|
221
216
|
*
|
|
222
217
|
*/
|
|
223
|
-
matchPrimary(): Expression | null;
|
|
218
|
+
matchPrimary(until?: Partial<Terminator>): Expression | null;
|
|
224
219
|
/**
|
|
225
220
|
* Parse an expression:
|
|
226
221
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
2
2
|
import { Expression } from '../../math-json/math-json-format';
|
|
3
3
|
import type { IComputeEngine } from '../public';
|
|
4
4
|
/**
|
|
@@ -23,7 +23,7 @@ export type LibraryCategory = 'algebra' | 'arithmetic' | 'calculus' | 'collectio
|
|
|
23
23
|
* This indicates a condition under which parsing should stop:
|
|
24
24
|
* - an operator of a precedence higher than specified has been encountered
|
|
25
25
|
* - the last token has been reached
|
|
26
|
-
* - or if a
|
|
26
|
+
* - or if a condition is provided, the condition returns true;
|
|
27
27
|
*/
|
|
28
28
|
export type Terminator = {
|
|
29
29
|
minPrec: number;
|
|
@@ -51,13 +51,13 @@ export type Terminator = {
|
|
|
51
51
|
*
|
|
52
52
|
*/
|
|
53
53
|
export type EnvironmentParseHandler = (parser: Parser, reqArgs: Expression[], optArgs: Expression[]) => Expression | null;
|
|
54
|
-
export type
|
|
55
|
-
export type FunctionParseHandler = (parser: Parser) => Expression | null;
|
|
54
|
+
export type IdentifierParseHandler = (parser: Parser, until?: Terminator) => Expression | null;
|
|
55
|
+
export type FunctionParseHandler = (parser: Parser, until?: Terminator) => Expression | null;
|
|
56
56
|
export type PostfixParseHandler = (parser: Parser, lhs: Expression) => Expression | null;
|
|
57
57
|
export type PrefixParseHandler = (parser: Parser, until: Terminator) => Expression | null;
|
|
58
58
|
export type InfixParseHandler = (parser: Parser, until: Terminator, lhs: Expression) => Expression | null;
|
|
59
59
|
export type MatchfixParseHandler = (parser: Parser, body: Expression) => Expression | null;
|
|
60
|
-
export type ParseHandler =
|
|
60
|
+
export type ParseHandler = IdentifierParseHandler | FunctionParseHandler | EnvironmentParseHandler | PostfixParseHandler | PrefixParseHandler | InfixParseHandler | MatchfixParseHandler;
|
|
61
61
|
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` */
|
|
62
62
|
/**
|
|
63
63
|
* Maps a string of LaTeX tokens to a function or symbol and vice-versa.
|
|
@@ -74,7 +74,7 @@ export type BaseEntry = {
|
|
|
74
74
|
* However, an entry with no `name` can be used to define a synonym (for example
|
|
75
75
|
* for the symbol `\varnothing` which is a synonym for `\emptyset`).
|
|
76
76
|
*
|
|
77
|
-
* If
|
|
77
|
+
* If no `parse` handler is provided, only the trigger is used to select this
|
|
78
78
|
* entry. Otherwise, if the trigger of the entry matches the current
|
|
79
79
|
* token, the `parse` handler is invoked.
|
|
80
80
|
*/
|
|
@@ -159,39 +159,26 @@ export type EnvironmentEntry = BaseEntry & {
|
|
|
159
159
|
kind: 'environment';
|
|
160
160
|
parse: EnvironmentParseHandler;
|
|
161
161
|
};
|
|
162
|
-
export type
|
|
163
|
-
kind: '
|
|
162
|
+
export type IdentifierEntry = BaseEntry & {
|
|
163
|
+
kind: 'identifier';
|
|
164
164
|
/** Used for appropriate wrapping (i.e. when to surround it with parens) */
|
|
165
165
|
precedence?: number;
|
|
166
|
-
parse: Expression |
|
|
166
|
+
parse: Expression | IdentifierParseHandler;
|
|
167
167
|
};
|
|
168
|
+
/**
|
|
169
|
+
* A function has the following form:
|
|
170
|
+
* - a prefix such as `\mathrm` or `\operatorname`
|
|
171
|
+
* - a trigger string, such as `gcd`
|
|
172
|
+
* - some postfix operators such as `\prime`
|
|
173
|
+
* - an optional list of arguments in an enclosure (parentheses)
|
|
174
|
+
*
|
|
175
|
+
* For more complex situations, for example implicit arguments or
|
|
176
|
+
* inverse functions postfix (i.e. ^{-1}), use a custom parse handler with a
|
|
177
|
+
* base entry.
|
|
178
|
+
*/
|
|
168
179
|
export type FunctionEntry = BaseEntry & {
|
|
169
180
|
kind: 'function';
|
|
170
|
-
|
|
171
|
-
* Indicate if this symbol can be followed by arguments.
|
|
172
|
-
*
|
|
173
|
-
* The presence of arguments will indicate that the arguments should be
|
|
174
|
-
* applied to the symbol. Otherwise, the invisible operator is applied
|
|
175
|
-
* to the symbol and the arguments.
|
|
176
|
-
*
|
|
177
|
-
* If `arguments` is `"group"`:
|
|
178
|
-
*
|
|
179
|
-
* "f(x)" -> `["f", "x"]`
|
|
180
|
-
* "f x" -> `["Multiply", "f", "x"]`
|
|
181
|
-
*
|
|
182
|
-
* If `arguments` is `""`:
|
|
183
|
-
*
|
|
184
|
-
* "f(x)" -> `["Multiply", "f", "x"]`
|
|
185
|
-
* "f x" -> `["Multiply", "f", "x"]`
|
|
186
|
-
*
|
|
187
|
-
* If `arguments` is `"implicit"` and the symbol is followed either
|
|
188
|
-
* by a group or by a primary (prefix + symbol + subsupfix + postfix).
|
|
189
|
-
* Used for trig functions. i.e. `\sin x` vs `\sin(x)`:
|
|
190
|
-
*
|
|
191
|
-
* "f(x)" -> `["f", "x"]`
|
|
192
|
-
* "f x" -> `["f", "x"]`
|
|
193
|
-
*
|
|
194
|
-
*/
|
|
181
|
+
trigger: string;
|
|
195
182
|
parse: Expression | FunctionParseHandler;
|
|
196
183
|
};
|
|
197
184
|
/**
|
|
@@ -199,11 +186,11 @@ export type FunctionEntry = BaseEntry & {
|
|
|
199
186
|
*/
|
|
200
187
|
export type DefaultEntry = BaseEntry & {
|
|
201
188
|
precedence?: number;
|
|
202
|
-
parse?: Expression |
|
|
189
|
+
parse?: Expression | IdentifierParseHandler;
|
|
203
190
|
};
|
|
204
|
-
export type LatexDictionaryEntry = DefaultEntry | MatchfixEntry | InfixEntry | PostfixEntry | PrefixEntry |
|
|
191
|
+
export type LatexDictionaryEntry = DefaultEntry | MatchfixEntry | InfixEntry | PostfixEntry | PrefixEntry | IdentifierEntry | FunctionEntry | EnvironmentEntry;
|
|
205
192
|
/** @internal */
|
|
206
|
-
export declare function
|
|
193
|
+
export declare function isIdentifierEntry(entry: LatexDictionaryEntry): entry is IdentifierEntry;
|
|
207
194
|
/** @internal */
|
|
208
195
|
export declare function isFunctionEntry(entry: LatexDictionaryEntry): entry is FunctionEntry;
|
|
209
196
|
/** @internal */
|
|
@@ -222,7 +209,8 @@ export type ParseLatexOptions = {
|
|
|
222
209
|
* This function is invoked when a number is followed by a symbol,
|
|
223
210
|
* an open delimiter or a function.
|
|
224
211
|
*
|
|
225
|
-
* If this function is set to `null`, the lhs and rhs are joined as a
|
|
212
|
+
* If this function is set to `null`, the lhs and rhs are joined as a
|
|
213
|
+
* `Sequence`.
|
|
226
214
|
*
|
|
227
215
|
* If this function is set to `undefined` it behaves in the following way:
|
|
228
216
|
* - a number followed by a numeric expression is considered as separated
|
|
@@ -236,7 +224,7 @@ export type ParseLatexOptions = {
|
|
|
236
224
|
*/
|
|
237
225
|
applyInvisibleOperator: 'auto' | null | ((parser: Parser, lhs: Expression, rhs: Expression) => Expression | null);
|
|
238
226
|
/**
|
|
239
|
-
* If true, ignore space characters.
|
|
227
|
+
* If true, ignore space characters in math mode.
|
|
240
228
|
*
|
|
241
229
|
* **Default**: `true`
|
|
242
230
|
*
|
|
@@ -261,22 +249,24 @@ export type ParseLatexOptions = {
|
|
|
261
249
|
*/
|
|
262
250
|
parseNumbers: boolean;
|
|
263
251
|
/**
|
|
264
|
-
* This handler is invoked when the parser
|
|
265
|
-
*
|
|
252
|
+
* This handler is invoked when the parser encounters an identifier
|
|
253
|
+
* that does not have a corresponding entry in the dictionary.
|
|
266
254
|
*
|
|
267
|
-
* The `
|
|
255
|
+
* The `identifier` argument is a valid identifier
|
|
256
|
+
* (see https://cortexjs.io/math-json/#identifiers for the definition of a
|
|
257
|
+
* valid identifier).
|
|
268
258
|
*
|
|
269
259
|
* The handler can return:
|
|
270
260
|
*
|
|
271
|
-
* - `symbol
|
|
261
|
+
* - `"symbol"`: the identifier is a constant or variable name.
|
|
272
262
|
*
|
|
273
|
-
* - `function
|
|
274
|
-
* function operator (typically, parentheses) follow,
|
|
275
|
-
* to the function.
|
|
263
|
+
* - `"function"`: the identifier is a function name. If an apply
|
|
264
|
+
* function operator (typically, parentheses) follow, they will be parsed
|
|
265
|
+
* as arguments to the function.
|
|
276
266
|
*
|
|
277
|
-
* - `
|
|
267
|
+
* - `"unknown"`: the identifier is not recognized.
|
|
278
268
|
*/
|
|
279
|
-
parseUnknownIdentifier: (
|
|
269
|
+
parseUnknownIdentifier: (identifier: string, parser: Parser) => 'symbol' | 'function' | 'unknown';
|
|
280
270
|
/**
|
|
281
271
|
* If true, the expression will be decorated with the LaTeX
|
|
282
272
|
* fragments corresponding to each elements of the expression.
|
|
@@ -454,7 +444,7 @@ export interface Parser {
|
|
|
454
444
|
/** Return the next token, without advancing the index */
|
|
455
445
|
readonly peek: LatexToken;
|
|
456
446
|
/** Return true if the terminator condition is met */
|
|
457
|
-
atTerminator(t: Terminator): boolean;
|
|
447
|
+
atTerminator(t: Terminator | undefined): boolean;
|
|
458
448
|
/** Return an array of string corresponding to tokens ahead.
|
|
459
449
|
* The index is unchanged.
|
|
460
450
|
*/
|
|
@@ -502,36 +492,42 @@ export interface Parser {
|
|
|
502
492
|
*/
|
|
503
493
|
matchTabular(endName: string): null | Expression[][];
|
|
504
494
|
applyInvisibleOperator(terminator: Terminator, lhs: Expression | null): Expression | null;
|
|
505
|
-
/**
|
|
506
|
-
*
|
|
507
|
-
* as an expression and advance the index past the closing `]`.
|
|
495
|
+
/** Some LaTeX commands (but not all) can accept an argument without braces,
|
|
496
|
+
* for example `^` , `\sqrt` or `\frac`.
|
|
508
497
|
*
|
|
509
|
-
*
|
|
498
|
+
* The following tokens are excluded from consideration to fail early when
|
|
499
|
+
* encountering a likely syntax error, for example `x^(2)` (instead of
|
|
500
|
+
* `x^{2}`). With `(` in the list of excluded tokens, the match will fail
|
|
501
|
+
* and the error can be recovered.
|
|
502
|
+
*
|
|
503
|
+
* The excluded tokens are `!"#$%&(),/;:?@[]`|~", `\left` and `\bigl`
|
|
510
504
|
*/
|
|
511
|
-
|
|
505
|
+
matchSingleAtomArgument(): Expression | null;
|
|
512
506
|
/**
|
|
513
|
-
* Match a required LaTeX argument:
|
|
514
|
-
* - either enclosed in `{}`
|
|
515
|
-
* - or a single token (except if token is in `excluding`)
|
|
516
507
|
*
|
|
517
|
-
*
|
|
518
|
-
* syntax error, for example `x^(2)` (instead of `x^{2}`). With `(` in the list
|
|
519
|
-
* of excluded tokens, the match will fail and the error can be recovered.
|
|
520
|
-
*
|
|
521
|
-
* If none is provided, `excluding` is `!"#$%&(),/;:?@[]`|~", `\left` and `\bigl`
|
|
508
|
+
* Match a LaTeX expression enclosed in `[]`
|
|
522
509
|
*
|
|
510
|
+
* Otherwise, return `null`.
|
|
511
|
+
*/
|
|
512
|
+
matchLatexOptionalGroup(): Expression | null;
|
|
513
|
+
/**
|
|
514
|
+
* Match a LaTeX group enclosed in `{}`
|
|
523
515
|
*
|
|
524
516
|
* Return null if no argument was found
|
|
525
517
|
* Return `['Sequence']` if an empty argument `{}` was found
|
|
526
518
|
*/
|
|
527
|
-
|
|
519
|
+
matchLatexGroup(): Expression | null;
|
|
528
520
|
/**
|
|
529
521
|
* - 'enclosure' : will look for an argument inside an enclosure (an open/close fence)
|
|
530
522
|
* - 'implicit': either an expression inside a pair of `()`, or just a primary
|
|
531
523
|
* (i.e. we interpret `\cos x + 1` as `\cos(x) + 1`)
|
|
532
524
|
*/
|
|
533
|
-
matchArguments(kind: '' | 'implicit' | 'enclosure'): Expression[] | null;
|
|
525
|
+
matchArguments(kind: '' | 'implicit' | 'enclosure', until?: Terminator): Expression[] | null;
|
|
534
526
|
matchStringArgument(): string | null;
|
|
527
|
+
matchPrimeSuffix(): number;
|
|
528
|
+
/** Parse function 'id' followed optionally by some prefix (primes, etc
|
|
529
|
+
* and an argument list in an enclosure. */
|
|
530
|
+
matchFunctionSuffix(id: string): Expression;
|
|
535
531
|
/** If matches the normalized open delimiter, returns the
|
|
536
532
|
* expected closing delimiter.
|
|
537
533
|
*
|
|
@@ -578,7 +574,7 @@ export interface Parser {
|
|
|
578
574
|
* - a single-letter variable: `x`
|
|
579
575
|
* - a single LaTeX command: `\pi`
|
|
580
576
|
*/
|
|
581
|
-
matchSymbol(): Expression | null;
|
|
577
|
+
matchSymbol(until?: Terminator): Expression | null;
|
|
582
578
|
/**
|
|
583
579
|
* Parse an expression:
|
|
584
580
|
*
|
|
@@ -597,6 +593,7 @@ export interface Parser {
|
|
|
597
593
|
* `until` is `{ minPrec:0 }` by default.
|
|
598
594
|
*/
|
|
599
595
|
matchExpression(until?: Partial<Terminator>): Expression | null;
|
|
596
|
+
latex(start: number, end?: number): string;
|
|
600
597
|
/** Return an error expression with the specified code and arguments */
|
|
601
598
|
error(code: string | [string, ...Expression[]], fromToken: number): Expression;
|
|
602
599
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.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';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
2
2
|
import { WarningSignalHandler } from '../../common/signals';
|
|
3
|
-
import { NumberFormattingOptions, LatexString, SerializeLatexOptions
|
|
4
|
-
import { IndexedLatexDictionary,
|
|
3
|
+
import { NumberFormattingOptions, LatexString, SerializeLatexOptions } from './public';
|
|
4
|
+
import { IndexedLatexDictionary, IndexedIdentifierEntry, IndexedFunctionEntry } from './dictionary/definitions';
|
|
5
5
|
export declare class Serializer {
|
|
6
6
|
readonly onError: WarningSignalHandler;
|
|
7
7
|
options: NumberFormattingOptions & SerializeLatexOptions;
|
|
@@ -15,14 +15,18 @@ export declare class Serializer {
|
|
|
15
15
|
* @todo: don't wrap Abs, Floor, Ceil, Delimiter
|
|
16
16
|
*/
|
|
17
17
|
wrap(expr: Expression | null, prec?: number): string;
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* If this is a "short" expression, wrap it.
|
|
20
|
+
* Do not wrap identifiers, positive numbers or functions.
|
|
21
|
+
*
|
|
22
|
+
* This is called by the serializer for power and division (i.e. "(a+1)/b")
|
|
19
23
|
*
|
|
20
24
|
*/
|
|
21
25
|
wrapShort(expr: Expression | null): string;
|
|
22
26
|
wrapString(s: string, style: 'paren' | 'leftright' | 'big' | 'none', fence?: string): string;
|
|
23
27
|
wrapArguments(expr: Expression): string;
|
|
24
|
-
serializeSymbol(expr: Expression, def?:
|
|
25
|
-
serializeFunction(expr: Expression, def?:
|
|
28
|
+
serializeSymbol(expr: Expression, def?: IndexedIdentifierEntry | IndexedFunctionEntry): string;
|
|
29
|
+
serializeFunction(expr: Expression, def?: IndexedFunctionEntry | IndexedIdentifierEntry): string;
|
|
26
30
|
serializeDictionary(dict: {
|
|
27
31
|
[key: string]: Expression;
|
|
28
32
|
}): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.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,6 @@ export 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 countTokens(s: string): number;
|
|
15
16
|
export declare function joinLatex(segments: Iterable<string>): string;
|
|
16
17
|
export declare function tokensToString(tokens: Token | Token[] | [Token[] | Token][]): string;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
2
2
|
/** The canonical form of `Add`:
|
|
3
3
|
* - removes `0`
|
|
4
4
|
* - capture complex numbers (a + ib or ai +b)
|
|
5
5
|
* */
|
|
6
6
|
export declare function canonicalAdd(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression;
|
|
7
7
|
export declare function domainAdd(_ce: IComputeEngine, args: BoxedDomain[]): BoxedDomain | null;
|
|
8
|
-
export declare function simplifyAdd(ce: IComputeEngine, args: BoxedExpression[]): BoxedExpression
|
|
8
|
+
export declare function simplifyAdd(ce: IComputeEngine, args: BoxedExpression[]): BoxedExpression;
|
|
9
9
|
export declare function evalAdd(ce: IComputeEngine, ops: BoxedExpression[], mode?: 'N' | 'evaluate'): BoxedExpression;
|
|
10
10
|
export declare function canonicalSummation(ce: IComputeEngine, body: BoxedExpression, range: BoxedExpression | undefined): BoxedExpression;
|
|
11
11
|
export declare function evalSummation(ce: IComputeEngine, expr: BoxedExpression, range: BoxedExpression, mode: 'simplify' | 'N' | 'evaluate'): BoxedExpression | undefined;
|
|
12
|
+
export declare function normalizeLimits(range: BoxedExpression): [string, number, number, boolean];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
2
2
|
/** The canonical form of `Multiply`:
|
|
3
3
|
* - remove `1`
|
|
4
4
|
* - combine literal integers and rationals
|
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
export declare function canonicalMultiply(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression;
|
|
15
15
|
export declare function simplifyMultiply(ce: IComputeEngine, ops: BoxedExpression[]): BoxedExpression;
|
|
16
16
|
export declare function evalMultiply(ce: IComputeEngine, ops: BoxedExpression[], mode?: 'N' | 'evaluate'): BoxedExpression | undefined;
|
|
17
|
-
export declare function
|
|
17
|
+
export declare function canonicalProduct(ce: IComputeEngine, body: BoxedExpression | undefined, range: BoxedExpression | undefined): BoxedExpression;
|
|
18
18
|
export declare function evalMultiplication(ce: IComputeEngine, expr: BoxedExpression, range: BoxedExpression, mode: 'simplify' | 'evaluate' | 'N'): BoxedExpression | undefined;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
2
2
|
export declare const ARITHMETIC_LIBRARY: IdTable[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
2
2
|
export declare const CALCULUS_LIBRARY: IdTable[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
2
2
|
export declare const COLLECTIONS_LIBRARY: IdTable;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
2
2
|
export declare const CORE_LIBRARY: IdTable[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
2
2
|
export declare const LOGIC_LIBRARY: IdTable;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
2
2
|
export declare const POLYNOMIALS_LIBRARY: IdTable[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
2
2
|
export declare function randomExpression(level?: number): Expression;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
2
2
|
export declare const RELOP_LIBRARY: IdTable;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
2
2
|
export declare const SETS_LIBRARY: IdTable;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
2
2
|
export declare const TRIGONOMETRY_LIBRARY: IdTable[];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
2
2
|
export declare function isSymbolDefinition(def: BoxedSymbolDefinition | BoxedFunctionDefinition | SymbolDefinition | FunctionDefinition | undefined | null): def is BoxedSymbolDefinition;
|
|
3
3
|
export declare function isFunctionDefinition(def: BoxedSymbolDefinition | BoxedFunctionDefinition | SymbolDefinition | FunctionDefinition | undefined | null): def is BoxedFunctionDefinition;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/* 0.12.
|
|
1
|
+
/* 0.12.4 */
|
|
2
2
|
export declare function isPrime(n: number): boolean | undefined;
|