Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten option seems to be not functional #52

Open
Deseux opened this issue Jun 11, 2024 · 0 comments
Open

Flatten option seems to be not functional #52

Deseux opened this issue Jun 11, 2024 · 0 comments

Comments

@Deseux
Copy link

Deseux commented Jun 11, 2024

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant