From 338328ae81c91544bdbfc7334303d42b6f031548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20MANSUY?= Date: Thu, 4 Dec 2025 19:15:04 +0800 Subject: [PATCH] cherry-pick 8f4bfbf1 --- .../src/components/retrieval/ChatMessage.tsx | 10 ++++++++-- lightrag_webui/src/types/katex.d.ts | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lightrag_webui/src/components/retrieval/ChatMessage.tsx b/lightrag_webui/src/components/retrieval/ChatMessage.tsx index e490941c..a4703e46 100644 --- a/lightrag_webui/src/components/retrieval/ChatMessage.tsx +++ b/lightrag_webui/src/components/retrieval/ChatMessage.tsx @@ -76,15 +76,21 @@ export const ChatMessage = ({ ? message.content : (displayContent !== undefined ? displayContent : (message.content || '')) - // Load KaTeX rehype plugin dynamically - // Note: KaTeX extensions (mhchem, copy-tex) are imported statically in main.tsx + // Load KaTeX dynamically with extensions useEffect(() => { const loadKaTeX = async () => { try { + // Load KaTeX extensions (must be loaded before rehype-katex) + // 1. mhchem: enables \ce and \pu commands for chemistry formulas + await import('katex/contrib/mhchem'); + // 2. copy-tex: allows users to copy rendered formulas as LaTeX source code + await import('katex/contrib/copy-tex'); + // Then load rehype-katex const { default: rehypeKatex } = await import('rehype-katex'); setKatexPlugin(() => rehypeKatex); } catch (error) { console.error('Failed to load KaTeX plugin:', error); + // Set to null to ensure we don't try to use a failed plugin setKatexPlugin(null); } }; diff --git a/lightrag_webui/src/types/katex.d.ts b/lightrag_webui/src/types/katex.d.ts index de362150..499dbf30 100644 --- a/lightrag_webui/src/types/katex.d.ts +++ b/lightrag_webui/src/types/katex.d.ts @@ -1 +1,2 @@ declare module 'katex/contrib/mhchem'; +declare module 'katex/contrib/copy-tex';