feat(function): add allowedInArgument instead of greediness property (#2134)

* Remove `greediness` property

Use boolean `grouped` property instead, which is more consistent with 
LaTeX.

BREAKING CHANGE: \cfrac, \color, \textcolor, \colorbox, \fcolorbox are 
no longer grouped.

* Rename grouped to allowedInArgument

* Reenable tests

* Update documentation

* Fix typo

Co-authored-by: Kevin Barabash <kevinb@khanacademy.org>
This commit is contained in:
ylemkimon
2020-09-07 13:38:17 +09:00
committed by GitHub
parent 37990cc5b3
commit 5a90558116
10 changed files with 53 additions and 61 deletions

View File

@@ -241,14 +241,14 @@ const mathmlBuilder = (group, options) => {
defineFunction({
type: "genfrac",
names: [
"\\cfrac", "\\dfrac", "\\frac", "\\tfrac",
"\\dfrac", "\\frac", "\\tfrac",
"\\dbinom", "\\binom", "\\tbinom",
"\\\\atopfrac", // cant be entered directly
"\\\\bracefrac", "\\\\brackfrac", // ditto
],
props: {
numArgs: 2,
greediness: 2,
allowedInArgument: true,
},
handler: ({parser, funcName}, args) => {
const numer = args[0];
@@ -259,7 +259,6 @@ defineFunction({
let size = "auto";
switch (funcName) {
case "\\cfrac":
case "\\dfrac":
case "\\frac":
case "\\tfrac":
@@ -290,7 +289,6 @@ defineFunction({
}
switch (funcName) {
case "\\cfrac":
case "\\dfrac":
case "\\dbinom":
size = "display";
@@ -304,7 +302,7 @@ defineFunction({
return {
type: "genfrac",
mode: parser.mode,
continued: funcName === "\\cfrac",
continued: false,
numer,
denom,
hasBarLine,
@@ -319,6 +317,31 @@ defineFunction({
mathmlBuilder,
});
defineFunction({
type: "genfrac",
names: ["\\cfrac"],
props: {
numArgs: 2,
},
handler: ({parser, funcName}, args) => {
const numer = args[0];
const denom = args[1];
return {
type: "genfrac",
mode: parser.mode,
continued: true,
numer,
denom,
hasBarLine: true,
leftDelim: null,
rightDelim: null,
size: "display",
barSize: null,
};
},
});
// Infix generalized fractions -- these are not rendered directly, but replaced
// immediately by one of the variants above.
defineFunction({
@@ -374,7 +397,7 @@ defineFunction({
names: ["\\genfrac"],
props: {
numArgs: 6,
greediness: 6,
allowedInArgument: true,
argTypes: ["math", "math", "size", "text", "math", "math"],
},
handler({parser}, args) {