UNPKG

1.5 kBJavaScriptView Raw
1// @flow
2import defineFunction, {ordargument} from "../defineFunction";
3import buildCommon from "../buildCommon";
4import Style from "../Style";
5
6import * as html from "../buildHTML";
7import * as mml from "../buildMathML";
8
9import type {ParseNode} from "../parseNode";
10
11const 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
21defineFunction({
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});