Introduction
LaTeX provides a rich ecosystem for chemistry typesetting — from simple chemical formulas to complex molecular structures, reaction mechanisms, and spectroscopy data. The right packages turn tedious manual drawing into declarative, reproducible code.
This guide covers the major LaTeX chemistry packages and shows working examples for chemical formulas, molecular diagrams, reaction schemes, NMR/IR spectroscopy notation, biochemistry structures, and periodic table figures.
Package Overview and Comparison
| Package | Purpose | Strength | Complexity |
|---|---|---|---|
| mhchem | Chemical formulas and equations | Natural syntax with \ce{} |
Low |
| chemfig | Molecular structure diagrams | Bond-angle specification, ring drawing | Medium |
| chemnum | Compound numbering | Auto-numbering with \cmpd{} |
Low |
| xymtex | Advanced cyclic structures | Fused rings, steroids, sugars | High |
| bpchem | Biochemical notation | Amino acids, DNA/RNA | Medium |
| chemstyle | Journal-style formatting | RSC, ACS templates | Medium |
| modiagram | Molecular orbital diagrams | MO energy levels | Medium |
| pst-3dplot | 3D molecular visualization | Perspective rendering | High |
| chemmacros | General chemistry toolkit | Isotopes, redox, units | Low |
For most documents, start with mhchem for equations and chemfig for structures. Add chemnum when you need numbered compound references.
Setting Up the Preamble
% Minimum preamble for chemistry typesetting
\usepackage{chemfig}
\usepackage[version=4]{mhchem}
\usepackage{chemmacros}
\usepackage{chemnum}
\usepackage{booktabs} % for tables
\usepackage{siunitx} % for units
% chemfig: set bond angle and length globally
\setchemfig{
atom sep = 2em,
bond offset = 2pt
}
Chemical Formulas with mhchem
The mhchem package provides the \ce{} command for inline chemical formulas and \ce{} for entire equations. The syntax is intuitive — write formulas naturally and the package handles subscripts, superscripts, charges, and arrows.
% Simple formulas
\ce{H2O} % water
\ce{CO2} % carbon dioxide
\ce{CH4} % methane
\ce{C6H12O6} % glucose
% Ions and isotopes
\ce{Fe^{3+}} % iron(III) ion
\ce{^{14}C} % carbon-14 isotope
\ce{SO4^{2-}} % sulfate ion
\ce{[Cr(H2O)6]^{3+}} % complex ion
% pH calculation
\ce{pH = -\log([H3O+])}
Chemical equations with reaction arrows:
% Simple reaction
\ce{2H2 + O2 -> 2H2O}
% Reversible reaction
\ce{N2 + 3H2 <=> 2NH3}
% Reaction with catalyst and conditions
\ce{A ->[catalyst][300\,\celsius] B}
% Precipitation
\ce{AgNO3 + NaCl -> AgCl v + NaNO3}
% Multiple steps
\ce{A ->[-H2O] B ->[O3] C}
The reaction environment centers and numbers equations:
\begin{reaction}
\ce{CH4 + 2O2 -> CO2 + 2H2O}
\end{reaction}
\begin{reaction}
\ce{6CO2 + 6H2O ->[h\nu] C6H12O6 + 6O2}
\end{reaction}
Molecular Structures with chemfig
chemfig builds molecules from a string that describes the atom sequence and bond connections. The syntax uses a backbone with branch specifications in square brackets.
Simple Organic Molecules
% Ethanol: CH3CH2OH
\chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-OH}
% Acetic acid
\chemfig{H-C(-[2]H)(-[6]H)-C(=[:-30]O)(-[:-150]OH)}
% Benzene ring
\chemfig{*6(-=-=(-OH)-=-=)}
% Cyclohexane chair conformation
\chemfig{*6(-(-H)(-H)-(-H)(-H)-(-H)(-H)-(-H)(-H)-(-H)(-H)-(-H)(-H))}
Branching and Angles
chemfig uses clock-face notation for bond angles: [2] means 12 o’clock (90°), [6] means 6 o’clock (270°), [0] is 3 o’clock (0°), and fractional values like [:-30] specify exact degrees.
% Branching with explicit angles
\chemfig{H_3C-C(-[2]H)(-[6]CH_3)-C(=[:-30]O)-OH}
% Double bond at specific angle
\chemfig{C(=[:90]O)(-[:270]H)-C}
% Triple bond
\chemfig{H-C~C-H}
Rings and Heterocycles
Prefix the ring specification with the size number: *6 is a 6-membered ring, *5 is 5-membered.
% Benzene (Kekulé structure)
\chemfig{*6(-=-=(-NO2)-=-=)}
% Pyridine
\chemfig{*6(=N-=-=(-Cl)-=)}
% Furan (5-membered ring with oxygen)
\chemfig{*5(-O-=-(-CH3)=-)}
% Naphthalene (fused rings)
\chemfig{*6(-=*6(-=-=--)-=---)}
Compound Numbering with chemnum
The chemnum package auto-numbers compounds so you can refer to them by label rather than hard-coded numbers:
\usepackage{chemnum}
% In the document:
\cmpd{aspirin} % numbers: 1
\chemfig[][scale=0.8]{*6(-=-(-O-\cmpdref{aspirin})=(-OH)-=)}
\cmpd{paracetamol} % numbers: 2
\chemfig[][scale=0.8]{*6((-OH)=(-NHCOCH_3)-=-=--)}
% Refer to compounds later:
Compound \cmpdref{aspirin} was synthesised...
Advanced Structures with xymtex
The xymtex package excels at fused ring systems like steroids, terpenes, and sugars. It uses a domain-specific language for ring fusion patterns.
\usepackage{xymtex}
% Basic fused rings
\cyclohexane{1H:1OH,2H,3H,4H,5OH,6H}
% Steroid skeleton (four fused rings)
\steroid[a]{1H,2H,3H,4H,5H,6H,7H,8H,9H,10CH3,11H,12H,13H,14H,15H,16H,17H,18CH3,19H}
% Pyranose ring (glucose)
\pyranose[a]{1OH,2H,3OH,4H,5H,6CH2OH}
Reaction Schemes and Mechanisms
Combine chemfig and mhchem to build multi-step reaction schemes with arrow annotations:
% Single-step reaction
\schemestart
\chemfig{*6(-=-=(-OH)-=-=)}
\arrow{->[\ce{NaOH}][\Delta]}
\chemfig{*6(-=-=(-O^{-}Na^{+})-=-=)}
\schemestop
% Multi-step synthesis
\schemestart
\chemfig{*6(-=--(-CH3)-=)}
\arrow{->[\ce{Br2}][FeBr3]}
\chemfig{*6(-=--(-CH3)(-Br)-=)}
\arrow{->[\ce{KMnO4}][\Delta]}
\chemfig{*6(-=--(-COOH)(-Br)-=)}
\schemestop
Chemical Mechanisms with Curved Arrows
chemfig supports curved arrows for electron-pushing mechanisms:
% SN2 reaction mechanism
\schemestart
\chemfig{Br-[:30]C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-Br}
\arrow{0}[,0]
\chemfig{\charge{90=\:}{Br}-[:90]C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-Br}
\schemestop
Spectroscopy Formatting
NMR Data
For NMR peak lists in experimental sections, combine mhchem with siunitx for consistent formatting:
\usepackage{siunitx}
% ^1H NMR data
\ce{^{1}H NMR} (CDCl\ce{3}, \SI{400}{\mega\hertz}):
$\delta$ = \SI{7.26}{\ppm} (m, 2H, Ar-H),
\SI{3.72}{\ppm} (s, 3H, OCH\ce{3}),
\SI{2.15}{\ppm} (s, 3H, CH\ce{3})
% ^13C NMR data
\ce{^{13}C NMR} (CDCl\ce{3}, \SI{100}{\mega\hertz}):
$\delta$ = 168.2 (C=O), 134.5 (Cq), 129.1 (CH),
128.4 (CH), 52.3 (OCH\ce{3}), 21.8 (CH\ce{3})
% Multiplets with coupling constants
$\delta$ = \SI{7.42}{\ppm} (dd, $J = \SI{8.2}{\hertz}$, \SI{1.9}{\hertz}, 1H, H-3),
\SI{7.15}{\ppm} (t, $J = \SI{7.6}{\hertz}$, 1H, H-4),
\SI{3.88}{\ppm} (q, $J = \SI{7.1}{\hertz}$, 2H, CH\ce{2})
IR Spectroscopy
% IR peak table
\begin{tabular}{lll}
\toprule
Wavenumber (\si{\per\centi\meter}) & Intensity & Assignment \\
\midrule
3350 & broad, strong & O-H stretch \\
2950 & medium & C-H stretch \\
1720 & strong & C=O stretch \\
1620 & medium & C=C stretch \\
1250 & strong & C-O stretch \\
\bottomrule
\end{tabular}
Mass Spectrometry
% HRMS data
HRMS (\ce{ESI^{+}}): $m/z$ calc. for \ce{C11H13NO3} [M+H]\ce{^{+}}:
\SI{208.0968}{}, found: \SI{208.0972}{}.
% Fragmentation pattern
\ce{M^{+.}} ($m/z$ 250) $\xrightarrow{-\ce{CH3}}$ \ce{[M-CH3]+} ($m/z$ 235)
$\xrightarrow{-\ce{CO}}$ \ce{[M-CH3-CO]+} ($m/z$ 207)
Biochemistry Structures
Amino Acids
% Alanine (generic backbone)
\chemfig{H_2N-C(-[2]H)(-[6]CH_3)-COOH}
% Cysteine with thiol side chain
\chemfig{H_2N-C(-[2]H)(-[6]CH_2-SH)-COOH}
% Peptide bond
\chemfig{H_2N-C(-[2]H)(-[6]R_1)-C(=[:-30]O)-N(-[2]H)-C(-[2]H)(-[6]R_2)-COOH}
DNA Base Pairing
% Thymine base
\chemfig{*6(-(=O)-N(-[2]H)-(-CH_3)=(-[6]O)-N(-H)=)}
% Adenine base
\chemfig{*6(-N=-N(-[2]H)-*5(-N=-N(-H)-)=N-)}
% Watson-Crick pairing notation (textual)
Adenine---Thymine \quad (2 H-bonds) \\
Guanine---Cytosine \quad (3 H-bonds)
Carbohydrates (Haworth Projections)
% $\beta$-D-Glucose (pyranose form)
\chemfig{?[a]-[:30]O-[2]?[b](-[2,0.5,,,draw=none]H)
-[:90](-[:150]OH)(-[:30]H)
-[:150](-[:150]H)(-[:30]OH)
-[:210](-[:150]HO)(-[:30]H)
-[:270](-[:150]H)(-[:30]CH_2OH)
-[:330]?[b](-[:30]OH)}
Periodic Table Figures
For drawing portions of the periodic table in LaTeX:
% Block of the periodic table using tikz
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{tikzpicture}[
element/.style={draw, minimum width=2em, minimum height=2em, font=\small}
]
\matrix[column sep=2pt, row sep=2pt] {
\node[element, fill=blue!20] {H}; & & & & & & & & & & & & & & & & &
\node[element, fill=blue!20] {He}; \\
\node[element, fill=red!20] {Li}; &
\node[element, fill=red!20] {Be}; & & & & & & & & & & &
\node[element, fill=green!20] {B}; &
\node[element, fill=green!20] {C}; &
\node[element, fill=green!20] {N}; &
\node[element, fill=green!20] {O}; &
\node[element, fill=green!20] {F}; &
\node[element, fill=blue!20] {Ne}; \\
};
\end{tikzpicture}
Thermodynamic and Kinetics Notation
% Enthalpy and Gibbs free energy
$\Delta H = \SI{-92.4}{\kilo\joule\per\mole}$
$\Delta G^{\ddagger} = \SI{85.3}{\kilo\joule\per\mole}$
$\Delta S = \SI{198.7}{\joule\per\mole\per\kelvin}$
% Rate constants
$k = A e^{-E_a/RT}$
% Equilibrium constant
$K_{eq} = \frac{[\ce{NH3}]^2}{[\ce{N2}][\ce{H2}]^3}$
% Half-life
$t_{1/2} = \frac{\ln 2}{k}$
Complete Document Example
\documentclass{article}
\usepackage{chemfig}
\usepackage[version=4]{mhchem}
\usepackage{chemmacros}
\usepackage{chemnum}
\usepackage{siunitx}
\usepackage{booktabs}
\setchemfig{atom sep = 2em}
\begin{document}
\section{Synthesis of Aspirin}
\cmpd{salicylic-acid}
\chemfig{*6(-=-(-OH)=(-COOH)-=)}
\quad
\arrow{->[\ce{Ac2O}][\ce{H2SO4}]}
\quad
\cmpd{aspirin}
\chemfig{*6(-=-(-O-\cmpdref{aspirin})(=O)-(-COOH)-=)}
\ce{^{1}H NMR} (\SI{400}{\mega\hertz}, CDCl\ce{3}):
$\delta$ = 11.05 (s, 1H, COOH),
8.12 (dd, $J = 7.9$, 1.7 Hz, 1H, H-3),
7.64 (td, $J = 7.5$, 1.8 Hz, 1H, H-5),
7.29 (t, $J = 7.6$ Hz, 1H, H-4),
7.11 (dd, $J = 8.1$, 1.1 Hz, 1H, H-6),
2.35 (s, 3H, COCH\ce{3}).
\end{document}
Resources
- chemfig — Molecular structure diagrams
- mhchem — Chemical formulas and equations
- chemnum — Compound numbering
- xymtex — Advanced ring structures
- chemmacros — General chemistry toolkit
- bpchem — Biochemical notation
- modiagram — Molecular orbital diagrams
- siunitx — Units and numbers
Comments