import React, { useMemo } from 'react'; import katex from 'katex'; interface MathFormulaProps { math: string; displayMode?: boolean; className?: string; } export const MathFormula: React.FC = ({ math, displayMode = true, className = '', }) => { const renderedHtml = useMemo(() => { try { return katex.renderToString(math, { displayMode, throwOnError: false, output: 'htmlAndMathml', }); } catch (err) { console.warn('KaTeX rendering error:', err); return null; } }, [math, displayMode]); if (!renderedHtml) { return ( {math} ); } return (
); };