Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Cannot use defined Unit using ° (U+00B0) #2351

Closed
modellking opened this issue Nov 15, 2021 · 1 comment
Closed

Cannot use defined Unit using ° (U+00B0) #2351

modellking opened this issue Nov 15, 2021 · 1 comment
Labels

Comments

@modellking
Copy link

Documentation states that the only barrier to adding extended character support is overwriting the Unit.isValidAlpha method (https://mathjs.org/docs/datatypes/units.html#support-of-custom-characters-in-unit-names)

The following code produces an Error

const isAlphaOriginal = math.Unit.isValidAlpha
const isDegOrPercent = function (c) {
    return c === "°" || c === "%"
}
math.Unit.isValidAlpha = function (c) {
    return isAlphaOriginal(c) || isDegOrPercent(c)
}
math.createUnit('°', '1 deg')
math.createUnit('%', '0.01')

math.evaluate('12.7 ° to deg')

Error:
SyntaxError: Syntax error in part "° to deg"

This is reproducible in the demo JSBin (2021-11-15) and Version 9.4.1

Thank you for your library.

@modellking modellking changed the title Cannot define Unit using ° (U+00B0) Cannot use defined Unit using ° (U+00B0) Nov 15, 2021
@josdejong
Copy link
Owner

You'll also have to override the isAlpha of the expression parser, math.expression.parse.isAlpha.

See #1268

Repository owner locked and limited conversation to collaborators Aug 17, 2022
@josdejong josdejong converted this issue into discussion #2672 Aug 17, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

2 participants