mhchemParser is a JavaScript/TypeScript library designed to convert chemical equations and physical units written in the mhchem syntax into standard LaTeX syntax. This conversion is crucial for rendering chemical notation accurately in environments that support LaTeX, such as MathJax and KaTeX. The current stable version is 4.2.1. It serves as a foundational parser, allowing developers to process mhchem input directly before feeding it into a LaTeX rendering engine. The library is actively maintained and differentiates itself by providing a robust, standalone parsing capability specifically for mhchem syntax, rather than being an integrated component of a larger rendering system. Its primary utility is for downstream software integration, enabling flexible handling of chemical typesetting.
npm install mhchemparserVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import the mhchemParser class and use its static 'toTex' method for converting mhchem syntax in chemical equations, physical units, and embedded TeX strings into LaTeX.
Always consult the mhchem manual (mhchem.github.io/MathJax-mhchem/) for correct syntax. Validate user input before passing it to `mhchemParser.toTex` to ensure it conforms to expected mhchem patterns.
Ensure the second argument to `mhchemParser.toTex` is one of the supported strings: 'ce' for chemical equations, 'pu' for physical units, or 'tex' for general TeX strings containing mhchem commands.
Before upgrading to a new major version, check the project's GitHub releases page and the `MathJax-mhchem` manual for any migration guides or breaking changes that might affect your integration.
Ensure you are using `import { mhchemParser } from 'mhchemparser';` (ESM) or `const { mhchemParser } = require('mhchemparser');` (CommonJS). `toTex` is a static method of the exported class.Add the correct import statement at the top of your file: `import { mhchemParser } from 'mhchemparser';` (ESM) or `const { mhchemParser } = require('mhchemparser');` (CommonJS).Ensure that you call `mhchemParser.toTex(yourInput, 'ce')` or `mhchemParser.toTex(yourInput, 'pu')` on your input string *before* passing it to MathJax or KaTeX for rendering. The output of `toTex` is standard LaTeX.
No dependency data recorded yet.