"use client";

import { renderToString } from "katex";

interface KatexRendererProps {
  latex: string;
  displayMode?: boolean;
}

export default function KatexRenderer({
  latex,
  displayMode = false,
}: KatexRendererProps) {
  const html = renderToString(latex, {
    displayMode,
    throwOnError: false,
  });
  const Tag = displayMode ? "div" : "span";

  return <Tag dangerouslySetInnerHTML={{ __html: html }} />;
}
