mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-10 05:28:41 +00:00
Add accents
Summary: Add support for math-mode accents. This involves a couple changes. First, in order to correctly position the accents, we must know the kern between every character and the "skewchar" in that font. To do this, we improve our tfm parser to run the mini-kern-language and calculate kerns. We then export these into fontMetrics.js. Then, we add normal support for accents. In particular, we do some special handling for supsubs around accents. This involves building the supsub separately without the accent, and then replacing its base with the built accent. Finally, the character in the fonts for the \vec command is a combining unicode character, so it is shifted to the left, but none of the other characters do this. We add some special handling for \vec to account for this. Fixes #7 Test Plan: - Make sure tests pass - Make sure no huxley screenshots changed, and the new one looks good Reviewers: alpert Reviewed By: alpert Differential Revision: http://phabricator.khanacademy.org/D13157
This commit is contained in:
BIN
test/huxley/Accents.hux/firefox-1.png
Normal file
BIN
test/huxley/Accents.hux/firefox-1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
5
test/huxley/Accents.hux/record.json
Normal file
5
test/huxley/Accents.hux/record.json
Normal file
@@ -0,0 +1,5 @@
|
||||
[
|
||||
{
|
||||
"action": "screenshot"
|
||||
}
|
||||
]
|
@@ -183,5 +183,11 @@
|
||||
"name": "SupSubOffsets",
|
||||
"screenSize": [1024, 768],
|
||||
"url": "http://localhost:7936/test/huxley/test.html?m=\\displaystyle \\int_{2+3}x f^{2+3}+3\\lim_{2+3+4+5}f"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "Accents",
|
||||
"screenSize": [1024, 768],
|
||||
"url": "http://localhost:7936/test/huxley/test.html?m=\\vec{A}\\vec{x}\\vec x^2\\vec{x}_2^2\\vec{A}^2\\vec{xA}^2"
|
||||
}
|
||||
]
|
||||
|
@@ -998,3 +998,45 @@ describe("A markup generator", function() {
|
||||
expect(markup).not.toContain("marginRight");
|
||||
});
|
||||
});
|
||||
|
||||
describe("An accent parser", function() {
|
||||
it("should not fail", function() {
|
||||
expect("\\vec{x}").toParse();
|
||||
expect("\\vec{x^2}").toParse();
|
||||
expect("\\vec{x}^2").toParse();
|
||||
expect("\\vec x").toParse();
|
||||
});
|
||||
|
||||
it("should produce accents", function() {
|
||||
var parse = parseTree("\\vec x")[0];
|
||||
|
||||
expect(parse.type).toMatch("accent");
|
||||
});
|
||||
|
||||
it("should be grouped more tightly than supsubs", function() {
|
||||
var parse = parseTree("\\vec x^2")[0];
|
||||
|
||||
expect(parse.type).toMatch("supsub");
|
||||
});
|
||||
|
||||
it("should not parse expanding accents", function() {
|
||||
expect("\\widehat{x}").toNotParse();
|
||||
});
|
||||
});
|
||||
|
||||
describe("An accent builder", function() {
|
||||
it("should not fail", function() {
|
||||
expect("\\vec{x}").toBuild();
|
||||
expect("\\vec{x}^2").toBuild();
|
||||
expect("\\vec{x}_2").toBuild();
|
||||
expect("\\vec{x}_2^2").toBuild();
|
||||
});
|
||||
|
||||
it("should produce mords", function() {
|
||||
expect(getBuilt("\\vec x")[0].classes).toContain("mord");
|
||||
expect(getBuilt("\\vec +")[0].classes).toContain("mord");
|
||||
expect(getBuilt("\\vec +")[0].classes).not.toContain("mbin");
|
||||
expect(getBuilt("\\vec )^2")[0].classes).toContain("mord");
|
||||
expect(getBuilt("\\vec )^2")[0].classes).not.toContain("mclose");
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user