MathJax on Wikipedia/Reddit a guest Jun 2nd, 2013 188 Never a guest188Never

Not a member of Pastebin yet? Sign Up , it unlocks many cool features!

rawdownloadcloneembedreportprint JavaScript 2.32 KB // ==UserScript== // @name MathJax in Wikipedia and Reddit // @namespace http://www.mathjax.org/ // @description Insert MathJax into Wikipedia and Reddit pages // @include http://en.wikipedia.org/wiki/* // @include http://www.reddit.com/* // ==/UserScript== /* this is a slight modification of http://docs.mathjax.org/en/latest/_static/mathjax_wikipedia.user.js to work on Reddit pages */ var CDN_url = "https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full" ; if ( ( window. unsafeWindow == null ? window : unsafeWindow ) . MathJax == null ) { if ( document. location . href . indexOf ( 'wikipedia.org' ) != - 1 ) WikiImages ( ) ; if ( document. location . href . indexOf ( 'reddit.com' ) != - 1 ) uncode ( ) ; inlineConfig ( ) ; MathJax ( ) ; } // // Replace the images with MathJax scripts of type math/tex // function WikiImages ( ) { var images = document. getElementsByTagName ( 'img' ) , count = 0 ; for ( var i = images. length - 1 ; i >= 0 ; i -- ) { var img = images [ i ] ; if ( img. className === "tex" ) { var script = document. createElement ( "script" ) ; script. type = "math/tex" ; if ( window. opera ) { script. innerHTML = img. alt } else { script. text = img. alt } img. parentNode . replaceChild ( script , img ) ; count ++; } } return count ; } // // Unescape <code> surrounding TeX the World brackets [; ;] // function uncode ( ) { var code = document. getElementsByTagName ( "code" ) ; for ( var i = 0 ; i < code. length ; ) { var cd = code. item ( i ) ; if ( ! cd. innerHTML . match ( /\[;[\s\S]+;\]/ ) ) { ++ i ; continue ; } var span = document. createElement ( 'span' ) ; span. innerHTML = cd. innerHTML ; cd. parentNode . replaceChild ( span , cd ) ; } } function inlineConfig ( ) { var head = document. getElementsByTagName ( "head" ) [ 0 ] , script ; script = document. createElement ( "script" ) ; script. type = "text/x-mathjax-config" ; script [ ( window. opera ? "innerHTML" : "text" ) ] = "MathJax.Hub.Config({

" + " tex2jax: { inlineMath: [ ['[;',';]'], [' \\ \\ (',' \\ \\ )'] ]}

" + "});" head. appendChild ( script ) ; } function MathJax ( ) { var head = document. getElementsByTagName ( "head" ) [ 0 ] , script ; script = document. createElement ( "script" ) ; script. type = "text/javascript" ; script. src = CDN_url ; head. appendChild ( script ) ; }

RAW Paste Data

// ==UserScript== // @name MathJax in Wikipedia and Reddit // @namespace http://www.mathjax.org/ // @description Insert MathJax into Wikipedia and Reddit pages // @include http://en.wikipedia.org/wiki/* // @include http://www.reddit.com/* // ==/UserScript== /* this is a slight modification of http://docs.mathjax.org/en/latest/_static/mathjax_wikipedia.user.js to work on Reddit pages */ var CDN_url = "https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full"; if ((window.unsafeWindow == null ? window : unsafeWindow).MathJax == null) { if(document.location.href.indexOf('wikipedia.org') != -1) WikiImages(); if(document.location.href.indexOf('reddit.com') != -1) uncode(); inlineConfig(); MathJax(); } // // Replace the images with MathJax scripts of type math/tex // function WikiImages() { var images = document.getElementsByTagName('img'), count = 0; for (var i = images.length - 1; i >= 0; i--) { var img = images[i]; if (img.className === "tex") { var script = document.createElement("script"); script.type = "math/tex"; if (window.opera) {script.innerHTML = img.alt} else {script.text = img.alt} img.parentNode.replaceChild(script,img); count++; } } return count; } // // Unescape <code> surrounding TeX the World brackets [; ;] // function uncode() { var code = document.getElementsByTagName("code"); for (var i = 0; i < code.length; ) { var cd = code.item(i); if (!cd.innerHTML.match(/\[;[\s\S]+;\]/)) { ++i; continue; } var span = document.createElement('span'); span.innerHTML = cd.innerHTML; cd.parentNode.replaceChild(span,cd); } } function inlineConfig() { var head = document.getElementsByTagName("head")[0], script; script = document.createElement("script"); script.type = "text/x-mathjax-config"; script[(window.opera ? "innerHTML" : "text")] = "MathJax.Hub.Config({

" + " tex2jax: { inlineMath: [ ['[;',';]'], ['\\\\(','\\\\)'] ]}

" + "});" head.appendChild(script); } function MathJax() { var head = document.getElementsByTagName("head")[0], script; script = document.createElement("script"); script.type = "text/javascript"; script.src = CDN_url; head.appendChild(script); }