13
$\begingroup$

I found that MathJax is extremely slow. Is there a better, lighter and faster Javascript library that can render mathematical notation equally well?

$\endgroup$

closed as off-topic by quid, Surb, Shailesh, Thomas, achille hui Jun 28 '16 at 14:39

  • This question does not appear to be about Mathematics Stack Exchange or the software that powers the Stack Exchange network within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 8
    $\begingroup$ It may be your browser that is slow. What browser and version are you using? Have you tried using Chrome or Firefox? $\endgroup$ – Bill Dubuque Aug 30 '10 at 15:03
  • $\begingroup$ @Bill, I am using Chrome, latest dev build. $\endgroup$ – Graviton Sep 2 '10 at 14:37
  • 4
    $\begingroup$ I agree that it's very slow. I often see the LaTeX formatted text as the page is being Typeset by MathJax. I'm using Chrome 12, Ubuntu 11.04, and a fast computer, and the performance even for a single equation on an empty page is quite poor. $\endgroup$ – slacy May 25 '11 at 23:54
  • 1
    $\begingroup$ @Graviton Huh? MathJax slow? Maybe you encountered a page entirely filled with math formulas, which MathJax will take time compiling it. $\endgroup$ – user93957 Nov 3 '13 at 15:38
  • 1
    $\begingroup$ Since some feel it more important to engage in useless debate and downvote actual concrete answers to the question, I guess I'll post this as a comment: See meta.math.stackexchange.com/questions/16809/… and khan.github.io/KaTeX $\endgroup$ – Jeff Ward Jun 27 '16 at 22:10
  • 3
    $\begingroup$ @JeffWard While the written question is indeed "is there a faster alternative", the obvious implicit context is "that we can use on math.SE". People were telling you in the comments that it had already been discussed here and found not satisfactory. This isn't a general software recommendation Q&A website, this is a website to discuss what happens on math.SE, in case you hadn't noticed. $\endgroup$ – Najib Idrissi Jun 28 '16 at 7:51
  • 9
    $\begingroup$ I'm voting to close this question as off-topic because it is not current anymore. If somebody wishes to revisit this matter I feel it is better to make a new start. $\endgroup$ – quid Jun 28 '16 at 9:29
  • 1
    $\begingroup$ @quid: Thank you. $\endgroup$ – Asaf Karagila Jun 28 '16 at 21:32
  • $\begingroup$ Not sure if this is relevant anymore, but Mathjax has a 1 second delay when doing transforms. You can speed this up by setting MathJax.Hub.processSectionDelay = 0 $\endgroup$ – Matt Aug 19 '16 at 13:43
17
$\begingroup$

Mathjax performance depends on several factors, like:

  • the browser you use
  • the hardware in your computer
  • your internet connection/latency

If you want to improve the performance of mathjax, you think of a couple of things:

  1. Use a better computer. I did a short test, and if run a page with much mathjax at my 5 year old laptop, it takes around 4 times longer, then if I run the page at my newest computer.

  2. Download local fonts. There are two options. You can either download the STIX fonts locally, or download the TeX fonts locally. For the TeX fonts, download mathjax 2.2 from this page: http://www.mathjax.org/download/. Once downloaded, go to this map: fonts\HTML-CSS\TeX\otf and install all the fonts in this map. If you prefer the look of the STIX fonts, you can download them from here: http://www.stixfonts.org/

  3. Use Firefox in combination with MathML rendering I just found this out, and I'm amazed by how much faster MathML rendering is compared with HTML-CSS rendering. This only works in firefox. You can turn the MathML rendering on by right clicking on a math formula:
    Math Settings -> Math Renderer -> MathML

Here is more information about MathML rendering:

The NativeMML output processor uses the browser’s internal MathML support (if any) to render the mathematics. Currently, Firefox has native support for MathML, and IE has the MathPlayer plugin for rendering MathML. Opera has some built-in support for MathML that works well with simple equations, but fails with more complex formulas, so we don’t recommend using the NativeMML output processor with Opera. Safari has some support for MathML since version 5.1, but the quality is not as high as either Firefox’s implementation or IE with MathPlayer. Chrome, Konqueror, and most other browsers don’t support MathML natively, but this may change in the future, since MathML is part of the HTML5 specification.

The advantage of the NativeMML output Processor is its speed, since native MathML support is much faster than using complicated HTML and CSS to typeset mathematics, as the HTML-CSS output processor does. The disadvantage is that you are dependent on the browser’s MathML implementation for your rendering, and these vary in quality of output and completeness of implementation. MathJax relies on features that are not available in some renderers (for example, Firefox’s MathML support does not implement the features needed for labeled equations). The results using the NativeMML output processor may have spacing or other rendering problems that are outside of MathJax’s control.

(from http://docs.mathjax.org/en/latest/output.html)

$\endgroup$
  • 1
    $\begingroup$ I tried FF's MathML renderer, and it introduces vertical whitespace above and below maths expressions. This makes any use of inline maths very ugly. But I have to concur -- it's fast. $\endgroup$ – Lord_Farin Nov 2 '13 at 20:45
4
$\begingroup$

I don't think it is MathJax that is the problem, but rather the nature of the way web pages are formatted. MathJax has to generate a bunch of div and span blocks, which takes time for a browser to render. While we're writing posts, these get (re)rendered all the time.

The solution to this problem might be implementation of one or more of the feature requests:

  1. Make a better SE parser of what formulas need rerendering, so that MathJax has less rerendering to do.
    I expect this to be very hard to implement, and would probably be buggy.

  2. Make a delay in rendering, as it is with the syntax highlighting.
    In other words, formulas get displayed as a source ($formula$), until the poster has stopped typing for a short period of time, let's say 3 or 5 seconds. After such a delay, post's formulas would get rendered as we're used to.

  3. Add a "Don't process formulas while I'm typing" checkbox.
    This would go either somewhere near the post-writing area, or in the profile (or, preferably, both, with the one in the profile being the default state), and could mean either "don't process at all" or "behave as I've described in the item 2 above".

  4. Some kind of delay as described in 2 and, implicitly, in 3, but with the delay time growing with the post size (up to a limit of, IMO, no more than 30 seconds).
    This way, shorter posts (which are not troublesome) would not be affected, while the longer ones would be so hard on our computers. I leave the definition of "length" here opened. It might be the number of characters, which implements trivially, but could also be the number of formulas (which in itself takes some parsing).
    I think that this (as well as, maybe, item 3) would warrant a "Process now" button to do a single rendering when the poster requests it, so that (s)he doesn't have to wait unnecessarily.

The way things are now, I type my longer posts in gvim, and then copy/paste them here. It's not ideal, but for me it is an acceptable workaround.

$\endgroup$
  • 2
    $\begingroup$ I perceive that MathJax performance has improved over the time since the Question was originally posed, but there are a lot of variables to try and account for. To me the speed is adequate for me, running Chrome on Windows 7 or a Linux platform. On Editing existing Answers, there is a Hide Preview option (fine print at left between the Answer box and the Preview window), so it might be simple to give that on initial Answers (although this place is now used for "draft saved" indiciations). $\endgroup$ – hardmath Nov 2 '13 at 17:18
  • $\begingroup$ I knew I saw it somewhere, but I couldn't remember where! Thank you. As for the speed, I had a hard time and I had to switch to gvim when I was writing this answer. Usually, it's not as much of a problem, but it would still be better if the site was more friendly towards slower computers. $\endgroup$ – Vedran Šego Nov 2 '13 at 18:46
  • $\begingroup$ Point 1 would probably be fairly simple to do - just cache the generated DOM object mapped from the TeX. The problem then is keeping memory usage under control. But this is probably something which doesn't help much in most contexts in which MathJax is used: I suspect that MSE is unusual in using it in a continuous edit mode. $\endgroup$ – Peter Taylor Nov 2 '13 at 23:27
  • 1
    $\begingroup$ @PeterTaylor MathJax actually has quite a decent support for rerendering. What I see as a problem in point 1 is how to determine what in the post to rerender. That would have to include some LaTeX parsing by the MSE before invoking MathJax renderer, because formulas don't go just in $...$ and $$...$$. Maybe rerendering just the edited paragraph would be sufficient, given that formulas cannot include empty lines. $\endgroup$ – Vedran Šego Nov 3 '13 at 2:07

Not the answer you're looking for? Browse other questions tagged .