UNPKG

1.92 kBJavaScriptView Raw
1//@flow
2// Horizontal spacing commands
3
4import defineFunction from "../defineFunction";
5import buildCommon from "../buildCommon";
6import mathMLTree from "../mathMLTree";
7import {calculateSize} from "../units";
8import {assertNodeType} from "../parseNode";
9
10// TODO: \hskip and \mskip should support plus and minus in lengths
11
12defineFunction({
13 type: "kern",
14 names: ["\\kern", "\\mkern", "\\hskip", "\\mskip"],
15 props: {
16 numArgs: 1,
17 argTypes: ["size"],
18 allowedInText: true,
19 },
20 handler({parser, funcName}, args) {
21 const size = assertNodeType(args[0], "size");
22 if (parser.settings.strict) {
23 const mathFunction = (funcName[1] === 'm'); // \mkern, \mskip
24 const muUnit = (size.value.unit === 'mu');
25 if (mathFunction) {
26 if (!muUnit) {
27 parser.settings.reportNonstrict("mathVsTextUnits",
28 `LaTeX's ${funcName} supports only mu units, ` +
29 `not ${size.value.unit} units`);
30 }
31 if (parser.mode !== "math") {
32 parser.settings.reportNonstrict("mathVsTextUnits",
33 `LaTeX's ${funcName} works only in math mode`);
34 }
35 } else { // !mathFunction
36 if (muUnit) {
37 parser.settings.reportNonstrict("mathVsTextUnits",
38 `LaTeX's ${funcName} doesn't support mu units`);
39 }
40 }
41 }
42 return {
43 type: "kern",
44 mode: parser.mode,
45 dimension: size.value,
46 };
47 },
48 htmlBuilder(group, options) {
49 return buildCommon.makeGlue(group.dimension, options);
50 },
51 mathmlBuilder(group, options) {
52 const dimension = calculateSize(group.dimension, options);
53 return new mathMLTree.SpaceNode(dimension);
54 },
55});