forked from KaTeX/KaTeX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment.js
31 lines (30 loc) · 900 Bytes
/
environment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// @flow
import defineFunction from "../defineFunction";
import ParseError from "../ParseError";
import {assertNodeType} from "../parseNode";
// Environment delimiters. HTML/MathML rendering is defined in the corresponding
// defineEnvironment definitions.
defineFunction({
type: "environment",
names: ["\\begin", "\\end"],
props: {
numArgs: 1,
argTypes: ["text"],
},
handler({parser}, args) {
const nameGroup = args[0];
if (nameGroup.type !== "ordgroup") {
throw new ParseError("Invalid environment name", nameGroup);
}
let name = "";
for (let i = 0; i < nameGroup.body.length; ++i) {
name += assertNodeType(nameGroup.body[i], "textord").text;
}
return {
type: "environment",
mode: parser.mode,
name,
nameGroup,
};
},
});