Merge pull request #2443 from danielaskdd/fix-ktax
Fix KaTeX chemistry formula rendering (\ce command) not working
This commit is contained in:
commit
607c11c083
5 changed files with 11 additions and 4 deletions
|
|
@ -1 +1 @@
|
|||
__api_version__ = "0257"
|
||||
__api_version__ = "0258"
|
||||
|
|
|
|||
|
|
@ -76,7 +76,8 @@ export const ChatMessage = ({
|
|||
? message.content
|
||||
: (displayContent !== undefined ? displayContent : (message.content || ''))
|
||||
|
||||
// Load KaTeX dynamically
|
||||
// Load KaTeX rehype plugin dynamically
|
||||
// Note: KaTeX extensions (mhchem, copy-tex) are imported statically in main.tsx
|
||||
useEffect(() => {
|
||||
const loadKaTeX = async () => {
|
||||
try {
|
||||
|
|
@ -84,7 +85,6 @@ export const ChatMessage = ({
|
|||
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);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ import './index.css'
|
|||
import AppRouter from './AppRouter'
|
||||
import './i18n.ts';
|
||||
import 'katex/dist/katex.min.css';
|
||||
// Import KaTeX extensions at app startup to ensure they are registered before any rendering
|
||||
import 'katex/contrib/mhchem'; // Chemistry formulas: \ce{} and \pu{}
|
||||
import 'katex/contrib/copy-tex'; // Allow copying rendered formulas as LaTeX source
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
1
lightrag_webui/src/types/katex.d.ts
vendored
1
lightrag_webui/src/types/katex.d.ts
vendored
|
|
@ -1 +1,2 @@
|
|||
declare module 'katex/contrib/mhchem';
|
||||
declare module 'katex/contrib/copy-tex';
|
||||
|
|
|
|||
|
|
@ -10,7 +10,10 @@ export default defineConfig({
|
|||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src')
|
||||
}
|
||||
},
|
||||
// Force all modules to use the same katex instance
|
||||
// This ensures mhchem extension registered in main.tsx is available to rehype-katex
|
||||
dedupe: ['katex']
|
||||
},
|
||||
// base: import.meta.env.VITE_BASE_URL || '/webui/',
|
||||
base: webuiPrefix,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue