-
-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add mhchem support to rehype-katex #81
Comments
They are closed because An updated example looks like: import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkMath from "remark-math";
import remarkRehype from "remark-rehype";
import rehypeKatex from "rehype-katex";
import rehypeStringify from "rehype-stringify";
import "katex/dist/contrib/mhchem";
const sourceMarkdown = `
$\\ce{a A + b B -> c \\textbf{C} + d D}$
`;
const file = await unified()
.use(remarkParse)
.use(remarkMath)
.use(remarkRehype)
.use(rehypeKatex)
.use(rehypeStringify)
.process(sourceMarkdown); runnable example: https://codesandbox.io/s/katex-mhchem-wl7q64 |
This comment has been minimized.
This comment has been minimized.
Thank you so much! Excuse me, but how can I use this with Next.js? I've tried to add import Script from 'next/script'
...
<Script src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/contrib/mhchem.min.js" /> However, Thanks again for your patience, do you have any idea with this? |
Could you share what you are trying to do in a sandbox? Using https://next.new as a starter? |
Hi, I have a similar issue where I'm importing mhchem to a Nextjs project but the equations aren't rendering correctly. https://stackblitz.com/edit/nextjs-idj33f?file=pages%2Fmath.js,pages%2Findex.js,pages%2F_app.js |
Thanks @philipbalbas! Given that https://codesandbox.io/s/katex-mhchem-wl7q64 works in browser |
Taking that further, I tried to isolate the issue a bit more. |
Hi, thanks for taking a look. Noted on the nextjs issues. |
That is the side effect, yes. Combined with #80 it leads me to believe something about Next SSR messes with Katex and Mathjax. |
I'm getting the same issue to make mhchem work with nextjs. Have anyone solved the issue?
|
Welcome @edward1127! 👋
This doesn't appear to be a remark/mdx issue, so there isn't necessarily a remark/mdx workaround to be offered. |
Thanks. I just reposted your summary to the Next.js team vercel/next.js#54852 |
I tried to use CSR with Next https://stackblitz.com/edit/nextjs-ftepsg?file=pages%2Findex.js, and it's still not working. I believe somehow nextjs cannot get the context of import "katex/dist/contrib/mhchem"; |
If explicitly import the mhchem extension, it will work for nextjs |
Initial checklist
Problem
I'm using LaTeX to write some docs about Chemistry, and I need mhchem to write equations easily.
Solution
However, rehype-katex is pure, and does not support
\ce{}
syntax by default. To use mhchem in KaTeX, I need mhchem extension, which is an official extension made by KaTeX team.Adding
<script />
into<head />
directly is not recommended, and doesn't work properly with Next.js built-in router.Alternatives
Well, switching to rehype-mathjax works, but, #80 happens to me, too.
Related
#69 and #34 are both closed and marked as wontfix, a little bit confused, why not?
The text was updated successfully, but these errors were encountered: