Page MenuHomePhabricator

Chemistry formulae ignore significant spaces, opposite to LateX source
Closed, ResolvedPublic

Description

When using the <chem> tag to write a formula like "CO2 + C -> 2 CO" , the plus sign ends up as superscript to CO2, as if it was a charge (reported on it.wp). It's the first formula you see when you open the editor to add one.

And also: 2.5 should give 2 * 5, and it works. But 2 . 5, with spaces, should give 2.5, and it doesn't, so there is no way to add decimal fractions.

Event Timeline

That the plus sign on the line has a meaning, while the plus sign displayed as superscript means something else?

Of course. The question is why do you expect something else than superscript? This is the way how it works. If you need it different, use "{CO2} + C -> 2 CO".

@IKhitron If there is a space between CO2 and +, I would expect + not being a superscript. If there isn't a space between CO2 and +, I would expect + to be a superscript.

I see. What's the result in LateX? It must be the same.

I guess I'm expecting something different because of the spaces (I'm writing it CO2 + , not CO2+).
I would have never thought about using parentheses. If anyone else actually writing and understanding formulas would naturally know that, please decline this task.

Again, we need to compare to LateX. If it's the same - it's their problem, not our. If it isn't - there is computation bug here.

I agree with @IKhitron, but I can't help, I used to use LateX a long time ago.

If it behaves the same way like LateX, the predefined formula is what should be fixed. If it doesn't behave like LateX, the problem is in a computation as @IKhitron pointed out

But I think it is a wrong behavior, because if I write CO2+, it changes to "CO²+". I believe these two are just switched in the computation. The last predefined formula is broken too, in the opposite way.

Well, checked in LateX \ce. There is a bug, indeed. Something ignores spaces in the parsing. It can be also in other example:
2.5 should give 2 * 5, and it works. But 2 . 5, with spaces, should give 2.5, and it doesn't, so there is no way to add decimal fractions.

IKhitron renamed this task from Formula doesn't look right to Chemistry formulae ignore significant spaces, opposite to LateX source.Mar 7 2017, 4:29 PM
IKhitron edited projects, added Math; removed VisualEditor.
IKhitron updated the task description. (Show Details)
IKhitron added a project: Mathoid.

(Is LateX the only relevant comparison, BTW?)

Math markup goes inside <math>...</math>. Chemistry markup goes inside <math chem>...</math> or <chem>...</chem>. All these tags use TeX.
The TeX code has to be put literally: MediaWiki templates, predefined templates, and parameters cannot be used within math tags: pairs of double braces are ignored and "#" gives an error message. However, math tags work in the then and else part of #if, etc

Pkra moved this task from Mathoid to Inbox on the Math board.
Physikerwelt added a subscriber: Physikerwelt.

It seems to be a pure texvcjs bug. If someone provides a test case, we can probably fix it in the grammar. What I understand is that the input

  • \ce{2.5} should be sanitized to \ce{2.5} and
  • \ce{2 . 5} should be sanitized to \ce{2 . 5}

curl -X POST "https://en.wikipedia.org/api/rest_v1/media/math/check/chem" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "q=\ce{2.5}"

currently results in
"checked": "{\\ce {2.5}}",

and
curl -X POST "https://en.wikipedia.org/api/rest_v1/media/math/check/chem" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "q=\ce{2 . 5}"

results in
"checked": "{\\ce {2 . 5}}",

See https://en.wikipedia.org/api/rest_v1/#/Math/post_media_math_check__type_
No doubt about the additional space between \ce and the argument is stupid and also the extra curly brackets, but that's another issue.

Also CO2 + C -> 2 CO becomes {\\ce {CO2 + C -> 2 CO}} so no issue here, or?

Physikerwelt claimed this task.