/
kern.js
55 lines (52 loc) · 1.87 KB
/
kern.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//@flow
// Horizontal spacing commands
import defineFunction from "../defineFunction";
import buildCommon from "../buildCommon";
import mathMLTree from "../mathMLTree";
import {calculateSize} from "../units";
import {assertNodeType} from "../parseNode";
// TODO: \hskip and \mskip should support plus and minus in lengths
defineFunction({
type: "kern",
names: ["\\kern", "\\mkern", "\\hskip", "\\mskip"],
props: {
numArgs: 1,
argTypes: ["size"],
allowedInText: true,
},
handler({parser, funcName}, args) {
const size = assertNodeType(args[0], "size");
if (parser.settings.strict) {
const mathFunction = (funcName[1] === 'm'); // \mkern, \mskip
const muUnit = (size.value.unit === 'mu');
if (mathFunction) {
if (!muUnit) {
parser.settings.reportNonstrict("mathVsTextUnits",
`LaTeX's ${funcName} supports only mu units, ` +
`not ${size.value.unit} units`);
}
if (parser.mode !== "math") {
parser.settings.reportNonstrict("mathVsTextUnits",
`LaTeX's ${funcName} works only in math mode`);
}
} else { // !mathFunction
if (muUnit) {
parser.settings.reportNonstrict("mathVsTextUnits",
`LaTeX's ${funcName} doesn't support mu units`);
}
}
}
return {
type: "kern",
mode: parser.mode,
dimension: size.value,
};
},
htmlBuilder(group, options) {
return buildCommon.makeGlue(group.dimension, options);
},
mathmlBuilder(group, options) {
const dimension = calculateSize(group.dimension, options);
return new mathMLTree.SpaceNode(dimension);
},
});