Skip to content

Instantly share code, notes, and snippets.

@neighthan
Last active January 16, 2023 04:42
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save neighthan/756fbb4ce6ccc40b77cc4eeb13379fe4 to your computer and use it in GitHub Desktop.
Save neighthan/756fbb4ce6ccc40b77cc4eeb13379fe4 to your computer and use it in GitHub Desktop.
Tampermonkey User Script to add MathJax to, e.g., Trello
// ==UserScript==
// @name MathJax
// @namespace http://tampermonkey.net/
// @version 2.0
// @description Add Mathjax to webpages
// @author Nathan Hunt
// @match https://trello.com/*
// @grant none
// ==/UserScript==
// Note that github blocks this <.< I haven't found a viable workaround.
// See http://docs.mathjax.org/en/latest/web/configuration.html for
// instructions on loading mathjax and
// http://docs.mathjax.org/en/latest/advanced/typeset.html for
// instructions on using mathjax with dynamic webpages
(function() {
'use strict'
if (window.MathJax !== undefined) {
return
}
window.MathJax = {
tex: {
inlineMath: [['$', '$'], ['\\(', '\\)']]
},
svg: {
fontCache: 'global'
}
};
let script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js';
script.async = true;
document.head.appendChild(script);
// Run mathjax every second
(function typesetForever() {
window.setTimeout(typesetForever, 1000)
if (window.MathJax.typeset !== undefined) { // done loading
window.MathJax.typeset()
}
})()
})()
@NoRePercussions
Copy link

Someone I shared this with pointed out that this causes an infinite recursion, and something like the following would be more robust:

    function typesetNow() {
        if (window.MathJax.typeset !== undefined) { // done loading
            window.MathJax.typeset();
        }
    }
    window.setInterval(typesetNow, 1000);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment