Recently when writing/editing an answer, MathJax has at some point stopped rendering formulas and will only start rendering again if I refresh the page. I've had the problem for maybe a month now. Writing long answers is harrowing as I am afraid that I will lose the work when refreshing, and I do not want to submit before seeing the rendering. Do others have problems and could this be fixed? Things used to work well last year.

I'm running Google Chrome 48.0.2564.109 m in 64-bit Windows 10.

Screen capture Sample screen capture

The developer tools console gives this error at the moment things stop working:

Uncaught TypeError: Cannot read property 'insertBefore' of null

The code seems to have been crammed to a single line but if I click that link the cursor goes to:


I don't have a minimal example but if you copy-paste the following as a new question and write enough new text (100 letters or so, maybe with spaces and line changes) to the beginning or to the end, the error should be reproduced:

You can use logarithms to get rid of the division. For $(x, y)$ in the first quadrant:

$$z = \log_2(y)-\log_2(x)\\
\text{atan2}(y, x) = \text{atan}(y/x) = \text{atan}(2^z)$$

[Figure removed]

*Figure 1. Plot of $\text{atan}(2^z)$*

You would need to approximate $\text{atan}(2^z)$ in range $-30 < z < 30$ to get your required accuracy of 1E-9. You can take advantage of the symmetry $\text{atan}(2^{-z}) = \frac{\pi}{2}-\text{atan}(2^z)$. To approximate $\log_2(a)$:

$$b = \text{floor}(\log_2(a))\\
c = \frac{a}{2^b}\\ 
\log_2(a) = b + \log_2(c)$$

$b$ can be calculated by finding the location of the most significant non-zero bit. $c$ can be calculated by a bit shift. You would need to approximate $\log_2(c)$ in range $1 \le c < 2$.

[Figure removed]

*Figure 2. Plot of $\log_2(c)$*

For your accuracy requirements, linear interpolation and uniform sampling, $2^{14} + 1 = 16385$ samples of $\log_2(c)$ and $30\times 2^{12} + 1 = 122881$ samples of $\text{atan}(2^z)$ for $0 < z < 30$ should suffice. The latter table is pretty large. With it, the error due to interpolation depends greatly on $z$:

[Figure removed]

*Figure 3. $\text{atan}(2^z)$ approximation largest absolute error for different ranges of $z$ (horizontal axis) for a different number of samples (32 to 8192) per unit interval of $z$. The largest absolute error for $0 \le z < 1$ (omitted) is slightly less than for $\text{floor}(\log_2(z)) = 0$.* 

The $\text{atan}(2^z)$ table can be split into multiple subtables that correspond to $0 \le z < 1$ and different $\text{floor}(\log_2(z))$ with $z \ge 1$, which is easy to calculate. The subtable lengths can be chosen as guided by Fig. 3. The within-subtable index can be calculated by a simple bit string manipulation. For your accuracy requirements the $\text{atan}(2^z)$ subtables will have a total of 29217 unique samples if you extend the range of $z$ to $0 \le z < 32$ for simplicity.

The error due to linear interpolation can also be estimated analytically. In the limit of infinitely dense sampling the largest error is halfway between the samples:

$$\left|\hat f(x) - \right| \approx$$

It may be that the new text needs to be written fast enough for the error to occur. If I allow it to finish rendering the page between each keystroke, then there are no problems -- unless it stopped working already at pasting.

  • $\begingroup$ There have been similar reports on math.SE, e.g., meta.math.stackexchange.com/questions/22554/…. StackOverflow is aware of these but more reports will probably help. $\endgroup$ Feb 16 '16 at 11:03
  • $\begingroup$ @PeterKrautzberger I added instructions for reproducing the bug, and the resulting javascript console output. $\endgroup$ Feb 16 '16 at 14:36
  • $\begingroup$ Yes, that corresponds to the issues seen elsewhere. They are not caused by MathJax but by something overwriting it. $\endgroup$ Feb 16 '16 at 14:38
  • $\begingroup$ Nicely done, @OlliNiemitalo! Let's see if we can get this escalated. $\endgroup$
    – Peter K. Mod
    Feb 16 '16 at 15:04
  • $\begingroup$ Same browser & OS, still no repro, have been trying for 5 minutes now - i.stack.imgur.com/Y0eWa.png $\endgroup$
    – m0sa StaffMod
    Feb 22 '16 at 21:43
  • $\begingroup$ same error in this github issue: github.com/mathjax/MathJax/issues/1384 $\endgroup$
    – m0sa StaffMod
    Feb 22 '16 at 21:48
  • $\begingroup$ @m0sa Hmm I also could not reproduce it now using my instructions. But I finally got the error by pasting that thing multiple times in quick succession. $\endgroup$ Feb 22 '16 at 22:52
  • $\begingroup$ still no repro with quick pasting - i.stack.imgur.com/5doQO.png $\endgroup$
    – m0sa StaffMod
    Feb 22 '16 at 22:55
  • $\begingroup$ This is the same issue as on math.se. There are instructions there that reproduce the issue, and I'm looking into it. $\endgroup$ Feb 25 '16 at 17:23
  • $\begingroup$ One idea, if you slow down your computer's processor then maybe the bug will occur more often. I'm often running mine in a power save mode. $\endgroup$ Feb 25 '16 at 19:06
  • $\begingroup$ Just a note that I'm still having this problem. $\endgroup$ Mar 25 '16 at 17:33
  • $\begingroup$ See my post that includes a user-script that should resolve this issue until the editing code is updated. $\endgroup$ Apr 8 '16 at 23:32

I haven't had any problems for a long time so looks like this has been resolved. 🍻


You must log in to answer this question.

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