Katex: Wrong convertion LaTEX-code to MathML

Created on 15 Oct 2020  ยท  9Comments  ยท  Source: KaTeX/KaTeX

Describe the bug:
The LATEX-code are converted to MathML wrong, although by visually all OK. The correct MathML is needed to read math formulas by screen-readers.

To Reproduce:
Steps to reproduce the behavior:

  1. Try to type the difficult LaTEX-formula which contains, for example, log or trigonometric function. My example is:
    $${\log_{\sqrt{11}} 121}^2$$
  2. see the source MathML-code (not a visual picture of the formula).

Expected behavior:
I should get something about this:
<math> <msup ><mrow ><msub ><mi>log</mi><msqrt ><mn>11</mn></msqrt></msub><mo>โก</mo><mn>121</mn></mrow><mn>2</mn></msup></math>
But I get such MathML:
<math ><msup ><mrow ><msub ><mo><mi>log</mi><mo>&#x2061;</mo></mo><msqrt ><mn>11</mn></msqrt></msub><mn>121</mn></mrow><mn>2</mn></msup><mrow encoding = "application/x-tex"></mrow></math>
Environment (please complete the following information):

  • KaTeX Version: latest (the problem is relevant even or your demo)
  • Device: laptop, but the problem is relevant for all devices.
  • OS: Windows 10, iOS 14
  • Browser: Chrome, mobile safari
  • Version: Chrome 86, Safari 14

Additional context:

The log and other functions shouldn't be wrapped into <mi></mi> tags as it is interpreted incorrectly by different MathML-readers (such as MathPlayer). The wrong convertion of LaTEX-code breaks an accessibility The problems almost at all formulas with log or trigonometric functions. Also in some situations, for example, there is an excess subscript, and so on.

bug

Most helpful comment

@Futyn-Maker Thank you for the comment. I believe that this MathML can be written in more than one way and still meet the W3C spec for MathML. So we want to write the version that works in both visible browsers and in screen readers. I've volunteered quite a lot of time in the last year to cleaning up KaTeX's MathML and your feedback tells me that I have some more work to do.

So here is what is going to happen next. I'm going to go work up a modification of KaTeX. Maybe a couple different versions. I'll put the output up on a test page somewhere and then I'll come back here, give you the URL, and ask you to tell me how they work. When we get something that works properly for all viewers readers, then I'll turn in a PR to this repository.

Give me a couple of days. I've got some other things on my plate right now.

All 9 comments

the problem is relevant even or your demo
functions are completely disapeared like in the example above

I cannot reproduce your result in the demo. Your example input is {\log_{\sqrt{11}} 121}^2. And you report that a <mo> element is empty which should contain log. When I examine the output, I find that the same <mo> element is

<mo>
   <mi>log</mi><mo>&#x2061;</mo>
</mo>

Now one could argue that KaTeX should not wrap that <mi> element with a <mo>. But that would be a different discussion. In this discussion, it it incorrect to say that the <mo> is empty and that the log term is missing.

@ronkok How do You read output MathML in katex.org demo page?

In Chrome, I right click the element, invoke the Inspect option, drill down to the relevant <math> element, right click again, invoke the Copy Outer HTML option, and copy to a text editor where I can more easily read the code.

@ronkok OK, I'm sorry for confuse. Actually The problem is that log (for example) is wrapped into <mi></mi> tags. I'm blind and I use the NVDA screen reader with Access8Math addon and MathPlayer from Design Science, and these programs are interpret such MathML incorrectly. More than, the VoiceOver in iPhone are same behaveour, too. If I remove <mi></mi tags, it's OK. Maybe such convertion (with these tags) is really wrong? I very doubt that at minimum 3 programs have the same bug...

I've edited the heading comment.

@Futyn-Maker Thank you for the comment. I believe that this MathML can be written in more than one way and still meet the W3C spec for MathML. So we want to write the version that works in both visible browsers and in screen readers. I've volunteered quite a lot of time in the last year to cleaning up KaTeX's MathML and your feedback tells me that I have some more work to do.

So here is what is going to happen next. I'm going to go work up a modification of KaTeX. Maybe a couple different versions. I'll put the output up on a test page somewhere and then I'll come back here, give you the URL, and ask you to tell me how they work. When we get something that works properly for all viewers readers, then I'll turn in a PR to this repository.

Give me a couple of days. I've got some other things on my plate right now.

OK, thank You for Your interest! I'll wait for Your comment. An accessibility is real important.

Hey, @Futyn-Maker, could you visit the page at https://deploy-preview-2596--katex.netlify.app/docs/support_table.html, and scroll down to the entry for \operatorname*? If you can read the asin in that entry, then we should have something that works.

Yes, it seem that all OK. The operator name are spoken correctly. The MathML code which generated the Access8Math addon in NVDA is following (it can bit differ of original KaTEX-code):
<math ><munder ><mrow ><mi>asin</mi><mo>โก</mo></mrow><mi>y</mi></munder><mi>x</mi><mrow encoding = "application/x-tex"></mrow></math>

Andrey

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StaloneLab picture StaloneLab  ยท  3Comments

trollanfer picture trollanfer  ยท  5Comments

mpolyak picture mpolyak  ยท  3Comments

oddhack picture oddhack  ยท  3Comments

shaunc picture shaunc  ยท  4Comments