The mhchem package

Typesets chemical formulas and reaction equations from plain input with \ce, for example \ce{2H2 + O2 -> 2H2O}.

Loading the package

\usepackage[version=4]{mhchem}

In math mode, H_2O gives italic letters, and every index and charge needs _{} or ^{}. Inside \ce{...} you type the formula the way you would write it in a text file: digits after an element become subscripts, + and - after a formula become charges, and -> becomes a reaction arrow. The letters stay upright.

\ce works in text and in math mode. Structural formulas with drawn bonds are a job for chemfig.

Main commands

\ce{H2O}Formula; the digit becomes a subscript.
\ce{SO4^2-}Ion with charge 2−.
\ce{2H2 + O2 -> 2H2O}Reaction equation with stoichiometric numbers and an arrow.
\ce{A <=> B}Equilibrium arrow.
\ce{A ->[H2O][\Delta] B}Text above and below the arrow.
\ce{^{14}_{6}C}Isotope with mass number and atomic number.
\ce{AgCl v}, \ce{CO2 ^}Arrow down for a precipitate, arrow up for a gas; a space has to come before v or ^.

Complete example

\documentclass{article}
\usepackage[version=4]{mhchem}
\begin{document}
Water is \ce{H2O}, the sulfate ion is \ce{SO4^2-},
and carbon-14 is written \ce{^{14}_{6}C}.

\begin{center}
\ce{2H2 + O2 -> 2H2O}

\ce{CO2 + H2O <=> H2CO3}

\ce{CaCO3 ->[\Delta] CaO + CO2 ^}

\ce{Ag+ + Cl- -> AgCl v}
\end{center}
\end{document}
Result
The compiled example

Open in the editor

Compiled with pdfLaTeX from TeX Live 2023.

Pitfalls

Related pages