[Tex/LaTex] Typesetting Chemical Formulas

best practiceschemistry

What is the 'best' package for typesetting chemical formulas? (I don't need anything but the chemical formulas.)

Assume I want to typeset

The dissociation of a AgBr molecure requires an energy of $E = \SI{123456789}{\J}$.

I am using the siunitx package for the physical quantity but what about AgBr?

Best Answer

The answer depends a bit on what you actually need. If all your formulae are as simple as AgBr or FeO there is no need for any package and you can just type them as they are. If you want some macro for marking the formulae in your source something like

\newcommand*\chem[1]{\textup{#1}}

would suffice. Or - if you plan to use it in math mode, too -

\newcommand*\chem[1]{\ensuremath{\mathrm{#1}}}

The second version would even allow you to typeset formulae like AlBr3 and even simple reaction equations:

\documentclass{article}
\newcommand*\chem[1]{\ensuremath{\mathrm{#1}}}
\begin{document}

\chem{AlBr_3}

$\chem{H_2} + (1/2)\,\chem{O_2} = \chem{H_2O}$

$2\,\chem{H_2} + \chem{O_2} \to 2\,\chem{H_2O}$

\end{document}

Output 1

Only if you need more complicated features or if you have to type a lot of those formulae and not just some ten or twenty then one of the chemistry packages will start to bring you benefits. There are two packages to consider:

  1. mhchem
  2. chemformula

The differences between both of them are

  • subtle differences in the syntax,
  • differences in the layout of the equations, e.g., regarding spacing,
  • a different set of options for customization,
  • probably more I have forgotten right now.
\documentclass{article}
\usepackage[version=4]{mhchem}
\begin{document}

\ce{AlBr3}

\ce{H2 + (1/2) O2 = H2O}

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

\end{document}

Output 2

\documentclass{article}
\usepackage{chemformula}
\begin{document}

\ch{AlBr3}

\ch{H2 + (1/2) O2 == H2O}

\ch{2 H2 +  O2 -> 2 H2O}

\end{document}

Output 3

Related Question