---
name: formulaa-math
description: >
Read and write formulAA AA math โ 2D plain-text formulas (Unicode-first
ASCII art) that map one-to-one to a math AST and convert losslessly to
LaTeX. Use when asked to write, edit or interpret formulas in
formulAA AA form, or to embed re-editable math in plain-text documents.
---
# Reading and writing formulAA AA math
The formulAA AA format looks like the formula itself while converting
mechanically to LaTeX. This document alone should let you write correct
AA.
## Verification commands (always use them when available)
```sh
```
Your AA is correct when `formulaa --format` accepts it and the output matches
your intent. Hand-written input is **lenient**: a lone ASCII letter is
an italic variable (`x+1` โ ๐ฅ+1), but a **run of 2+ letters is
upright** (`asiny` โ \operatorname{asiny}, `sin` โ \sin), so write a
product of variables as `a b` (spaced) or `๐๐` (italic code points).
## Principles
1. A formula is a character grid. **Every subexpression owns a
rectangle plus a baseline row**; siblings occupy disjoint column
ranges.
2. Vertical relationships (numerator/denominator, limits, scripts) are
marked by **structural glyphs** (bars, bands, delimiter columns),
never by whitespace alone.
3. When unsure, write on one line: `xยฒ+1`-style one-liners are almost
always safe.
## Structures
### Fractions โ the bar `โ` (U+2500)
The bar is wider than either half (max width + 2); the bar row is the
baseline.
```plain
1 a+b
โโโ โโโโโโโโโ
2 c + d
```
Minus stays ASCII `-` (a different character from the bar).
### Scripts โ inline characters when possible
`xยฒ` `aแตข` `eโปโฑ` (available: โฐยนยฒยณโดโตโถโทโธโนโบโปโผโฝโพโฟโฑ /
โโโโโโ
โโโโโโโโโโโโแตขโฑผโโโโโโแตฃโโแตคแตฅโ). Anything else becomes a 2D block at
the base's **upper/lower right**:
```plain
ฮฑ+1
๐ฅ โ x^(ฮฑ+1) ๐ฅ โ x_(ฮฑ+1)
ฮฑ+1
```
A script at the start of a row needs the explicit base `โฌ`: `โฌยฒ`.
### Radicals โ `โ โ โ` plus the overline `โโโ`
```plain
โโโโโ โโโโ
โx+12 โ 1
โโโโ โ the stem โ covers every content row; the bottom is the root glyph
โ 2
```
Top row: `โ` (the stem's column) + a `โ` run as long as the argument.
One-line content sits directly right of `โ`.
### Limits โ the band `โ` (U+2508)
**Anything sandwiched by `โ` without spaces** takes limits above and
below (โ and lim use the same notation). One space separates a band
from its neighbors. No limits โ the bare `โซ` is fine.
```plain
โ
โโโโโ aโ โlimโ f(x) โargmaxโ f(x) โ one word, no spaces
n=1 xโ0 xโS
```
### Delimiters โ `( ) [ ] { } โจ โฉ โข โฅ โ โ โ โ โ โ โ` on one line, columns when tall
```plain
โ 1 โ โง 1 โซ โฑ 1 โฒ
โฒ โฑ
```
- Parens `โโโ`, brackets `โกโขโฃ`, braces `โงโชโจโฉ` (**the vertex โจ is
always the baseline row**); tall angles are **diagonal arms `โฑ โฒ`
only** (even height, `โจ โฉ` on one line only). The fold is a vertical
pair in one column โ left: `โฑ` directly above `โฒ` โ and the upper
row of the pair is the baseline.
- Absolute value: left `โข` / right `โฅ` (bracket extension pieces; a
column with no corners reads as a bar; `|` is an atom, `โ` is the
radical stem / segment separator).
- **Middles** (bra-kets, set-builder): full-height `โ` columns split
segments: `โจฯโHโฯโฉ`, `{๐ฅโ๐ฅ > 0}` โ \{x \mid x>0\}.
- Mismatched pairs are fine: `(0,1]`.
- Ceil/floor: `โ โ โ โ` (tall: bracket pieces with one corner dropped โ
ceil has no foot, floor has no head). Norm: a full-height `โ` column
(tall: the same `โ` stacked; a norm directly inside a norm cannot be
written โ use `โข โฅ` inside).
- **Null delimiters** left `โ` U+2506 / right `โ` U+250A ("no wall
here", `\left.`/`\right.`). `cases` is `โง` + a grid + a right `โ`.
### Matrices and grids โ the lattice (the same picture everywhere)
Junction glyphs `โโฌโ โโผโค โโดโ` sit at every separator intersection,
outer border included; a matrix just wraps the grid in a delimiter
pair. Whitespace inside cells is free โ markers decide the boundaries:
```plain
โ โฌ โ โก a b โค โก โฌ โค โ a โ
a b โข โผ โฅ โข a b โฅ โ โค
โ โผ โค โฃ c d โฆ โฃ โด โฆ โ b โ
c d โ bmatrix one row one column (the โโค junctions
โ โด โ (separator (โฌโด rows) bite into the delimiter column)
rows: spaces + โผ)
```
### Accents โ marks directly above/below a one-character base (stackable)
For multi-character bases, a **marked band row** hugs the base:
```plain
โโหฐโโ โโโพโ โ___โ
๐๐๐ ๐ด๐ต ๐ง+1 โ \widehat / \vec / \overline
(below: โยฏยฏยฏโ = \underline, โหหหโ = \utilde;
the base stays bare)
```
All marks draw in base-hugging forms: bar above is `_`, hat `หฐ`, tilde
`หท`, check `หฏ`, ring `หณ`, dot `โค` U+2024 (not the atom `.`), vec `โพ`
U+21FE (not the atom `โ`), ddot `โคโค` (overhanging one column right,
that column's baseline stays blank), underline is `ยฏ` below, utilde `ห`
below (the tildes swap between AST and drawing).
```plain
โพ โพ หฐ
E โ
d A โพ โ stacks grow outward: \hat{\vec{a}}
๐
```
### Negation โ precomposed slashed atoms only
Combining overlays like U+0338 are rejected (explicit error). Write
โ โ โ โข โฆ directly.
### Spaces
Real spaces are formatting: they survive a parse as formatting, but
carry no meaning. To put a space into the
LaTeX output use the visible atom `โฃ` U+2423 (`\space`; a LaTeX control space).
### Upright text โ bare runs, `'โฆ'`, `"โฆ"`
Letter runs like `dx` `asiny` are upright (`\operatorname`);
abbreviations with dots (`i.i.d.`, `w.r.t.`) are one run. A single
letter is roman only when glued to a letter (`d๐ฆ`, the differential);
isolate it as `'d'`. `"if x"` โ `\text{if x}` (real spaces allowed,
`\"` `\\` escape). `'` is **always** a quote delimiter โ the prime is
the atom `โฒ` U+2032.
### Labelled stretchy arrows โ body `โ` (`โ` for โโ) + head `>` `<`
```plain
f
Aโโโโ>B โ A \xrightarrow{f} B (labels centered above/below)
```
A head glued to the run makes an arrow; a space makes a fraction bar
plus an atom (`โโโ >`). Double arrows: `โโ>` / `<โโ`.
### overbrace / underbrace โ `โญโโโฎ` / `โฐโโโฏ`
```plain
n
โญโโโโฎ
a+b + c โ \overbrace{a+b}^{n} + \underbrace{c}_{m}
โฐโโฏ
m
```
### Function names โ upright ASCII
`sin cos tan log ln exp lim det โฆ` are written upright (variables
italicize to `๐ฅ`, so they stay distinct). Write `\sin x` as `sin x` or
`sin๐ฅ` (`sinx` is not a dictionary word and becomes
`\operatorname{sinx}`).
## Reserved characters (never atoms)
`โ โ โ โ โโโ ( ) [ ] โโโโโโ โกโขโฃโคโฅโฆ { } โจ โฉ โงโชโจโฉโซโฌโญ โฑ โฒ โ โ โฌ โ
โ โฌ โ โ โผ โค โ โด โ โญ โฎ โฐ โฏ ยฏ ห หท _ หฐ หฏ หณ โค โพ ' "`,
math-italic letters, inline script characters. Beyond those, only
characters in the symbol tables are usable (ฮฑ โค โ โ โ โ โฆ); anything
else โ full-width characters, emoji โ is a parse error (it would shear
the one-cell grid and has no LaTeX spelling). In ASCII, `^ ~ \` and the
backtick are also unusable โ write `\sim`, `\backslash`.
## Multi-line formulas
Stack line blocks with a **lone `โ` line** between them:
```plain
๐ฆ=(๐ฅ+1)ยฒ
โ
=๐ฅยฒ+2๐ฅ+1
```
LaTeX `\\`. There is no alignment.
## Avoiding ambiguity
- Never write an empty script (a `โฌ`-only exponent) โ it doesn't exist
in canonical form.
- Use `โฃ` where the space is part of the formula; a real space is
formatting (kept, but it means nothing to LaTeX).
- Always band (`โ`) the limits of โ/โซ โ bare stacking is ambiguous with
nesting and errors out.
- Never overlap content directly above/below a baseline token (other
than accent marks) โ it errors rather than being dropped.
## Examples
(Real spaces are formatting spacers; the parser keeps them.)
Quadratic formula:
```plain
โโโโโโโ
-๐ยฑโ๐ยฒ-4๐๐
โโโโโโโโโโโโ
2๐
```
Gaussian integral:
```plain
โ -๐ฅยฒ โโ
โโซโโ ๐ ๐๐ฅ=โฯ
-โ
```
Bayes (a one-liner is enough):
```plain
Rotation matrix:
```plain
โก cosฮธ -sinฮธ โค
๐
=โข โผ โฅ
โฃ sinฮธ cosฮธ โฆ
```
## Full specification
See `docs/aa-spec.md` (the format spec) and `docs/adr.md` (decision
records). For any structure you are unsure of, generate a reference
picture first with the `formulAA` TUI or the library
(`formulaa::render::render_root` + `RenderCtx::canonical()`).