Math in the browser with Mathjs

import { parse, simplify } from 'mathjs'

// Define a symbolic expression
const expression = 'x + 2x + 1';

// Parse the expression into a Math.js node
const node = parse(expression);

// Simplify the expression
const simplifiedNode = simplify(node);

// Convert the original and simplified expressions to LaTeX
const originalLatex = node.toTex();
const simplifiedLatex = simplifiedNode.toTex();