#how to add katex
3 messages · Page 1 of 1 (latest)
Hi @gusty helm. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
To add KaTeX to your Astro project, you can import the KaTeX CSS file in your project. Here's an example of how you can do it:
Initially, you might be importing the KaTeX CSS as:
<link rel="preload" as="stylesheet" href="<https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css"> crossorigin="anonymous">
But you should change it to:
<link rel="stylesheet" href="<https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css"> crossorigin="anonymous">
This should fix any issues you might be having with rendering math equations with KaTeX in your Astro project.
If you're using .mdx files and want to include JavaScript expressions and custom components within your Markdown, you can use the is:raw directive. This instructs the Astro compiler to treat any children of that element as text. This means that all special Astro templating syntax will be ignored inside of this component. Here's an example:
---import Katex from '../components/Katex.astro';---<Katex is:raw>Some conflicting {syntax} here</Katex>
For more information, you can refer to the following sources:
- Github Issue (closed): Issues while rendering math equations with katex and astro/katex (https://github.com/withastro/astro/issues/5697)
- Astro Documentation:
is:rawdirective (https://docs.astro.build/en/reference/directives-reference#israw) - Astro Documentation: MDX Authoring (https://docs.astro.build/en/guides/content#mdx-authoring)