Files
bobbie-pkm/.trash/2026-01-21 mhchem for MathJax, mhchem for KaTeX.md
2026-03-02 17:06:32 +00:00

5.3 KiB
Raw Blame History

created, up, title, source, author, published, topics, tags
created up title source author published topics tags
2026-01-21T22:39:55
Library
mhchem for MathJax, mhchem for KaTeX https://mhchem.github.io/MathJax-mhchem/

mhchem is a tool for writing beautiful chemical equations easily.

This is the manual for mhchems input syntax (as implemented in JavaScript display engines for mathematics).

Chemical Equations (ce)

\ce{CO2 + C -> 2 CO} \ce{CO2 + C -> 2 CO}

\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-} \ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}

Chemical Formulae

Charges

Stoichiometric Numbers

Nuclides, Isotopes

It might be ambiguous whether a superscript belongs to the left or right element. There is automatic detection (digits only = mass number = belongs to right side), but to make sure you can type {} as a separator.

Reaction Arrows

not to be used according to IUPAC and ACS

Each arrow can take two optional arguments: one for above and one for below. The arrow arguments use the same input syntax as the \ce command.

$\ce{

upright text, see below

$\ce{

italic math, see below

Unfortunately, MathJax cannot stretch <-->, <=>, <=>> and <<=> arrows properly. All the arrows do stretch in LaTeX and KaTeX.

Parentheses, Brackets, Braces

Use parentheses ( ) and brackets [ ] normally. Write braces as \{ \}.

For large parentheses, \left and \right macros need to be in the same math environment, so you might have to put \ce into $ into \ce, but thats fine.

$\ce{

States of Aggregation (not fully supported for LaTeX yet)

not IUPAC-conform, not ACS-conform

Crystal Systems (not fully supported for LaTeX yet)

Variables like x, n, 2n+1**

Typographical conventions say that variables are typeset in an italic font, while other entities (like chemical elements) are typeset in an upright font. mhchem tries to recognize common patterns and use the correct (italic) font, like the x and n in the following examples.

$\ce{

If a more complex term is not properly recognized, you can switch to math mode (= italics) explicitly.

Greek Characters

Just write \alpha etc. Typographical conventions say that variables are typeset in an italic font, while other entities (like chemical elements) are typeset in an upright font. In the following examples, the Greek character is not a variable that stands for a number, therefore an upright font should be used. Unfortunately, neither MathJax nor KaTeX support upright lower-case Greek characters.

$\ce{

Spaces after a greek character are ignored. This is standard TeX behavior. Insert {} to get the desired output.

$\ce{

(Italic) Math

By using $...$ you can escape to math mode.

$\ce{

(With mhchem for LaTex there is a difference between $...$ and ${...}$. But because neither MathJax nor KaTeX have a text font, both inputs will yield identical results there.)

Italic Text

With the same mechanism you can mimic an italic text font.

$\ce{

Spaces will be ignored. Use a ~ when you need to typeset a space.

Upright Text, Escape Parsing

Enclose upright text with {...}.

$\ce{

With the same mechanism, you can escape parsing, for instance if you need a simple hyphen (that should not become a bond).

$\ce{

Bonds

mhchem tries to differentiate whether \ce{-} should be a bond, a charge or a hyphen.

$\ce{
$\ce{
$\ce{
$\ce{
$\ce{
$\ce{

Addition Compounds

$\ce{

Oxidation States

$\ce{

Unpaired Electrons, Radical Dots

Kröger-Vink Notation (not supported for LaTeX yet)

$\ce{
$\ce{

upright V = Vanadium, italic V = vacancy

Equation Operators

not to be confused with bonds

not to be confused with bonds

Precipitate and Gas

$\ce{
$\ce{

Other Symbols and Shortcuts (not fully supported for LaTeX yet)

Complex Examples

$\ce{
$\ce{
$\ce{
$\ce{

Physical Units (pu) (MathJax or KaTeX only, not for LaTeX)

There are two conventions regarding the multiplication within units.

There are four conventions regarding divisions.

There are four main conventions for writing numbers in scientific notation.

If you need more control than is offered here, take a look at the siunitx extension.

Compatibility with mhchem for LaTeX

Most of these examples work identically for mhchem for MathJax, mhchem for KaTeX and mhchem and LaTeX. Exceptions are indicated. Also, some edge-cases may render differently. I will try to minimize the differences in the future. But even then, the MathJax and KaTeX versions will always be more tolerant of sloppy input (e.g. a missing space) than mhchem for LaTeX.

Contact and Support

If you have a question and cannot find an answer—neither here nor with a web search—then

Test Drive