From 8f4bfbf1a3419dcce63efaca8948c29f1cd3785c Mon Sep 17 00:00:00 2001 From: yangdx Date: Mon, 1 Dec 2025 12:20:17 +0800 Subject: [PATCH] Add KaTeX copy-tex extension support for formula copying --- lightrag_webui/src/components/retrieval/ChatMessage.tsx | 8 +++++--- lightrag_webui/src/types/katex.d.ts | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lightrag_webui/src/components/retrieval/ChatMessage.tsx b/lightrag_webui/src/components/retrieval/ChatMessage.tsx index c9b67a87..a4703e46 100644 --- a/lightrag_webui/src/components/retrieval/ChatMessage.tsx +++ b/lightrag_webui/src/components/retrieval/ChatMessage.tsx @@ -76,13 +76,15 @@ export const ChatMessage = ({ ? message.content : (displayContent !== undefined ? displayContent : (message.content || '')) - // Load KaTeX dynamically with mhchem extension for chemistry formulas + // Load KaTeX dynamically with extensions useEffect(() => { const loadKaTeX = async () => { try { - // First load mhchem extension (must be loaded before rehype-katex) - // This enables \ce and \pu commands for chemistry formulas + // 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); 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';