OK, so chat is now available... but; it has been suggested that for Mathematics we should have TeX support.

The current TeX processing has some non-trivial client impact. Before I even attempt trying to hack this in, is this something that the community would want / use?

(this would only apply to maths rooms, and would presumably only apply to posts written with what is, for other sites, the fixed-font indent - i.e 4 spaces)

share
13  
Well first of all, there currently aren't that many users of that chat room. Unless more people show up to use it, $\TeX$-ing it up may well end up to be a waste of your time. –  J. M. Nov 6 '10 at 12:11
14  
We were just now lamenting the lack of TeX support in chat. Would it be possible to reconsider this? –  Glen Wheeler May 11 '11 at 19:26
1  
Half a year has passed after the comment by @Glen. If there are any news? Chat still seem to have a lack of TeX support. –  Ilya Dec 2 '11 at 9:36
19  
My old comment is now irremediably false, as there's now a bunch of us discussing math and a bunch of other stuff animatedly on chat... –  J. M. Dec 6 '11 at 15:12
    
Is there anyone who is enough of a coding wizard that can put things together into a working Greasemonkey script that continually re-TeXs the page? Having to click a bookmark is crazy when things like this script exist and don't require clicking anywhere for it to work. –  kahen Oct 22 '12 at 0:51
    
Corresp. feature request: Why is there no support for MathJax in chat? –  Grigory M Jul 16 at 13:30

4 Answers 4

I will leave the original post for historical reference, but as mentioned in the Update below, all four bookmarks are located on this installation page. There are four bookmarks:

  1. start ChatJax installs MathJax and starts a loop that renders $\LaTeX$ as needed. This is intended for use in chat, where the contents of the page are not static. Reloading the page will stop the loop, so the bookmark needs to be run again.

  2. render MathJax installs MathJax and renders $\LaTeX$ once per execution. This is intended for use on web pages where the contents of the page are static.

  3. rendering off disables MathJax while editing. This is useful when rendering is slow while editing questions and answers.

  4. rendering on enables MathJax after being disabled by rendering off.

If you are simply interested in getting the bookmarks mentioned above, there is no need to read further. Just go to this installation page.


Original Post

This bookmark processes the current page with MathJax. It has been modified from the bookmark on this page to handle $$...$$ and to handle \\[...\\] properly, to include AMS additions, and to update automatically.

The COPY TO CLIPBOARD link on pastebin.com should copy the bookmark to your clipboard. Simply create a bookmark or bookmarklet with the copied text as the "Location".

Once installed, activating the bookmark or bookmarklet (choosing it from a menu or clicking on its button) will render most $\LaTeX$ on the current page. Rendering is now automatic, so if new $\LaTeX$ appears on the chat page, the bookmark does not need to be activated again. If you are using the bookmark (not a Chrome extension), refreshing the page will lose the code, so the bookmark will need to be reactivated after refreshing.

The code below is the same as on pastebin.com:

javascript:(function(){if(window.MathJax===undefined){var%20script%20=%20document.createElement("script");script.type%20=%20"text/javascript";script.src%20=%20"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML";var%20config%20=%20'MathJax.Hub.Config({'%20+%20'extensions:%20["tex2jax.js"],'%20+%20'tex2jax:%20{%20inlineMath:%20[["$","$"],["\\\\\\\\\\\\(","\\\\\\\\\\\\)"]],%20displayMath:%20[["$$","$$"],["\\\\[","\\\\]"]],%20processEscapes:%20true%20},'%20+%20'jax:%20["input/TeX","output/HTML-CSS"]'%20+%20'});'%20+%20'MathJax.Hub.Startup.onload();';if%20(window.opera)%20{script.innerHTML%20=%20config}%20else%20{script.text%20=%20config}%20document.getElementsByTagName("head")[0].appendChild(script);}else{MathJax.Hub.Queue(["Typeset",MathJax.Hub]);}$('html').ajaxComplete(function(){MathJax.Hub.Queue(["Typeset",MathJax.Hub]);});})();

If all else fails try this alternate installation link.

Update:

I have modified the bookmark to make up for the change made to the chat that stopped the automatic update (an AjaxComplete() issue). There are now two bookmarks, one for static pages (render MathJax), and one for chat and other pages with non-static content (start ChatJax).

To consolidate things, I have put $\large\text{all versions here}$, including a pair of bookmarks to disable and re-enable MathJax rendering when the editing of questions and answers becomes slow (rendering off and rendering on).

share
35  
I would nominate you to a Hacker badge if I could. –  Asaf Karagila Dec 6 '11 at 8:58
13  
@Asaf: It's okay, I got a Necromancer badge for this answer. :-) –  robjohn Dec 6 '11 at 10:30
1  
To get automatic processing, register the code above as a callback to the global AJAX complete event: $('html').ajaxComplete(function() { ... }); Warning: this is just a hack and will cause MathJax to be reloaded on each use. –  Zhen Lin Dec 6 '11 at 11:39
    
@ZhenLin: Thanks! I have added your automatic processing addition. –  robjohn Dec 6 '11 at 13:06
1  
Here is how to handle the bookmark bar in Chrome. Create an empty bookmark, copy all of the text above starting with "javascript:(function(){if(window.MathJax'" into the destination for a bookmark in the bar. –  robjohn Jan 4 '12 at 13:53
    
How persistent is the (Cloudfront) site hosting MathJax.js? –  Willie Wong Jan 5 '12 at 10:20
    
@Willie: if you are asking about "d3eoax9i5htok0", this explains the weird domain name. –  robjohn Jan 5 '12 at 22:15
    
@robjohn: thanks. That's precisely what I was wondering about. BTW: thanks for the bookmark! –  Willie Wong Jan 6 '12 at 9:04
    
Alert! Linux and Windows versions have different bookmarking with Google Chrome but the combo SHIFT+CTRL+B should show you the bookmark -bar. –  hhh Mar 20 '12 at 7:54
1  
@Willie: the cloudfront.net url seems to be down, so I am switching to the mathjax.org url since that is what the main site uses. –  robjohn Jun 6 '12 at 17:09
    
For some odd reason, single $...$ -thing does not work in Twitter but the double $$...$$ -thing works, odd, investigating... –  hhh Sep 2 '12 at 1:28
    
note to myself: click on Firefox bookmark whenever I enter math chat –  Theta33 Mar 2 '13 at 19:58
    
@Theta30 I bet some greasemonkeying could save you that click –  Tobias Kienzler Mar 21 '13 at 14:34
    
Does this only work for SE or any website? –  Alyosha Apr 6 '13 at 21:40
    
The render MathJax and start ChatJax bookmarks will work on any website. The rendering off and rendering on bookmarks only work on websites that use MathJax. –  robjohn Apr 7 '13 at 3:31

yes please! That would be excellent!

share

Revision 3. This one actually has a working loop, and uses jQuery instead of directly injecting a script element.


Unfortunately, it seems that new chat messages no longer trigger the ajaxComplete event, so my hack has to be replaced with a different one. This one runs MathJax on a 1-second cycle.

Bookmarklet:

javascript:(function()%7Bif(window.MathJax===undefined)%7BjQuery.getScript(%22http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML%22,function()%7BMathJax.Hub.Config(%7B%22HTML-CSS%22:%7BpreferredFont:%22TeX%22,availableFonts:%5B%22STIX%22,%22TeX%22%5D,linebreaks:%7Bautomatic:true%7D,EqnChunk:MathJax.Hub.Browser.isMobile?10:50%7D,tex2jax:%7BinlineMath:%5B%5B%22$%22,%22$%22%5D,%5B%22%5C%5C%5C%5C(%22,%22%5C%5C%5C%5C)%22%5D%5D,displayMath:%5B%5B%22$$%22,%22$$%22%5D,%5B%22%5C%5C%5B%22,%22%5C%5C%5D%22%5D%5D,processEscapes:true,ignoreClass:%22tex2jax_ignore%7Cdno%22%7D,TeX:%7BnoUndefined:%7Battributes:%7Bmathcolor:%22red%22,mathbackground:%22#FFEEEE%22,mathsize:%2290%25%22%7D%7D%7D,messageStyle:%22none%22%7D);MathJax.Hub.Startup.onload();theLoop=function()%7BMathJax.Hub.Queue(%5B%22Typeset%22,MathJax.Hub%5D);window.setTimeout(theLoop,1e3)%7D;theLoop()%7D)%7Delse%7BMathJax.Hub.Queue(%5B%22Typeset%22,MathJax.Hub%5D)%7D%7D)()

Source code:

(function () {
    if (window.MathJax === undefined) {
        jQuery.getScript('http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML', function () {
            MathJax.Hub.Config({
                "HTML-CSS": {
                    preferredFont: "TeX",
                    availableFonts: ["STIX", "TeX"],
                    linebreaks: {
                        automatic: true
                    },
                    EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50)
                },
                tex2jax: {
                    inlineMath: [
                        ["$", "$"],
                        ["\\\\(", "\\\\)"]
                    ],
                    displayMath: [
                        ["$$", "$$"],
                        ["\\[", "\\]"]
                    ],
                    processEscapes: true,
                    ignoreClass: "tex2jax_ignore|dno"
                },
                TeX: {
                    noUndefined: {
                        attributes: {
                            mathcolor: "red",
                            mathbackground: "#FFEEEE",
                            mathsize: "90%"
                        }
                    }
                },
                messageStyle: "none"
            });

            MathJax.Hub.Startup.onload();

            theLoop = function () {
                MathJax.Hub.Queue(['Typeset', MathJax.Hub]);
                window.setTimeout(theLoop, 1000);
            };
            theLoop();
        });
    } else {
        MathJax.Hub.Queue(['Typeset', MathJax.Hub]);
    }

})();
share

With MathJax 2.x the way to load it dynamically has changed and the documentation says that one should use a new method.

It seems to me that it ought to be possible to turn this into a Greasemonkey script that runs automatically when receiving new input.

share

You must log in to answer this question.

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