I'm using KaTeX in a Svelte project to render chemical equations with the \ce{}
command, but the mhchem
extension isn't working. Other extensions like copytex
load successfully.
<script lang="ts"> import katex from 'katex'; export function renderMath(math: string, displayMode = false) { return katex.renderToString(math, { displayMode, throwOnError: false }); }</script><svelte:head><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous" /><script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/mhchem.min.js" integrity="sha384-ifpG+NlgMq0kvOSGqGQxW1mJKpjjMDmZdpKGq3tbvD3WPhyshCEEYClriK/wRVU0" crossorigin="anonymous"></script></svelte:head>{@html renderMath('\\ce{H2O}')}
What I've Tried:
- Importing mhchem.min.js script
- Various configuration options
- Different KaTeX rendering methods
- Confirmed other extensions like copytex work correctly
Error:Renders nothing or throws an "Undefined control sequence" error for \ce{}
Environment:
- Svelte
- KaTeX 0.16.11
- Vite
Questions:
- How can I properly load the mhchem extension in Svelte?
- Are there any specific configuration steps needed for Svelte?