This site describes solve-engine as it is on main: 2.43.0, which npm does not have yet. npm installs 2.40.0, so a page may show an answer that version does not give yet.
Sections
Package:
LINES_PACKAGE. Registered bycreateEngine(); for a slimmer engine, register it explicitly (see choosing packages).
A long note is usually split into parts: a budget with one part for travel, one
for food, one for the house. In markdown, each part starts with a heading, a
line that begins with #. The number of # marks says how deep the heading
sits, so # Travel is a top-level heading and ## Flights is a smaller one
inside it. The lines under a heading, down to the next heading at the same level
or above, are its section.
A section total names the heading and adds up the figures under it, wherever the total is written. It finds the block by name rather than by line numbers, so it keeps giving the right answer as lines are added to the section or the note is rearranged.
| Expression | Meaning |
|---|---|
total of section "Travel" | the sum of the figures under the Travel heading |
sum of section "Travel" | the same, sum is a synonym for total |
average of section "Travel" | the mean of those figures |
count of section "Travel" | how many figures there are |
A worked note, with a summary at the bottom. A label before a colon
(Flights:) names the line and is set aside, so the line is its figure:
# TravelFlights: $450Hotel: $220Taxi: $50
# FoodGroceries: $40Dinner: $25
# Summarytotal of section "Travel" // $720.00total of section "Food" // $65.00average of section "Travel" // $240.00count of section "Travel" // 3The name is matched without regard to case or extra spaces, so
total of section "travel" finds # Travel. Nothing else is forgiven: a name
that is not quite a heading’s is an error, not a guess at the nearest block.
Why not total above or a line range
Section titled “Why not total above or a line range”total above adds up the lines directly above it
and stops at the first blank line or heading, so it only works written at the
foot of its own block. sum(line 2 : line 4) names the lines by number, and
those numbers go stale as soon as a line is inserted above them. A section
total can sit anywhere below the block, a summary at the bottom of the note
included, and it reads whatever is under the heading at the time.
What a section holds
Section titled “What a section holds”A heading’s section takes in the smaller headings inside it. # Travel runs
down to the next # heading, so it holds ## Flights and ## Hotels and
everything under them, while ## Flights stops at the next ##:
# Travel## FlightsOutbound: $300Return: $150## HotelsRome: $220
# Summarytotal of section "Travel" // $670.00total of section "Flights" // $450.00total of section "Hotels" // $220.00The last section in the note runs to the end of the note.
Blank lines and the smaller headings inside a section are passed over, and so
is a line that is only a comment, a note to yourself starting with //. None of
them interrupts the total:
# TravelFlights: $450
## ExtrasSeat upgrade: $20
# Summarytotal of section "Travel" // $470.00Money and units carry through, read in the unit the first figure is written in:
# WalksPark: 1.2 kmCanal: 3 kmHill: 800 m
# Weektotal of section "Walks" // 5.00 kmSubtotals are not counted twice
Section titled “Subtotals are not counted twice”A section often ends with its own subtotal, and a summary part of the note can hold one total per section. A line that is itself a summary of other lines is left out of a section total, because the figures it sums are already counted:
# TravelFlights: $450Hotel: $220Subtotal: total above // $670.00
# Summarytotal of section "Travel" // $670.00count of section "Travel" // 2The summaries left out are total above and its siblings, a
sum(line 2 : line 4) span, a category tag total,
total by tag, and another section total. A line that reads a single other
line, such as prev or line 3, is a figure of its own and is counted.
A section total can also sit at the foot of the section it totals. It leaves itself out:
# TravelFlights: $450Hotel: $220total of section "Travel" // $670.00The answer is a value like any other, so it can be scaled, compared or kept in a variable:
# TravelFlights: $450Hotel: $220
# Plantotal of section "Travel" * 1.2 // $804.00:budget = total of section "Travel" // $670.00budget - $100 // $570.00A clear error, never a silent figure
Section titled “A clear error, never a silent figure”A name that no heading carries is an error that lists the headings there are, so a slip in the name is a one-look fix:
# TravelFlights: $450
# Summarytotal of section "Travle" // ERROR: No heading is named "Travle". The headings in this note are "Travel" and "Summary".A name two headings carry is refused rather than guessed at, since either block could be the one meant:
# March## TravelTrain: $40# April## TravelTrain: $55
# Summarytotal of section "Travel" // ERROR: 2 headings are named "Travel" (lines 2 and 5), so the section is unclear. Give each its own name.To add up the same heading repeated across a note, a ## Travel under every
month, tag those lines and total the tag instead (see
category tags).
A figure that is not a number, a mix of measures, and a section with no figures
at all are each refused the same way. count of section counts presence rather
than value, so it counts a line of text too, and gives 0 for an empty section:
# TravelFlights: $450"booked in May"
# Summarytotal of section "Travel" // ERROR: Line 3, under "Travel", is text, so it cannot be added: only numbers and quantities can.count of section "Travel" // 2# TravelFlights: $450Luggage: 23 kg
# Summarytotal of section "Travel" // ERROR: money and mass cannot be added# Travel
# Summarytotal of section "Travel" // ERROR: The section "Travel" has no figures to add up.count of section "Travel" // 0A sentence of prose inside a section is a line the engine cannot read as a
figure, so it stops the total with an error naming that line. Write notes to
yourself after // and they are passed over.
Boundaries
Section titled “Boundaries”A few boundaries, each deliberate:
- The total goes below the block it reads. It reads lines that have already
been worked out, the way
total abovedoes, so a section total written above its section reports the first line it could not read yet:
total of section "Travel" // ERROR: Line 3 has not been evaluated yet (forward reference, or out of range)# TravelFlights: $450- One heading per name. Two headings with the same name are refused rather
than added together; a heading path such as
"April / Travel"is not read. - Headings are read the way the rest of the engine reads them. Any line
whose first character is
#is a heading, so#Travelwith no space is one too, while a colour such as#fffis not. A closing run of#after the name (## Travel ##) is ignored. - Only
total,sum,averageandcount. The median, smallest and largest of a section are not offered; the statistics forms read a list or a table column. - The word
sectionis only special in the whole phrase. A quoted name has to follow it, so a variable namedsectionkeeps working (see trigger words).
Like line references, these forms only work inside a document, since they read other lines. They return an error through the single-expression entry point, which has no document to read.