1 |
|
2 |
|
3 |
|
4 | import {binrelClass} from "./mclass";
|
5 | import defineFunction from "../defineFunction";
|
6 |
|
7 | import * as html from "../buildHTML";
|
8 | import * as mml from "../buildMathML";
|
9 |
|
10 | import type {ParseNode} from "../parseNode";
|
11 |
|
12 | const htmlBuilder = (group: ParseNode<"font">, options) => {
|
13 | const font = group.font;
|
14 | const newOptions = options.withFont(font);
|
15 | return html.buildGroup(group.body, newOptions);
|
16 | };
|
17 |
|
18 | const mathmlBuilder = (group: ParseNode<"font">, options) => {
|
19 | const font = group.font;
|
20 | const newOptions = options.withFont(font);
|
21 | return mml.buildGroup(group.body, newOptions);
|
22 | };
|
23 |
|
24 | const fontAliases = {
|
25 | "\\Bbb": "\\mathbb",
|
26 | "\\bold": "\\mathbf",
|
27 | "\\frak": "\\mathfrak",
|
28 | "\\bm": "\\boldsymbol",
|
29 | };
|
30 |
|
31 | defineFunction({
|
32 | type: "font",
|
33 | names: [
|
34 |
|
35 | "\\mathrm", "\\mathit", "\\mathbf", "\\mathnormal",
|
36 |
|
37 |
|
38 | "\\mathbb", "\\mathcal", "\\mathfrak", "\\mathscr", "\\mathsf",
|
39 | "\\mathtt",
|
40 |
|
41 |
|
42 | "\\Bbb", "\\bold", "\\frak",
|
43 | ],
|
44 | props: {
|
45 | numArgs: 1,
|
46 | greediness: 2,
|
47 | },
|
48 | handler: ({parser, funcName}, args) => {
|
49 | const body = args[0];
|
50 | let func = funcName;
|
51 | if (func in fontAliases) {
|
52 | func = fontAliases[func];
|
53 | }
|
54 | return {
|
55 | type: "font",
|
56 | mode: parser.mode,
|
57 | font: func.slice(1),
|
58 | body,
|
59 | };
|
60 | },
|
61 | htmlBuilder,
|
62 | mathmlBuilder,
|
63 | });
|
64 |
|
65 | defineFunction({
|
66 | type: "mclass",
|
67 | names: ["\\boldsymbol", "\\bm"],
|
68 | props: {
|
69 | numArgs: 1,
|
70 | greediness: 2,
|
71 | },
|
72 | handler: ({parser}, args) => {
|
73 | const body = args[0];
|
74 |
|
75 |
|
76 | return {
|
77 | type: "mclass",
|
78 | mode: parser.mode,
|
79 | mclass: binrelClass(body),
|
80 | body: [
|
81 | {
|
82 | type: "font",
|
83 | mode: parser.mode,
|
84 | font: "boldsymbol",
|
85 | body,
|
86 | },
|
87 | ],
|
88 | };
|
89 | },
|
90 | });
|
91 |
|
92 |
|
93 | defineFunction({
|
94 | type: "font",
|
95 | names: ["\\rm", "\\sf", "\\tt", "\\bf", "\\it"],
|
96 | props: {
|
97 | numArgs: 0,
|
98 | allowedInText: true,
|
99 | },
|
100 | handler: ({parser, funcName, breakOnTokenText}, args) => {
|
101 | const {mode} = parser;
|
102 | const body = parser.parseExpression(true, breakOnTokenText);
|
103 | const style = `math${funcName.slice(1)}`;
|
104 |
|
105 | return {
|
106 | type: "font",
|
107 | mode: mode,
|
108 | font: style,
|
109 | body: {
|
110 | type: "ordgroup",
|
111 | mode: parser.mode,
|
112 | body,
|
113 | },
|
114 | };
|
115 | },
|
116 | htmlBuilder,
|
117 | mathmlBuilder,
|
118 | });
|