index.tsx 823 Bytes
Newer Older
dechen lin's avatar
dechen lin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import React from 'react';
import 'katex/dist/katex.min.css';
import { BlockMath } from 'react-katex';
import style from './index.module.scss';
import classNames from 'classnames';

interface LatexRendererProps {
  formula: string;
  className?: string;
  'aria-label'?: string;
  title?: string;
}

function LatexRenderer({ formula, className = '', 'aria-label': ariaLabel, title }: LatexRendererProps) {
  try {
    return (
      <div
        className={`${className} max-w-[100%] max-h-[100%] scrollbar-thin  ${style.customStyle}`}
        aria-label={ariaLabel}
      >
        <BlockMath math={formula} className="scrollbar-thin" />
      </div>
    );
  } catch (error) {
    console.error('Error rendering Latex:', error);
    return <div>Unable to render Latex formula.</div>;
  }
}

export default LatexRenderer;