Chemical equations, molecular skeletons, the Feynman diagrams of particle physics — figures in the sciences each have their own “grammar” of drawing. You could build them from scratch in general-purpose TikZ, but domain-specific packages let you write the very notation a chemist or physicist would put on paper and get a correct figure from a short snippet. This page surveys the chemistry tools mhchem, chemfig, and XyMTeX; the physics tools tikz-feynman and feynmf; and modiagram for molecular-orbital diagrams — organized around what each one is actually for.
First, the lay of the land. Even within “chemistry and physics figures,” the tool you reach for depends sharply on what you want to make. The table below maps each package to its domain before we look at them one by one.
| Package | Domain | What it makes |
|---|---|---|
mhchem | Chemistry | Formulas & equations (H₂O, 2H₂+O₂→2H₂O as type) |
chemfig | Chemistry | Structural/skeletal formulas & reaction schemes |
XyMTeX | Chemistry | Structural formulas (older, command-based) |
tikz-feynman | Physics | Feynman diagrams (TikZ-based, auto-layout) |
feynmf / feynmp | Physics | Feynman diagrams (METAFONT/MetaPost, two-pass) |
modiagram | Chem./Phys. | Molecular-orbital (energy-level) diagrams |
Formulas and equations — mhchem
mhchem typesets chemical formulas and equations as type. It is not for structural pictures but for the chemical notation you write inline in prose or math** — things like H2O or 2 H2 + O2 -> 2 H2O. Load it with \usepackage[version=4]{mhchem} in the preamble, then write your expression inside its central command, **\ce{...}** (chemical equation).
The cleverness of \ce{} is that typing naturally produces correct chemistry. A digit right after an element symbol becomes a subscript (\ce{H2O} → H₂O), and a number or sign written with ^ becomes a charge superscript (\ce{SO4^2-} → SO₄²⁻). Arrows are written literally — **-> (forward), <=> (equilibrium), <-** (reverse) — and + is set as an addition of reactants with the right spacing. States are appended in parentheses, as in \ce{H2O(l)}; a precipitate is v and an evolved gas is ^, set off by spaces (\ce{BaSO4 v}).
\usepackage[version=4]{mhchem}
% ...
\ce{2 H2 + O2 -> 2 H2O}
\ce{CO2 + C ->[\Delta] 2 CO}
\ce{H2O <=> H+ + OH-}
\ce{Ba^2+ + SO4^2- -> BaSO4 v}These set, in order: the formation of water (the coefficients 2 and the subscripts align automatically); heating (->[\Delta] places the condition label Δ above the arrow); the autoionization of water (a two-way equilibrium arrow); and the precipitation of barium sulfate (the trailing v becomes a downward arrow ↓). An arrow can take two labels, ->[above][below], to annotate conditions above and below. \ce{} works both in running text and inside $...$ math.
mhchem cannot draw structures — bond lines and rings are out of scope. Short bond symbols such as single or double bonds can be shown with \bond, as in \ce{C\bond{-}C}, but for a real skeletal figure you want chemfig, next. (A newer package with overlapping goals, chemformula, offers the same idea through a \ch{...} command.)
Structures and schemes — chemfig
chemfig is the go-to package for drawing structural (skeletal) formulas of molecules. Built on TikZ, it describes a molecule almost in one stroke through a mini-language of bonds and branches.** Loading is just \usepackage{chemfig}. The central command is **\chemfig{...}**, and inside the braces you lay out atoms and bonds.
The grammar turns on bond symbols and angles. Bonds are - (single), = (double), and ~ (triple), placed between atoms. Each bond’s direction is set in the square brackets right after it. **A digit 0–7 such as [2] is a predefined direction in 45° steps**: [0] is east (right, 0°), and going counterclockwise, [2] is straight up (90°), [4] west (180°), [6] straight down (270°). An arbitrary angle is written with a colon as an absolute degree value, e.g. **[:30]**. A branch is a parenthesized group (...) that splits off from the main chain.
\usepackage{chemfig}
% ...
% メタン CH4:中心 C に H を 4 方向へ
\chemfig{H-C(-[2]H)(-[6]H)-H}
% ベンゼン環(交互の二重結合)
\chemfig{*6(=-=-=-)}In the methane above, H-C first places a hydrogen to the west of the carbon; the two branches (-[2]H) and (-[6]H) add hydrogens straight up and straight down; and the final -H extends one to the east (the default direction) — giving the cross-shaped CH₄. In the benzene below, *6(...) means a six-membered ring, and the =-=-=- inside alternates single and double bonds, drawing the familiar hexagonal aromatic ring. * makes an ordinary ring; ** gives the aromatic form with an inscribed circle.
chemfig also draws reaction schemes — figures linking several molecules with arrows. Wrap them in **\schemestart ... \schemestop**, place molecules (\chemfig{...}) inside, and insert arrows with **\arrow**. You can label an arrow with reagents or conditions, as in \arrow{->[reagent]}, and \arrow{<=>} gives an equilibrium arrow. The next snippet is a simple A → B scheme.
\schemestart
\chemfig{H-C(-[2]H)(-[6]H)-H}
\arrow{->[\small oxidation]}
\chemfig{O=C(-[2]H)-[6]H}
\schemestopThis produces a left-to-right reaction scheme that goes from the structural formula of methane, through a labeled arrow marking oxidation, to the structural formula of formaldehyde. chemfig runs under pdfLaTeX, LuaLaTeX, or XeLaTeX, and because it sits on TikZ it usually needs no extra driver setup (under DVI-based pLaTeX, specify dvipdfmx).
Another structural tool — XyMTeX
An older package for structural formulas is XyMTeX (by Shinsaku Fujita). Where chemfig thinks in terms of “drawing bonds in one stroke,” XyMTeX thinks in terms of calling up whole rings and skeletons as commands. For a benzene derivative, say, you pass the positions and kinds of substituents as arguments to a dedicated command. Its strength is setting complex fused polycyclics and substitution patterns reliably through fixed, structured commands.
Load it with \usepackage{xymtex}; it provides commands for vertical and horizontal forms of benzene rings, among many others. For brand-new work most people choose chemfig, whose notation is more intuitive and which is actively maintained — but XyMTeX remains useful for legacy manuscripts built on it, or when its command system already suits your hand. It supports a standard LaTeX output mode as well as PostScript and PDF modes.
Feynman diagrams — tikz-feynman and feynmf
On to physics. For Feynman diagrams — the pictures of particle interactions — there are two main families of tools. The modern one is **tikz-feynman, built on TikZ: you declare vertices and propagators and it lays them out automatically.** The recommended load is with a compatibility key, \usepackage[compat=1.0.0]{tikz-feynman}.
For a quick figure, use the one-shot command **\feynmandiagram**. You set each line’s style with [fermion] (a fermion — a straight line with an arrow), [photon] (a photon — a wavy line), [gluon] (a gluon — a coil), and so on, and vertices are created implicitly just by naming them. For precise placement, open the **feynman environment** inside a tikzpicture, place vertices with **\vertex, and connect them with \diagram***.
\usepackage[compat=1.0.0]{tikz-feynman}
% ...
% 一発命令:e+ e- → μ+ μ-(光子交換)
\feynmandiagram [horizontal=a to b] {
i1 -- [fermion] a -- [fermion] i2,
a -- [photon] b,
f1 -- [fermion] b -- [fermion] f2,
};This is a textbook s-channel scattering: an electron–positron pair on the left meets at vertex a, a wavy line (a photon) joins a and b, and on the right it splits into another pair. The horizontal=a to b is a layout hint meaning “place a and b horizontally.” Important: the automatic layout needs LuaTeX — tikz-feynman uses a Lua algorithm internally. It will run under pdfLaTeX, but the layout degrades to a rudimentary one and it warns you. Treat LuaLaTeX as effectively required.
The other family is the classic **feynmf / feynmp. They set each diagram separately in METAFONT (feynmf) or MetaPost (feynmp) and then include the result — a two-pass workflow.** Diagrams are grouped by file name in an fmffile environment; inside an fmfgraph (or fmfgraph*) you give external legs with \fmfleft and \fmfright and lines with \fmf{...}. The first LaTeX run writes out the diagram-definition files; mf/mpost converts them to a font/figure; and the second run pulls them in.
\usepackage{feynmp-auto}
% ...
\begin{fmffile}{myfd}
\begin{fmfgraph*}(120,80)
\fmfleft{i1,i2}
\fmfright{o1,o2}
\fmf{fermion}{i1,v1,o1}
\fmf{photon}{v1,v2}
\fmf{fermion}{i2,v2,o2}
\end{fmfgraph*}
\end{fmffile}This draws the same scattering with feynmp. Using feynmp-auto automates the MetaPost step, easing the manual two-pass. feynmf/feynmp are mature, produce beautiful output, and are still widely used in older papers and TeX setups — but they carry the extra step of invoking MetaFont/MetaPost. As a rule: for new work, the convenient tikz-feynman; for legacy material or minimal dependencies, the feynmf family.
MO and energy-level diagrams — modiagram
At the border of chemistry and physics sits the molecular-orbital (MO) diagram — a picture showing how atomic orbitals (AOs) combine into bonding and anti-bonding molecular orbitals (MOs), stacked vertically by energy. The package built for this is **modiagram**, also founded on TikZ. Load it with \usepackage{modiagram}, and inside the **MOdiagram environment describe the left and right atomic orbitals with \atom and the connecting molecular orbitals with \molecule**.
\usepackage{modiagram}
% ...
\begin{MOdiagram}
\atom{left}{ 1s = {0; up} }
\atom{right}{ 1s = {0; up} }
\molecule{ 1sMO = {1; pair, } }
\end{MOdiagram}This is the simplest MO diagram, for the hydrogen molecule H₂. \atom{left} and \atom{right} each place one spin-up electron in a 1s orbital ({0; up}, where 0 is the energy level), and \molecule merges them into a bonding orbital holding an electron pair (pair). By giving just the occupancy (up, down, pair) and the level heights as arguments, you get a level diagram of horizontal lines and spin arrows. Such energy-level diagrams can also be drawn in plain TikZ, but because modiagram specializes in MO conventions, it sets these stock figures more briefly and correctly.
Choosing, and notes on compilation
Finally, practical guidance. You can choose straightforwardly by what you want to make. For chemical formulas and equations in prose, mhchem; for structures and reaction schemes, chemfig (or XyMTeX where a command-based approach suits complex fused rings); for Feynman diagrams, tikz-feynman (or feynmf/feynmp for older setups and legacy manuscripts); for MO diagrams, modiagram. mhchem and chemfig are complementary, and a common pattern is to use both in one document — mhchem for inline equations and chemfig for displayed skeletons.
Mind the engine and pass requirements, too. The automatic layout of tikz-feynman assumes LuaLaTeX; on other engines the layout degrades. feynmf/feynmp need a two-pass run that invokes MetaFont/MetaPost separately (which feynmp-auto can automate). chemfig and modiagram are TikZ-based and run under pdfLaTeX, LuaLaTeX, or XeLaTeX — but TikZ figures are computationally heavy, and many of them make compilation slow. Caching figures with tikzexternalize, or compiling them alone with the standalone class, keeps editing comfortable.