1 |
|
2 | import defineFunction, {ordargument} from "../defineFunction";
|
3 | import buildCommon from "../buildCommon";
|
4 | import Style from "../Style";
|
5 |
|
6 | import * as html from "../buildHTML";
|
7 | import * as mml from "../buildMathML";
|
8 |
|
9 | import type {ParseNode} from "../parseNode";
|
10 |
|
11 | const chooseMathStyle = (group: ParseNode<"mathchoice">, options) => {
|
12 | switch (options.style.size) {
|
13 | case Style.DISPLAY.size: return group.display;
|
14 | case Style.TEXT.size: return group.text;
|
15 | case Style.SCRIPT.size: return group.script;
|
16 | case Style.SCRIPTSCRIPT.size: return group.scriptscript;
|
17 | default: return group.text;
|
18 | }
|
19 | };
|
20 |
|
21 | defineFunction({
|
22 | type: "mathchoice",
|
23 | names: ["\\mathchoice"],
|
24 | props: {
|
25 | numArgs: 4,
|
26 | },
|
27 | handler: ({parser}, args) => {
|
28 | return {
|
29 | type: "mathchoice",
|
30 | mode: parser.mode,
|
31 | display: ordargument(args[0]),
|
32 | text: ordargument(args[1]),
|
33 | script: ordargument(args[2]),
|
34 | scriptscript: ordargument(args[3]),
|
35 | };
|
36 | },
|
37 | htmlBuilder: (group, options) => {
|
38 | const body = chooseMathStyle(group, options);
|
39 | const elements = html.buildExpression(
|
40 | body,
|
41 | options,
|
42 | false
|
43 | );
|
44 | return buildCommon.makeFragment(elements);
|
45 | },
|
46 | mathmlBuilder: (group, options) => {
|
47 | const body = chooseMathStyle(group, options);
|
48 | return mml.buildExpressionRow(body, options);
|
49 | },
|
50 | });
|