"use client";

import { renderToString } from "katex";

interface KatexRendererProps {
  latex: string;
  displayMode?: boolean;
  output?: "htmlAndMathml" | "mathml";
}

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

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