# Advanced formatting

> Tables that add themselves up, math, code you can run, Mermaid diagrams, embeds, columns, tabs, toggles, comments and dates, plus everything in the slash menu.

Source: https://terramd.io/docs/advanced-formatting

Beyond the [basics](https://terramd.io/docs/formatting-syntax), a Terra note can hold tables that add themselves up, math, code that runs, diagrams, live views of other notes and [databases](https://terramd.io/docs/databases), and layouts with columns and tabs. Most of it is plain Markdown that other apps can read. Where Markdown has no syntax, Terra writes an HTML comment, which other apps hide, or keeps the details in the note's sidecar file, `<note>.terra.json`.

## Insert a block

Type `/` at the start of a line or after a space, then a few letters to narrow the list: `/table`, `/mer`, `/sprout`. Press <kbd>Return</kbd> or click. The **Insert block** button in the editor toolbar types the `/` for you, and <kbd>Esc</kbd> closes the menu. Every entry is listed in [the slash menu reference](#everything-in-the-slash-menu) at the end of this page.

![The slash menu open under a line, listing Bullet list, Sprout, Code block, Divider, Heading 1 to 3, Math block and Mermaid diagram under Blocks.](https://terramd.io/docs/shots/fmt-adv-slash.webp "The slash menu, grouped into Blocks, Inline, Insert and Connected apps. Keep typing to filter it.")

## Tables

Type `/table` and pick a size in the grid (up to 8 by 8). The first row is the header. In Markdown, a table is rows of cells between pipes:

```md
| Item | Cost |
| --- | --- |
| Printing | $4,850 |
| Bookmarks | $30 |
| Launch party | $300 |
| Total | $5,180.00 |
```

- <kbd>Tab</kbd> moves to the next cell; in the last cell it adds a row.
- Hover the table for its handles: grips select a column or row, dots between cells insert one, and the dashed edges add one at the end. Drag the dot at a cell's corner to fill the cells beside it, holding <kbd>⇧</kbd> to continue a series.
- Right-click a cell to add or delete rows and columns, **Rename column** or **Delete table**.
- Alignment (`:---:`) isn't kept: Terra writes `---`. Cells can't be merged.

### Formulas

Start a cell with `=` to calculate. `=SUM(above)` adds up the numbers above the cell; `below`, `left` and `right` work too, and so do references such as `=B2*C2` or `=SUM(B2:B4)`, where row 1 is the header. Click away to see the result, and click the cell again to see its formula. Functions include SUM, AVERAGE, MIN, MAX, MEDIAN, COUNT, ROUND and IF.

The Total above is `=SUM(above)`. The file holds its result, `$5,180.00`, and keeps the formula in the sidecar, so other apps see plain numbers. Results take the column's format, here dollars. If someone changes the table outside Terra, Terra drops its formulas and keeps their values.

### Quick sums

At the end of any line, type a sum followed by `=`. The answer appears in grey; press <kbd>Tab</kbd> to keep it.

```md
Bookmarks: 40 * 0.75=
```

It converts units as well: `3 h 20 min in min=` gives `200 min`. Length, weight, time, data sizes and temperature work.

![A four-row cost table whose Total reads $5,180.00, and below it the line Bookmarks: 40 * 0.75= with a grey 30 after it.](https://terramd.io/docs/shots/fmt-adv-table.webp "The Total is a formula. Below the table, the grey 30 is a quick sum waiting for Tab.")

## Math

```md
A run of $n$ copies costs $4850 + 3.9(n - 1000)$ dollars.

Average sightings per walk:

$$
\bar{s} = \frac{1}{n} \sum_{i=1}^{n} s_i
$$
```

![The sentence with n and the cost formula set as math, and the average formula centred on its own line.](https://terramd.io/docs/shots/fmt-adv-math.webp "Inline math sits in the sentence; a math block gets its own line.")

- **Inline:** type `$`, the TeX and a closing `$`; it turns into math as you type the closing one. Leave no space just inside the dollar signs. Prices such as `$5 and $6` stay text.
- **Block:** on an empty line, type `$$` and press <kbd>Return</kbd>.
- **From the menu:** choose **Math block** or **Math (inline)**.
- **Edit:** click the formula to edit its TeX in place. It renders again when the caret leaves.

Terra draws math with KaTeX.

## Code blocks

Code blocks start as in [Basic formatting](https://terramd.io/docs/formatting-syntax#code). Click the language badge at a block's top right to set its language: **Python**, **R**, **JavaScript**, **TypeScript**, **Rust**, **Shell**, **JSON**, **YAML**, **TOML**, **SQL**, **HTML**, **CSS**, **Markdown** or **Plain text**.

| Keys, inside a code block | What they do |
| --- | --- |
| <kbd>⌘</kbd> <kbd>;</kbd> | Show or hide line numbers |
| <kbd>⇧</kbd> <kbd>⌘</kbd> <kbd>I</kbd> | Format the code, with a formatter installed on your Mac such as ruff or Prettier |
| <kbd>⌘</kbd> <kbd>/</kbd> | Comment out the line |
| <kbd>⌥</kbd> <kbd>↑</kbd> or <kbd>⌥</kbd> <kbd>↓</kbd> | Move the line up or down |
| <kbd>⌘</kbd> <kbd>E</kbd> | Turn the block back into text, one paragraph per line |
| <kbd>⇧</kbd> <kbd>Return</kbd> or <kbd>⌘</kbd> <kbd>Return</kbd> | Leave the block |

### Run code

Python and R blocks can run, notebook-style, and show their output under the code.

1. Click the language badge and choose **Python · runnable** or **R · runnable**. Terra rewrites the fence as `` ```{python, label=blk_…} `` so it can keep track of the cell.
2. Click **Run**. Terra saves the note, and the first time a cell runs, or after you change it, macOS asks **Run this exact saved code?**. Click **Allow**.
3. The output appears under the cell: text, plots and tables. **Stop** halts a run, and the buttons beside **Run** restart Python or R and clear the output. **Run all**, at the top of the note, runs every cell in order.

![A runnable Python cell with Run, restart and clear buttons, the Python · runnable badge, three numbered lines of code and Last run: never.](https://terramd.io/docs/shots/fmt-adv-code.webp "A runnable cell before its first run.")

- Python needs `ipykernel` installed; R needs IRkernel. The notes in a [Library](https://terramd.io/docs/libraries) share one Python and one R session, so variables carry over between them.
- Options go after the label, as in Quarto: `echo=false` hides the code in Read mode, `eval=false` never runs the cell, and `output=false` runs it without showing output.
- **Settings › Code › Runnable code** can turn Run off, run code in an isolated sandbox (on by default) and stop asking before new code runs.

## Mermaid diagrams

````md
```mermaid
graph LR
  Draft --> Proof --> Print --> Launch
```
````

![A flowchart with four boxes in a row, Draft, Proof, Print and Launch, joined by arrows.](https://terramd.io/docs/shots/fmt-adv-mermaid.webp "The diagram, drawn from the four lines above.")

Type `/mermaid` for a starter diagram, or write the diagram as a paragraph and choose **Turn into › Mermaid diagram**. To change it, hover and click the pencil (**Edit diagram source**) or double-click; <kbd>⌘</kbd> <kbd>Return</kbd> saves and <kbd>Esc</kbd> cancels. Drag its corner to resize it: Terra saves the width on the fence, as in `` ```mermaid width=480 ``. A diagram with a mistake shows Mermaid's message, with **View source**.

## Embeds

An embed shows another note, a database or an item from a connected app inside your note.

```md
![[Printer quotes]]

![[jira:https://example.atlassian.net/browse/WEB-142]]
```

![A card for the Printer quotes note with its first line, and a Jira issue card showing its title, status, checklist progress and due date.](https://terramd.io/docs/shots/fmt-adv-embeds.webp "A note embed and a Jira issue. Click the note card to open the note.")

- **Another note:** in **Markdown source**, put `![[Note title]]` on a line of its own. Back in **Edit**, it shows as a card with the note's title and opening lines; click it to open the note. Typing `![[` in the editor doesn't make an embed in this version. Right-click the card to **Replace target…**, **Refresh** or **Open source note**.
- **A database:** type `/database` and pick one in **Insert database**, or click **New database**. The view stays live, and changing its layout here changes only this block. Terra saves it as a `<!-- terra:inline-db … -->` comment.
- **An item from a connected app:** type the app's name after `/`, for example `/jira`, pick **Jira issue**, then search for the item or paste its link and click **Embed**. Pasting a link on an empty line offers **Embed** too. The card's **⋯** menu can **Refresh**, **Convert to note** or **Remove embed**. Only apps you've connected on this Mac appear: Jira, Confluence, Slack, Google Calendar, Granola and GitHub.

## Columns, tabs and toggles

![Two columns comparing Harbor Press and Northline Print, a tab group with the same two quotes, and a folded Budget heading with a chevron.](https://terramd.io/docs/shots/fmt-adv-layout.webp "Two columns, a tab group, and a heading folded with a toggle.")

### Columns

Drag a block by its ⠿ handle onto the left or right edge of another block. When a vertical line appears, let go: the two sit side by side. Drop more blocks on a column's edge for up to four columns. Drag the gap between columns to resize them, or double-click it to even them out. Drag a column's last block out and the column goes away. Columns sit at the top level of a note, not inside a Sprout or a tab, and they stack in a narrow window.

```md
<!-- terra:columns -->
<!-- terra:column width=0.5 -->
**Harbor Press**

$4,850, ready in three weeks.

<!-- terra:column width=0.5 -->
**Northline Print**

$5,200, ready in two weeks.

<!-- terra:columns:end -->
```

### Tabs

A tab group shows one section at a time: two printers' quotes, or the same code in two languages. Type `/tabs` for a group with **Tab 1** and **Tab 2**, or select a run of headings with their text and choose **Turn into › Tabs from sections** in the toolbar. Click **+** (**Add tab**) to add one, and **Tab actions** (**⋯**) to rename, duplicate, move or **Dissolve group to sections**. Right-click a tab for its **Color** and **Glyph**. A group needs two tabs: removing one of two turns the group back into sections.

```md
<!-- terra:tabs v="1" -->
<!-- terra:tab -->
### Harbor Press
$4,850, ready in three weeks.

<!-- terra:tab -->
### Northline Print
$5,200, ready in two weeks.

<!-- terra:tabs:end -->
```

Each tab is a heading and its text, so other apps show the tabs one after another.

### Toggles

A paragraph, heading, list item, quote, code block or [Sprout](https://terramd.io/docs/sprouts) can be a *toggle* that folds away what belongs to it. A heading folds its whole section. Put the caret in the block and press <kbd>⌥</kbd> <kbd>⌘</kbd> <kbd>7</kbd>, or switch on **Toggle** in its ⠿ menu. Click the chevron to fold or unfold it; <kbd>⌘</kbd> <kbd>Return</kbd> does the same for the toggle you're in, and <kbd>⌥</kbd> <kbd>⌘</kbd> <kbd>T</kbd> folds or unfolds every toggle in the note.

```md
<!-- terra:toggle collapsed -->

## Budget

Printing, bookmarks and the launch party.
```

## Comments

Comments sit beside a note, never in its text. Click **Comments** in the window toolbar, or press <kbd>⇧</kbd> <kbd>⌘</kbd> <kbd>M</kbd>, to comment on the whole note: type in **Add comment…** and press <kbd>Return</kbd>. To comment on one paragraph, heading or list item, hover it, click the faint **⋯** in the right margin and choose **Comment**. A speech-bubble mark then shows the block has a thread.

Terra keeps comments in the note's sidecar file and marks the block with a `^ID` at the end of its line. You can't comment on part of a paragraph yet.

## Dates

Type `@` and pick **Today**, **Tomorrow** or **Yesterday** under **Date**, or type a date such as `@2026-06-14` and pick it there. The toolbar's **Insert date** opens a calendar instead. Terra shows a date chip, and saves plain text:

```md
Launch day is @2026-06-14.
```

Click a chip to pick another date.

## Images

Hover an image to resize it: drag the round handle at its bottom-right corner. Terra keeps its proportions and saves the width in the alt text, as in `![Map of the lower valley|480](…)`.

![The trail map in a note with a round resize handle at its bottom-right corner.](https://terramd.io/docs/shots/fmt-adv-image.webp "Drag the round handle to resize. The width is saved in the Markdown.")

**Insert image** (`/image`) has three tabs: **Library** for images already in your Library, **Upload** for a file on your Mac, and **Link** for a web address, which you can **Save to library** (a copy in the note's attachments) or **Keep as link**.

For a cover across the top of a note, click the picture icon (**Banner image**) under the title, then **Upload cover** or **Import cover from web**. **Reposition cover** lets you drag it into place; **Apply cover position** keeps it. The cover is saved as the note's `cover` [property](https://terramd.io/docs/properties).

## Not yet in Terra

Footnotes: `[^1]` stays plain text.

## Everything in the slash menu

| Entry | Type | What you get |
| --- | --- | --- |
| **Heading 1**, **Heading 2**, **Heading 3** | `/h1`, `/h2`, `/h3` | A heading. On a heading of that level, back to text. |
| **Bullet list** | `/list` | A bulleted list |
| **Numbered list** | `/num` | A numbered list |
| **To-do** | `/todo` | A to-do |
| **Quote** | `/quote` | A quote |
| **Sprout** | `/sprout` | A Note [Sprout](https://terramd.io/docs/sprouts) |
| **Code block** | `/code` | A code block |
| **Divider** | `/hr` | A horizontal rule |
| **Math block** | `/math` | A block of math |
| **Mermaid diagram** | `/mermaid` | A starter diagram |
| **Table** | `/table` | A size picker, then a table |
| **Tabs** | `/tabs` | A tab group with two tabs |
| **Database** | `/database` | A live view of a database |
| **Bold**, **Italic**, **Strikethrough**, **Highlight**, **Inline code** | `/bold`, `/italic`, `/strike`, `/highlight`, `/inline` | That style for what you type next |
| **Math (inline)** | `/tex` | Inline math, with a placeholder `x` to type over |
| **Citation** | `/cite` | A citation picker; see [Build a research library](https://terramd.io/docs/research-library) |
| **Image** | `/image` | **Insert image** |
| **Jira issue**, **GitHub pull request** and others | `/jira`, `/github`, … | An embed, for apps you've connected |

The menu doesn't open in the middle of a word, or inside code or math. **Image** appears once you type a few letters of it.

## Related

- [Basic formatting syntax](https://terramd.io/docs/formatting-syntax): headings, emphasis, links, lists and code.
- [Sprouts](https://terramd.io/docs/sprouts): coloured blocks with properties.
- [Databases](https://terramd.io/docs/databases): the views you can embed in a note.
- [Links and backlinks](https://terramd.io/docs/links-and-backlinks): linking to notes, headings and single paragraphs.
