Add \choose support

Test Plan: Looked at `1 + 2\choose {3 \over 4}`, npm tested.

Reviewers: emily

Reviewed By: emily

Differential Revision: http://phabricator.khanacademy.org/D13903
This commit is contained in:
Ben Alpert 2014-10-15 16:05:58 -07:00
parent 006a0a761c
commit 2cbee18010
2 changed files with 28 additions and 10 deletions

View File

@ -164,16 +164,6 @@ var functions = {
type: "katex"
};
}
},
"\\over": {
numArgs: 0,
handler: function (func) {
return {
type: "infix",
replaceWith: "\\frac"
};
}
}
};
@ -477,6 +467,31 @@ var duplicatedFunctions = [
};
}
}
},
// Infix generalized fractions
{
funcs: ["\\over", "\\choose"],
data: {
numArgs: 0,
handler: function (func) {
var replaceWith;
switch (func) {
case "\\over":
replaceWith = "\\frac";
break;
case "\\choose":
replaceWith = "\\binom";
break;
default:
throw new Error("Unrecognized infix genfrac command");
}
return {
type: "infix",
replaceWith: replaceWith
};
}
}
}
];

View File

@ -559,6 +559,9 @@ describe("An over parser", function() {
it("should fail with multiple overs in the same group", function () {
var badMultipleOvers = "1 \\over 2 + 3 \\over 4";
expect(badMultipleOvers).toNotParse();
var badOverChoose = "1 \\over 2 \\choose 3";
expect(badOverChoose).toNotParse();
});
});