obsidian-numerals
obsidian-numerals copied to clipboard
Add additional units
Hi,
I enjoyed this wonderful plugin since its installation. I started experimenting using it to portion recipe, but ran into issues parsing units such as tsp (teaspoon) or tbsp (tablespoon). Is there a way to add more units to the plug-in or even the potential to add custom units, such as through the settings or a .js file, etc. Thanks!
Checkout the mathjs documentation. it allows you to create your own custom units.
Also, teaspoon and tablespoon are already implemented. see: https://mathjs.org/docs/datatypes/units.html
Very cool. I'm not such a pro on this. Would you be able to provide an example of how to create a custom unit with numerals calling this mathjs function? What would be awesome.
In a Numerals's block, follow the syntax and type something like
createUnit('furlong', '220 yards')
Note that you don't need the math.
Prefix.
Let the equation execute and when you're done, go to edit it and go out of it. It should give you an error saying you can't have the same unit defined. It should persist after that
Nice, I did that I see the error you mentioned. How long does this new custom unit persist for? It seems to persist across notes but when I close obsidian and reboot it, the custom unit doesn't seem to be recognized anymore.
Definitely plan to support custom units.
The error you are seeing is mathjs throws an error when a unit is created that matches the name of an existing one. Which, currently, will happen if you use createUnit
since it is run every time the codeblock is rendered.
I just need to check if the unit already exists and then not re-call the mathjs function. I might need a custom syntax.
It’d be a cool option to have in the settings that you can specify a unit and a relation to other units. Then when the block runs, have that check to see if the unit exists or refresh it if it changes
On Jul 3, 2023, at 3:25 PM, Ryan C @.***> wrote:
Definitely plan to support custom units.
The error you are seeing is mathjs throws and error when a unit is created that matches the name of an existing one. Which, currently, will happen if you use createUnit since it is run every time the codeblock is rendered.
I just need to check if the unit already exists and then not re-call the mathjs function. I might need a custom syntax.
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.
- @merchantscp2 Good point. Feature should support
- Custom unit definition in a code-block
- Custom unit definition in settings for all code-blocks
- (Lower priority) Unit definition in a code-block persists for all code-block on the page
- (Lower priority) Unit definition in metadata, e.g. frontmater, that persists across the page
As a temporary hack, this works, and you just need to define unit once on top of the page, and no need to repeat the definition.
```math
createUnit('kcal', '4184 joule', {override: true});
1kcal
```