Add tie symbol (~)
Summary: Add real support for the tie symbol. Also, get rid of any of the leftover bad support Test Plan: - See the new normal tests succeed - See huxley tests didn't change except the new ones, which looks good Reviewers: alpert Reviewed By: alpert Differential Revision: http://phabricator.khanacademy.org/D7772
This commit is contained in:
parent
d729ba5281
commit
4154c370ec
6
Lexer.js
6
Lexer.js
|
@ -25,13 +25,15 @@ var mathNormals = [
|
|||
[/^{/, "{"],
|
||||
[/^}/, "}"],
|
||||
[/^[(\[]/, "open"],
|
||||
[/^[)\]?!]/, "close"]
|
||||
[/^[)\]?!]/, "close"],
|
||||
[/^~/, "spacing"]
|
||||
];
|
||||
|
||||
var textNormals = [
|
||||
[/^[a-zA-Z0-9`!@*()-=+\[\]'";:?\/.,]/, "textord"],
|
||||
[/^{/, "{"],
|
||||
[/^}/, "}"]
|
||||
[/^}/, "}"],
|
||||
[/^~/, "spacing"]
|
||||
];
|
||||
|
||||
// Build a regex to easily parse the functions
|
||||
|
|
|
@ -317,13 +317,11 @@ var groupTypes = {
|
|||
|
||||
spacing: function(group, options, prev) {
|
||||
if (group.value === "\\ " || group.value === "\\space" ||
|
||||
group.value === " ") {
|
||||
group.value === " " || group.value === "~") {
|
||||
return makeSpan(
|
||||
["mord", "mspace"],
|
||||
[mathrm(group.value, group.mode)]
|
||||
);
|
||||
} else if(group.value === "~") {
|
||||
return makeSpan(["mord", "mspace"], [mathrm(" ", group.mode)]);
|
||||
} else {
|
||||
var spacingClassMap = {
|
||||
"\\qquad": "qquad",
|
||||
|
|
10
symbols.js
10
symbols.js
|
@ -437,6 +437,11 @@ var symbols = {
|
|||
group: "spacing",
|
||||
replace: "\u00a0"
|
||||
},
|
||||
"~": {
|
||||
font: "main",
|
||||
group: "spacing",
|
||||
replace: "\u00a0"
|
||||
},
|
||||
"\\,": {
|
||||
font: "main",
|
||||
group: "spacing"
|
||||
|
@ -565,6 +570,11 @@ var symbols = {
|
|||
font: "main",
|
||||
group: "spacing",
|
||||
replace: "\u00a0"
|
||||
},
|
||||
"~": {
|
||||
font: "main",
|
||||
group: "spacing",
|
||||
replace: "\u00a0"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -20,7 +20,7 @@ url=http://localhost:7936/test/huxley/test.html?m=\alpha\beta\gamma\omega
|
|||
url=http://localhost:7936/test/huxley/test.html?m=a+b-c\cdot d/e
|
||||
|
||||
[Spacing]
|
||||
url=http://localhost:7936/test/huxley/test.html?m=[-1][1-1]1%%3D1(%%3D1)\lvert a\rvert
|
||||
url=http://localhost:7936/test/huxley/test.html?m=[-1][1-1]1%%3D1(%%3D1)\lvert a\rvert~b
|
||||
|
||||
[Functions]
|
||||
url=http://localhost:7936/test/huxley/test.html?m=\sin\cos\tan\ln\log
|
||||
|
@ -35,7 +35,7 @@ url=http://localhost:7936/test/huxley/test.html?m=\Huge{x}\LARGE{y}\normalsize{z
|
|||
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
|
||||
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
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 12 KiB |
Binary file not shown.
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
@ -534,3 +534,40 @@ describe("A color parser", function() {
|
|||
}).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe("A tie parser", function() {
|
||||
var mathTie = "a~b";
|
||||
var textTie = "\\text{a~ b}";
|
||||
|
||||
it("should parse ties in math mode", function() {
|
||||
expect(function() {
|
||||
parseTree(mathTie);
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it("should parse ties in text mode", function() {
|
||||
expect(function() {
|
||||
parseTree(textTie);
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it("should produce spacing in math mode", function() {
|
||||
var parse = parseTree(mathTie);
|
||||
|
||||
expect(parse[1].type).toMatch("spacing");
|
||||
});
|
||||
|
||||
it("should produce spacing in text mode", function() {
|
||||
var text = parseTree(textTie)[0];
|
||||
var parse = text.value.value;
|
||||
|
||||
expect(parse[1].type).toMatch("spacing");
|
||||
});
|
||||
|
||||
it("should not contract with spaces in text mode", function() {
|
||||
var text = parseTree(textTie)[0];
|
||||
var parse = text.value.value;
|
||||
|
||||
expect(parse[2].type).toMatch("spacing");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user