1 |
|
2 |
|
3 |
|
4 | import defineFunction from "../defineFunction";
|
5 | import buildCommon from "../buildCommon";
|
6 | import mathMLTree from "../mathMLTree";
|
7 | import {calculateSize} from "../units";
|
8 | import ParseError from "../ParseError";
|
9 | import {assertNodeType} from "../parseNode";
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | defineFunction({
|
17 | type: "cr",
|
18 | names: ["\\cr", "\\newline"],
|
19 | props: {
|
20 | numArgs: 0,
|
21 | numOptionalArgs: 1,
|
22 | argTypes: ["size"],
|
23 | allowedInText: true,
|
24 | },
|
25 |
|
26 | handler({parser, funcName}, args, optArgs) {
|
27 | const size = optArgs[0];
|
28 | const newRow = (funcName === "\\cr");
|
29 | let newLine = false;
|
30 | if (!newRow) {
|
31 | if (parser.settings.displayMode &&
|
32 | parser.settings.useStrictBehavior(
|
33 | "newLineInDisplayMode", "In LaTeX, \\\\ or \\newline " +
|
34 | "does nothing in display mode")) {
|
35 | newLine = false;
|
36 | } else {
|
37 | newLine = true;
|
38 | }
|
39 | }
|
40 | return {
|
41 | type: "cr",
|
42 | mode: parser.mode,
|
43 | newLine,
|
44 | newRow,
|
45 | size: size && assertNodeType(size, "size").value,
|
46 | };
|
47 | },
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | htmlBuilder(group, options) {
|
53 | if (group.newRow) {
|
54 | throw new ParseError(
|
55 | "\\cr valid only within a tabular/array environment");
|
56 | }
|
57 | const span = buildCommon.makeSpan(["mspace"], [], options);
|
58 | if (group.newLine) {
|
59 | span.classes.push("newline");
|
60 | if (group.size) {
|
61 | span.style.marginTop =
|
62 | calculateSize(group.size, options) + "em";
|
63 | }
|
64 | }
|
65 | return span;
|
66 | },
|
67 |
|
68 | mathmlBuilder(group, options) {
|
69 | const node = new mathMLTree.MathNode("mspace");
|
70 | if (group.newLine) {
|
71 | node.setAttribute("linebreak", "newline");
|
72 | if (group.size) {
|
73 | node.setAttribute("height",
|
74 | calculateSize(group.size, options) + "em");
|
75 | }
|
76 | }
|
77 | return node;
|
78 | },
|
79 | });
|