-
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 But when input is The internal nthRoot is recognized as a SymbolNode. Why isn't it recognized as a FunctionNode? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You're having for example |
Beta Was this translation helpful? Give feedback.
You're having for example
node.args[1]
when creating your string, which will simply call the default.toString()
on your arguments. That should benode.args[1].toString(options)
, passing yourcustomHtml
handler via theoptions
to nested arguments.