How should I use mhchem in vue?
See original GitHub issueI have tried a lot of methods to get mhchem run. Not working.
Math equations are working fine.

Here is my code:
I use a .js file to import katex
import katex from 'katex'
import "katex/dist/katex.min.css"
import 'katex/dist/contrib/mhchem'
This is not working properly as I render as following
let tex = data[i].data.trim()
if(tex.indexOf("\\ce{") === -1 )
washedData.push(katex.renderToString(tex, {displayMode: false}))
else
washedData.push(katex.renderToString(tex.slice(4, -1), {displayMode: false}))

I tried to remove
\ce, not working.ERORR:KaTeX parse error: Undefined control sequence: \ce at position 1: \̲c̲e̲{x Na(NH4)HPO4 …
My problem is , how do we import mhchem when using webpack, such as vue which I am using now.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
mhchem for MathJax, mhchem for KaTeX - GitHub Pages
mhchem is a tool for writing beautiful chemical equations easily. ... Each arrow can take two optional arguments: one for above and one...
Read more >Vue with MathJax - CodePen
Insecure Resource. The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https....
Read more >Chemistry notation using mhchem - MoodleDocs
The mhchem extension allows a more adaptable display and more natural input of chemical formulae and equations. In Moodle, mhchem syntax can use...
Read more >JavaScript Gems: KaTeX - Beautiful Formulas in the Browser
KaTeX \KaTeX KATEX is a JavaScript library to render formulas in Mathematics, Physics, and Chemistry, and probably several related realms.
Read more >mathjax-mhchem: Docs, Tutorials, Reviews | Openbase
mhchem for MathJax is a 3rd-party extension for MathJax, for typesetting chemical equations. Usage. \ce{CO2 + C -> 2 CO} ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thank you for the complete example! This is very helpful.
Fix: replace
import 'katex/dist/contrib/mhchem'withimport 'katex/dist/contrib/mhchem.js'insrc/components/HelloWorld.vueand everything seems to work.How I got there: I’ve found something that may be causing the problem: the built app code compiles
import katex from 'katex'intowhereas the built
mhchem.jscode compilesimport katex from "katex"intoAh, the issue seems to be that
import 'katex/dist/contrib/mhchem'ends up including"./node_modules/katex/dist/contrib/mhchem.mjs"instead of.../mhchem.js, which in turn importskatex.mjsinstead ofkatex.js.I’m not sure whether this suggests any changes on the KaTeX side. I believe we currently don’t expose
katex.mjsviapackage.json, but perhaps now is the time to do so, if Webpack gets confused in this way?Thank You Very Much !!!
@edemaine
Well, for me, the problem is solved.
If someone happens to go the same way I went through, he can find the solution here.
Update the document, either inside mhchem source code or in mainpage of mhchem would help a lot.
More professional thoughts or changes is far out of my ability.
Thank you again. If there is something I can do for katex, please let me know.