-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Labels
Description
Hi. I'm running some tests to use the mathjs.
I want to render custom HTML using the handler option with toString or toHTML.
I wrote the code below to express the exponent in nthRoot or power.
function customHtml(node, options) {
if (node.type === "FunctionNode" && node.fn.name === "nthRoot") {
return `<sup>${node.args[1]}</sup>√${node.args[0]}`;
} else if(node.type === "OperatorNode" && node.op === "^") {
return `${node.args[0]}<sup>${node.args[1]}</sup>`;
}
}
...
const node = math.parse(input); //input is expression string
const html = node.toString({
handler: customHtml,
});In the code above, when input is nthRoot(1, 2), I expect html to be <sup>2</sup>√1. This works fine.
But when input is nthRoot(1,(nthRoot(1,2))), the result is: <sup>(nthRoot(1, 2))</sup>√1</div>
The internal nthRoot is recognized as a SymbolNode. Why isn't it recognized as a FunctionNode?
Reactions are currently unavailable