Created
December 29, 2013 11:52
-
-
Save t1anchen/8169626 to your computer and use it in GitHub Desktop.
Display Mathjax expression (including LaTeX and MathML) in the trivial web page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name mathjax for douban | |
// @namespace [email protected] | |
// @author Changsheng Jiang<[email protected]> // 感谢原作者,并且我把math_jax_src改回原来的mathjax.org了 | |
// @include http://*.douban.com/* | |
// @description texify formula using mathjax | |
// @date 2011-07-12 | |
// @version 20110712 | |
// ==/UserScript== | |
(function() { | |
function check_init_mathjax() { | |
if (typeof MathJax == "undefined") { | |
// var math_jax_src = "http://img3.douban.com/static/book/math/MathJax.js?config=TeX-AMS-MML_HTMLorMML&delayStartupUntil=configured"; | |
var math_jax_src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML&delayStartupUntil=configured"; | |
var script = document.createElement("script"); | |
script.src = math_jax_src; | |
script.type = "text/javascript"; | |
script.addEventListener( | |
"load", | |
function() { | |
MathJax.Hub.Config( | |
{ | |
jax: ["input/TeX", "output/HTML-CSS"], | |
extensions: ["tex2jax.js","TeX/AMSmath.js","TeX/AMSsymbols.js", "TeX/noUndefined.js"], | |
tex2jax: { | |
inlineMath: [ ['$','$'], ["\\(","\\)"], ["[;", ";]"] ], | |
displayMath: [ ['$$','$$'], ["\\[","\\]"] ], | |
skipTags: ["script","noscript","style","textarea", "pre"], | |
ignoreClass: "tex2jax_ignore", | |
processEscapes: true, | |
processEnvironments: true, | |
preview: "TeX" | |
}, | |
showProcessingMessages: true | |
}); | |
MathJax.Hub.Configured(); | |
}, false); | |
document.body.appendChild(script); | |
} | |
} | |
var script = document.createElement("script"); | |
script.textContent = "(" + check_init_mathjax.toString() + ")();"; | |
document.body.appendChild(script); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is an easier way you could do all of this.
Simply interpret all alternate text for images as latex, which is how most websites with maths images do it.
You just have to make sure that if the alt text is not latex then the userscript understands that so it doesn't break the page.
Sadly, my scripting skills are not that good.