15
$\begingroup$

If there's any TeX formatting in comments of a post, after you add a comment to that post, or click "add / show n more comments", all formulae are reverted to $...$.

Steps to reproduce:

  1. Go to a post where there are formulae in the comments, e.g. Dot product in coordinates
  2. Click the "add / show 1 more comment" link, or add a comment.
  3. See that formula ($v \cdot w = |v| |w| \cos \theta$) is reverted to code i.e. $v \cdot w = |v| |w| \cos \theta$.
$\endgroup$
  • $\begingroup$ Reproduced on Safari 5 and Opera 10.6. $\endgroup$ – Larry Wang Aug 1 '10 at 17:16
  • $\begingroup$ (Problem still exists even with MathJax.) $\endgroup$ – kennytm Aug 3 '10 at 18:10
  • $\begingroup$ test 1: $\LaTeX$ $\endgroup$ – Larry Wang Aug 14 '10 at 17:40
  • $\begingroup$ test 2: plaintext only here $\endgroup$ – Larry Wang Aug 14 '10 at 17:41
  • $\begingroup$ test 3: $\LaTeX$ again $\endgroup$ – Larry Wang Aug 14 '10 at 17:43
  • $\begingroup$ new comment without TeX $\endgroup$ – Larry Wang Aug 14 '10 at 17:44
  • $\begingroup$ another $\LaTeX$ $\endgroup$ – T.. Aug 14 '10 at 18:49
  • $\begingroup$ on my browser this replicates the TeX-sensitivity of the bug in the form I had reported it: prior to adding [another LaTeX], with only K.H.'s [new comment without TeX], the Tex formatting was lost; after adding it, TeX formatting is retained or reprocessed, so no problem when clicking on "show more comments". $\endgroup$ – T.. Aug 14 '10 at 18:53
  • $\begingroup$ @T..: I can't reproduce it even with another $\LaTeX$ (Firefox 3.6.8, OS X). $\endgroup$ – kennytm Aug 14 '10 at 18:55
  • $\begingroup$ @Kenny: you get no bug at all, or no TeX-sensitive bug (for the test in these comments)? $\endgroup$ – T.. Aug 14 '10 at 18:57
  • $\begingroup$ @T..: I mean even with "another $\LaTeX$" I can only see the raw TeX code. $\endgroup$ – kennytm Aug 14 '10 at 18:59
  • $\begingroup$ I also get only the raw TeX code now, despite the LaTeX in the additional comments, and no matter what further comments are added. So there is some instability to this bug, at least on my system (Firefox 3.6.8, Mac OS X). $\endgroup$ – T.. Aug 14 '10 at 19:55
  • $\begingroup$ @T..: Can't reproduce with a fresh install of Firefox 3.6.8 on OSX 10.5.8. That is, comments always get de-TeXed. Are you still using John Gietzen's plugin? $\endgroup$ – Larry Wang Aug 14 '10 at 20:22
  • $\begingroup$ Test: $\mathbf{R}_{+}^{\times }$ for $\{x\in\mathbf{R}:x>0\}$ This is not properly displayed here, but it is OK in my profile's page. $\endgroup$ – Américo Tavares Aug 23 '10 at 21:58
  • 2
    $\begingroup$ Is anyone working on fixing this? $\endgroup$ – anon Sep 20 '10 at 15:04
4
$\begingroup$

. See Re-render MathJax in comments.


A workaround is to use the following userscript. (can some GM gurus see if it's possible to remove all those unsafeWindows?)

// ==UserScript==
// @name           Fix TeX related problems on math.SE
// @namespace      http://networkpx.googlecode.com
// @description    Fix TeX related problems on math.SE
// @include        https://math.meta.stackexchange.com/*
// @include        http://math.stackexchange.com/*
// ==/UserScript==

var rl = unsafeWindow.removeLoader;
unsafeWindow.removeLoader = function(){
    rl();
    unsafeWindow.styleCode();
}

There are 2 options to fix this problem.

Option 1:

  1. Edit "question.js".
  2. Find the "var n = function (r, q)" function, inside the comments object.
  3. Modify this function to:

    var p = h(r, " > table > tbody");
    if (p.children().length > 0) {
        p.children().remove()
    }
    p.append(q);
    d();
    o();
    if (typeof MathJax != "undefined")                // <--
        MathJax.Hub.Queue(["Typeset", MathJax.Hub]);  // <--
    removeLoader()
    

This should fully solve the problem (I haven't tested), but it requires changing a file that is shared by every site.

Option 2:

  1. Edit any Javascript file, e.g. "math-tex.js", after "master.js" is loaded.
  2. Add these lines of code:

    var rl = removeLoader;
    removeLoader = function(){
      rl();
      MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
    }
    

This relies on the loader is being removed when a comment is successfully added, fetched or edited. It is pretty hackish.

$\endgroup$
  • $\begingroup$ While it improves the experience of using the site, hiding problems using scripts like that just reduces the impetus to solve it properly, for everyone. $\endgroup$ – anon Sep 20 '10 at 15:05
  • $\begingroup$ @muad: Looking at the history of new features/bugfixes, I get a vague sense that the opposite is true - it seems to be easier to get something changed if you can provide the code to make it work, and the stackexchange folks need only implement it, rather than expecting them to come up with a solution from scratch. $\endgroup$ – Larry Wang Sep 21 '10 at 18:03
  • $\begingroup$ Awesome. Thanks for sharing the workaround! Although I am not a “GM guru”, I found a way to eliminate the use of unsafeWindow and posted it as a separate answer. $\endgroup$ – Tsuyoshi Ito Nov 11 '10 at 3:46
2
$\begingroup$

Here is a way to eliminate the need for unsafeWindow in KennyTM’s awesome workaround. I also added cstheory.stackexchange.com and the corresponding Meta.

// ==UserScript==
// @name           Fix TeX related problems on Stack Exchange sites
// @namespace      https://math.meta.stackexchange.com/questions/1114
// @description    Fix TeX related problems on Stack Exchange sites
// @include        https://math.stackexchange.com/*
// @include        https://math.meta.stackexchange.com/*
// @include        https://cstheory.stackexchange.com/*
// @include        http://meta.cstheory.stackexchange.com/*
// ==/UserScript==

var HTML_NS = 'http://www.w3.org/1999/xhtml';
var script = document.createElementNS(HTML_NS, 'script');
script.type = 'text/javascript';
script.appendChild(document.createTextNode(' \
    void function(){ \
        var rl = removeLoader; \
        removeLoader = function(){ \
            rl(); \
            styleCode(); \
        } \
    }(); \
'));
document.body.appendChild(script);

(Edit: I changed the value of @namespace because now I realized that if I use other people’s URL as @namespace, it defeats the purpose of namespaces.)

Tested on Firefox 3.6.12 with Greasemonkey 0.8.20100408.6. I used the following posts to test the functionality.

In principle, the same user script should work on other Stack Exchange websites using MathJax if you add the corresponding @include lines.

$\endgroup$
1
$\begingroup$

(reposting analysis of the bug from related but not exact duplicate question that was closed.)

Example here: Question Relating Gamma Function to Riemann Zeta function evaluated at integers (see comments under Robin Chapman's answer).

When the page is loaded, TeX is processed for an initial set of visible comments. When clicking on "show more comments" below the answer, the Tex processor is not invoked unless the additional comments contain TeX. Comments in the original visible set that contain TeX and that are shuffled when the full set of comments appear, will revert to non-graphical plain text (dollar signs, TeX code).

I experimented on this in the example by posting another comment with TeX code. In the presence of "more comments" that do contain TeX, the display of TeX in all comments was re-processed after the click and worked correctly. So there is apparently no run of the TeX processing (for the entire displayed page) when additional comments are displayed, unless TeX code is detected in those comments. But the TeX display can be disturbed if lower-ranked comments chronologically precede top-ranked comments containing TeX.

$\endgroup$
  • $\begingroup$ Are you saying you do not get this bug when (hidden comments contain only plaintext or when hidden comments are the most recent), or that you have not come across such situations? $\endgroup$ – Larry Wang Aug 13 '10 at 21:10
  • $\begingroup$ That's hard for me to answer, because on repeating the experiment I can't replicate the earlier results. Earlier, posting TeX in the comments (repeatably) prevented reversion to plaintext, but now it reverts to plaintext no matter whether the added comments are plain or TeXed. In the latter case the added TeX displays as plaintext. This is in Firefox running on Mac OS X, though the problem seems browser independent. $\endgroup$ – T.. Aug 14 '10 at 5:21
  • $\begingroup$ In that case, do you agree that it appears to be the same bug that KennyTM describes here? The only difference I could see based on your description would be if the situations I mentioned previously did not cause reversion to plaintext. $\endgroup$ – Larry Wang Aug 14 '10 at 16:53
  • $\begingroup$ I'm not sure why my agreement is relevant. I posted an analysis and some experimental data on what trigger(ed) the bug. As such it is new information and not subsumed in the original posting by KennyTM. That it was repeatable before and not now may indicate any number of things, such as SE making changes to the software. It does not indicate that there was no sensitivity to the presence of TeX in new comments, since as I mentioned, the earlier experiments showed that to be a factor, at least when viewed on my platform. $\endgroup$ – T.. Aug 14 '10 at 17:10

You must log in to answer this question.

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