# Maths in notes

> Write formulas, use chemistry and physics notation, and number equations.

Source: https://workroad.app/docs/note-maths

## Maths

Formulas are written in LaTeX and 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. At the start of a line, `$$x^2$$`, `$$$x^2$$$` or `\[x^2\]` makes a block. Inside a line of text, `$$x^2$$` and `\(x^2\)` make a formula in the line, and so does `$x^2$` once you type a space or punctuation after it. `/math` inserts a block through a dialog with a live preview and a symbol palette instead, and clicking a formula opens it again for editing. Right-click or long-press a formula to copy its LaTeX or a picture of it. 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 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 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 work too: `\newcommand`, `\renewcommand`, `\def` and `\DeclareMathOperator`. 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.

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.
