1 |
|
2 | import defineFunction from "../defineFunction";
|
3 | import mathMLTree from "../mathMLTree";
|
4 | import Style from "../Style";
|
5 | import {sizingGroup} from "./sizing";
|
6 |
|
7 | import * as mml from "../buildMathML";
|
8 |
|
9 | const styleMap = {
|
10 | "display": Style.DISPLAY,
|
11 | "text": Style.TEXT,
|
12 | "script": Style.SCRIPT,
|
13 | "scriptscript": Style.SCRIPTSCRIPT,
|
14 | };
|
15 |
|
16 | defineFunction({
|
17 | type: "styling",
|
18 | names: [
|
19 | "\\displaystyle", "\\textstyle", "\\scriptstyle",
|
20 | "\\scriptscriptstyle",
|
21 | ],
|
22 | props: {
|
23 | numArgs: 0,
|
24 | allowedInText: true,
|
25 | },
|
26 | handler({breakOnTokenText, funcName, parser}, args) {
|
27 |
|
28 | const body = parser.parseExpression(true, breakOnTokenText);
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | const style: StyleStr = funcName.slice(1, funcName.length - 5);
|
34 | return {
|
35 | type: "styling",
|
36 | mode: parser.mode,
|
37 |
|
38 |
|
39 | style,
|
40 | body,
|
41 | };
|
42 | },
|
43 | htmlBuilder(group, options) {
|
44 |
|
45 | const newStyle = styleMap[group.style];
|
46 | const newOptions = options.havingStyle(newStyle).withFont('');
|
47 | return sizingGroup(group.body, newOptions, options);
|
48 | },
|
49 | mathmlBuilder(group, options) {
|
50 |
|
51 |
|
52 |
|
53 | const styleMap = {
|
54 | "display": Style.DISPLAY,
|
55 | "text": Style.TEXT,
|
56 | "script": Style.SCRIPT,
|
57 | "scriptscript": Style.SCRIPTSCRIPT,
|
58 | };
|
59 |
|
60 | const newStyle = styleMap[group.style];
|
61 | const newOptions = options.havingStyle(newStyle);
|
62 |
|
63 | const inner = mml.buildExpression(group.body, newOptions);
|
64 |
|
65 | const node = new mathMLTree.MathNode("mstyle", inner);
|
66 |
|
67 | const styleAttributes = {
|
68 | "display": ["0", "true"],
|
69 | "text": ["0", "false"],
|
70 | "script": ["1", "false"],
|
71 | "scriptscript": ["2", "false"],
|
72 | };
|
73 |
|
74 | const attr = styleAttributes[group.style];
|
75 |
|
76 | node.setAttribute("scriptlevel", attr[0]);
|
77 | node.setAttribute("displaystyle", attr[1]);
|
78 |
|
79 | return node;
|
80 | },
|
81 | });
|