Formulas and code

Maths in a line or on its own, in TeX or Typst; inline code and highlighted code blocks.

Formulas and code

Incipit sets mathematics properly, in either of the two languages people write it in, and shows code with its keywords coloured. Neither needs anything installed.

Formulas in a line

Type $, then the formula, then $ again:

text
The area of a circle is $\pi r^2$, near enough.

As you type the opening $, a formula starts and the cursor is inside it. Write the formula, then type $ at its end to step out and carry on with the sentence. Tab steps out too.

A formula in a line is set at the size of the text around it, and sits on the same baseline.

Formulas on their own line

For a formula that deserves its own line, start a line with $$ and press Return. A math block opens; write the formula inside it, across several lines if it’s long. The formula is set below as you write, centred and at display size.

TeX or Typst

Incipit can set formulas written in two languages:

  • TeX, the long-standing language of mathematical writing, used by LaTeX and much of the web: \frac{a}{b}, \sum_{i=1}^{n} x_i.
  • Typst, a newer language that reads closer to plain writing: a / b, sum_(i=1)^n x_i.

Choose which one new formulas use in Settings › Editor › Formulas › Default math dialect. Formulas you’ve already written keep their own language, so a notebook can hold both without confusion. To change the language of one formula, put the cursor in it and choose Switch Math Dialect in the formatting bar. You can give it a key in Keyboard shortcuts if you switch often.

Formulas are set in a typeface drawn for mathematics, in the tradition of TeX’s own, so they sit comfortably beside text.

Finding formulas

Search for $has:math to find every sheet with a formula in it.

Code in a line

Wrap a stretch of text in backticks, `like this`, or select it and press ⌘ E. Code is set in a monospaced face and left exactly as typed: no curly quotes, no dashes, no tags, no spelling check.

Code blocks

For several lines of code, start a line with three backticks, optionally followed by the name of the language, and press Return:

text
```python

A code block opens. Inside it:

  • Spacing and indentation are kept exactly as typed.
  • Return starts a new line of code, not a new block.
  • Keywords, strings, numbers and comments are coloured, when you’ve named the language.

You can also make a code block from any paragraph with Turn Into › Code block.

Code blocks are good for more than programs: song chords, a poem whose spacing matters, terminal output, or anything you’d like to keep exactly as it is.

Searching code

$code: followed by a word finds sheets with that word inside code, and $has:code finds every sheet that contains code at all. See Tags and search.

Helpers stay out of code and maths

The typing helpers described in Help while you type, such as typographic dashes, curly quotes and CJK spacing, don’t touch code or formulas. Spelling isn’t checked there either. What you type in them is what you get.