Inline calculator

Type math into any file and see the answer at the end of the line, with named values you can reuse further down.

Write an expression on its own line and its result appears in faint text at the end of that line. Give a value a name with name = … and use it on any later line of the same file. Names can be several words and ignore case, so Monthly rent and monthly rent are the same value. In this example you type the left side; the editor adds the = … results:

rent = 1200
utilities = 180
rent + utilities          = 1380
rent + utilities + 15%    = 1587
+ − * / ( )Arithmetic
450 + 15%= 517.5 · percent of the left side
15% of 200= 30
1,200 * 3= 3600 · thousands separators
rent = rent + 100Redefines a value from its old one
2^10 · sqrt(16)Powers, and sqrt, round, min, max

You can also write it in words. If a line isn't plain math, the calculator tries reading it as a sentence. Labels and filler words such as VAT or each are skipped, and a currency shows with the result:

Server cost: 3 nodes multiplied by 45 plus 19% VAT =   160.65
5k divided by 2 =                                     2500
$40 times 3 =                                         $120
25 is what % of 200 =                                 12.5%
9 squared plus square root of 16 =                    85

Words it understands: times, x, multiplied by, divided by, over, plus, and, minus, less, percent, squared, cubed, square root of, and 5k, 2.5m, 1b or 3 million. A value you named yourself always wins, so x = 4 then x times 2 shows 8. Lines that already worked as plain math work the same as before.

Only lines that are math get a result. Prose, headings, plain numbers (1200), simple definitions (rent = 1200), dates and phone numbers are left alone, and so is everything in frontmatter, code blocks and $$ math blocks. List items work: - rent + utilities still shows its total. Comparisons such as a == b or a >= b never define a value.

Results are rounded to four decimals and have no thousands separator. If a line can't be worked out, for example because it uses a name that isn't defined above it, it simply shows no result.