asciimath / asciimathml

A new home for asciimathml
http://asciimath.org/
MIT License
957 stars 183 forks source link

Inconsistent whitespace sensitivity with numbers #124

Closed kozross closed 3 years ago

kozross commented 3 years ago

If you type the equivalent of "1.2 00" into the test environment, it renders as '1.200' (i.e. one number). This is consistent with doing "12 00", which renders as '1200'. However, if you try "1. 200", you instead get '1. 200' (i.e two 'numbers').

This raises multiple questions regarding parsing of whitespace and numbers:

Furthermore, even though some specification of the grammar exists, how numbers are parsed is not specified: I had to discover myself that, for example, insignificant leading or trailing zeroes remain. This should likely get fixed too, and it relates to this issue, which is why I mention it here.

drlippman commented 3 years ago

The short answer is that whitespace breaks tokens. So "1200" becomes <mn>1200<mn>, while "12 00" becomes <mn>12</mn><mn>00</mn>. So in the MathML it is two numbers, but it's up the renderer (FireFox or MathJax if you're using that) how to display that, and it appears they display them without a space. That's not something AsciiMathML controls, so not anything to "fix" here.

Now, interestingly, it does appear "1.2" becomes <mn>1.2</mn> while "12." becomes <mn>12</mn><mo>.</mo>. So currently "12." does not get parsed as a number, but as a number and an operator, and the rendering engine seems to add a space after operators, which is why "1. 200" is appearing to you as two numbers. I would argue that parsing is actually wrong, and "12." should get parsed as a number, since an ending decimal point can be used to indicate trailing zeros are significant digits in science fields. So if anything needs fixing, it'd be getting "12." to get parsed as a single number.

kozross commented 3 years ago

@drlippman Thank you for that - it's very useful information. I feel it would help a lot if all this got added to the description of the grammar on the main AsciiMath site.

drlippman commented 3 years ago

Feel free to make a PR to the website repo with suggested changes.