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 )
| 56 | * `alpha`), and `**` for exponentiation — in addition to canonical LaTeX. |
| 57 | * Pass `{ strict: true }` to opt back into the strict LaTeX grammar. */ |
| 58 | function 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 | |
| 73 | export function parse( |
| 74 | latex: LatexString, |
no test coverage detected