Skip to content
All LaTeX symbols

Chemical equations in LaTeX (\ce, mhchem)

Miscellaneous

⇌

LaTeX command

\ce{H2O}

a formula; numbers after an element become subscripts

Write \ce{...} in math mode or on its own; inside the braces type the formula as plain text.

The mhchem package's \ce command writes chemical formulas and reactions the way chemists type them: element symbols upright, numbers after an element turned into subscripts, charges after ^, and arrows written as -> or <=>. Load it with \usepackage[version=4]{mhchem}.

All ways to write it

  • \ce{H2O}a formula; numbers after an element become subscriptsPackage: mhchem
  • \ce{2H2 + O2 -> 2H2O}a reaction; -> is the reaction arrowPackage: mhchem
  • \ce{N2 + 3H2 <=> 2NH3}an equilibrium arrowPackage: mhchem
  • \ce{SO4^2-}a charge, written after ^Package: mhchem
  • \ce{NaCl(aq)}a state in brackets: (s), (l), (g), (aq)Package: mhchem
  • \ce{CaCO3 ->[\Delta] CaO + CO2}text or a symbol above the arrowPackage: mhchem
  • \mathrm{H_2O}without mhchem: upright letters and manual subscriptsNo package needed

Commands marked with a package need that \usepackage line in a LaTeX document.

Example

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

The combustion of methane, with subscripts and the arrow handled by \ce.

Questions

How do I write a chemical equation in LaTeX?

Load mhchem with \usepackage[version=4]{mhchem} and write the reaction inside \ce{...}: \ce{2H2 + O2 -> 2H2O}. The subscripts and the arrow come out right without any further markup.

How do I write an equilibrium arrow?

Inside \ce use <=>, as in \ce{N2 + 3H2 <=> 2NH3}. Outside mhchem, \rightleftharpoons draws the same pair of harpoons.

How do I write ions and charges?

Put the charge after ^: \ce{Na+}, \ce{Cl-}, \ce{SO4^2-}, \ce{Fe^3+}. A single + or - needs no ^.

Can I write chemistry without mhchem?

Yes, but by hand: \mathrm{H_2O} for the formula and \rightarrow for the arrow. \ce is shorter and harder to get wrong, so use it where it is available.

Does \ce work in KaTeX and Confluence?

KaTeX supports \ce through its mhchem extension, which the page has to load. LaTeX Math for Confluence includes it, so \ce works in both the inline and the block macro.

Using chemical equations in Confluence

Confluence Cloud has no built-in LaTeX. With LaTeX Math for Confluence you add a math macro to any page, type \ce{H2O} and it renders inline or as a block, with a live preview while you edit. Every command on this page renders there without extra packages.

Related symbols

Also in Miscellaneous

See all LaTeX symbols