19
$\begingroup$

Last updated: 9 May 2017

This is an offshoot of ChatJax, which enables MathJax along with mhchem on chat.

In order to enable MathJax in chat, please follow the following instructions (courtesy of mhchem's answer below):

  1. Copy this code into your clipboard
    javascript:(function(){if(window.MathJax===undefined){var script=document.createElement("script");script.type="text/javascript";script.src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML";var config='MathJax.Ajax.config.path["mhchem"]="https://cdnjs.cloudflare.com/ajax/libs/mathjax-mhchem/3.2.0";MathJax.Hub.Config({extensions: ["tex2jax.js"],tex2jax:{inlineMath:[["$","$"],["\\\\\\\\\\\\(","\\\\\\\\\\\\)"]],displayMath:[["$$","$$"],["\\\\[","\\\\]"]],processEscapes:true},TeX:{extensions:["[mhchem]/mhchem.js","cancel.js"]},jax:["input/TeX","output/HTML-CSS"]});MathJax.Hub.Startup.onload();';if(window.opera){script.innerHTML=config}else{script.text=config}document.getElementsByTagName("head")[0].appendChild(script);window.setInterval(function(){MathJax.Hub.Queue(["Typeset",MathJax.Hub]);},1000);}else{MathJax.Hub.Queue(["Typeset",MathJax.Hub]);}})();
  1. Create a bookmark with this (Chrome: Menu > Bookmarks > Bookmark manager > right click > Add page > ...)
  2. Whenever you are on a chat page, click the bookmark.
$\endgroup$
  • 1
    $\begingroup$ I'll just add a link to the post Should chat have TeX support? from meta.math.SE, where several other similar bookmarklets/scripts are linked. $\endgroup$ – Martin Jun 29 '14 at 7:57
  • $\begingroup$ Does this work on Android? $\endgroup$ – Pritt Balagopal Jun 1 '17 at 4:13
10
$\begingroup$

Update 2017-05-01

The MathJax CDN retired and the javascript-URL idea is not so easy any more, because of browser security. (Chrome stips away any leading javascript: when pasting into the URL line. SE modified the javascript: link so that it does not work.)

So here is my take. I modified the script to load the new mhchem (v3), together with cancel (and shortened the URL a little bit).

One-time usage

  1. Copy code to clipboard

    (function(){if(window.MathJax===undefined){var script=document.createElement("script");script.type="text/javascript";script.src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML";var config='MathJax.Ajax.config.path["mhchem"]="https://cdnjs.cloudflare.com/ajax/libs/mathjax-mhchem/3.2.0";MathJax.Hub.Config({extensions: ["tex2jax.js"],tex2jax:{inlineMath:[["$","$"],["\\\\\\\\\\\\(","\\\\\\\\\\\\)"]],displayMath:[["$$","$$"],["\\\\[","\\\\]"]],processEscapes:true},TeX:{extensions:["[mhchem]/mhchem.js","cancel.js"]},jax:["input/TeX","output/HTML-CSS"]});MathJax.Hub.Startup.onload();';if(window.opera){script.innerHTML=config}else{script.text=config}document.getElementsByTagName("head")[0].appendChild(script);window.setInterval(function(){MathJax.Hub.Queue(["Typeset",MathJax.Hub]);},1000);}else{MathJax.Hub.Queue(["Typeset",MathJax.Hub]);}})();
    
  2. On chat page, open dev tools (F12 on most browsers)

  3. Paste code in console and press ENTER

Use several times

  1. Copy this code into your clipboard

    javascript:(function(){if(window.MathJax===undefined){var script=document.createElement("script");script.type="text/javascript";script.src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS_HTML";var config='MathJax.Ajax.config.path["mhchem"]="https://cdnjs.cloudflare.com/ajax/libs/mathjax-mhchem/3.2.0";MathJax.Hub.Config({extensions: ["tex2jax.js"],tex2jax:{inlineMath:[["$","$"],["\\\\\\\\\\\\(","\\\\\\\\\\\\)"]],displayMath:[["$$","$$"],["\\\\[","\\\\]"]],processEscapes:true},TeX:{extensions:["[mhchem]/mhchem.js","cancel.js"]},jax:["input/TeX","output/HTML-CSS"]});MathJax.Hub.Startup.onload();';if(window.opera){script.innerHTML=config}else{script.text=config}document.getElementsByTagName("head")[0].appendChild(script);window.setInterval(function(){MathJax.Hub.Queue(["Typeset",MathJax.Hub]);},1000);}else{MathJax.Hub.Queue(["Typeset",MathJax.Hub]);}})();
    
  2. Create a bookmark with this (Chrome: Menu > Bookmarks > Bookmark manager > right click > Add page > ...)

  3. Whenever you are on a chat page, click the bookmark.
$\endgroup$
  • $\begingroup$ Hi, thanks for your answer! I tried your "one-time usage" snippet, as you've written, but it didn't work in the "Periodic Table" chatroom. I mean to say it did format the mathjax immediately (on pressing Enter), but then on refreshing the page, that formatting disappeared. Is that the intended behavior or is there a bug? Thanks! $\endgroup$ – Gaurang Tandon Feb 15 '18 at 3:47
  • $\begingroup$ That is what I would expect. "One-time" means "works just for this page until you go somewhere else or reload". $\endgroup$ – mhchem Feb 15 '18 at 14:41
  • $\begingroup$ Ah, I actually understood it to mean, "use for one time, and then enjoy the results forever" sorry! :P $\endgroup$ – Gaurang Tandon Feb 15 '18 at 14:42
  • $\begingroup$ Does this work for mobile browsers? $\endgroup$ – Avnish Kabaj Mar 8 '18 at 4:33
  • $\begingroup$ The 2nd version is a so called "bookmarklet". On some mobile browsers, you cannot even create them. In Chrome on Android, for instance, you cannot create them, but you can use them if you share your bookmarks across devices. $\endgroup$ – mhchem Mar 9 '18 at 13:52
8
$\begingroup$

Based on the same principle, this little bookmarklet loads cancel in addition to mhchem:

javascript:(function(){if(window.MathJax===undefined){var%20script%20=%20document.createElement(%22script%22);script.type%20=%20%22text/javascript%22;script.src%20=%20%22http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML%22;var%20config%20=%20%27MathJax.Hub.Config({%27%20+%20%27extensions:%20[%22tex2jax.js%22],%27%20+%20%27tex2jax:%20{%20inlineMath:%20[[%22$%22,%22$%22],[%22\\\\\\\\\\\\(%22,%22\\\\\\\\\\\\)%22]],%20displayMath:%20[[%22$$%22,%22$$%22],[%22\\\\[%22,%22\\\\]%22]],%20processEscapes:%20true%20},%27%20+%20%27TeX:%20{%20extensions:%20[%22mhchem.js%22,%22cancel.js%22]%20},%27%20+%20%27jax:%20[%22input/TeX%22,%22output/HTML-CSS%22]%27%20+%20%27});%27%20+%20%27MathJax.Hub.Startup.onload();%27;if%20(window.opera)%20{script.innerHTML%20=%20config}%20else%20{script.text%20=%20config}%20document.getElementsByTagName(%22head%22)[0].appendChild(script);(doChatJax=function(){window.setTimeout(doChatJax,1000);MathJax.Hub.Queue([%22Typeset%22,MathJax.Hub]);})();}else{MathJax.Hub.Queue([%22Typeset%22,MathJax.Hub]);}})();

Start ChatJax with mhchem and cancel

(This also switches to the MathJax distributed network service, http://cdn.mathjax.org/mathjax/latest/MathJax.js)


$\endgroup$
  • $\begingroup$ doesn't work for me for some unknown reason. $\endgroup$ – gannex Jan 13 '17 at 18:43
  • $\begingroup$ If you have time, it would be helpful to update this to the newest MathJax CDN (this one is sadly dead now), but it's not really urgent, since mhchem has posted a working bookmarklet already. $\endgroup$ – orthocresol May 9 '17 at 20:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .