# Why is there no support for MathJax in chat?

The question Should chat have TeX support was first asked 3½ years ago, and it has been asked at intervals since then. I am not asking that question. I know that chat should have TeX support and so does everyone else. My questions are, why hasn't this been done and when will it be done? The lack of MathJax support in chat is a serious problem with the site, and it should be fixed as soon as possible, preferably today.

I am aware of the existing solutions such as greasemonkey scripts. I use them myself. They do not solve the problem because while they allow one to receive formatted mathematics, they don't allow one to send it, unless the recipient also has a script installed. But in general I can't expect the person I am talking to will have one installed. Then I think I am sending “No, you need to consider $\int_0^\infty \def\O{\mathcal O} \O\left(\operatorname{erf}(\frac x2)\right)\;dx$” but the hapless loser I am trying to help only sees “No, you need to consider \int_0^\infty \def\O{\mathcal O} \O\left(\operatorname{erf}(\frac x2)\right)\;dx”.

When a discussion goes on in comments, SE posts a notice telling the people involved to take the discussion to chat:

That sounds great at first, but it is completely unhelpful, because if the discussion is taken to chat, you will no longer be able to actually discuss mathematics. And the prior discussion, imported automatically, will look like this to the person you are trying to help:

It seems to me completely obvious that this feature is crucial, and its lack should have been addressed years ago, and yet it has not been. So I repeat: What is causing the delay on this? When will this be fixed? And if it's been decided for some reason that it will never happen, then what is going to be done instead? What's the point of having chat at all, when it doesn't work? The purpose of the site is to ask and answer questions about mathematics, and the only purpose of chat is to support that. Other features of the site assume that it will. But in its present form, it does not and it cannot.

• You're kidding right? There is TeX support, ChatJAX, provided by robjohn. It is as simple as pasting a button to the toolbar and clicking it to render the code.
– Pedro Mod
Jun 17, 2014 at 17:35
• @PedroTamaroff Do you think you could read as far as paragraph 2 before you post ill-considered comments? I have such a button in my toolbar, and I click it when necessary, but I can't paste it into the toolbar of the person I am talking to, or click it to render my code for them, which is what is really needed.
– MJD
Jun 17, 2014 at 17:37
• I think the current method of using a user script is the worst of both worlds, new users in chat only see TeX source which looks rather ugly, and anyone actually using the chat will still have to pay the performance penalty of MathJax. I'm also pretty sure that there is currently no plan by SE to implement this, so I'd suggest that one of the Math mods points an SE community team member to this post once clear community support is evident.
– user9733
Jun 17, 2014 at 17:49
• Back in my chat days, the channel was small enough for it to be a nice temporary solution, and there weren't many rooms for this to be a problem. I don't know how large the main chatroom is, but it seems that there are more rooms, in particular due to the "automatic chat" feature. So I agree this can no longer constitute as a proper solution.
– Asaf Karagila Mod
Jun 17, 2014 at 18:33
• @rob: I know very well that ChatJax works in every chatroom, in fact in any webpage (and I have used that fact before). But my point was exactly that not everyone is aware of that script and how to use it.
– Asaf Karagila Mod
Jun 17, 2014 at 19:42
• @robjohn I'd guess that enabling MathJax on the whole SE chat won't ever happen. But if it is technically possible, I think enabling it only for certain rooms, or all rooms associated with certain sites, could be possible.
– user9733
Jun 17, 2014 at 19:47
• @MJD: Wouldn't this be more a feature-request than a bug?
– robjohn Mod
Jun 17, 2014 at 20:02
• @robjohn IMHO, it is a bug when the system suggest something (moving discussion to chat) that didn't work. Jun 17, 2014 at 20:09
• @robjohn I think I stated my reasons for why this is a bug, but I will try to make them clearer. This web site has exactly one purpose, which is to provide a platform for asking and answering questions about mathematics. Every feature of the site is intended to advance that purpose. The chat system was added so that querents and respondents could discuss the questions and answers that are about mathematics. But it cannot be used effectively for this without both users installing additional software in their browsers. Therefore, it is not fulfilling its sole purpose, and that is a bug.
– MJD
Jun 17, 2014 at 20:21
• The ability to enable MathJax in chat literally does not exist right now (as far as I'm aware). I'm coming down on the side of "feature request" here.
Jun 18, 2014 at 0:17
• I find it especially odd that nothing was done as the person asking the question seemed to be asking from a vaguely official position. As in, it was almost StackExchange itself asking the question! Jun 18, 2014 at 10:14
• Performance doesn't matter if the software is completely unable to perform its core function. It doesn't matter how efficiently Math SE Chat can be used to discuss the weather or the World Cup, because this site is not about those subjects. It can't be used to discuss mathematics, so it is not performing its core function, and any efficiency gained thereby is wasted.
– MJD
Jun 18, 2014 at 11:57
• @user1729PhD: Anna only edited. The original post was by MJD. Jun 18, 2014 at 13:29
• @MadScientist My guess is that you're right, and the math chat room would have to be distinguished from other chats if it were to automatically load MathJax, as after all this wouldn't be useful in most (any?) other SE chat rooms. Still, maybe we could get the ChatJax script integrated into the sidebar as a button or preference, so that users could elect to turn it on and off as they choose. This would be more newbie-friendly than the current solution.
– Alexander Gruber Mod
Jun 19, 2014 at 5:00
• @PedroTamaroff I have been using the chat system for 2 years and I didn't know about the MathJax script. I thought people were just copying and pasting it into forms to see the rendered output. There should at the very minimum be a notice put on the page about enabling this MathJax script. Preferably, MathJax should be supported by default on the chatrooms of SE sites that require it such as this one. Jul 29, 2014 at 15:12

I don't really relish being the bearer of bad news, but here's a recent answer by Shog9 on Meta Stack Exchange:

This request was discussed by the team on April 9th, 2014. The potential rendering cost would be such that it would need to be a per-room and per-user option; this would then create a situation where users would potentially never be sure how their messages would look to other readers - in other words, little better than the user-script solution currently available.

• Well, just like the solution for the site itself is simple - On for all users, one should do it in Chat Room as well. Otherwise no one would move comments to Chat Room.
– Royi
Mar 14, 2018 at 20:49

I can offer the following piece of information about trying to tweak chatjax to work on the chat page.

Usually sites enable Mathjax by using javascript in their global header, so having specific options for certain pages doesn't work well with this configuration.

That is, trying to have chatjax work as specific option on the chat page would probably conflict with the global header.

My hypothesis on the delay would be trying to figure out how to have page specific options in Mathjax not conflict with the global configuration. I don't know the inner workings of the site but that is my guess.

• The MathJax script config options are injected on each page, so there's no technical reason why we couldn't have MathJax support only in some chat rooms and not in others. A natural choice would be to only enable it in chat rooms that are associated with SE sites that use MathJax on the site. Dec 15, 2014 at 15:39

If you are using firefox like me, then using this script on Greasemonkey add-on may fix the issue perfectly. To install this script just click on "New user script" in the add-on then copy and paste this as it is.

// ==UserScript==
// @name     Unnamed Script 781864
// @version  1
// @grant    none
// ==/UserScript==

var stop = false;
var update = true;

if(window.MathJax === undefined)
{
var script = document.createElement("script");
script.type="text/javascript";
script.src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
var config='MathJax.Hub.Config({"HTML-CSS": { ' +
'webFont: "TeX", ' +
'preferredFont: "TeX", ' +
'availableFonts: ["STIX","TeX"], ' +
'linebreaks: { automatic:true }, '+
'EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50) }, ' +
'tex2jax: { inlineMath: [ ["$$", "$$"] ], displayMath: [ ["$$","$$"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno|last-message" }, ' +
'TeX: { extensions: ["mhchem.js", "enclose.js", "cancel.js"], noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%25" } } }, ' +
'messageStyle: "none"}); ' +

if(window.opera) {
script.innerHTML = config;
} else {
script.text = config;
}

$$('#chat-buttons').prepend('');$$('#math-button').click(function() {
('body').append('<div id="jax-popup-bg" class="wmd-prompt-background" style="position: fixed; top: 0px; z-index: 1000; opacity: 0.5; left: 0px; width: 100%; height: 100%;"></div>' + '<div id="jax-popup" style="top: 50%; left: 50%; display: block; padding: 10px; position: fixed; width: 150px; z-index: 1001; margin-top: -93.5px; margin-left: -113px;" class="wmd-prompt-dialog">' + '<div align="center">' + '<b>MathJax</b><br>' + 'Interval:' + '<input type="text" id="jax-heartbeat" style="width: 80px; margin-left: 10px" title="In miliseconds" value="' + beatInterval + '"/><br>' + '<input type="checkbox" id="jax-update" title="Use an ajax handler instead of a heartbeat">Update</input>' + '<input type="checkbox" id="jax-disable" style="margin-left: 10px" title="Temporarily stops MathJax from updating">Disable</input>' + '</div>' + '<button id="jax-ok" class="button">Ok</button>' + '<button id="jax-cancel" style="margin-left: 10px" class="button">Cancel</button>' + '<script type="text/javascript">' + '$$("#jax-update").prop("checked", update);' + '$$("#jax-disable").prop("checked", stop);' + '$$("#jax-heartbeat").prop("disabled", !update || stop);' + '$$("#jax-update").prop("disabled", stop);' + '$$("#jax-ok").click(function() {' + 'if(.isNumeric(("#jax-heartbeat").val()) && parseInt(("#jax-heartbeat").val()) >= 1000) {' + 'if(("#jax-update").prop("checked") && !("#jax-disable").prop("checked")) {' + 'beatInterval = parseInt($$("#jax-heartbeat").val());' + '}' + 'if(!$$("#jax-disable").prop("checked")) {' + 'update =$$("#jax-update").prop("checked");' + '}' + 'stop = $$("#jax-disable").prop("checked");' + '$$("#jax-popup").remove();' + '("#jax-popup-bg").remove();' +
'} else {' +
'alert("Values must be numeric and no less than 1000");' +
'}' +
'});' +

'$$("#jax-cancel").click(function() {' + '("#jax-popup").remove();' + '$$("#jax-popup-bg").remove();' +
'});' +

'$$("#jax-update").click(function() {' + '("#jax-heartbeat").prop("disabled", !$$("#jax-update").prop("checked"));' +
'});' +

'$$("#jax-disable").click(function() {' + '("#jax-heartbeat").prop("disabled", ("#jax-disable").prop("checked"));' + '("#jax-update").prop("disabled",$$("#jax-disable").prop("checked"));' +
'});' +
'</script>' +
'</div>');
});
} else {
if(window.MathJax !== undefined)
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}

$('document').ready(function() { beat(); });$('html').ajaxComplete(function() {
if(!update && !stop)
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
});

var beatInterval = 5000;
function beat() {
setTimeout(function() {
if(window.MathJax !== undefined)
{
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);

$$.each($$('script[type="math/tex"]'), function(index, value) {
if ($$(value).parent().data('events') === undefined) { (value).parent().click(function() { if ((value).parent().html().split((value).html() || []).length - 1 === 1) { (value).parent().append(' \\' + (value).html() + '\\$$');
}
});
}
});
}

if(update && !stop)
beat();

}, beatInterval);
};
$$$$
`