Skip to content

Instantly share code, notes, and snippets.

@tjsudarsan
Created April 12, 2023 08:38
Show Gist options
  • Save tjsudarsan/169998f883d97462efabd37a8fd1e2ee to your computer and use it in GitHub Desktop.
Save tjsudarsan/169998f883d97462efabd37a8fd1e2ee to your computer and use it in GitHub Desktop.
Rendering math with react-markdown [UPDATED]
import ReactMarkdown from "react-markdown";
import remarkMath from "remark-math";
import rehypeKatex from "rehype-katex";
import "katex/dist/katex.min.css";
const App = (props) => {
const md = `The equation for softmax function is:\n\n$$\\sigma(z)_j = \\frac{e^{z_j}}{\\sum\\limits_{k=1}^{K}e^{z_k}}$$\n\nwhere $z$ is the input vector of length $K$ and $\\sigma(z)$ is the output vector of length $K$, with each element representing the probability of the input belonging to that class.`;
return (
<ReactMarkdown remarkPlugins={[remarkMath]} rehypePlugins={[rehypeKatex]}>
{md}
</ReactMarkdown>
);
};
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment