From fabae7c6583c41693d8f92bc1221177d84c5e065 Mon Sep 17 00:00:00 2001 From: Ashish Myles Date: Sat, 19 May 2018 21:36:20 -0400 Subject: [PATCH] Move infix operator handling into functions/genfrac.js. (#1328) --- src/functions.js | 26 -------------------------- src/functions/genfrac.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/functions.js b/src/functions.js index 4360025a..7d663dda 100644 --- a/src/functions.js +++ b/src/functions.js @@ -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"; diff --git a/src/functions/genfrac.js b/src/functions/genfrac.js index b16bea65..ab0a38a8 100644 --- a/src/functions/genfrac.js +++ b/src/functions/genfrac.js @@ -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, + }; + }, +}); +