cortex-js/cortexjs.io

Flatten option seems to be not functional

Opened this issue · 0 comments

For example,

function customCanonical(expr) {
  if (typeof expr.value === 'number') {
    if (expr.head === 'Divide' || expr.head === 'Rational') {
      if (expr.engine.box(['GCD', expr.op1, expr.op2]).value !== 1) return expr;
    }
    return expr.engine.number(expr.value);
  }

  if (expr.ops)
    return expr.engine.box([expr.head, ...expr.ops.map(customCanonical)], {
      canonical: ['InvisibleOperator', 'Order', 'Flatten'],
    });

  return expr.canonical;
}
console.log(customCanonical(engine.parse('\lparen2y+2\rparen\div7', { canonical: false })).toString())
// -> Divide(Delimiter(Add(Multiply(2, y), 2)), 7)
console.log(customCanonical(engine.parse('\dfrac{2y+2}{7}', { canonical: false })).toString())
// -> Divide(Add(Multiply(2, y), 2), 7)