From 672f1a05257e6122eeb418a2ace809af71ade566 Mon Sep 17 00:00:00 2001 From: Evgeny Metelkin Date: Wed, 7 Feb 2024 15:22:20 +0200 Subject: [PATCH] add support of logbase, nthRoot, e, pi --- src/cmathml-handler.js | 22 ++++++++++++++++++---- test/cases/nodes.json | 4 ++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/cmathml-handler.js b/src/cmathml-handler.js index f58df6c..ec3a69d 100644 --- a/src/cmathml-handler.js +++ b/src/cmathml-handler.js @@ -7,14 +7,18 @@ const dictFunc = require('./dictionary'); } */ -function cMathMLHandler(_this, { handler, csymbols }){ +function cMathMLHandler(_this, { handler, csymbols}) { if (_this.type === 'SymbolNode') { let definitionURL = csymbols && csymbols[_this.name]; - if (typeof definitionURL === 'undefined') { - return `${_this.name}`; - } else { + if (_this.name === 'pi') { + return ``; + } else if (_this.name === 'e') { + return ``; + } else if (definitionURL) { // use return `${_this.name}`; + } else { + return `${_this.name}`; } } else if (_this.type === 'ConstantNode') { let isExponential = String(_this.value) // if it is exponential form @@ -25,6 +29,10 @@ function cMathMLHandler(_this, { handler, csymbols }){ return `${value[1]}${value[2]}`; } else if (isBoolean) { return `<${_this.value}/>` + } else if (_this.value === Infinity) { + return ``; + } else if (isNaN(_this.value)) { + return ``; } else { return `${_this.value}`; } @@ -37,8 +45,14 @@ function cMathMLHandler(_this, { handler, csymbols }){ return `${args[0]}2`; } else if(_this.fn.name==='log' && _this.args.length===2) { return `${args[1]}${args[0]}`; + } else if(_this.fn.name==='logbase') { + return `${args[1]}${args[0]}`; } else if(_this.fn.name==='log2') { return `2${args[0]}`; + } else if (_this.fn.name==='nthRoot' && _this.args.length>=2) { + return `${args[1]}${args[0]}`; + } else if (_this.fn.name==='nthRoot' && _this.args.length===1) { + return `${args[0]}`; } else if (_this.fn.name === 'piecewise') { if (args.length === 0) throw new Error('piecewise function must have at least one argument.'); diff --git a/test/cases/nodes.json b/test/cases/nodes.json index 46302b6..3ffa1b7 100644 --- a/test/cases/nodes.json +++ b/test/cases/nodes.json @@ -140,5 +140,9 @@ "piecewise without otherwise": { "formula": "123 * piecewise(x > 1, 1, x > 2, 2)", "expected": "1231x12x2" + }, + "Infinity and e": { + "formula": "Infinity * e * NaN * pi", + "expected": "" } }