Formulas

Formulas turn a document into a living calculation. Define a value once, reference it in later formulas, and Return shows the results next to each line - interest, contractual penalties, settlement scenarios - without a spreadsheet and without leaving the text.

Everything is computed locally, instantly, and deterministically. Results are shown next to your text but are never written into the file: the document stays plain markdown, fully readable in any other editor.

Defining a value

Start a line with $ and give the value a name - a named formula creates a variable you can reference anywhere in the document:

$principal = 120 000
$rate = 11,5%
$months = 8

The result appears at the right edge of each line, and consecutive formula lines group into one calculation block - a blank line starts a new block. Values are visible in the whole document (order doesn’t matter - you can reference a value before the line that defines it), and each document has its own private set: nothing leaks between files.

Names can use letters (including accented characters), digits and _, and must start with a letter or _: $kwota, $rate_2026, $całość.

Each name is defined once per document. A second $name = ... line for the same name is flagged with #duplicate - the first definition stays in effect.

Quick calculations

A $ line without name = is a quick formula - it evaluates without storing anything:

$ 120 000 * 11,5% / 12
$ $principal * $rate
$principal

The last form - just a reference on its own line - shows the current value.

Comments

Annotate a formula with // - everything after it is a note, not part of the calculation:

$rata = $cena / 12 // monthly, per §4 of the contract
$ // financing costs
$odsetki = $rata * 5%

A $ // line with only a comment works as a label inside a calculation block. Notes are dimmed so the formula and its result stay in the foreground, and a $name mentioned inside a note is just text - it is not a reference.

Numbers

Both decimal separators work: 0,5 and 0.5 are the same number. Thousands can be grouped with spaces: 1 000 000. Results are displayed using your system’s number format.

One rule to remember: a comma directly followed by a digit is always a decimal separator - 1,500 means one and a half. When listing function arguments, separate them with a comma plus a space, or with a semicolon: min(1,5; 2).

Percent

A percent sign attached to a number makes it a percentage, with natural semantics:

$net = 10 000
$ $net + 23%     -> 12 300   (adding a percent scales the value)
$ $net - 10%     -> 9 000
$ $net * 5%      -> 500      (multiplying takes the fraction)
$vat = 23%

With a space, % is the remainder operator instead: 10 % 3 is 1.

Operators and functions

Arithmetic: + - * / ^ (power), % (remainder, with spaces). Comparisons: < > <= >= = !=, combined with &&, ||, !.

The function set is deliberately small:

FunctionMeaning
if(condition, then, else)pick one of two values
match(x, v1, r1, v2, r2, ..., default)multi-way branch on a value
min(...), max(...)smallest / largest argument
round(x) or round(x, digits)rounding
clamp(x, low, high)constrain a value to a range
$cap = 15 000
$penalty = clamp($principal * $rate, 0, $cap)
$tier = match($months, 12, 10%, 24, 15%, 5%)
$ if($penalty >= $cap, 1, 0)

if() and match() evaluate only the branch they pick, so a guard like if($months = 0, 0, $total / $months) is safe - the division never runs when the guard says no.

Formulas are calculations, not a programming language: there are no loops, no multi-line blocks, no text values.

Tip: put spaces around operators ($a * 3, not $a*3). It reads better, and asterisks glued to names can be styled as markdown emphasis in the editor.

Formulas in tables

A table cell whose entire content is a formula referencing your values shows its result next to the cell content:

ItemAmount
$principal$principal * $rate

Cells that merely mention a $name inside prose (“payable: $principal net”) stay plain text - only a cell that IS a formula participates. Results in cells follow the same rules as lines: they update live and are never written into the file.

When something can’t be computed

Errors show as a short code in the chip, in place of a value:

CodeMeaning
#unresolvedthe referenced value is not defined in this document
#cycledefinitions reference each other in a circle ($a = $b, $b = $a)
#refa referenced variable has an error of its own
#div/0division (or remainder) by zero
#duplicatethis name was already defined above
#syntaxthe expression could not be parsed
#errorthe expression is malformed in another way (wrong number of arguments, an unknown function)

Fix the underlying line and every dependent result recomputes immediately.

Working with results

What variables are not

Formulas vs placeholders

They look related but serve different jobs:

A template can use both: placeholders for the parties and dates, formulas for the amounts that follow from them.