1 |
|
2 | import defineFunction from "../defineFunction";
|
3 | import ParseError from "../ParseError";
|
4 |
|
5 |
|
6 | defineFunction({
|
7 | type: "styling",
|
8 | names: ["\\(", "$"],
|
9 | props: {
|
10 | numArgs: 0,
|
11 | allowedInText: true,
|
12 | allowedInMath: false,
|
13 | consumeMode: "math",
|
14 | },
|
15 | handler({funcName, parser}, args) {
|
16 | const outerMode = parser.mode;
|
17 | parser.switchMode("math");
|
18 | const close = (funcName === "\\(" ? "\\)" : "$");
|
19 | const body = parser.parseExpression(false, close);
|
20 |
|
21 |
|
22 | parser.expect(close, false);
|
23 | parser.switchMode(outerMode);
|
24 | parser.consume();
|
25 | return {
|
26 | type: "styling",
|
27 | mode: parser.mode,
|
28 | style: "text",
|
29 | body,
|
30 | };
|
31 | },
|
32 | });
|
33 |
|
34 |
|
35 | defineFunction({
|
36 | type: "text",
|
37 | names: ["\\)", "\\]"],
|
38 | props: {
|
39 | numArgs: 0,
|
40 | allowedInText: true,
|
41 | allowedInMath: false,
|
42 | },
|
43 | handler(context, args) {
|
44 | throw new ParseError(`Mismatched ${context.funcName}`);
|
45 | },
|
46 | });
|