---
title: "Text, code and math"
description: "Format text, show code with highlights and diffs, document a shell session, write math, and add margin notes."
---

Pages are Markdown with MDX on top, so everything in [CommonMark](https://commonmark.org) works: headings, lists,
tables, links, `inline code`, **bold** and *italic*. This page covers what Specly adds for code, math and notes.

## Code blocks

Start a block with three backticks and a language. Add a title and options after it, in any order:

```js server.js {2,4-5} lines
import http from 'node:http';
const port = 3000;

http.createServer((req, res) => {
  res.end('ok');
}).listen(port);
```

That block's first line is ` ```js server.js {2,4-5} lines `.

| Option | What it does |
| --- | --- |
| `server.js` | A bare word or a quoted string is the block's title. `title="server.js"` works too. A title that looks like a file name shows as one. |
| `{2,4-5}` | Highlights those lines. `highlight={2}` does the same. |
| `lines` | Shows line numbers. `showLineNumbers` does the same. |
| `wrap` | Wraps long lines. Readers can also switch wrapping on with the **Wrap lines** button when a line is cut off. |
| `focus={2-3}` | Dims every line except the ones listed. |

Every block has a **Copy** button. Specly also knows `run` and `norun`, which are for [runnable code](/write/runnable-code).

### Mark lines in the code

To mark a line from inside the code, end it with a comment. Use `// [!code ++]` to show an added line,
`// [!code --]` for a removed one, `// [!code highlight]` to highlight it and `// [!code focus]` to focus it. Add a
count, as in `// [!code focus:3]`, to mark that many lines from the line down. Use the comment syntax of the language, for
example `# [!code ++]` in Python or YAML.

```js config.js
export default {
  retries: 3, // [!code --]
  retries: 5, // [!code ++]
  timeout: 30, // [!code highlight]
};
```

The markers are removed from the page. **Copy** takes the code as it ends up, without the removed lines.

## Shell sessions

Start the commands in a `bash` or `shell` block with `$ `. The prompt is drawn for you and isn't copied, and every other
line is output. A command that ends in `\` continues on the next line.

```bash
$ npm install specly-example
added 1 package in 2s
$ npm run build \
  -- --verbose
```

**Copy** takes the commands only.

## Math

Write LaTeX between dollar signs, and it's typeset when the site is built: `$E = mc^2$` gives $E = mc^2$ inline. A
block between `$$` lines is shown on its own:

$$
\int_0^1 x^2 \, dx = \frac{1}{3}
$$

A dollar sign before a number is a price, not math: a plan costs $5 a month, or $50 a year.

## Margin notes

A margin note is an aside that sits in the right column beside the text it belongs to. On a narrow screen, it moves into
the text. Write one with `:::margin`:

```mdx
:::margin
Notes can hold `code` and [links](/write/pages).
:::
```

:::margin
A margin note sits in the right column. It can hold `code` and [links](/write/pages).
:::

Margin notes are for side remarks. Anything the reader needs belongs in the text.

Margin notes work in `.md` pages. In an `.mdx` page, `:::margin` isn't read, so the note doesn't show.
