\usepackage[version=4]{mhchem} to your preamble and write \ce{CO2}. The \ce{...} command works in both text mode and math mode, keeps element symbols upright, and formats subscripts, charges, and isotopes automatically. If you only need a single formula without loading a package, write $\mathrm{CO_2}$ rather than $CO_2$ (plain math mode italicizes C and O as variables).
For 2D molecular structures and reaction schemes, pair mhchem with \usepackage{chemfig}. For numerical units and data tables, add \usepackage{siunitx}.
Chemical formulas with mhchem
Pass [version=4] when loading mhchem to select the current parser and avoid a missing-version warning. Inside \ce{...}, numbers after element symbols become subscripts, trailing + and - become charges, a leading ^{...} sets the isotope mass number, phase labels such as (g) or (aq) stay upright, and . inserts a centered hydrate dot.
chemical-formulas.tex
Ready to use this syntax? Continue in the browser editor when you want to adapt the example in a real project.Open LaTeX Cloud Studio
Chemical reactions and equations
Inside\ce{...}, put spaces around + and reaction arrows so mhchem distinguishes operators from ionic charges:
->draws a forward arrow;<=>draws a reversible equilibrium arrow.- Attach reaction conditions above and below an arrow with bracketed arguments:
->[above][below]or<=>[above][below]. ^andvafter a space render gas evolution () and precipitation () arrows.- Combine
\ce{...}withamsmath’salign*environment and&before the arrow to align multi-step reactions cleanly.
chemical-reactions.tex
Molecular structures with chemfig
Use chemfig to draw 2D structural formulas directly in LaTeX without external drawing software. Bonds are written between atom groups:
-single bond,=double bond,~triple bond.[angle]sets the bond direction in multiples of 45 degrees ([0]right,[2]up,[4]left,[6]down), or in exact degrees with[:angle].(...)creates a branch off the preceding atom.*n(...)draws an n-membered ring—for example\chemfig{*6(=-=-=-)}for benzene.
molecular-structures.tex
Reaction schemes with chemfig
Wrap multiple \chemfig structures in \schemestart ... \schemestop to build a reaction scheme with \+ between reactants and \arrow{...} for reaction arrows. Adjust \setchemfig{atom sep=...} if a wide scheme needs tighter bond lengths to fit within the page margins.
reaction-scheme.tex
Units and chemical data tables
Usesiunitx alongside mhchem and booktabs for lab measurements and thermodynamic tables. \qty{value}{unit} formats numbers and SI units with proper spacing, \unit{...} formats standalone units in headers, and S columns align numerical columns on the decimal point.
thermodynamic-table.tex
Alternative syntax: chemformula
If your document uses the chemmacros bundle or you prefer chemformula syntax, \ch{...} covers formulas, isotopes, charges, and reactions with a similar shorthand. Both mhchem and chemformula are included in TeX Live; pick one per document so subscripts, arrows, and spacing stay consistent.
chemformula-example.tex
Quick reference: common mhchem syntax
Common mistakes
- Omitting
[version=4]in\usepackage{mhchem}:mhchemprints a package warning when loaded without a version option; write\usepackage[version=4]{mhchem}. - Typing
$CO_2$in math mode: Plain math mode rendersCandOas italic math letters. Use\ce{CO2}or, without packages,$\mathrm{CO_2}$. - Missing spaces around
+orvin\ce{...}: Write\ce{A + B}to distinguish the reaction separator from a charge, and put a space beforevor^for precipitate and gas arrows (\ce{AgCl v}). - Wide
chemfigschemes overflowing the margin: Reduce bond length with\setchemfig{atom sep=1.5em}, as the reaction-scheme example does.
In LaTeX Cloud Studio
LaTeX Cloud Studio compiles with TeX Live 2026 (full distribution), somhchem, chemfig, chemformula, siunitx, and booktabs work out of the box with no manual installation. Every example on this page compiles under PDFLaTeX; if your project uses Unicode fonts with XeLaTeX or LuaLaTeX, you can select PDFLaTeX, XeLaTeX, or LuaLaTeX explicitly under Settings -> General -> LaTeX Engine (default Auto (Recommended)), and your explicit choice is kept.
Ready to write a chemistry paper or lab report in the browser? Start from the Lab Report template in LaTeX Cloud Studio and replace main.tex with whichever complete example above fits your document.
