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:
parent
c79fb58936
commit
3083efba66
|
@ -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;
|
||||
|
|
|
@ -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)]);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -909,6 +909,31 @@ describe("A rule parser", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe("A kern parser", function() {
|
||||
var emKern = "\\kern{1em}";
|
||||
var exKern = "\\kern{1ex}";
|
||||
var badUnitRule = "\\kern{1px}";
|
||||
var noNumberRule = "\\kern{em}";
|
||||
|
||||
it("should list the correct units", function() {
|
||||
var emParse = getParsed(emKern)[0];
|
||||
var exParse = getParsed(exKern)[0];
|
||||
|
||||
expect(emParse.value.dimension.unit).toEqual("em");
|
||||
expect(exParse.value.dimension.unit).toEqual("ex");
|
||||
});
|
||||
|
||||
it("should not parse invalid units", function() {
|
||||
expect(badUnitRule).toNotParse();
|
||||
expect(noNumberRule).toNotParse();
|
||||
});
|
||||
|
||||
it("should parse negative sizes", function() {
|
||||
var parse = getParsed("\\kern{-1em}")[0];
|
||||
expect(parse.value.dimension.number).toBeCloseTo(-1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("A left/right parser", function() {
|
||||
var normalLeftRight = "\\left( \\dfrac{x}{y} \\right)";
|
||||
var emptyRight = "\\left( \\dfrac{x}{y} \\right.";
|
||||
|
|
BIN
test/screenshotter/images/Kern-chrome.png
Normal file
BIN
test/screenshotter/images/Kern-chrome.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.2 KiB |
BIN
test/screenshotter/images/Kern-firefox.png
Normal file
BIN
test/screenshotter/images/Kern-firefox.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.2 KiB |
|
@ -58,6 +58,7 @@ FractionTest: \dfrac{a}{b}\frac{a}{b}\tfrac{a}{b}\;-\dfrac12\;1\tfrac12
|
|||
Functions: \sin\cos\tan\ln\log
|
||||
GreekLetters: \alpha\beta\gamma\omega
|
||||
KaTeX: \KaTeX
|
||||
Kern: \frac{a\kern{1em}b}{c}a\kern{1em}b\kern{1ex}c\kern{-0.25em}d
|
||||
Lap: ab\llap{f}cd\rlap{g}h
|
||||
LeftRight: \left( x^2 \right) \left\{ x^{x^{x^{x^x}}} \right.
|
||||
LeftRightListStyling: a+\left(x+y\right)-x
|
||||
|
|
Loading…
Reference in New Issue
Block a user