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.
£3.40 * 5 gives £17.0045 min + 1 hour 20 min gives 2 hours 5 min1.5 litres in ml gives 1,500 mLBlank 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:
rent = £1,150rnt + £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:
rent = £1,150rent2 + £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.00Lines 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:
- 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.30A 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:
basin + pedestal £145 gives £145.00food cost per head £14.20 gives £14.20milk, bread, eggs £12.40 gives £12.40Netflix -£10.99 gives -£10.99DIRECT DEBIT REF 4471 £62.40 gives £62.40Invoice #123: £250 gives £250.00double cream 600 mL gives 600 mLchlorine 3 ppm gives 3 ppmt-shirt £12 gives £12.00on the day 60 at £28 gives £1,680.00That 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:
Year 1 £5,000 + Year 2 £6,000 gives £11,000.00Year 1 5,000 + Year 2 6,000 gives 11,000ISA 2025 £20,000 + ISA 2026 £20,000 gives £40,000.00Room 12 £40 + Room 14 £50 gives £90.00Q3 2026 £5,000 + Q4 2026 £6,000 gives £11,000.00July 2026 £500 + August 2026 £600 gives £1,100.00A 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:
hour 1 £40 + hour 2 £50 gives £90.00hours 8 + hours 7 gives 15Week 2 150 hours + Week 3 160 hours gives 310 hoursComments
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 |
# Weekly shopmilk = £1.45bread = £1.20 // sourdougheggs = £2.30 "free range"milk + bread + eggs # without the extras gives £4.95A 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:
$999 (for iPhone 16) gives $999.00laptop £899 (refurbished) + £49 case gives £948.00Boing "747" is $386.8M gives $386.8MQuotes 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:
$999 (3) gives $2,997.00So 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:
£134 (25% discount already applied) gives £134.00£10 (mother-in-law) gives £10.00A 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.
£12.50 lunch #food gives £12.50£8 coffee #food gives £8.00total of #food gives £20.50A 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.
Invoice #123: £250 gives £250.00part #4 weighs 20 g gives 20 gLabels
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:
rent = £1,250bills = £180Rent and bills: rent + bills gives £1,430.00Café bill: £12.50 + £4 gives £16.50Labels 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.
price = £85 gives £85.00price + 20% gives £102.00To update a name you have already defined, use +=, -=, *= or /=:
holiday fund = £400holiday fund += £150 gives £550.00holiday fund -= £85 gives £465.00servings = 4servings *= 3 gives 12flour = 750 gflour /= 3 gives 250 gIf 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:
guests = 0per head = £120 / guests gives Error: divide by zeroper head + £5 gives Error: divide by zeroA 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.
paid rent = £1,150daily spend = paid rent / 16 gives £71.88Names
Names can be several words long, and can contain accented and non-Latin letters, digits, underscores and emoji:
flat white = £3.40flat white * 5 gives £17.00crème brûlée = £6.50crème brûlée * 2 gives £13.00🍎 price = £0.45🍎 price * 6 gives £2.70q1 sales = £12,400q2 sales = £14,100q1 sales + q2 sales gives £26,500.00bedroom_width = 3.2 mbedroom_width * 2 gives 6.4 mA 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:
time to work = 25 mintime to work * 10 gives 4 hours 10 minpaint needed = 12.44 Lpaint needed to 1 dp gives 12.4 Lfloor = 12 m²floor * 2 gives 24 m²floor(3.7) gives 3Followed 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:
table for four = £96table for four / 4 gives £24.00When two of your names start the same way, the longer one wins, so a numbered name is read whole:
batch = £8.01batch 2 = £8.21batch 2 - batch gives £0.20Names 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:
rate = £14 / hourhours = 7.5rate * 7.5 hours gives £105.00nights = 14£118/night * 14 nights gives £1,652.00tip = $12.69$84.60 + 18% tip gives $99.83Hold 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:
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 NIn a few cases your definition does change what a line means:
- A single letter always means your value, so after
m = 3,2 mis 6 rather than two metres. - A number before a singular name multiplies it, so after
width = 3,2 widthis 6. The same goes for a one-letter name before a unit or an operator. The hint says so and suggests writing2 * widthto make it clear. - Number words and constants are replaced too: after
one = 7,one times twois 14.
Two habits avoid most surprises:
- Don’t use unit symbols on their own as names, such as
m,s,horin, or reuse constants and number words such aspi,oneori. - Prefer descriptive names like
hours worked,day rateorrun 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.
price = £20quantity = 3cost = price * quantity gives £60.00price = £25price * quantity gives £75.00cost gives £60.00Redefining 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:
£1,250 * 12 gives £15,000.00prev / 52 gives £288.46ans + £20 gives £308.46To 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:
price = £100 gives £100.00line1 * 2 gives £200.00A 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
rentforrent = $1,200, which works once the note defines it or uses it. A line without a name becomes a reference such asline2_of_Budget, which says so until you replace it:
5 + line2_of_Budget gives Unsupported: line2_of_Budget is a line of another noteThe 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.
# Option A: the flat in townrent = £1,250travel = £60rent + travel gives £1,310.00---# Option B: the flat further outrent = £980travel = £210rent + travel gives £1,190.00Below 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:
basket = £34.50delivery = if basket >= £40 then £0 else £3.99 gives £3.99basket + delivery gives £38.49Chain else if for more than two outcomes:
basket = £34.50if basket < £20 then £4.99 else if basket < £40 then £2.99 else £0 gives £2.99Only the chosen branch is worked out, so the other branch may contain something that would fail:
guests = 0if guests > 0 then £120 / guests else £0 gives £0.00Postfix 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.
basket = £34.50£3.99 if basket < £40 gives £3.99£3.99 unless basket >= £40 gives £3.99The 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:
conversion = 0.667%"on target" if conversion > 0.5% gives on targetAssigning inside a conditional
Both branches can assign to the same name:
basket = £34.50if basket >= £40 then shipping = £0 else shipping = £3.99 gives £3.99shipping gives £3.99With only a then branch, the assignment happens when the condition holds and the name keeps
its old value otherwise:
basket = £34.50points = 0if basket > £30 then points = 50 gives 50points gives 50Comparisons 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:
# March invoiceday rate = £420days worked = 6travel = £86.40 // train faresfees = day rate * days worked gives £2,520.00subtotal = fees + travel gives £2,606.40vat registered = truevat = if vat registered then subtotal * 20% else £0 gives £521.28Total due: subtotal + vat gives £3,127.68Every 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.