mhchem Examples for MathJax
mhchem is the MathJax extension for chemistry. Write formulas and reactions inside \ce{...} and
units inside \pu{...}, and mhchem handles subscripts, charges and arrows for you. The results
below are rendered live with MathJax 4.
Formulas, charges and states
| What | Code | Result |
|---|---|---|
| Formula | \ce{H2SO4} |
\(\ce{H2SO4}\) |
| Ion charge | \ce{SO4^2-} |
\(\ce{SO4^2-}\) |
| Cation | \ce{Fe^3+} |
\(\ce{Fe^3+}\) |
| State of matter | \ce{NaCl(aq)} |
\(\ce{NaCl(aq)}\) |
| Hydrate | \ce{CuSO4 * 5H2O} |
\(\ce{CuSO4 * 5H2O}\) |
| Isotope | \ce{^{227}_{90}Th+} |
\(\ce{^{227}_{90}Th+}\) |
| Oxidation states | \ce{Fe^{II}Fe^{III}2O4} |
\(\ce{Fe^{II}Fe^{III}2O4}\) |
| Bonds | \ce{CH3-CH=CH2} |
\(\ce{CH3-CH=CH2}\) |
Reactions and arrows
| What | Code | Result |
|---|---|---|
| Reaction | \ce{2H2 + O2 -> 2H2O} |
\(\ce{2H2 + O2 -> 2H2O}\) |
| Equilibrium | \ce{N2 + 3H2 <=> 2NH3} |
\(\ce{N2 + 3H2 <=> 2NH3}\) |
| Gas released | \ce{Zn + 2HCl -> ZnCl2 + H2 ^} |
\(\ce{Zn + 2HCl -> ZnCl2 + H2 ^}\) |
| Precipitate | \ce{Ba^2+ + SO4^2- -> BaSO4 v} |
\(\ce{Ba^2+ + SO4^2- -> BaSO4 v}\) |
| Condition above arrow | \ce{CaCO3 ->[\Delta] CaO + CO2 ^} |
\(\ce{CaCO3 ->[\Delta] CaO + CO2 ^}\) |
| Text above and below | \ce{A ->[{above}][{below}] B} |
\(\ce{A ->[{above}][{below}] B}\) |
| Half reaction | \ce{Fe^3+ + e- -> Fe^2+} |
\(\ce{Fe^3+ + e- -> Fe^2+}\) |
Units with \pu
| What | Code | Result |
|---|---|---|
| Unit | \pu{123 kJ/mol} |
\(\pu{123 kJ/mol}\) |
| Scientific notation | \pu{1.2e3 kJ} |
\(\pu{1.2e3 kJ}\) |
How to enable mhchem
MathJax 3 and 4
Nothing to do: mhchem loads automatically the first time \ce or \pu appears. To
load it up front instead:
window.MathJax = {
loader: { load: ['[tex]/mhchem'] },
tex: { packages: { '[+]': ['mhchem'] } }
};
MathJax 2
Add the extension to your configuration. By default MathJax 2.7 loads an older version of
mhchem; set legacy: false to use the current one, which matches MathJax 3 and 4:
MathJax.Hub.Config({
TeX: {
extensions: ['mhchem.js'],
mhchem: { legacy: false }
}
});
The older version doesn't support newer syntax such as \pu, so chemistry content can look
different between MathJax 2 and later versions. The live preview uses the MathJax 2 default,
so you can see exactly where your content is affected.