import { Fragment } from "react"; // A name ending in digits, such as w1 or x_1, with or without a bar or dot; not a number like 2 or 1e5 const SUBSCRIPTED_NAME = /(?. export default function MathText({ text, svg = false }: { text: string; svg?: boolean }) { const parts = text.split(SUBSCRIPTED_NAME); // split gives [before, name, digits, before, name, digits, ..., after] return parts.map((part, i) => { if (i % 3 !== 2) { // x_1 is drawn as x with a subscript, without its underscore const shown = i % 3 === 1 ? part.replace(/_$/, "") : part; const afterSubscript = svg && i % 3 === 0 && i > 0; return afterSubscript ? ( {shown} ) : ( {shown} ); } return svg ? ( {part} ) : ( {part} ); }); }