const mathify = content => { let result = '' let close = null; let symbol = null; Array.from(content).forEach(c => { if (symbol !== null) { if (c === ' ') { if (symbol === 'rightarrow') { result += '→' } else if (symbol === 'geq') { result += '≥' } else { result += '?' } symbol = null; result += ' ' } else { symbol += c } } else if (c == '$') { symbol = '' } else if (c === '*') { result += '×' } else if (c === '^') { result += '' close = '' } else if (c === '_') { result += ''; close = ''; } else if (c === ' ' || c == '\n') { if (close !== null) { result += close close = null } result += ' ' } else { result += c } }) if (close !== null) { result += close; } return `${result.trim()}` } const parse_maths = html => html.replaceAll(/\(\(.+?\)\)/g, match => mathify(match.slice(2, -2)) ); Array.from(document.getElementsByClassName('matrix')).forEach(matrix => { let result = '
${mathify(elem.trim())} | ` }) result += '