The site supports mathjax for mathematical equations and the mhchem extension for describing chemical reactions. What is the markdown syntax to add these to my own posts?


1 Answer 1


Getting started

On earthscience.SE, we use MathJax to format our math. MathJax is a tool that lets us display LaTeX math on a browser.

To use mathjax, enclose your math within single($...$) or double($$...$$) dollars. Single dollars make the math inline, for example, Let $x$ be a variable gives:

Let $x$ be a variable.

On the other hand, double dollars make the math a block element. It gets its own line, and is slightly larger. For example, The Navier-Stokes equation of motion in a rotating reference frame is: $$\dfrac{\partial\mathbf u}{\partial t} = - \mathbf u \cdot \nabla \mathbf u -\dfrac{1}{\rho}\nabla p-2 \mathbf \Omega \times \mathbf u + \mathbf g + \mathbf F$$ gives:

The Navier-Stokes equation of motion in a rotating reference frame is: $$\dfrac{\partial\mathbf u}{\partial t} = - \mathbf u \cdot \nabla \mathbf u -\dfrac{1}{\rho}\nabla p-2 \mathbf \Omega \times \mathbf u + \mathbf g + \mathbf F$$

Note that, in math mode, MathJax ignores the spaces you type, e.g. $a b$ yields $a b$. MathJax formats expressions the way it is common in mathematics texts. However, the printing rules for signs and symbols used in the natural sciences and technology may require additional spaces (in particular, between the numerical value and the unit symbol). In math mode, use (backslash space) or ~ (tilde) if you want the equivalent of space in normal text. Where separation of numbers into groups of three digits is used, the groups shall be separated by a thin space \, (backslash comma); e.g. $299\,792\,458$ yields $299\,792\,458$.

Basic chem

We use the mhchem $\LaTeX$ package for chemistry. It lets us easily format chemical names/reactions without typing too much.

There really is only one command you need to know here: \ce{...}. \ce{...} takes its parameters and automagically formats it. For example,

$\ce{HCl}$ dissociates in water as follows:
$$\ce{H2O + HCl <=> H3O+ + Cl-}$$

Renders as

$\ce{HCl}$ dissociates in water as follows: $$\ce{H2O + HCl <=> H3O+ + Cl-}$$

Note that spaces are very important for mhchem to separate super/subscripts from normal text. \ce{H3O+} will display $\ce{H3O+}$, but \ce{H2O +} will display $\ce{H2O +}$. Various types of reaction arrows are supported, including ->, <=>, <==>>, etc.

It also supports various types of bonds, via the \bond{..} command (to be called inside \ce{...}). You need not call \bond for normal bonds.

Eg: \ce{H\bond{->}A-B=C#D\bond{~}E\bond{~-}F\bond{...}G\bond{<-}E} displays:


Full documentation of mhchem here

Basic math

Superscripts and subscripts

You can denote superscripts via the ^ character, and subscripts via _. For example, x^2 renders as $x^2$, x_1 renders as $x_1$, and x_1^3 renders as $x_1^3$.

If you want to include more than one character in the super/sub script, enclose it in curly braces ({...}).

For example, x^10 renders as $x^10$, but x^{10} renders as $x^{10}$

Fractions and square roots

Fractions can be easily displayed using \frac{..}{..}. For example, \frac{a+b^c}{de+f} renders as $\frac{a+b^c}{de+f}$

Protip: You can exclude the braces for single-character numerators/denominators (if the first character is a letter, you need to use a space after \frac, though). For example \frac12 renders as $\frac12$, and \frac ab renders as $\frac ab$

Square roots can be added in a similar manner, via \sqrt{....}. For example, \sqrt{x+y} renders as $\sqrt{x+y}$.

Greek letters

Greek letters can be added usung a backslash ('\'), followed by the name of the letter. Captialise the first letter of the name for greek capital letters.

Eg \alpha \beta \gamma \Omega renders as $\alpha \beta \gamma \Omega$.

Make sure that you put spaces after these if you are typing normal alphabet characters. Eg e^{\pii} gives an error, you need to use e^{\pi i}.

Note that there are special commands \varepsilon , \varsigma , \varrho , and \varpi to distinguish between the lunate Greek letters.

Further reading

This post based upon this post, a CW primarily by ManishEarth on chemistry.SE


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .