Skip to content

When there is nthRoot in the argument of nthRoot, it becomes a SymbolNode. #2145

@fed-gren

Description

@fed-gren

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions