josdejong / josdejong/mathjs

Support Chinese punctuation like full-width parentheses

Open
#3,593 5 comments 0 reactions 0 assignees View on GitHub
category:expressions feature
Dominant language
JavaScript
Stars
15.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

I got an email from a Chinese user explaining that he has to switch the input from Chinese to English in order to type parenthesis in an expression. It would be really convenient for Chinese users if it is possible to use the Chinese full-width variants of characters like parentheses.

This Wikipedia page gives a useful overview: https://en.wikipedia.org/wiki/Chinese_punctuation#Marks_similar_to_European_punctuation. The characters that are relevant for mathjs are:

Chinese full-width character | Chinese full-width code | English character | Character name
---- | ---- | ---- | ----
`,` | U+FF0C | `,` | Comma
`、` | U+3001 | `,` | Enumeration comma
`!` | U+FF01 | `!` | Exclamation mark
`?` | U+FF1F | `?` | Question mark
`;` | U+FF1B | `;` | Semicolon
`:` | U+FF1A | `:` | Colon
`(` | U+FF08 | `(` | Left parenthesis
`)` | U+FF09 | `)` | Right parenthesis
`[` | U+FF3B | `[` | Left square bracket
`]` | U+FF3D | `]` | Right square bracket

If there is indeed need for this, we can implement support for it in two ways:

1. Simple way: in the parse function, write a regular expression which replaces all full-width Chinese characters with their English variant. Or we could just provide two helper functions to replace Chinese full-width characters with their English variants and vice versa.
2. More work: similar to functions like `parse.isDigit`, introduce functions like `isParenthesisOpen` which test for the English and Chinese variant of the character. We can also think though how to make sure that stringifying an expression keeps track on the originally used character. I'm not sure if this is worth the added complexity though.

Any thoughts:

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.