mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-06 11:48:41 +00:00
First attempt at \text
function
Summary: Make all of the parsing functions keep track of whether they are parsing in math mode or text mode. Then, add a separate lexing function to lex text mode, which is different than the normal mode because it does weird things with spacing and allows a different set of characters. Test Plan: - See that the normal tests work - See that the huxley screenshot looks reasonable - See that none of the other huxley screenshots changed Reviewers: alpert Reviewed By: alpert Differential Revision: http://phabricator.khanacademy.org/D7578
This commit is contained in:
@@ -34,5 +34,8 @@ url=http://localhost:7936/test/huxley/test.html?m=\Huge{x}\LARGE{y}\normalsize{z
|
||||
[SizingBaseline]
|
||||
url=http://localhost:7936/test/huxley/test.html?m=\tiny{a+b}a+b\Huge{a+b}&pre=x&post=M
|
||||
|
||||
[Text]
|
||||
url=http://localhost:7936/test/huxley/test.html?m=\frac{a}{b}\text{c {ab} \ e}+fg
|
||||
|
||||
[KaTeX]
|
||||
url=http://localhost:7936/test/huxley/test.html?m=\KaTeX
|
||||
url=http://localhost:7936/test/huxley/test.html?m=\KaTeX
|
||||
|
1
test/huxley/Text.huxley/record.json
Normal file
1
test/huxley/Text.huxley/record.json
Normal file
@@ -0,0 +1 @@
|
||||
{"py/object": "huxley.run.Test", "screen_size": {"py/tuple": [1024, 768]}, "steps": [{"py/object": "huxley.steps.ScreenshotTestStep", "index": 0, "offset_time": 0}]}
|
BIN
test/huxley/Text.huxley/screenshot0.png
Normal file
BIN
test/huxley/Text.huxley/screenshot0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
@@ -447,3 +447,52 @@ describe("A sizing parser", function() {
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("A text parser", function() {
|
||||
var textExpression = "\\text{a b}";
|
||||
var badTextExpression = "\\text{a b%}";
|
||||
var nestedTextExpression = "\\text{a {b} \\blue{c}}";
|
||||
var spaceTextExpression = "\\text{ a \\ }";
|
||||
|
||||
it("should not fail", function() {
|
||||
expect(function() {
|
||||
parseTree(textExpression);
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it("should produce a text", function() {
|
||||
var parse = parseTree(textExpression)[0];
|
||||
|
||||
expect(parse.type).toMatch("text");
|
||||
expect(parse.value).toBeDefined();
|
||||
});
|
||||
|
||||
it("should produce textords instead of mathords", function() {
|
||||
var parse = parseTree(textExpression)[0];
|
||||
var group = parse.value.value;
|
||||
|
||||
expect(group[0].type).toMatch("textord");
|
||||
});
|
||||
|
||||
it("should not parse bad text", function() {
|
||||
expect(function() {
|
||||
parseTree(badTextExpression);
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it("should parse nested expressions", function() {
|
||||
expect(function() {
|
||||
parseTree(nestedTextExpression);
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it("should contract spaces", function() {
|
||||
var parse = parseTree(spaceTextExpression)[0];
|
||||
var group = parse.value.value;
|
||||
|
||||
expect(group[0].type).toMatch("spacing");
|
||||
expect(group[1].type).toMatch("textord");
|
||||
expect(group[2].type).toMatch("spacing");
|
||||
expect(group[3].type).toMatch("spacing");
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user