Closed fabiospampinato closed 2 years ago
@fabiospampinato I am trying to resolve this little bug. The problem apparently lies in the vertical bar, which is considered a leftright_bracket
even when, as in this case, it is actually a binary operator. The same expression without the bars is parsed correctly. More or less connected seems the only other test which fails, that is (a,b]={x in RR | a < x <= b}
: even if visually the result is accettable, the formula is parsed incorrectly. But the code is rather complex... @christianp, do you have any hint in the right direction?
Edit: I have published Math, an extension for the CMS Yellow. I translated for it asciimath2tex.js in PHP, it works very well!
@GiovanniSalmeri thanks for looking at this. It's a very tricky problem! I looked at this a year or two ago, but didn't get very far.
The reason this is a problem for my parser is that its grammar doesn't make it easy to deal with an ambiguous delimiter. I'll have another think about it now, but I don't have much hope!
@christianp Thank you very much for investigating it! I suspect that in fact ASCIImath syntax is in this inherently ambiguous. Perhaps the easy way for avoiding this problem would be to modify the ASCIImath syntax and introduce different tokens for the vertical bars as delimiters (for example :|
and |:
), or disallowing them altogether (in the end, they can be written with abs()
). Perhaps it would be a better compromise. Just thinking aloud!
I've had a closer look at the output of the standard asciimath parser, and I think it doesn't correctly identify when |
is used as a left or right delimiter for a bracketed expression, when the other delimiter is a different symbol.
For example, (x|
produces
<mrow><mo>(</mo><mi>x</mi><mrow><mo>∣</mo></mrow></mrow>
while (x)
produces
<mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow>
and |x|
produces
<mrow><mo>|</mo><mi>x</mi><mo>|</mo></mrow>
but MathJax correctly makes the delimiters stretchy in all cases, so it must be doing something to the MathML that asciimath produces.
I'm trying to work out how to replicate that in one go, in this parser!
MathJax correctly makes the delimiters stretchy in all cases, so it must be doing something to the MathML that asciimath produces.
As opposed to TeX, in MathML everything defaults to stretchy.
Thanks, @pkra! So it stretches based on what is in the same <mrow>
?
So it stretches based on what is in the same
?
Yes (the relevant row may be implicit).
I have the following AsciiMath expression:
Which this library converts to:
Then rendering it via KaTeX I get:
While instead I should get:
I'm no TeX expert, I guess the generated TeX isn't quite right? 🤔