Skip to content

An AI-powered search engine with a generative UI

Add support for rendering math equations in BotMessage component

Yoshiki Miura8bf657549af0
diff --git a/bun.lockb b/bun.lockb
index 6bfc8468..0a2b95b9 100755
Binary files a/bun.lockb and b/bun.lockb differ
diff --git a/components/message.tsx b/components/message.tsx
index 5be78e0c..7ba97110 100644
--- a/components/message.tsx
+++ b/components/message.tsx
@@ -4,6 +4,9 @@ import { StreamableValue, useStreamableValue } from 'ai/rsc'
import { MemoizedReactMarkdown } from './ui/markdown'
import rehypeExternalLinks from 'rehype-external-links'
import remarkGfm from 'remark-gfm'
+import remarkMath from 'remark-math'
+import rehypeKatex from 'rehype-katex'
+import 'katex/dist/katex.min.css'
export function BotMessage({ content }: { content: StreamableValue<string> }) {
const [data, error, pending] = useStreamableValue(content)
@@ -13,8 +16,8 @@ export function BotMessage({ content }: { content: StreamableValue<string> }) {
return (
<MemoizedReactMarkdown
- rehypePlugins={[[rehypeExternalLinks, { target: '_blank' }]]}
- remarkPlugins={[remarkGfm]}
+ rehypePlugins={[[rehypeExternalLinks, { target: '_blank' }], rehypeKatex]}
+ remarkPlugins={[remarkGfm, remarkMath]}
className="prose-sm prose-neutral prose-a:text-accent-foreground/50"
>
{data}
diff --git a/package.json b/package.json
index bfcceb63..2de036e9 100644
--- a/package.json
+++ b/package.json
@@ -31,6 +31,7 @@
"clsx": "^2.1.0",
"embla-carousel-react": "^8.0.0",
"exa-js": "^1.0.12",
+ "katex": "^0.16.10",
"lucide-react": "^0.363.0",
"next": "^14.2.3",
"next-themes": "^0.3.0",
@@ -40,7 +41,9 @@
"react-markdown": "^9.0.1",
"react-textarea-autosize": "^8.5.3",
"rehype-external-links": "^3.0.0",
+ "rehype-katex": "^7.0.0",
"remark-gfm": "^4.0.0",
+ "remark-math": "^6.0.0",
"sonner": "^1.4.41",
"tailwind-merge": "^2.2.2",
"tailwindcss-animate": "^1.0.7"