Skip to content

Instantly share code, notes, and snippets.

@vyznev
Last active August 26, 2021 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vyznev/d0c338f0f9dbec43e313794299063b60 to your computer and use it in GitHub Desktop.
Save vyznev/d0c338f0f9dbec43e313794299063b60 to your computer and use it in GitHub Desktop.
User script to disable MathJax display math in comments on Stack Exchange sites
// ==UserScript==
// @name Disable display math in comments
// @namespace https://github.com/vyznev/
// @description Forces all MathJax elements in comments to be rendered inline
// @author Ilmari Karonen
// @version 1.1
// @match *://*.stackexchange.com/*
// @match *://*.mathoverflow.net/*
// @homepageURL http://meta.math.stackexchange.com/questions/23250/disable-display-math-in-comments
// @grant none
// @run-at document-start
// ==/UserScript==
var inject = function () {
MathJax.Hub.Register.MessageHook( "Begin Process", function (message) {
var elements = message[1];
var selector = '.comment script[type="math/tex; mode=display"]';
$(elements).find(selector).attr('type', 'math/tex');
} );
};
var script = document.createElement('script');
script.type = 'text/x-mathjax-config';
script.textContent = "(" + inject + ")();";
var parent = (document.head || document.documentElement);
if (parent) parent.appendChild(script);
else {
// work-around for https://github.com/greasemonkey/greasemonkey/issues/2996
var obs = new MutationObserver(function () {
var parent = (document.head || document.documentElement);
if (parent) { obs.disconnect(); parent.appendChild(script); }
});
obs.observe(document, {childList: true});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment