Skip to content

Flatten option seems to be not functional #52

Open
@Deseux

Description

@Deseux

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions