Inline and display formulas
There are two kinds of formula:
- Inline: sits inside a sentence, with the words.
- Display: sits on its own line, usually larger and centred.
The famous formula is $E = mc^2$ and it stays in the sentence.
$$\int_0^1 x\,dx = \tfrac{1}{2}$$
The four delimiters
Delimiters are the marks around the formula. You will meet four:
| Delimiters | Kind | Example |
|---|---|---|
$…$ | inline | $a^2 + b^2 = c^2$ |
$$…$$ | display | $$a^2 + b^2 = c^2$$ |
\(…\) | inline | \(a^2 + b^2 = c^2\) |
\[…\] | display | \[a^2 + b^2 = c^2\] |
These are conventions. Maths is not part of the CommonMark or GitHub Flavored Markdown specification, so each tool decides what it reads.
- GitHub reads
$…$and$$…$$. It also has a fenced block that needs no dollars:
```math
\sum_{k=1}^n k = \frac{n(n+1)}{2}
```
- Many AI chats write
\( \)and\[ \]in their answers. If you paste that into a tool that only reads dollars, you see raw code. Replace the delimiters by hand. - Web tools depend on setup. KaTeX auto-render, for example, reads
$$,\( \)and\[ \]by default, but single$must be turned on.
If you are not sure, use $…$ and $$…$$. They have the widest support.
LaTeX bits you will need
Copy these and change the letters.
| You want | You write |
|---|---|
| Fraction | \frac{a}{b} |
| Power | x^2, and x^{10} for more than one character |
| Subscript | x_1, and x_{max} |
| Square root | \sqrt{x}, and \sqrt[3]{x} for a cube root |
| Greek letters | \alpha \beta \pi \Delta |
| Sum | \sum_{i=1}^{n} i |
| Integral | \int_0^1 x\,dx |
| Text in a formula | \text{speed} |
A matrix:
$$
\begin{pmatrix} a & b \\ c & d \end{pmatrix}
$$
Several lines lined up on the equals sign:
$$
\begin{aligned}
x + y &= 5 \\
x - y &= 1
\end{aligned}
$$
The & marks the point where the lines align. \\ starts a new line.
Chemistry with \ce{}
Chemical formulas use \ce{}. It comes from the mhchem package. Put it inside a formula:
$\ce{H2O}$ and $\ce{CrO4^2-}$
$$\ce{CH4 + 2O2 -> CO2 + 2H2O}$$
$$\ce{A <=> B}$$
Numbers become subscripts, ^ sets a charge, -> draws an arrow and <=> draws an equilibrium arrow. The tool must support mhchem, as not all do.
Common mistakes
A dollar sign for money. Two prices in one line can look like a formula:
It costs $5 and the other costs $10.
A tool that reads single dollars may treat 5 and the other costs as maths. Escape each money dollar with a backslash:
It costs \$5 and the other costs \$10.
On GitHub, you can also write <span>$</span>5. Inside a formula on GitHub, a backslash works: $\sqrt{\$4}$.
Spaces just inside the dollars. Write $x$, not $ x $. Some tools do not read a formula when a space follows the opening $. Keeping the formula tight avoids the problem.
A blank line inside a display formula. A blank line ends a paragraph, and many tools then stop reading the formula. Keep the whole $$ … $$ block on consecutive lines, with no empty line in the middle.
A $$ formula glued to text. For a display formula, put $$ on its own line, with an empty line before and after.
Reading maths in Markdown
PilcrowMD typesets formulas on your device. It does not use the internet or a hidden web page.
- Android: reads
$…$and$$…$$. A$…$formula stays in the sentence. A$$…$$formula on its own line becomes a display formula;$$…$$in the middle of a sentence stays in the sentence.\ce{}chemistry works too, and so do formulas in table cells. If an AI answer uses\( \)or\[ \], change them to dollars first. - Mac: reads
$and$$and also\( \)and\[ \].\ce{}and formulas in table cells work here too. If the app cannot draw a formula, it shows the source text instead, so nothing is lost.
To fix a formula, switch to the editor, change the LaTeX, and switch back to see the result.
Common questions
Does maths from ChatGPT, Claude or Gemini work in Markdown? Yes, if the answer is saved as Markdown and your reader knows the delimiters it uses. Many assistants write \( \) and \[ \]. If your reader only knows dollars, replace them with $…$ and $$…$$.
What is the difference between $ and $$? One dollar on each side gives an inline formula, inside the sentence. Two dollars give a display formula, on its own line.
Why does my formula show as plain text? The most common reasons are a reader without maths support, delimiters the reader does not know, a space just inside the $, or a blank line inside a display formula. Check these in that order.
Also on Mac: PilcrowMD for Mac (beta)