MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / toExpression

Function toExpression

src/compute-engine/free-functions.ts:58–71  ·  view source on GitHub ↗

Convert a LatexString, Expression, or ExpressionInput to a boxed Expression. * Strings are parsed as LaTeX. Parsing defaults to non-strict so the free * functions accept the looser AsciiMath/Typst-like syntax documented for them * — bare function names and multi-letter identifiers (`sqrt(5)`,

(
  input: LatexString | ExpressionInput,
  options?: FreeFunctionOptions
)

Source from the content-addressed store, hash-verified

56 * `alpha`), and `**` for exponentiation — in addition to canonical LaTeX.
57 * Pass `{ strict: true }` to opt back into the strict LaTeX grammar. */
58function toExpression(
59 input: LatexString | ExpressionInput,
60 options?: FreeFunctionOptions
61): Expression {
62 if (typeof input === 'string') {
63 const ce = getDefaultEngine();
64 return (
65 ce.parse(input, { strict: options?.strict ?? false }) ??
66 ce.expr('Nothing')
67 );
68 }
69 if (isExpression(input)) return input;
70 return getDefaultEngine().expr(input);
71}
72
73export function parse(
74 latex: LatexString,

Callers 8

simplifyFunction · 0.85
evaluateFunction · 0.85
NFunction · 0.85
expandFunction · 0.85
solveFunction · 0.85
expandAllFunction · 0.85
factorFunction · 0.85
compileFunction · 0.85

Calls 4

isExpressionFunction · 0.90
getDefaultEngineFunction · 0.85
parseMethod · 0.65
exprMethod · 0.65

Tested by

no test coverage detected