Typesetting chemistry in LaTeX

Yesterday I gave the following tip on TeXtip:

Set chemical formulas with math Roman. Example: sulfate is $mathrm{SO_4^{2-}}$

TorbjoernT and scmbradley let me know there’s a better way: use Martin Hansel’s package mhchem. The package is simpler to use and it correctly handles subtle typographical details.

Using the mhchem package, sulfate would be written ce{SO4^2-}. In addition to chemical compounds, mhchem has support for bonds, arrows, and related chemical notation.

Example:

Source:

\documentclass{article}
\usepackage[version=3]{mhchem}
\parskip=0.1in
\begin{document}

\ce{SO4^2-}

\ce{^{227}_{90}Th+}

\ce{A\bond{-}B\bond{=}C\bond{#}D}

\ce{CO2 + C -> 2CO}

\ce{SO4^2- + Ba^2+ -> BaSO4 v}

\end{document}

 

For more information, see the mhchem package documentation.

Related posts:

Top four LaTeX mistakes
Hyperlinks in LaTeX-generated PDF

Tagged with: ,
Posted in Typography
5 comments on “Typesetting chemistry in LaTeX
  1. Those supposed right angles are showing HTML entities instead.

  2. John says:

    Michael: Thanks for letting me know. I’ve fixed it.

    My plug-in for displaying code nicely failed me. So I reverted to putting the code in <pre> tags. Now it’s not as fancy, but it’s at least correct.

  3. Chris Smith says:

    Thanks for your notes. Very useful and work perfectly with MacTeX out of the box.

  4. Paul says:

    Thanks, John, for posting this! I was having trouble finding any documentation on the mhchem package. Now my nuclear reaction notation looks just right.

  5. Craig Finch says:

    mhchem is very useful, but one thing it won’t do is properly typeset IUPAC names like 3-ethyl-2,2,5-trimethylhexane. For IUPAC names, use bpchem along with mhchem.

2 Pings/Trackbacks for "Typesetting chemistry in LaTeX"
  1. [...] This post was mentioned on Twitter by John D. Cook and Dan Hagon, TeX tips. TeX tips said: More info on the chemistry package mentioned yesterday http://bit.ly/gAPATT [...]

  2. [...] Typesetting chemistry in LaTeX (johndcook.com) [...]