Add support for \kern

Summary:
This only supports em and ex units and doesn't handle vertical layouts.
Negative kerning works.

Test Plan:
- make test
- make screenshots (verify that d is slightly overlapping c in the screenshots)

Reviewers: emily
This commit is contained in:
Kevin Barabash
2015-12-30 16:58:50 -08:00
parent c79fb58936
commit 3083efba66
7 changed files with 62 additions and 0 deletions

View File

@@ -1178,6 +1178,25 @@ groupTypes.rule = function(group, options, prev) {
return rule;
};
groupTypes.kern = function(group, options, prev) {
// Make an empty span for the rule
var rule = makeSpan(["mord", "rule"], [], options.getColor());
var dimension = 0;
if (group.value.dimension) {
dimension = group.value.dimension.number;
if (group.value.dimension.unit === "ex") {
dimension *= fontMetrics.metrics.xHeight;
}
}
dimension /= options.style.sizeMultiplier;
rule.style.marginLeft = dimension + "em";
return rule;
};
groupTypes.accent = function(group, options, prev) {
// Accents are handled in the TeXbook pg. 443, rule 12.
var base = group.value.base;

View File

@@ -430,6 +430,13 @@ groupTypes.rule = function(group) {
return node;
};
groupTypes.kern = function(group) {
// TODO(kevin): Figure out if there's a way to add space in MathML
var node = new mathMLTree.MathNode("mrow");
return node;
};
groupTypes.llap = function(group, options) {
var node = new mathMLTree.MathNode(
"mpadded", [buildGroup(group.value.body, options)]);

View File

@@ -187,6 +187,16 @@ defineFunction("\\rule", {
};
});
defineFunction("\\kern", {
numArgs: 1,
argTypes: ["size"],
}, function(context, args) {
return {
type: "kern",
dimension: args[0].value,
};
});
// A KaTeX logo
defineFunction("\\KaTeX", {
numArgs: 0,