MathJax icon indicating copy to clipboard operation
MathJax copied to clipboard

Behaviour is not expected, \text width is 0

Open examgoal opened this issue 3 years ago • 6 comments

Issue Summary

Screenshot at Feb 23 22-25-19

\limits_\text{ফসফরিক অ্যাসিড}

Screenshot at Feb 23 22-17-17

Here if we inspect in chrome \text{ফসফরিক অ্যাসিড} width is 0, is it expected?

Steps to Reproduce:

$$\mathop {{H_3}P{O_3}}\limits_\text{ফসফরিক অ্যাসিড} + AgN{O_3} + {H_2}O \to \mathop {{H_3}P{O_4}}\limits_\text{ফসফরিক অ্যাসিড} + Ag \downarrow + \,2HN{O_3}$$

Technical details:

  • MathJax Version: 3
  • Client OS: Mac OS X 10.8.4
  • Browser: Chrome 29.0.1547.57

examgoal avatar Feb 23 '22 16:02 examgoal

Are you pre-processing the page server-side, or is MathJax actually running in the browser?

Can you provide a complete page that exhibits this failure? I'm wondering if something in the CSS might be affecting it. MathJax is set up to measure the characters that aren't in its fonts (like the Bengali letters you are using), but sometimes the page CSS can interfere with that.

dpvc avatar Feb 23 '22 17:02 dpvc

I made a codepen! you can see if the div is hidden at first then and if I make it visible, and the manual typeset is triggered nothing actually happens! It's broken.

Codepen

examgoal avatar Feb 23 '22 22:02 examgoal

Thanks, that helps. I am able to see the problem, and will investigate. Note that the SVG output doesn't seem to have the problem (or at least not the same problem), so maybe you can use that for the time being?

dpvc avatar Feb 23 '22 23:02 dpvc

OK, I didn't see that you edited your comment, and your are correct that it is tied to the fact that the initial div as display:hidden. Because the Bengali characters are not in MathJax's fonts, it has to ask the browser to measure the size of the text so that it knows how much space to use. But when an element is display:none, the browser returns 0 for all sizes (it doesn't to the layout that it would need to do to find the size when the element is not showing). When MathJax measures a width, it caches the result so that it doesn't have to remeasure it again (that causes page repainting, which is expensive), so it caches the 0 width, and when your onInput function changes the display to block and re-typesets the contents, MathJax uses the cached width of 0.

If you don't use the initial display:none, MathJax will get the correct width, but there is a bug in CHTML output that doesn't scale the size correctly when it is in a sub- or superscript position, so you will end up with a wide empty space after the subscript. That is fixed in mathjax/MathJax-src#755, which has been merged into the develop branch, but is not yet in a release version. That will be fixed in the next release. There is no easy patch for this until then.

The SVG version works better, though the measurement of the size does still seem to be slightly off, probably due to the conversion between units inside the SVG and outside, which is based on sizing information that is subject to round-off issue.

dpvc avatar Feb 24 '22 20:02 dpvc

But if some div is like a toggle for hidden or visible then we can't ever fix this, even though we are manually typesetting. At least the manual typeset function should have the option to avoid cache, like force typeset which causes repainting, and never use cache. Hope you understand

examgoal avatar Feb 24 '22 23:02 examgoal

You could have MathJax skip elements that are hidden and run MathJax on them when they are revealed. For example, if you use a class to mark those that are hidden (and remove the class when they are displayed) rather than directly modifying the style object of the element, you could use the ignoreHtmlClass option to have MathJax skip the hidden content until you are ready to reveal it.

I will consider options to control (and clear) the cache.

dpvc avatar Feb 25 '22 01:02 dpvc