144
$\begingroup$

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)

$\endgroup$
8
  • 15
    $\begingroup$ 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. $\endgroup$ Nov 6, 2010 at 12:11
  • 17
    $\begingroup$ We were just now lamenting the lack of TeX support in chat. Would it be possible to reconsider this? $\endgroup$ May 11, 2011 at 19:26
  • 1
    $\begingroup$ 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. $\endgroup$
    – SBF
    Dec 2, 2011 at 9:36
  • 28
    $\begingroup$ 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... $\endgroup$ Dec 6, 2011 at 15:12
  • $\begingroup$ 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. $\endgroup$
    – kahen
    Oct 22, 2012 at 0:51
  • $\begingroup$ Corresp. feature request: Why is there no support for MathJax in chat? $\endgroup$
    – Grigory M
    Jul 16, 2014 at 13:30
  • $\begingroup$ There is a user script now; see here. (I tried to post this as an answer, but it was auto-converted. Huh.) $\endgroup$
    – Raphael
    Sep 19, 2015 at 16:41
  • $\begingroup$ Is or how is mathjax available for mobiles? $\endgroup$
    – draks ...
    Apr 11, 2017 at 17:04

5 Answers 5

133
$\begingroup$

There are four bookmarks which are located on this installation page:

  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.

To get the bookmarks mentioned above, go to this installation page.

There is a section at the bottom of the installation page to install ChatJax on a browser that cannot add bookmarks using drag-and-drop or a contextual menu. This is how I installed ChatJax on my iPhone.

If you are still having trouble installing on an iOS device, see this answer on Ask Different.


On April 30, 2017, the MathJax CDN will be shutting down.

The bookmarks listed above will need to be reinstalled. I have updated the bookmarks to use the CDN at cdnjs.cloudflare.com. Make sure you reload this installation page so that the new bookmarks are not hidden behind a stale cache.

$\endgroup$
27
  • 52
    $\begingroup$ I would nominate you to a Hacker badge if I could. $\endgroup$
    – Asaf Karagila Mod
    Dec 6, 2011 at 8:58
  • 22
    $\begingroup$ @Asaf: It's okay, I got a Necromancer badge for this answer. :-) $\endgroup$
    – robjohn Mod
    Dec 6, 2011 at 10:30
  • 1
    $\begingroup$ 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. $\endgroup$
    – Zhen Lin
    Dec 6, 2011 at 11:39
  • $\begingroup$ @ZhenLin: Thanks! I have added your automatic processing addition. $\endgroup$
    – robjohn Mod
    Dec 6, 2011 at 13:06
  • 1
    $\begingroup$ 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. $\endgroup$
    – robjohn Mod
    Jan 4, 2012 at 13:53
  • $\begingroup$ How persistent is the (Cloudfront) site hosting MathJax.js? $\endgroup$ Jan 5, 2012 at 10:20
  • $\begingroup$ @Willie: if you are asking about "d3eoax9i5htok0", this explains the weird domain name. $\endgroup$
    – robjohn Mod
    Jan 5, 2012 at 22:15
  • $\begingroup$ @robjohn: thanks. That's precisely what I was wondering about. BTW: thanks for the bookmark! $\endgroup$ Jan 6, 2012 at 9:04
  • 1
    $\begingroup$ Alert! Linux and Windows versions have different bookmarking with Google Chrome but the combo SHIFT+CTRL+B should show you the bookmark -bar. $\endgroup$
    – hhh
    Mar 20, 2012 at 7:54
  • 1
    $\begingroup$ @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. $\endgroup$
    – robjohn Mod
    Jun 6, 2012 at 17:09
  • $\begingroup$ For some odd reason, single $...$ -thing does not work in Twitter but the double $$...$$ -thing works, odd, investigating... $\endgroup$
    – hhh
    Sep 2, 2012 at 1:28
  • $\begingroup$ note to myself: click on Firefox bookmark whenever I enter math chat $\endgroup$ Mar 2, 2013 at 19:58
  • $\begingroup$ @Theta30 I bet some greasemonkeying could save you that click $\endgroup$ Mar 21, 2013 at 14:34
  • $\begingroup$ Does this only work for SE or any website? $\endgroup$
    – Meow
    Apr 6, 2013 at 21:40
  • $\begingroup$ 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. $\endgroup$
    – robjohn Mod
    Apr 7, 2013 at 3:31
17
$\begingroup$

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]);
    }

})();
$\endgroup$
12
$\begingroup$

There is ChatJax++ now, a user script that enables MathJax in SE chat in a smart way, i.e. it requires no user interaction and renders new messages automatically.

$\endgroup$
8
$\begingroup$

For those of us who struggle to get ChatJax running on an iPad, you need to fake it into a bookmarklet that you can copy and paste into the Safari URL line, then save as a bookmark. Make an .html file on your desktop that you will save, put in Dropbox, and open with Safari on your iPad.

That .html file should have a textbox in it that you can copy here (go into edit mode):

ChatJax Bookmarklet
COPY AND PASTE ROBJOHN'S SCRIPT HERE

$\endgroup$
1
  • $\begingroup$ We can no longer edit your answer to get the textbox because community Wiki answers cannot be edited. $\endgroup$
    – user400188
    May 19, 2020 at 7:36
6
$\begingroup$

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.

$\endgroup$

You must log in to answer this question.

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