mathjs icon indicating copy to clipboard operation
mathjs copied to clipboard

Customize supported characters for units

Open zcohan opened this issue 7 years ago • 3 comments

Following the instructions in the documentation on overriding the 'math.expression.parse.isAlpha' function, I have successfully customised supported characters for variables.

Can I do the same for units? The issue I'm running into is syntax errors when defining aliases for certain currencies with non-alpha symbols (i.e '£' for GBP & '€' for EUR).

Here's my code:

math.createUnit('USD')
math.createUnit('EUR', {definition: '1.18 USD', aliases: ['€']})
math.eval('10 USD in €')

I get "SyntaxError: Unexpected "€" in "€" at index 0"

zcohan avatar Sep 30 '18 21:09 zcohan

Good point!

Right now Unit has its own parseUnit function which only allows a-zA-Z0-9. I think it should use the the math.expression.parse.isAlpha instead, to make the behavior consistent.

Anyone interested in implementing this change? I don't think it's very complicated.

josdejong avatar Oct 03 '18 13:10 josdejong

Any updates on this? Thanks!

larissa-n avatar Nov 02 '21 16:11 larissa-n

No one picked it up yet, help would be welcome

josdejong avatar Nov 03 '21 11:11 josdejong