Fix the greediness of the \color function

Summary:
The greediness of the `\color` function wasn't set correctly,
leading to expressions like `\color{red}\text{a}` parsing correctly,
when they shouldn't. (This is based on how MathJax parses, since TeX
doesn't have a `\color` function, so MathJax is the standard).

Test Plan:
 - Make test
 - See that `\color{red}\text{a}` doesn't parse (like MathJax)
 - See that `\color{red}{\text{a}}` does parse (like MathJax)
 - See that `\color{red}\frac12` doesn't parse (like MathJax)
 - See that `\color{red}{\frac12}` does parse (like MathJax)
 - See that `\red\text{a}` doesn't parse (like MathJax)
 - See that `\red{\text{a}}` does parse (like MathJax)
 - See that `\red\frac12` doesn't parse (like MathJax)
 - See that `\red{\frac12}` does parse (like MathJax)

Reviewers: alpert

Reviewed By: alpert

Differential Revision: https://phabricator.khanacademy.org/D17130
This commit is contained in:
Emily Eisenberg 2015-04-01 15:29:04 -07:00
parent 379b98880d
commit 99a81aca50
2 changed files with 9 additions and 0 deletions

View File

@ -112,6 +112,7 @@ var functions = {
"\\color": {
numArgs: 2,
allowedInText: true,
greediness: 3,
argTypes: ["color", "original"],
handler: function(func, color, body) {
// Normalize the different kinds of bodies (see \text above)
@ -235,6 +236,7 @@ var duplicatedFunctions = [
data: {
numArgs: 1,
allowedInText: true,
greediness: 3,
handler: function(func, body) {
var atoms;
if (body.type === "ordgroup") {

View File

@ -676,6 +676,13 @@ describe("A color parser", function() {
it("should not parse a bad custom color", function() {
expect(badCustomColorExpression).toNotParse();
});
it("should have correct greediness", function() {
expect("\\color{red}a").toParse();
expect("\\color{red}{\\text{a}}").toParse();
expect("\\color{red}\\text{a}").toNotParse();
expect("\\color{red}\\frac12").toNotParse();
});
});
describe("A tie parser", function() {