Note: This documentation is for Moodle 2.7. For up-to-date documentation see Chemistry notation using mhchem.

# Chemistry notation using mhchem

Note: This page is a work-in-progress. Feedback and suggested improvements are welcome. Please join the discussion on moodle.org or use the page comments.

The mhchem pack­age pro­vides com­mands for type­set­ting chem­i­cal molec­u­lar for­mu­lae and equa­tions.

## Why mhchem?

It is possible to display chemical formulae and equations using TeX mathematics mode. However, it is rather cumbersome for a range or reasons. Different display conventions: uppercase letters are displayed in italics for mathematics, whereas element symbols are upright for chemistry. The complexities of supercript and subscript notation, ions and isotopes. Bonds, equilibrium reaction arrows etc.

The mhchem extension allows a more adaptable display and more natural input of chemical formulae and equations. In Moodle, mhchem syntax can use text input directly into an HTML editor (TinyMCE or Atto) or by an Atto chemistry plugin (similar to the equation plugin).

This is particularly useful for documenting isotopes, relative atomic and relative molecular mass, empirical and molecular formulae, balanced equations (full and ionic), equilibium reactions and themodynamics.

For more complex structural and displayed formulae (e.g. organic chemistry), homologous series and functional groups, you may also wish to consider a 'drawing' plugin such as the MarvinJS-based Chemical structures and reaction editor

## Installation

The mhchem package can be integrated with Moodle in one of two ways, though the first (via MathJax) is recommended.

### via MathJax

The recommended way is by using MathJax to render TeX notation and include the mhchem extension. MathJax has become the de facto standard for displaying mathematics on the Web and since version 2.7 Moodle has a MathJax loader filter enabled by default. However, mhchem needs to be added to the MathJax configuration.

In Administration > Site administration > Plugins > Filters > Mathjax > Local Mathjax installation, edit the Mathjax configuration to include mhchem.js in the TeX extensions:

TeX: {extensions: ["mhchem.js","color.js","AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"]},

### via LaTeX

It is also possible to add the mhchem bundle alongside LaTex on the Moodle server, and then use theTeX filter. However, this may be tricky and display issues can be difficult to debug. If you do wish to pursue the TeX filter option, installation details will depend on the server operating system. Some Linux distributions can use their standard package manager to install mhchem and dependencies. For Fedora 20, this is simply:

yum install texlive-mhchem

Once installed, in your Moodle Administration > Site administration > Plugins > Filters > TeX notation > LaTeX renderer Settings, add the following to the LaTeX preamble:

\usepackage{mhchem}

The following gives a filled arrowhead style, which may be preferred.

\usepackage[arrows=pgf-filled]{mhchem}

## Basics

Note that mhchem is not currently installed in this documentation wiki. Therefore the chemical display of chemical formulae and equations is simulated and may not exactly correspond to rendering using mhchem, which is usually nicer!.

The default TeX delimiters are $...$ or $$...$$ for displayed mathematics, and $$...$$ for in-line mathematics. For mhchem the additional delimiter \ce{...} is required inside the mathematics delimeters i.e .$\ce{...}$ or $$\ce{...}$$ for displayed chemical formulae, and $$\ce{...}$$ for in-line chemical formulae. In the rest of this document the TeX delimiters are not explicitly shown.

${\displaystyle \mathrm {H_{2}O} }$ \ce{H2O}

${\displaystyle \mathrm {Sb_{2}O_{3}} }$ \ce{Sb2O3}

${\displaystyle \mathrm {H^{+}} }$ \ce{H+}

${\displaystyle \mathrm {CrO_{4}^{2-}} }$ \ce{CrO4^2-}

${\displaystyle \mathrm {AgCl_{2}^{-}} }$ \ce{AgCl2-}

${\displaystyle \mathrm {[AgCl_{2}]^{-}} }$ \ce{[AgCl2]-}

${\displaystyle \mathrm {Y^{99+}} }$ \ce{Y^{99}+}

${\displaystyle \mathrm {H_{2}(aq)} }$ \ce{H2_{(aq)}}

${\displaystyle \mathrm {NO_{3}^{-}} }$ \ce{NO3-}

${\displaystyle \mathrm {(NH_{4})_{2}S} }$ \ce{(NH4)2S}

### Amounts

Place amounts directly in front of a formula. A small space will be inserted automatically.

${\displaystyle \mathrm {2H_{2}O} }$ \ce{2H2O}

${\displaystyle \mathrm {{\frac {1}{2}}H_{2}O} }$ \ce{1/2H2O}

### Isotopes

${\displaystyle \mathrm {{}_{90}^{227}Th^{+}} }$ \ce{^{227}_{90}Th+}

### Fonts

When you are in a math environment (e.g. opened and closed with a $...$, \(...)\ or $$...$$), you could simply use \ce to set content in an upright font. Remember: all variables—like V for volume—are set using an italic font, physical units and chemical elements are set using an upright font.

${\displaystyle {\mathit {V}}\mathrm {_{H_{2}O}} }$ $V_{\ce{H2O}}$

When used in text mode, \ce adapts to the current text font. You could simply write a formula in one of your section titles it would be set with the correct, no matter where is appears (sectiontitle, header, contents, references, ...).

${\displaystyle \mathrm {H_{2}O} }$, ${\displaystyle \mathrm {H_{2}O} }$ \ce{H2O}, $\ce{H2O}$

${\displaystyle \mathrm {Ce^{IV}} }$ \ce{Ce^{IV}}

There are some special cases. A negative charge (-) in text mode is replaced with a dash (–), because a text minus sign often is too short. All ‘operators’, e.g. ‘+’ and reaction arrows, are always taken from the math font.

### Special Symbols

${\displaystyle \mathrm {KCr(SO_{4})_{2}\cdot 12H_{2}O} }$ \ce{KCr(SO4)2*12H2O}

${\displaystyle \mathrm {KCr(SO_{4})_{2}\cdot 12H_{2}O} }$ \ce{KCr(SO4)2.12H2O}

${\displaystyle \mathrm {[Cd\{SC(NH_{2})_{2}\}_{2}]\cdot [Cr(SCN)_{4}(NH_{3})_{2}]_{2}} }$ \cf{[Cd\{SC(NH2)2\}2].[Cr(SCN)4(NH3)2]2}

${\displaystyle \mathrm {RNO_{2}^{-.}} }$, ${\displaystyle \mathrm {RNO_{2}^{-.}} }$ $\ce{RNO2^{-.}}$, \ce{RNO2^{-.}}

${\displaystyle \mu \!-\!\mathrm {Cl} }$ \ce{$\mu\hyphen$Cl}

### Bonds

Horizontal bonds can be set using the characters -, = and # (single, double, triple bond) inside a formula (a - at the end of a formula yields a negative charge).

${\displaystyle \mathrm {C_{6}H_{5}\!-\!CHO} }$ \ce{C6H5-CHO}

${\displaystyle \mathrm {X\!=\!Y\!\equiv \!Z} }$ \ce{X=Y#Z}

${\displaystyle \mathrm {A\!-\!B\!=\!C\!\equiv \!D} }$ \ce{A\sbond B\dbond C\tbond D}

Different books visualise bonds in extremely different ways. Currently, the minus sign from the math font is used to display the bonds (even in text mode). The bonds are vertically aligned on the math axis. For most math fonts, this is lower than half the height of a capital letter.

The \bond command allows you to typeset some types of special bonds.

${\displaystyle \mathrm {A\!-\!B\!=\!C\!\equiv \!D} }$ \ce{A\bond{-}B\bond{=}C\bond{#}D}

${\displaystyle \mathrm {A\!\sim \!B\!\simeq \!C} }$ \ce{A\bond{~}B\bond{~-}C}

${\displaystyle \mathrm {A\!\cong \!B\!\cong \!C\!\cong \!D} }$ \ce{A\bond{~=}B\bond{~--}C\bond{-~-}D}

${\displaystyle \mathrm {A\!\cdots \!B\!\cdot \cdots \!C} }$ \ce{A\bond{...}B\bond{....}C}

${\displaystyle \mathrm {A\!\rightarrow \!B\!\leftarrow \!C} }$ \ce{A\bond{->}B\bond{<-}C}