diff --git a/src/functions.js b/src/functions.js index aa8b8eb..5bdbe02 100644 --- a/src/functions.js +++ b/src/functions.js @@ -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") { diff --git a/test/katex-spec.js b/test/katex-spec.js index 2042db9..e89ccdc 100644 --- a/test/katex-spec.js +++ b/test/katex-spec.js @@ -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() {