LaTeX Guide

LaTeX Chemistry

mhchem for formulas and reactions. chemfig for structural diagrams. \ce{H2SO4} is all you need to know to start.

Setup

\usepackage[version=4]{mhchem}    % version=4 is current

% Optional: structural diagrams
\usepackage{chemfig}

Common formulas

\ce{H2O}                    % H₂O
\ce{H2SO4}                  % H₂SO₄
\ce{CO2}                    % CO₂
\ce{Fe2O3}                  % Fe₂O₃
\ce{C6H12O6}                % glucose
\ce{Na+}                    % sodium cation
\ce{Cl-}                    % chloride anion
\ce{Ca^2+}                  % calcium ion
\ce{SO4^2-}                 % sulfate ion
\ce{NH4+}                   % ammonium
\ce{H3O+}                   % hydronium

Reactions

% Forward
\ce{2H2 + O2 -> 2H2O}

% Equilibrium
\ce{N2 + 3H2 <=> 2NH3}

% With states
\ce{NaCl(s) -> Na+(aq) + Cl-(aq)}

% With conditions over arrow
\ce{2KClO3 ->[\Delta][MnO2] 2KCl + 3O2}

% Half-reaction
\ce{Cu^2+ + 2e- -> Cu}

Isotopes and atomic notation

\ce{^{14}_{6}C}             % carbon-14
\ce{^{235}_{92}U}           % uranium-235
\ce{^14C}                   % short form (mass only)
\ce{Fe^{II}}                % iron(II) — oxidation state
\ce{Cu^{II}}                % copper(II)

Structural diagrams (chemfig)

\usepackage{chemfig}

% Methanol: CH3-OH
\chemfig{H_3C-OH}

% Ethanol
\chemfig{H_3C-CH_2-OH}

% Benzene ring (special syntax)
\chemfig{*6(-=-=-=)}

% With substituents
\chemfig{*6(-=-(-OH)-=-)}    % phenol

Reaction equations in display mode

\begin{align*}
  \ce{2H2 + O2 &-> 2H2O} \\
  \ce{N2 + 3H2 &<=> 2NH3} \\
  \ce{C6H12O6 &-> 2C2H5OH + 2CO2}
\end{align*}

Common mistakes

  • Using $H_2O$ in math mode. Produces HO with H italicized. mhchem's \ce{H2O} uses upright H — chemistry convention.
  • Forgetting version=4. Older mhchem versions had different syntax. Always specify the version.
  • Mixing math mode and \ce. \ce works inline OR in math mode, but the contents follow chemistry rules, not math rules.
  • Using \rightarrow instead of ->. Inside \ce, use ->, <-, <=> directly.
Typst chemistry — coming soon

Typst's chemistry tooling is younger than mhchem but improving fast. For now, write chemistry papers in LaTeX with mhchem, or compile your full document in Typst with manual subscript notation. TypeTeX supports both.

Try TypeTeX free

Frequently Asked Questions

How do I write chemical formulas in LaTeX?

Use the mhchem package: \usepackage[version=4]{mhchem}. Then \ce{H2O} produces H₂O with proper subscripts. Works for any formula: \ce{H2SO4}, \ce{CO2}, \ce{Fe2O3}. The \ce command auto-formats numbers as subscripts and capital letters as elements.

How do I write chemical reactions with arrows?

\ce{2H2 + O2 -> 2H2O} produces the reaction with a forward arrow. Equilibrium: \ce{H2O <=> H+ + OH-}. Reversible-but-stronger-forward: \ce{<=>>}. Stoichiometric coefficients (the 2H2) auto-format correctly.

How do I write isotopes in LaTeX?

\ce{^{14}_{6}C} produces ¹⁴₆C (carbon-14). The ^{} is mass number, _{} is atomic number, then the element symbol. Or use \ce{^14C} for just the mass number with no atomic number.

How do charges and oxidation states work?

Charges: \ce{Na+}, \ce{Cl-}, \ce{Ca^2+}, \ce{SO4^2-}. Oxidation: \ce{Fe^{II}} (Roman numerals via {}). The mhchem package handles superscript positioning automatically.

How do I show states (aq, l, g, s)?

\ce{NaCl(s) -> Na+(aq) + Cl-(aq)} renders states in italic parentheses next to formulas. Common states: (s) solid, (l) liquid, (g) gas, (aq) aqueous. mhchem formats these with the proper italic styling automatically.

How do I draw molecular structures (skeletal formulas)?

Use chemfig for structural diagrams: \usepackage{chemfig} \chemfig{H_3C-CH(-OH)-CH_3}. The hyphens are bonds, parentheses indicate branches. For more complex structures, learn chemfig's notation — it handles benzene rings, double/triple bonds, and 3D depictions.

How do I write balanced equations with electrons?

\ce{Cu^2+ + 2e- -> Cu} for half-reactions. Use \ce{->} or \ce{<=>}. Multiple equations align nicely in a gather environment: \begin{gather*} \ce{Cu^2+ + 2e- -> Cu} \\ \ce{Zn -> Zn^2+ + 2e-} \end{gather*}.

What's the difference between mhchem and chemfig?

mhchem is for inline formulas and reactions in regular sentences (\ce{H2SO4}). chemfig is for structural/skeletal diagrams (the kind organic chemists draw). They complement each other: mhchem for the text, chemfig for the figures. Both load independently.

How do I write reaction conditions over the arrow?

\ce{H2 + O2 ->[\Delta] H2O} puts \Delta (heat) over the arrow. \ce{->[catalyst][solvent]} puts catalyst above and solvent below. Always inside \ce{}.

More LaTeX guides