# Formula reference

> Every way to write a formula, chemistry and physics notation, your own commands, and equation numbering.

Source: https://workroad.app/docs/notes-advanced/formula-reference

This page lists everything the note editor's formulas support. For the basics, start with [Maths and formulas](https://workroad.app/docs/notes-advanced/maths).

## How formulas are written

Formulas are rendered by [KaTeX](https://katex.org/docs/supported). Every command KaTeX supports works, except those that add links, images or HTML, such as `\href` and `\includegraphics`, which show in red.

| Where                  | Type                                        | Becomes                     |
| ---------------------- | ------------------------------------------- | --------------------------- |
| At the start of a line | `$$x^2$$`, `$$$x^2$$$` or `\[x^2\]`         | a block                     |
| Inside a line          | `$$x^2$$` or `\(x^2\)`                      | a formula in the line       |
| Inside a line          | `$x^2$`, followed by a space or punctuation | a formula in the line       |
| Anywhere               | `/math`                                     | a block, through the dialog |

In imported Markdown, `$...$` is a formula in the line. `$$...$$` is a block when it has a line to itself or sits between two `$$` lines, and a formula in the line anywhere else.

## Chemistry

Chemistry comes from [mhchem](https://mhchem.github.io/MathJax-mhchem/): `\ce{H2O}`, `\ce{CO2 + C -> 2CO}`, `\ce{SO4^2-}` and quantities such as `\pu{123 kJ//mol}`.

## Physics

Physics notation comes from part of the LaTeX `physics` package:

- derivatives: `\dv{f}{x}`, `\dv[2]{y}{t}`, `\pdv{f}{x}`, `\pdv{f}{x}{y}`, and `\dd{x}` for the d at the end of an integral
- brackets that grow with what they hold: `\abs{x}`, `\norm{v}`, `\qty(\frac{a}{b})`, `\qty[x]` and `\qty|x|`. `\abs*{x}` and `\norm*{v}` keep them at text size.
- vectors: `\vb{F}` in bold, `\va{r}` with an arrow, `\vu{n}` with a hat, `\vdot`, `\cross`, `\grad`, `\divergence`, `\curl` and `\laplacian`
- quantum mechanics: `\bra{\psi}`, `\ket{\phi}`, `\braket{\psi}{\phi}`, `\expval{H}`, `\mel{n}{H}{m}` and `\comm{A}{B}`
- also `\eval{x^2}_0^1`, `\order{x^2}`, `\mqty(a & b \\ c & d)` for a matrix, and `\Tr`, `\rank`, `\erf` and `\Res`

`\div` stays division, as in plain LaTeX.

## Your own commands

`\newcommand`, `\renewcommand`, `\def` and `\DeclareMathOperator` all work. A command defined in a formula applies to that formula and to every formula after it in the same note, as in a LaTeX document, so `\newcommand{\R}{\mathbb{R}}` near the top serves the whole note.

- Moving or deleting the definition changes the formulas below it.
- Commands never carry over to another note.
- A formula on a study set card or in a test question stands alone: a command it defines works only inside it.

## Numbered equations

Formulas in `equation`, `align`, `gather` and `alignat` are numbered (1), (2), (3) down the note. The starred forms, such as `align*`, are not.

- Give a line `\label{name}`, and `\eqref{name}` in any formula shows its number, which follows when equations above it are added or removed.
- `\tag{A}` gives a line its own label instead of a number, and `\nonumber` leaves a line out.
- A label no formula has shows as `(??)`.

Copying, exporting and the AI still see the LaTeX as you wrote it, `\label` and `\eqref` included.

## Not supported yet

`multline`, `\cancelto`, `siunitx` (`\SI`) and drawing packages such as TikZ. A command KaTeX doesn't know shows in red.
