Slack does not display rendered math. This script injects MathJax into Slack's desktop client, which allows you to write nice-looking inline- and display-style math using familiar TeX/LaTeX syntax. You can also edit equations after you've posted them.
Download your platform's script and run it. After restarting the Slack client, you're all done! (It takes up to 30 seconds for MathJax to load when Slack starts, so be patient.)
Run the following in a terminal:
curl -OL https://github.com/fsavje/math-with-slack/releases/download/r/math_with_slack.sh
sudo bash math_with_slack.sh
Download this script and doubleclick to run. Alternatively, run it in the command prompt with:
math_with_slack.bat
(You'll most likely get a security warning from Windows since the script was downloaded from Internet.)
When you update the Slack app, it might overwrite the code injected by the script. If the client stops rendering math after an update, re-run the script as above and it should work again.
If you've installed Slack in some exotic place, the script might not find the installation by itself and you need to specify the location of Slack's index.js
file as a parameter. E.g., like this on Mac and Linux:
sudo bash math_with_slack.sh /My_Apps/Slack.app/Contents/Resources/app.asar.unpacked/src/static/index.js
and like this on Windows:
math_with_slack.bat E:\My_Apps\slack\app-2.5.1\resources\app.asar.unpacked\src\static\index.js
As you do in TeX, use $ ... $
for inline math and $$ ... $$
for display-style math. If you need to write a lot of dollar-signs in a message and want to prevent rendering, use backslash to escape them: \$
.
Note that only users with MathJax injected in their client will see the rendered version of your math. Users with the standard client will see the equations just as you wrote them (i.e., unrendered including the dollar signs).
The script alters how Slack is loaded. Under the hood, the desktop client is based on ordinary web technology. The modified client loads the MathJax library after start-up and adds a listener for messages. As soon as it detects a new message, it looks for TeX-styled math and tries to render. Everything is done in the client; messages are never sent to any server for rendering.
Yes, please. Just add an issue or a pull request.
Thanks to past contributors:
References and inspiration
This comment by jouni was extremely helpful. So was this snippet by etihwnad.