Skip to content
Varlig Guide
Varlig home

Writing a calculation line

This page covers the basics that every calc block relies on: how a line is read, how to leave notes beside your sums, how to name values and reuse them, and how to make a line depend on a condition. Start here if you are new to calculations in Varlig, and come back to it when a name or a comment doesn’t behave the way you expect.

One expression per line

Calculations live in a calc block inside a note. Type a ```calc fence, or press ⌘Y to insert one. Each line in the block is one calculation, and its answer appears beside the line.

calc
£3.40 * 5 gives £17.00
45 min + 1 hour 20 min gives 2 hours 5 min
1.5 litres in ml gives 1,500 mL

Blank lines and comment lines have no answer, so you can space a block out and explain it as you go.

Varlig reads the whole line as maths first, including everyday phrases such as £45 with 20% VAT. If the line doesn’t work that way, it sets aside the words it doesn’t recognise, so 5 apples + 3 oranges still comes to 8. That’s handy for quick jottings, but a description can collide with a phrase or a unit name, so when you want to say what a line is for, use a comment or a label, described next. How Varlig reads a phrase has the details.

A word standing where a value should be is an error naming that word, rather than a wrong answer, and the message suggests the closest name you’ve defined:

calc
rent = £1,150
rnt + £200 gives Unsupported: unrecognized calculation at "rnt"; did you mean "rent"?

The same goes for a name written with digits or underscores, such as rent2 or rent_2. It’s never set aside as a description or read as its number, and brackets, a function call or a conversion don’t hide it either. Digits are fine in a label, so describe the line there:

calc
rent = £1,150
rent2 + £200 gives Unsupported: unrecognized calculation at "rent2"; did you mean "rent"?
(rnt + £200) * 2 gives Unsupported: unrecognized calculation at "rnt"; did you mean "rent"?
Flat 2: rent + £200 gives £1,350.00

Lines that start with a bullet

A bullet at the start of a line marks a shopping-list item, so the description before the amount is set aside and the line still adds up. Use -, *, •, +, – or — and a space:

calc
- flowers 1,200 gives 1,200
* coffee $4.50 gives $4.50
- 12 mugs gives 12
- 6 bananas @ 18p gives £1.08
- 500g pasta 3 packs at £1.10 each gives £3.30

A dash before a bare amount is still a minus sign, so - 1,200 is -1,200 and - 12 kg is -12 kg. For a measurement in a list, start the line with * or •, which are bullets before anything.

Words beside an amount

A description keeps a line readable and never changes the number. Words joined by +, & or per are part of the description rather than a sum, a minus sign written against its amount belongs to the amount, and a reference number after a word stays out of the way:

calc
basin + pedestal £145 gives £145.00
food cost per head £14.20 gives £14.20
milk, bread, eggs £12.40 gives £12.40
Netflix -£10.99 gives -£10.99
DIRECT DEBIT REF 4471 £62.40 gives £62.40
Invoice #123: £250 gives £250.00
double cream 600 mL gives 600 mL
chlorine 3 ppm gives 3 ppm
t-shirt £12 gives £12.00
on the day 60 at £28 gives £1,680.00

That covers most of what a statement, an order confirmation or a parts list looks like when you paste it in: rows in capitals, things listed with commas, hyphenated names, and a line whose description happens to start with a word Varlig knows, such as double, per or on the day.

A label that numbers a row, such as Year 2, Room 12 or ISA 2026, or a period with its year, such as Q4 2026, July 2026 or week 40 2027, belongs to the description too, wherever it is in the line, when its amount follows it: an amount with a currency, a unit or a percent sign, or a plain number standing on its own before the next operator. Its number is never added in:

calc
Year 1 £5,000 + Year 2 £6,000 gives £11,000.00
Year 1 5,000 + Year 2 6,000 gives 11,000
ISA 2025 £20,000 + ISA 2026 £20,000 gives £40,000.00
Room 12 £40 + Room 14 £50 gives £90.00
Q3 2026 £5,000 + Q4 2026 £6,000 gives £11,000.00
July 2026 £500 + August 2026 £600 gives £1,100.00

A single number after a word is the amount, as in rent 1200 + 300, and a count still counts, as in tickets 2 £40 each. A unit such as hour, week or day measures the number before it, so written before a number it names the row like any other word: hour 2 is the second hour, never an hour and two minutes. And when a currency, a unit or a percent sign follows, a space after a label’s number starts the amount, so Week 2 150 hours is 150 hours rather than 2,150:

calc
hour 1 £40 + hour 2 £50 gives £90.00
hours 8 + hours 7 gives 15
Week 2 150 hours + Week 3 160 hours gives 310 hours

Comments

A comment is text the calculator ignores. There are four ways to write one:

Form Example What is ignored
Hash comment rent * 12 # per year or # Budget Everything from a # and a space to the end of the line
Slash comment rent * 12 // per year Everything from // to the end of the line
Quoted note "flat whites" £3.40 * 5 Anything inside double quotes, anywhere on a line
Bracketed note $999 (for iPhone 16) Words in brackets, anywhere on a line
calc
# Weekly shop
milk = £1.45
bread = £1.20 // sourdough
eggs = £2.30 "free range"
milk + bread + eggs # without the extras gives £4.95

A hash or a slash comments out the rest of the line, while quotes and brackets can sit in the middle of one. That lets you say what an amount is for and keep the sum going:

calc
$999 (for iPhone 16) gives $999.00
laptop £899 (refurbished) + £49 case gives £948.00
Boing "747" is $386.8M gives $386.8M

Quotes are the safer choice around something that looks like a number, which is how the 747 above stays out of the maths. Brackets holding only a number are arithmetic rather than a note, because a number beside a bracket multiplies:

calc
$999 (3) gives $2,997.00

So write a count outside the brackets, or spell out what you’re counting, as in $999 (3 handsets). Anything other than a bare number stays a note, including a hyphenated word or a percentage:

calc
£134 (25% discount already applied) gives £134.00
£10 (mother-in-law) gives £10.00

A line that starts with a hash and a space is a comment from start to finish, which makes it a handy heading inside a block.

The space is what makes a hash a comment. A # joined to a word, as in #food, is a tag: it labels the line, stays out of the calculation and lets you total every line carrying it, wherever they are in the block.

calc
£12.50 lunch #food gives £12.50
£8 coffee #food gives £8.00
total of #food gives £20.50

A hash followed by digits is neither: it numbers what the line is about and takes no part in the maths, so invoices, orders and part numbers read as they’re written.

calc
Invoice #123: £250 gives £250.00
part #4 weighs 20 g gives 20 g

Labels

A label is a few words followed by a colon and a space at the start of a line. It describes the answer without being part of the maths:

calc
rent = £1,250
bills = £180
Rent and bills: rent + bills gives £1,430.00
Café bill: £12.50 + £4 gives £16.50

Labels can use letters (including accented ones), digits, spaces and underscores, as in Flat 2: or Q3 rent:.

A label does not create a name. After Rent and bills: rent + bills, there is no value called Rent and bills. Use = when you want to reuse a result. Also avoid putting a label in front of an assignment: Housing: rent = £1,250 shows the amount, but rent is not stored.

Assignment

= gives a value a name. The line also shows the value, so you can check it as you go.

calc
price = £85 gives £85.00
price + 20% gives £102.00

To update a name you have already defined, use +=, -=, *= or /=:

calc
holiday fund = £400
holiday fund += £150 gives £550.00
holiday fund -= £85 gives £465.00
servings = 4
servings *= 3 gives 12
flour = 750 g
flour /= 3 gives 250 g

If the right-hand side fails, the name holds the error, and every line that uses it shows the same error until you assign the name again:

calc
guests = 0
per head = £120 / guests gives Error: divide by zero
per head + £5 gives Error: divide by zero

A name you store can carry a description, exactly as it would on a line of its own. What the right-hand side can’t be is stray words wrapped around a bare name, because then there’s no telling what you meant to store: with rent = £1,150 defined, x = spent excl rent reports spent excl rent rather than quietly storing the rent.

calc
paid rent = £1,150
daily spend = paid rent / 16 gives £71.88

Names

Names can be several words long, and can contain accented and non-Latin letters, digits, underscores and emoji:

calc
flat white = £3.40
flat white * 5 gives £17.00
crème brûlée = £6.50
crème brûlée * 2 gives £13.00
🍎 price = £0.45
🍎 price * 6 gives £2.70
q1 sales = £12,400
q2 sales = £14,100
q1 sales + q2 sales gives £26,500.00
bedroom_width = 3.2 m
bedroom_width * 2 gives 6.4 m

A name can include words that Varlig uses elsewhere, such as to, in or needed, and it can borrow the name of a built-in function such as floor. Wherever you use it as a value, Varlig reads your value:

calc
time to work = 25 min
time to work * 10 gives 4 hours 10 min
paint needed = 12.44 L
paint needed to 1 dp gives 12.4 L
floor = 12 m²
floor * 2 gives 24 m²
floor(3.7) gives 3

Followed by brackets, as in floor(3.7), the function still does its usual job.

A name can even end in a number word, so a price reads the way it’s written on the menu:

calc
table for four = £96
table for four / 4 gives £24.00

When two of your names start the same way, the longer one wins, so a numbered name is read whole:

calc
batch = £8.01
batch 2 = £8.21
batch 2 - batch gives £0.20

Names are case-sensitive: eggs and Eggs are two different values.

If you want a name available in every note, such as your hourly rate or a tax rate, add it to the global definitions in Settings rather than repeating it in each note.

Names that clash with built-in words

A name you define takes priority over anything else spelled the same way, such as a unit, a number word or a constant. Everyday names still leave your quantities alone. A number written straight before a plural name or a unit counts that thing, and a percentage before tip or tax names the tip or tax, so values called hours, nights or tip don’t change these lines:

calc
rate = £14 / hour
hours = 7.5
rate * 7.5 hours gives £105.00
nights = 14
£118/night * 14 nights gives £1,652.00
tip = $12.69
$84.60 + 18% tip gives $99.83

Hold the pointer over the word to see which reading Varlig used. On rate * 7.5 hours it says “Counts hours here, not the variable hours = 7.5.” Anywhere else on a line, the name is your value, as in split £90 among people.

A conversion works the same way: after in, to or as, a unit beats a name that holds a plain number, so a count you’ve named doesn’t block a conversion to its unit. With miles = 12, 20 km in miles still gives 12.4274238447 mi. A name in front of the unit scales it rather than naming a target, so 15.2 m in scale miles with scale = 76.2 reports Unsupported: conversion to scale miles rather than picking one of the two.

A unit written as a rate, with no spaces around the slash, is read as that unit however you’ve used its letters elsewhere, so a density or a speed copied from a datasheet still means what it says:

calc
g = 9.81 m/s²
2 g gives 19.62 m/s²
2.7 g/cm³ gives 2.7 g/cm³
50 kg * g gives 490.5 N

In a few cases your definition does change what a line means:

  • A single letter always means your value, so after m = 3, 2 m is 6 rather than two metres.
  • A number before a singular name multiplies it, so after width = 3, 2 width is 6. The same goes for a one-letter name before a unit or an operator. The hint says so and suggests writing 2 * width to make it clear.
  • Number words and constants are replaced too: after one = 7, one times two is 14.

Two habits avoid most surprises:

  • Don’t use unit symbols on their own as names, such as m, s, h or in, or reuse constants and number words such as pi, one or i.
  • Prefer descriptive names like hours worked, day rate or run distance.

Document order

Each line sees the names defined above it. Names also carry forward into later calc blocks in the same note, so you can set up your inputs once and use them further down the page.

calc
price = £20
quantity = 3
cost = price * quantity gives £60.00
price = £25
price * quantity gives £75.00
cost gives £60.00

Redefining price doesn’t change the earlier cost line: cost was worked out with the price at that point. To change the result of an earlier calculation, edit the line where its input is defined.

The answer above

prev is the answer on the nearest line above, and ans means the same unless you’ve named a value ans. They suit a quick follow-up sum:

calc
£1,250 * 12 gives £15,000.00
prev / 52 gives £288.46
ans + £20 gives £308.46

To add up a group of lines, write sum or total on a line of its own. See Adding up the lines above.

Referring to a line by number

line1, line2 and so on refer to a calculation by its position in the note, counting every calc block in order:

calc
price = £100 gives £100.00
line1 * 2 gives £200.00

A reference stays attached to the row it points at. Insert a line above it, or move lines with Format › Move Line Up and Move Line Down, and the answer keeps using the same row: Varlig renumbers the text for you, as its own undo step, so what you read and what you get agree.

Delete the row a reference points at and the line says Error: line2 refers to a deleted line rather than quietly using a different number. Undo brings both back.

Copy and paste keeps references

Copy or cut calc lines and paste them, and their line2 and ↑ references go on reading the lines they read before:

  • A reference to a line you copied follows the copy, renumbered to where it lands.
  • A reference to a line you didn’t copy keeps reading that line when you paste in the same note.
  • Pasted into another note, it becomes the name that line defines, such as rent for rent = $1,200, which works once the note defines it or uses it. A line without a name becomes a reference such as line2_of_Budget, which says so until you replace it:
calc
5 + line2_of_Budget gives Unsupported: line2_of_Budget is a line of another note

The clipboard holds only the text you selected, so other apps get exactly that, and the paste is one undo step. Lines copied from a password-protected note paste as written.

Turn prose into a calculation

Pasted an invoice, or written a few lines that should be adding up? Select the lines and choose Format › Convert to Calculation Block, or press ⌘Y with a selection: Varlig wraps them in a calc fence as a single undoable edit, and the answers appear beside them.

With nothing selected, ⌘Y inserts an empty block. Text outside a block is never calculated, so a pasted email keeps its numbers, dates and invoice references exactly as they are.

Scope reset

A line containing only --- starts a fresh scope. Names, custom units and your own functions defined above it are no longer visible below it. This is useful for comparing two scenarios in one note without their values leaking into each other.

calc
# Option A: the flat in town
rent = £1,250
travel = £60
rent + travel gives £1,310.00
---
# Option B: the flat further out
rent = £980
travel = £210
rent + travel gives £1,190.00

Below the ---, travel has to be defined again. If you forget, the line that uses it has nothing to refer to.

Conditionals

if … then … else … picks one of two values based on a comparison. You can use it on its own or assign the result to a name:

calc
basket = £34.50
delivery = if basket >= £40 then £0 else £3.99 gives £3.99
basket + delivery gives £38.49

Chain else if for more than two outcomes:

calc
basket = £34.50
if basket < £20 then £4.99 else if basket < £40 then £2.99 else £0 gives £2.99

Only the chosen branch is worked out, so the other branch may contain something that would fail:

calc
guests = 0
if guests > 0 then £120 / guests else £0 gives £0.00

Postfix if and unless

You can also put the condition after the value. value if condition shows the value when the condition holds, and value unless condition shows it when the condition does not. In either case the line shows nothing otherwise.

calc
basket = £34.50
£3.99 if basket < £40 gives £3.99
£3.99 unless basket >= £40 gives £3.99

The value can be text in double quotes, which turns a check into a line that tells you where you stand and stays blank the rest of the time:

calc
conversion = 0.667%
"on target" if conversion > 0.5% gives on target

Assigning inside a conditional

Both branches can assign to the same name:

calc
basket = £34.50
if basket >= £40 then shipping = £0 else shipping = £3.99 gives £3.99
shipping gives £3.99

With only a then branch, the assignment happens when the condition holds and the name keeps its old value otherwise:

calc
basket = £34.50
points = 0
if basket > £30 then points = 50 gives 50
points gives 50

Comparisons such as >= and the && and || operators are covered in Operators, comparisons and conditionals.

Putting it together

Here is a small freelance invoice, written the way you might keep it in a note:

calc
# March invoice
day rate = £420
days worked = 6
travel = £86.40 // train fares
fees = day rate * days worked gives £2,520.00
subtotal = fees + travel gives £2,606.40
vat registered = true
vat = if vat registered then subtotal * 20% else £0 gives £521.28
Total due: subtotal + vat gives £3,127.68

Every input has a name, so next month you only change days worked and travel, and the rest of the invoice follows. The comments and label keep the block readable, and the conditional means the same note works whether or not you charge VAT.