Skip to content

Instantly share code, notes, and snippets.

@jimmed
Last active January 23, 2018 13:34
Show Gist options
  • Save jimmed/287f62f3f2dcffa4615e4127612f1028 to your computer and use it in GitHub Desktop.
Save jimmed/287f62f3f2dcffa4615e4127612f1028 to your computer and use it in GitHub Desktop.

MathJax for Slack in Rambox

Instructions

  1. Fire up Rambox
  2. Switch to the Configuration tab (the first tab on the topbar in Rambox)
  3. In the Enabled Services section, find the Slack instance you want to add MathJax to, and click its settings cog.
  4. Expand the Advanced section at the bottom of the settings panel that pops up.
  5. Copy the contents of the script above, and paste it into the Custom Code text area.
  6. Save the settings and enjoy MathJaxiness
// math-with-slack $MWS_VERSION
// https://github.com/fsavje/math-with-slack
console.log('Installing Mathjax...');
var mathjax_config = document.createElement('script');
mathjax_config.type = 'text/x-mathjax-config';
mathjax_config.text = `
MathJax.Hub.Config({
messageStyle: 'none',
extensions: ['tex2jax.js'],
jax: ['input/TeX', 'output/HTML-CSS'],
tex2jax: {
displayMath: [['$$', '$$']],
element: 'msgs_div',
ignoreClass: 'ql-editor',
inlineMath: [['$', '$']],
processEscapes: true,
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
},
TeX: {
extensions: ['AMSmath.js', 'AMSsymbols.js', 'noErrors.js', 'noUndefined.js']
}
});
`;
var mathjax_script = document.createElement('script');
mathjax_script.type = 'text/javascript';
mathjax_script.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js';
document.head.appendChild(mathjax_config);
document.head.appendChild(mathjax_script);
var target = document.querySelector('#messages_container');
var options = { attributes: false, childList: true, characterData: true, subtree: true };
var observer = new MutationObserver(function (r, o) { MathJax.Hub.Queue(['Typeset', MathJax.Hub]); });
observer.observe(target, options);
console.log('MathJax setup complete');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment