mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-19 17:48:41 +00:00
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:
@@ -241,14 +241,14 @@ const mathmlBuilder = (group, options) => {
|
||||
defineFunction({
|
||||
type: "genfrac",
|
||||
names: [
|
||||
"\\cfrac", "\\dfrac", "\\frac", "\\tfrac",
|
||||
"\\dfrac", "\\frac", "\\tfrac",
|
||||
"\\dbinom", "\\binom", "\\tbinom",
|
||||
"\\\\atopfrac", // can’t 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) {
|
||||
|
Reference in New Issue
Block a user