How to Typeset Chemical Equations in LaTeX (mhchem Guide)

Scriveno Team ·

Chemical equations look simple until you try to typeset them. Subscripts belong to atoms, charges float above them, state symbols sit on the baseline, and the arrow sometimes carries conditions. Writing all of that with plain math mode (H_2O, \rightarrow) works, but it is slow, easy to get wrong and sets element symbols in italics like variables.

The standard answer is the mhchem package. It gives you one command, \ce{...}, that understands chemistry notation directly. This guide covers everything you need for coursework and lab reports.

Setting up mhchem

Add the package to your preamble:

\usepackage[version=4]{mhchem}

version=4 selects the current syntax. After that, \ce{} works in text and in math mode.

Formulas: subscripts are automatic

Inside \ce{} numbers after an element become subscripts on their own:

\ce{H2O}   \ce{H2SO4}   \ce{C6H12O6}   \ce{Ca(OH)2}

A number in front is a stoichiometric coefficient, and stays full size: \ce{2H2O}.

Charges and ions

Write the charge after a caret, or just put +/- at the end:

\ce{Na+}   \ce{Cl-}   \ce{SO4^2-}   \ce{Fe^3+}   \ce{NH4+}

State symbols

State symbols go in parentheses straight after the species:

\ce{NaCl(aq)}   \ce{H2O(l)}   \ce{CO2(g)}   \ce{AgCl(s)}

Reaction arrows

mhchem turns ASCII arrows into proper typeset ones:

  • -> - reaction goes forward

  • <- - reaction goes backward

  • <=> - equilibrium

  • <-> - resonance

\ce{2H2 + O2 -> 2H2O}
\ce{N2 + 3H2 <=> 2NH3}

Conditions above and below the arrow

Put conditions in square brackets straight after the arrow - the first bracket goes above, the second below:

\ce{CaCO3 ->[\Delta] CaO + CO2}
\ce{N2 + 3H2 <=>[Fe][450\,^{\circ}C] 2NH3}

Precipitates and gases

A space then v marks a precipitate (a down arrow), and a space then ^ marks a gas given off:

\ce{Fe^3+ + 3OH- -> Fe(OH)3 v}
\ce{Zn + 2HCl -> ZnCl2 + H2 ^}

Displaying equations

For a standalone equation, put \ce{} inside display math:

\[ \ce{CH4 + 2O2 -> CO2 + 2H2O} \]

To align reaction arrows, place & immediately before each arrow inside a single \ce{...} command, then separate rows with \\:” Then add the code below.

Common mistakes

  • Forgetting the space before v or ^. \ce{Fe(OH)3v} is read as part of the formula.

  • Using math-mode arrows inside \ce{}. Write ->, not \rightarrow.

  • Italic elements. If your formulas come out italic, they're in math mode without \ce{}.

  • Old syntax. Without version=4, some newer notation isn't recognised.

From handwritten notes to mhchem

If your reactions start life in a notebook, retyping each one into mhchem is the slow part. Scriveno's chemistry notes converter transcribes handwritten chemistry directly into \ce{} notation - keeping coefficients, charges, state symbols and the arrow you drew - and keeps hand-drawn structures as images cropped from your page. Check the rendered preview against your notes, then download the LaTeX and paste it into your report.

For typesetting the rest of a page, see convert handwriting to LaTeX.