Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GreaseMonkey script for rendering ChatJax automatically on stackexchange.com chat sites (like Physics or Math)
// ==UserScript==
// @name ChatJax
// @namespace http://stackexchange.com/
// @description Rendering ChatJax
// @include http://chat.stackexchange.com/*
// @author Bass
// @license Beerware
// @version 1
// @grant GM_addStyle
// ==/UserScript==
function main() {
window.doChatJax = function () {
window.setTimeout(doChatJax, 2000);
window.MathJax.Hub.Queue(['Typeset',window.MathJax.Hub]);
};
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_HTML';
var config = 'MathJax.Hub.Config({' + 'extensions: ["tex2jax.js"],' + 'tex2jax: { inlineMath: [["$","$"],["\\\\\\\\\\\\(","\\\\\\\\\\\\)"]], displayMath: [["$$","$$"],["\\\\[","\\\\]"]], processEscapes: true },' + 'jax: ["input/TeX","output/HTML-CSS"]' + '});' + 'MathJax.Hub.Startup.onload();';
if (window.opera) {
script.innerHTML = config
} else {
script.text = config
}
document.getElementsByTagName('head') [0].appendChild(script);
window.setTimeout(doChatJax, 500);
}
};
var script = document.createElement('script');
script.appendChild(document.createTextNode('('+ main +')();'));
(document.body || document.head || document.documentElement).appendChild(script);
@bassup

This comment has been minimized.

Copy link
Owner Author

commented Jan 12, 2016

How to install:

  • If you don't have it yet, you need the GreaseMonkey extension for Firefox or TamperMonkey for Chrome. IE users have to try Trixie, and for Safari users there's GreaseKit, but I don't know if this script works in IE or Safari.
  • On the github website, click on the "Raw" button above the code.
  • After a browser restart you should see MathJax rendered automatically. If it doesn't work, write a message to @bass in the PSE chat.
@diazona

This comment has been minimized.

Copy link

commented Jan 12, 2016

I think if you give it a name ending in .user.js, it will be possible to automatically install it by just clicking on "Raw"

@bassup

This comment has been minimized.

Copy link
Owner Author

commented Jan 12, 2016

Cool, didn't know that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.