Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
MathJax_Font_Test breaks responsive layouts in mobile browsers #681
MathJax adds a MathJax_Font_Test div into the body element when typesetting math formulas. Sometimes this div is too wide that it breaks responsive layouts, and add extra spaces to the web pages in mobile browsers.
In my case, I add viewport meta tag to the head of the html file
This makes my web page occupy the whole width of the browser. But when MathJax starts to typeset some formulas in this page, such as
It inserts a div of size 431px by 59px as follows:
At present, most of the mobile phones have device widths between 320px and 360px, therefore this div makes browsers add extra spaces to the page.
In desktop browsers, I could solve this problem by adding "overflow: hidden" to body element. But this way is not working in mobile browsers.
In android 4.1, I have tested the stock browser, mobile firefox and mobile chrome with the following web page:
You could see extra spaces in the right when draging the web page.
It is something we know about, and it is working as it "should" based on the current font test mechanism, so in that sense, "yes". But it would be good to be able to avoid the problem. I suspect that one solution would be to clear the font test div after it is used, so that the long string isn't left in place, and the content size would not be excessively long. That is probably easiest.
We ran into this some time ago and I suggested to the user at the time to alter the font sizes used for the test (which apparently worked for him). It might be that we could do that, either conditionally for mobile devices, or if the width of the page is small, or by some other condition.
In any case, I think it can be fixed, and could be included in the bug fix release that we are planning.
@zohooo, the reason that the string is so long is that it helps to have more characters involved in order to be able to detect the difference in width that indicates the presence of the font. The font detection is delicate, and longer strings help make it more reliable.
referenced this issue
Dec 16, 2013
Hey there. Any news about when this might happen?
I just put something like this into our page. It seems to at least clean up the problem, but it'd be nice to be able to remove the code at some point.