Search code examples
rgithubmathjax

Mathjax support in github using a Chrome browser plugin?


I'd like Mathjax to work on all my github pages (e.g., Markdown displayed on github, issue trackers). I have a lot of files generated from R Markdown that also have equations.

While I'd love github to provide optional support for Mathjax, I thought a more realistic aim would be to have some browser plugin that detects that I'm on a github page and automatically runs the mathjax script.

  • Are there any browser plugins for the Chrome browser that automatically run a MathJaX script on specified URLs (e.g., http*github*)?

Initial thoughts

There's quite a long discussion on MathOverflow. However, the discussion includes discussion of a range of technologies (not just MathJax) and many of the solutions are specific to the Firefox browser.


Solution

  • Here is a GreaseMonkey script that should do what you want: Run MathJax in Github. It should work in all the major browser (though some need plugins to run GreaseMonkey scripts; see the installation instructions for this question for details).

    This script only loads MathJax on pages that contain TeX or MathML markup (it does a very simple test for that, which certainly could be made more sophisticated). Note that the default delimiters are \(...\) for in-line math and \[...\] or $$...$$ for displayed math. In particular, single-dollars aren't enable as math delimiters (since they occur too frequently in ordinary non-math text). If you wanted to enable single-dollar delimiters, you would need to edit the script to add a MathJax configuration script prior to loading MathJax.js itself.

    The script is set to trigger on http://github.com/* and https://github.com/*. Not all the GreaseMonkey implementations provide for pattern matching in the host part of the URL, but if yours does, you can make it more sophisticated so that it will get subdomains of github as well.

    Hope that does what you need.

    Edit: The script now enables $...$ for in-line math, as requested by the asker.