Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional units #47

Open
lhebates opened this issue May 11, 2023 · 8 comments
Open

Add additional units #47

lhebates opened this issue May 11, 2023 · 8 comments
Labels
enhancement New feature or request roadmap Planned feature on the roadmap

Comments

@lhebates
Copy link

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!

@merchantscp2
Copy link

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

@freqyfreqy
Copy link

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.

@merchantscp2
Copy link

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

@freqyfreqy
Copy link

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.

@gtg922r
Copy link
Owner

gtg922r commented Jul 3, 2023

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.

@gtg922r gtg922r added enhancement New feature or request roadmap Planned feature on the roadmap labels Jul 3, 2023
@merchantscp2
Copy link

merchantscp2 commented Jul 3, 2023 via email

@gtg922r
Copy link
Owner

gtg922r commented Jul 3, 2023

  • @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

@emiraga
Copy link

emiraga commented Jul 23, 2023

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
```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request roadmap Planned feature on the roadmap
Projects
None yet
Development

No branches or pull requests

5 participants