A world-class math input for the web
1import { CaretParselet } from "@caret-js/core";
2import { DecimalParselet } from "./parselets/decimal";
3import { UnaryMinusParselet } from "./parselets/unaryMinus";
4import { SubSupParselet } from "./parselets/subsup";
5import { ParenthesesParselet } from "./parselets/parentheses";
6import { FractionParselet } from "./parselets/fraction";
7import { VariableParselet } from "./parselets/variable";
8import { MultiplyParselet } from "./parselets/multiply";
9import { AddParselet } from "./parselets/add";
10import { SubtractParselet } from "./parselets/subtract";
11import { CommaListParselet } from "./parselets/commaList";
12import { EquationParselet } from "./parselets/equation";
13import { AdjacentMultiplicationParselet } from "./parselets/adjacentMultiplication";
14import { FunctionCallParselet } from "./parselets/functionCall";
15import { UnaryPlusParselet } from "./parselets/unaryPlus";
16import { RadicalParselet } from "./parselets/radical";
17
18/**
19 * The default parselet configuration for mathematical expressions.
20 */
21export function defaultParselets(
22 options: { funcNames?: Set<string> } = {}
23): (CaretParselet | Set<CaretParselet>)[] {
24 return [
25 new Set([
26 new DecimalParselet(),
27 new VariableParselet(),
28 new ParenthesesParselet(),
29 new FractionParselet(),
30 new RadicalParselet(),
31 ]),
32 new SubSupParselet(),
33 new FunctionCallParselet(
34 options.funcNames ?? new Set<string>(["f", "g", "h"])
35 ),
36 new Set([new MultiplyParselet(), new AdjacentMultiplicationParselet()]),
37 new Set([new UnaryMinusParselet(), new UnaryPlusParselet()]),
38 new Set([new SubtractParselet(), new AddParselet()]),
39 new Set([new CommaListParselet()]),
40 new Set([new EquationParselet()]),
41 ];
42}