How to Write Chemistry Notation in LaTeX (mhchem, chemfig)
LaTeX is widely used in chemistry for typesetting chemical formulas, balanced equations, and molecular structures. The mhchem package handles chemical formulas and reaction equations with intuitive syntax, while chemfig draws structural formulas and reaction mechanisms. Together, they cover everything from simple formulas to complex organic chemistry. Bibby AI supports both packages with instant rendering, letting you see your molecules and reactions as you type — a major advantage over Overleaf's compile-and-wait approach for iterative diagram work.
Write Chemical Formulas and Reactions with mhchem
Use the \ce command from mhchem for chemical formulas, ions, isotopes, and balanced reaction equations:
\documentclass{article}
\usepackage[version=4]{mhchem} % Always use version 4
\begin{document}
% Simple formulas
\ce{H2O} \quad \ce{H2SO4} \quad \ce{Ca(OH)2} \quad \ce{[Cu(NH3)4]^{2+}}
% Isotopes
\ce{^{227}_{90}Th} \quad \ce{^{14}C} \quad \ce{^{235}U}
% Oxidation states
\ce{Fe^{II}Fe^{III}2O4} \quad \ce{Mn^{VII}}
% Balanced reactions
\ce{2H2 + O2 -> 2H2O}
\ce{CH4 + 2O2 -> CO2 + 2H2O}
% Reversible reaction
\ce{N2 + 3H2 <=> 2NH3}
% Reaction with conditions
\ce{Fe2O3 + 3CO ->[\Delta] 2Fe + 3CO2}
% Precipitation and gas evolution
\ce{BaCl2 + Na2SO4 -> BaSO4 v + 2NaCl}
\ce{CaCO3 + 2HCl -> CaCl2 + H2O + CO2 ^}
\end{document}Draw Molecular Structures with chemfig
Use chemfig to draw structural formulas, ring compounds, and reaction mechanisms:
\documentclass{article}
\usepackage{chemfig}
\begin{document}
% Simple molecules
\chemfig{H-C(-[2]H)(-[6]H)-C(-[2]H)(-[6]H)-H} % Ethane
\bigskip
% Methanol with lone pairs
\chemfig{H-C(-[2]H)(-[6]H)-O-H}
\bigskip
% Benzene ring
\chemfig{*6(-=-=-=)}
\bigskip
% Toluene (methylbenzene)
\chemfig{*6(-=-(-CH_3)=-=)}
\bigskip
% Aspirin (acetylsalicylic acid)
\chemfig{*6(-(=O)-O-(-[2]=O)(-[6]CH_3)=-=(-COOH)-=)}
\bigskip
% Amino acid (glycine)
\chemfig{H_2N-CH_2-C(=[2]O)(-[6]OH)}
\end{document}Combine Formulas and Structures in a Document
Create a chemistry document with both reaction equations and structural diagrams:
\documentclass{article}
\usepackage[version=4]{mhchem}
\usepackage{chemfig}
\begin{document}
\section{Esterification Reaction}
The reaction between acetic acid and ethanol:
\ce{CH3COOH + C2H5OH <=>[\ce{H2SO4}][\Delta] CH3COOC2H5 + H2O}
\subsection{Structural Representation}
\schemestart
\chemfig{H_3C-C(=[2]O)(-[6]OH)}
\+
\chemfig{H_3C-CH_2-OH}
\arrow{<=>[$\ce{H2SO4}$][$\Delta$]}
\chemfig{H_3C-C(=[2]O)(-[6]O-CH_2-CH_3)}
\+
\chemfig{H_2O}
\schemestop
\subsection{Reaction Conditions}
\begin{itemize}
\item Catalyst: \ce{H2SO4} (concentrated)
\item Temperature: \ce{60-70^{\circ}C}
\item Yield: $\sim$67\% (equilibrium limited)
\end{itemize}
\end{document}💡 Tips
- •Always load mhchem with [version=4] — older versions have different syntax and are less capable.
- •In mhchem, use -> for forward reactions, <=> for equilibrium, and ->[$catalyst$] for conditions above the arrow.
- •chemfig angles are in multiples of 45° by default — use [: angle] for arbitrary angles in degrees.
- •For complex organic structures, break the molecule into rings and substituents for more readable code.
Try This in Bibby AI
Write LaTeX faster with AI auto-complete and instant compilation.
Start Writing Free