7

I have a big problem with displaying math expressions in my responsive website. In particular, if you visit this page with a smartphone, you can see that most of the math expressions are cut off due to responsive design. I'm using Joomla and the Jextbox Equation plugin for displaying them.

I want formulas on my page to behave like this one on Wikipedia. If you open this page in your smartphone you can see that, where formulas are too long, they are not cut off. They are displayed if you scroll from left to right. I would like to do the same in my page.

Christopher Bottoms
  • 11,218
  • 8
  • 50
  • 99
mbistato
  • 139
  • 1
  • 7
  • Please make a [minimal, complete, and verifiable](http://stackoverflow.com/help/mcve) question. – Christopher Bottoms Apr 27 '15 at 11:40
  • Ok. I want that my page with formula too wide can be resized as wikipedia site do in this example: http://it.wikipedia.org/wiki/Integrale_multiplo. If you open this last page in your smartphone you can see that, where formulas are too long, they are not cutted but they are displayed if you scroll from left to right. I want obtain this in my page. I hope I've been more clear – mbistato Apr 27 '15 at 12:30
  • The link to your page appears broken. If you could post a minimal amount of code that reproduces your problem, it would make it easier for us to help. – Christopher Bottoms Apr 27 '15 at 12:39
  • Have you looked at the page source for that Wikipedia page? – Christopher Bottoms Apr 27 '15 at 12:40
  • The page is at this link: http://www.webtutordimatematica.it/materie/analisi-2/integrali-doppi-e-tripli/esercizi-sugli-integrali-doppi/item/278-integrale-doppio-1. Yes I've looked at the page source but it doesn't give me any hints – mbistato Apr 27 '15 at 12:44
  • I get a 404 error: `An error has occurred while processing your request.` `You may not be able to visit this page because of:` `* an out-of-date bookmark/favourite` `* a mistyped address` `* a search engine that has an out-of-date listing for this site` `* you have no access to this page` – Christopher Bottoms Apr 27 '15 at 12:46
  • But if you post a minimal amount of code that replicates the equation display problem, that link won't be so important.... – Christopher Bottoms Apr 27 '15 at 12:47
  • Please edit your question to include your code. – Christopher Bottoms Apr 27 '15 at 13:12
  • The problem is that Mathjax_Display is resized as well as container-fluid. I don't know if it enough but the code is this: `code`
    `code`
    – mbistato Apr 27 '15 at 13:22
  • the page should be now available – mbistato Apr 27 '15 at 13:28
  • The Wikipedia page you point to has equations rendered as images. In your page, the equations seem to be text. – Christopher Bottoms Apr 27 '15 at 16:38

5 Answers5

5

From the documentation on activating MathJax's line-breaking:

The HTML-CSS and SVG output processors implement (most of) the MathML3 >automatic line-breaking specification. (The NativeMML output processor relies on the browser’s native MathML support to handle line breaking when it is used.) Since line-breaking takes extra processing and so can slow down the mathematical output, it is off by default, but you can enable it by adding

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
 "HTML-CSS": { linebreaks: { automatic: true } },
         SVG: { linebreaks: { automatic: true } }
});
</script>

to your page just before the tag that loads MathJax.js itself.

However, in your example, there's a lot of tabular mathematics, i.e., layout using <mtables> (though people using TeX as input are often not aware, MathJax converts all inputs to MathML internally).

The problem is: mtables can't really be line-broken, much like html tables can't be line-broken -- responsive tables need some JS help and, more importantly, additional semantic markup.

PS: For what it's worth, we're actually working on semantic heuristics for mathematics to do something better than linebreaking but that's ongoing R&D with no ETA.

Peter Krautzberger
  • 5,145
  • 19
  • 31
  • Thanks Peter! At this point, I think the better way to display formulas is like this wikipedia article: [link] http://it.m.wikipedia.org/wiki/Integrale_multiplo [link]. In the mobile version, formulas are not cutted off and the user has the possibility to scroll from left to right to see it completely. There is a way to do it with mathjax? – mbistato Apr 28 '15 at 06:03
  • I don't quite see anything particular in that link but I'm guessing you're after something like `overflow:scroll`? Again, there's unfortunately not yet a built-in way but you can wrap your equations in a container and specify `overflow` on those. (Cf. the first equation on mathjax.org) – Peter Krautzberger Apr 28 '15 at 07:59
  • @PeterKrautzberger, in my circumstances (Latex w \begin{align} and Bootstrap grid) your script seemed at first to do nothing. Upon fiddling I found that it did work for equations in which I failed to put the ampersand in front of the equals sign for alignment. Thanks so much for MathJax! – Mike O'Connor Jun 09 '15 at 06:58
2

I have visited user3700643's page and see that there are still problems--- this when I use Firefox's Responsive Design View at 320×487. My solution is doofus I know, as it requires some duplication, but I have used it with not only MathJax (just now) but in the past for tables and other things--- all in a Twitter Bootstrap grid environment, but I'm pretty sure that that doesn't matter.

I have been using the CSS3 @media Rule. Here is my particular version:

@media(max-width:768px){
  .wide {display:none;}
  .mobilefont {font-size:0.8em;}
}
@media(min-width:768px){
  .tight {display:none;}
}

I just threw the mobilefont bit in just to further inspire you. I do sometimes use it. So, what I do is wrap an equation--- I'm using Latex with MathJax--- with a div and give the div the class "wide" if the equation is formatted for a wide screen and "tight" if it's formatted for a small screen. You can see how the max-width/min-width values in the CSS3 effect the disappearance of divs that have those class names according to whether the screen width is greater than or less than 768px, which is the popular breakpoint (but others can be defined by you).

That is, I duplicate my big-screen \begin{align}\end{align} block. I paste the copy in right under the original and wrap each with divs and give the two divs those two class names. I then edit the one with the "tight" class name to make it work in the Responsive Design View with a small screen size.

I have also done this outside of the MathJax context, with plain tables. I have, for example, used <td class="wide"> in every <td> of a given column of a table to make that column disappear on small-screen devices.

On your page where you have "L'integrale di partenza sarà allora la somma degli integrali sui due domini", inside your "tight" div version you could, if you were using a \begin{align}\end{align} block (but I see you're actually using \begin{eqnarray*} which I haven't tested with this scheme), simply put an ampersand in front of that double integral on the left, and then new-line characters \\ after that integral to break to a new line. And put ampersands in front of each equal sign on every line. That way the lines that start with equals signs will be moved far to the left, aligned under the expression for the integral instead of to the right of it.

That would not be too confusing, I don't think. It's only slightly unorthodox. But see my comment to Peter Krautzberger's answer... I have found that his script doesn't work when I use the ampersand. But the point is that it isn't needed at all with my CSS3 approach since I simply specify all of the re-formatting myself.

Mike O'Connor
  • 2,494
  • 1
  • 15
  • 17
2

You can achieve this with css as follows:

mjx-container mjx-math {
    white-space: normal;
}
0

All you need to do is make use of responsive tables. Customize your tables and problem solved. e.g., if you use Wordpress, then use the plugin "WP Responsive Table". If you code yourself your website, then use Bootstrap Responsive Table. Use transparent borders if needed and add your MathJax code inside the table.

stats con chris
  • 178
  • 1
  • 10
0

Came here in 2022, but don't see an answer that works in my case with MathJax 3. I have my formulas as nested content of a flex item and are hit by what this answer describes in the 2nd sentence.

A flex item cannot be smaller than the size of its content along the main axis.

With complex formulas I see explicit min-width CSS properties directly on MathJax elements. To overwrite these I needed the

mjx-container {
  overflow-x: auto;
  min-width: 0 !important;
}

and in addition, in my containing flex item

.the-containing-flex-item {
  width: 0;
  flex-basis: 60%; /* or whatever you need */
}

I can only guess why the width:0 is necessary, but this seems to actually kill the min-width from the contained element, while the flex-basis then sets the actual width of the flex item.

Harald
  • 4,575
  • 5
  • 33
  • 72