Search code examples
javascripthtmlcssmathjaxsweetalert2

Mathjax automatic linebreak when opened in a modal


For a math project, the solution of a problem should be displayed in a Sweetalert2 modal. Unfortunately although using

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

the automatic line break is not working in a Sweetalert2 modal (see image). Is there any fix for that.

With best greeting, Leon

problematic image


Solution

  • It looks like your code is rendered in different from HTML-CSS and SVG processor (most likely a Common HTML). Try adding more configs, like:

    CommonHTML: { 
      linebreaks: { automatic: true }
    }, 
    PreviewHTML: { 
      linebreaks: { automatic: true }
    }
    

    EDIT

    You are also able to specify the output processor by hand with

    MathJax.Hub.Register.StartupHook("End Jax", function () {
     return MathJax.Hub.setRenderer("HTML-CSS");
    });
    

    You can check more possibilities to determining right processor here