Write basic math in your NotePlan notes and use this plugin to calculate it.
See CHANGELOG for latest updates/changes to this plugin.

This Plugin allows you to write basic math with descriptive text in your NotePlan notes and calculate the values. The inspiration was the ever-useful Soulver App and incorporates some great open-source code from Lorenzo Corbella.
This Plugin searches the active document looking for "math" code blocks (aka Math Blocks) -- you can have as many Math Blocks on a page as you wish. When the Calculate command is run, all the Math Blocks on the page are calculated.
[!NOTE] The first step is always to add a math block, in which you can enter the items to be calculated. The plugin will not read or even see content on your page that is not in a math block.
The easiest way to start using this plugin is by running the command:
/Insert Math Block at Cursor
This will (as the name implies) insert a "Math Block" in your document and a "Calculate" link you can click to recalculate the Math Blocks on the page.
Clicking/tapping Calculate button will recalculate any Math Blocks in the currently active document, showing work on any line there are calculations.
The Clear button will clear any previous calculations/comments previously placed on the page by the plugin. Note: because recalculating is not automatic (you have to click/tap Calculate), it's a good habit to click "Clear" before you change/add/remove numbers in your Math Block so that you remember to recalculate and don't end up with stale calculations.
the Totals button will do the same as Calculate but will not show work along the way. You will only see annotated results next to "subtotal" or "total" lines. e.g.:
1+2
1
subtotal //= 4
2
total //= 6
NOTE It is generally a good idea to click "Calculate" just so you know the math parser understood your intended calculations correctly. You can then immediately click "Totals" to hide the line-by-line verifications and show the totals only.
2
3
4
total
...will be added together to get 9
4k)5M)10% of 100 (which will yield 10)20 as a % of 1000 (the answer will be .02)Assignment operations store values in named variables, e.g.
taxRate = 10%
Notes:
- Assigned numbers are tabulated when the assigned numbers are later used in a line (either alone on a line or as part of an equation), e.g.
taxRate or 20 * taxRate
- Always use the = to assign to a variable. Text like: taxrate: 20% does not do variable assignment.
NOTE Variables must not contain spaces (one block of characters)
If there are variables you want to use over and over again in different documents, you can save them in the "Preset Variables" field in this plugin's preferences. Those variables will then be available to you by name in any Math Block.
If, on the other hand, there are variables you want to re-use in multiple math blocks inside one particular note, you can save those variables in the frontmatter of the note indented (with spaces (NOT TABS)) under a heading called mathPresets, e.g.:
---
mathPresets:
myVar: 20
anotherOne: 50
---
note content here
Tip: An easy way to create frontmatter is a command in @jgclark's plugin "Note Helpers":
/convert note to frontmatter
Use the word "total" or "subtotal" (alone on a line) to add all the numbers on the previous lines
subtotal or total on a line adds all preceeding non-assignment numbers/equations (Note: these words are not case sensitive -- you can use Total or TOTAL and get the same result) 1
2
subtotal // will be 3
3
4
subtotal // will be 7 (only the numbers since the prev subtotal)
total // will be 10 (all the numbers in the math block)
As you can see subtotal can be very useful for large math blocks.
NOTE: You can also assign a (sub)total to a variable (thx George), e.g.
Quickbooks: 300
Windows: 500
softwareTotal = subtotal
PC: 1000
Mouse: 50
hardwareTotal = subtotal
bill = softwareTotal + hardwareTotal //= 1850
Text that is not a number or an assignment to a variable will be ignored. This means you can use words to create context. For instance:
Bought Groceries: 4 for bananas + 6.20 for apples
total
...will result in total //= 10.2
# this whole line will be ignored even if it has math (like 2+3)2 + 3 // the numbers will be added but this comment will be ignored6/19/2020: 2+2 (the date will be ignored)
Grocery list: 20 (will ignore the words "Grocery list")You can calculate basic time math as well, e.g.:
3h + 20mins
4hours + 1minute
total //= 7.35 h
NOTE Notice there is no space between the number and the abbreviation. If you enter a space, calculations will not work properly.
Legal abbreviations are:
WARNING Mixing time-math and regular math in the same Math Block will not be reliable.
Like time, there are other unit calculations that math.js understands and therefore will work in math blocks. For instance:
2inches + 2feet //= 26 inches
INFO Notice how the results are expressed in terms of the first item you gave -- in this case, the result is in inches, because the first item was in inches. If we wanted this same result in feet, we could do the reverse:
2feet + 2inches //= 2.1666666666666665 feet
So, if you want to ensure the following calculation comes out in hours vs. minutes, add a 0h in the first line (alternatively, you could add a line at the top that says "0h"):
initial draft session 0h + 36mins
session two 42mins
session three 17mins
total //= 1.5833333333333333 h
For the full list of units, click here.
['sin', 'cos', 'tan', 'exp', 'sqrt', 'ceil', 'floor', 'abs', 'acos', 'asin', 'atan', 'log', 'round'] ... that's just the beginning. There is a LOT of functionality in [math.js](https://mathjs.org/examples/basic_usage.js.html).
That said, getting all of it into the plugin will take some more coding, so be sure to mention on Discord which functions are highest priority for you!
This plugin is not a pretty math formatter a la LateX/MathJax. Those are great tools, and Jonathan Clark's Previews plugin can help with that. This plugin is designed for doing everyday calculations in your notes without having to go out to a calculator or spreadsheet and pasting the results in your note.