Move infix operator handling into functions/genfrac.js. (#1328)

This commit is contained in:
Ashish Myles
2018-05-19 21:36:20 -04:00
committed by Kevin Barabash
parent 5aad11eff3
commit fabae7c658
2 changed files with 33 additions and 26 deletions

View File

@@ -118,32 +118,6 @@ defineFunction("xArrow", [
};
});
// Infix generalized fractions
defineFunction("infix", ["\\over", "\\choose", "\\atop"], {
numArgs: 0,
infix: true,
}, function(context) {
let replaceWith;
switch (context.funcName) {
case "\\over":
replaceWith = "\\frac";
break;
case "\\choose":
replaceWith = "\\binom";
break;
case "\\atop":
replaceWith = "\\\\atopfrac";
break;
default:
throw new Error("Unrecognized infix genfrac command");
}
return {
type: "infix",
replaceWith: replaceWith,
token: context.token,
};
});
// Row and line breaks
import "./functions/cr";

View File

@@ -251,3 +251,36 @@ defineFunction({
return node;
},
});
// Infix generalized fractions -- these are not rendered directly, but replaced
// immediately by one of the variants above.
defineFunction({
type: "infix",
names: ["\\over", "\\choose", "\\atop"],
props: {
numArgs: 0,
infix: true,
},
handler(context) {
let replaceWith;
switch (context.funcName) {
case "\\over":
replaceWith = "\\frac";
break;
case "\\choose":
replaceWith = "\\binom";
break;
case "\\atop":
replaceWith = "\\\\atopfrac";
break;
default:
throw new Error("Unrecognized infix genfrac command");
}
return {
type: "infix",
replaceWith: replaceWith,
token: context.token,
};
},
});