From 73e0c13d109ca566fd6dd57efff3d6c8b4464260 Mon Sep 17 00:00:00 2001 From: Ashish Myles Date: Fri, 18 May 2018 09:59:03 -0400 Subject: [PATCH] Move the rest of the ops from functions.js to functions/ops.js. (#1323) --- src/functions.js | 62 --------------------------- src/functions/op.js | 102 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 62 deletions(-) diff --git a/src/functions.js b/src/functions.js index dac059ac..f9c7c808 100644 --- a/src/functions.js +++ b/src/functions.js @@ -118,68 +118,6 @@ defineFunction("mclass", ["\\stackrel", "\\overset", "\\underset"], { import "./functions/mod"; -const singleCharIntegrals: {[string]: string} = { - "\u222b": "\\int", - "\u222c": "\\iint", - "\u222d": "\\iiint", - "\u222e": "\\oint", -}; - -// There are 2 flags for operators; whether they produce limits in -// displaystyle, and whether they are symbols and should grow in -// displaystyle. These four groups cover the four possible choices. - -// No limits, not symbols -defineFunction("op", [ - "\\arcsin", "\\arccos", "\\arctan", "\\arctg", "\\arcctg", - "\\arg", "\\ch", "\\cos", "\\cosec", "\\cosh", "\\cot", "\\cotg", - "\\coth", "\\csc", "\\ctg", "\\cth", "\\deg", "\\dim", "\\exp", - "\\hom", "\\ker", "\\lg", "\\ln", "\\log", "\\sec", "\\sin", - "\\sinh", "\\sh", "\\tan", "\\tanh", "\\tg", "\\th", -], { - numArgs: 0, -}, function(context) { - return { - type: "op", - limits: false, - symbol: false, - body: context.funcName, - }; -}); - -// Limits, not symbols -defineFunction("op", [ - "\\det", "\\gcd", "\\inf", "\\lim", "\\max", "\\min", "\\Pr", "\\sup", -], { - numArgs: 0, -}, function(context) { - return { - type: "op", - limits: true, - symbol: false, - body: context.funcName, - }; -}); - -// No limits, symbols -defineFunction("op", [ - "\\int", "\\iint", "\\iiint", "\\oint", "\u222b", "\u222c", - "\u222d", "\u222e", -], { - numArgs: 0, -}, function(context) { - let fName = context.funcName; - if (fName.length === 1) { - fName = singleCharIntegrals[fName]; - } - return { - type: "op", - limits: false, - symbol: true, - body: fName, - }; -}); - import "./functions/op"; import "./functions/operatorname"; diff --git a/src/functions/op.js b/src/functions/op.js index a3e0a67a..dbe751cb 100644 --- a/src/functions/op.js +++ b/src/functions/op.js @@ -285,3 +285,105 @@ defineFunction({ htmlBuilder, mathmlBuilder, }); + +// There are 2 flags for operators; whether they produce limits in +// displaystyle, and whether they are symbols and should grow in +// displaystyle. These four groups cover the four possible choices. + +const singleCharIntegrals: {[string]: string} = { + "\u222b": "\\int", + "\u222c": "\\iint", + "\u222d": "\\iiint", + "\u222e": "\\oint", +}; + +defineFunction({ + type: "op", + names: ["\\mathop"], + props: { + numArgs: 1, + }, + handler: (context, args) => { + const body = args[0]; + return { + type: "op", + limits: false, + symbol: false, + value: ordargument(body), + }; + }, + htmlBuilder, + mathmlBuilder, +}); + +// No limits, not symbols +defineFunction({ + type: "op", + names: [ + "\\arcsin", "\\arccos", "\\arctan", "\\arctg", "\\arcctg", + "\\arg", "\\ch", "\\cos", "\\cosec", "\\cosh", "\\cot", "\\cotg", + "\\coth", "\\csc", "\\ctg", "\\cth", "\\deg", "\\dim", "\\exp", + "\\hom", "\\ker", "\\lg", "\\ln", "\\log", "\\sec", "\\sin", + "\\sinh", "\\sh", "\\tan", "\\tanh", "\\tg", "\\th", + ], + props: { + numArgs: 0, + }, + handler(context) { + return { + type: "op", + limits: false, + symbol: false, + body: context.funcName, + }; + }, + htmlBuilder, + mathmlBuilder, +}); + +// Limits, not symbols +defineFunction({ + type: "op", + names: [ + "\\det", "\\gcd", "\\inf", "\\lim", "\\max", "\\min", "\\Pr", "\\sup", + ], + props: { + numArgs: 0, + }, + handler(context) { + return { + type: "op", + limits: true, + symbol: false, + body: context.funcName, + }; + }, + htmlBuilder, + mathmlBuilder, +}); + +// No limits, symbols +defineFunction({ + type: "op", + names: [ + "\\int", "\\iint", "\\iiint", "\\oint", "\u222b", "\u222c", + "\u222d", "\u222e", + ], + props: { + numArgs: 0, + }, + handler(context) { + let fName = context.funcName; + if (fName.length === 1) { + fName = singleCharIntegrals[fName]; + } + return { + type: "op", + limits: false, + symbol: true, + body: fName, + }; + }, + htmlBuilder, + mathmlBuilder, +});