{"library":"mhchemparser","title":"mhchem Parser","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install mhchemparser"],"cli":null},"imports":["import { mhchemParser } from 'mhchemparser';","import { mhchemParser } from 'mhchemparser';\nmhchemParser.toTex(\"CO2\", \"ce\");","const { mhchemParser } = require('mhchemparser');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { mhchemParser } from 'mhchemparser';\n\n// Parse a chemical equation\nconst equationInput = \"CO2 + C -> 2 CO\";\nconst equationOutput = mhchemParser.toTex(equationInput, \"ce\");\nconsole.log(`Input: \\\\ce{${equationInput}}\\nOutput: ${equationOutput}`);\n// Expected output: Input: \\ce{CO2 + C -> 2 CO}\n// Output: {\\mathrm{CO}{\\vphantom{A}}_{\\smash[t]{2}} {}+{} \\mathrm{C} {}\\mathrel{\\longrightarrow}{} 2\\,\\mathrm{CO}}\n\n// Parse a physical unit\nconst unitInput = \"123 kJ*mol-1\";\nconst unitOutput = mhchemParser.toTex(unitInput, \"pu\");\nconsole.log(`Input: \\\\pu{${unitInput}}\\nOutput: ${unitOutput}`);\n// Expected output: Input: \\pu{123 kJ*mol-1}\n// Output: 123\\,\\mathrm{kJ}{\\cdot}\\mathrm{mol}^{-1}\n\n// Parse a TeX string containing mhchem commands\nconst texInput = \"m_{\\\\ce{H2O}}\";\nconst texOutput = mhchemParser.toTex(texInput, \"tex\");\nconsole.log(`Input: ${texInput}\\nOutput: ${texOutput}`);\n// Expected output: Input: m_{\\ce{H2O}}\n// Output: m_{\\mathrm{H}_{2}\\mathrm{O}}}","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}