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:
Emily Eisenberg
2014-03-26 22:17:41 -04:00
parent 2eca338e23
commit 7723d3dcaf
8 changed files with 785 additions and 626 deletions

View File

@@ -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

View 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}]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -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");
});
});