gtg922r / obsidian-numerals

An obsidian plugin which turns a math code block into a full featured calculator
Other
389 stars 7 forks source link

[Feature Request] Add non English variable names #39

Open LordPanda95 opened 1 year ago

LordPanda95 commented 1 year ago

Please add not only English variable name

gtg922r commented 3 months ago

What do you mean by variable names? Any variable name will work today.

Do you mean the built-in functions and physical constants such as speedOfLight?

LennoC commented 1 month ago

What do you mean by variable names? Any variable name will work today.

Do you mean the built-in functions and physical constants such as speedOfLight?

I think his meaning is that we can't type non-English words in the math block, an error SyntaxError will be reported.

e.g

math block
# Here can be writen in non-English word, eg Chinese-测试 Russian-Я думаю
# below the calc process, No non-English words can appear in.
Apple = 3 # This is OK.
苹果 = 3 # This line will occur `SynataError`
egwynn commented 1 month ago

This is a limitation of mathjs, and I don't think it should be in scope of this project. Here's an MRE:

import { evaluate } from 'mathjs';
evaluate('a = 1');
evaluate('好 = 1');

This will produce the error you saw:

SyntaxError: Syntax error in part "好 = 1" (char 1)

Note that mathjs has published a syntax doc which specifies allowed variable names. To quote their docs:

Variable names must:

  • Begin with an “alpha character”, which is:
    • A latin letter (upper or lower case). Ascii: a-z, A-Z
    • An underscore. Ascii: _
    • A dollar sign. Ascii: $
    • A latin letter with accents. Unicode:\u00C0 - \u02AF
    • A greek letter. Unicode: \u0370 - \u03FF
    • A letter-like character. Unicode: \u2100 - \u214F
    • A mathematical alphanumeric symbol. Unicode: \u{1D400} - \u{1D7FF} excluding invalid code points
  • Contain only alpha characters (above) and digits 0-9
  • Not be any of the following: mod, to, in, and, xor, or, not, end. It is possible to assign to some of these, but that’s not recommended.

I recommend closing this issue and taking it up with mathjs.