⚠️ ⚠️ This repo is not currently maintained, and the script will not work with Slack 4 or later versions. Please refer to this fork for a version that sees active development. ⚠️ ⚠️
Slack does not display rendered math. The
math-with-slack script allows you to write nice-looking math using familiar TeX syntax by injecting MathJax into Slack's desktop client. This approach has several advantages over the plugin/bot solution:
The downside is that equations are not rendered for team members without the MathJax injection.
Download and run your platform's script. Restart the Slack client. You're done!
Run the following in a terminal:
curl -OL https://github.com/fsavje/math-with-slack/releases/download/v0.2.5/math-with-slack.sh sudo bash math-with-slack.sh
Download the script and double-click to run. Alternatively, run it in the command prompt with:
(Windows will probably give you a security warning since the script is downloaded from Internet.)
The script needs write permissions in the Slack directory in order to inject the MathJax code. Some package and software managers write protect their directories, and
math-with-slack cannot be installed if Slack is installed through such a manager. This is the case for both the Windows Store and Snap versions of Slack. You should use the version downloaded from Slack's website if you want to use
math-with-slack. The script should, however, work with most package managers if you manage to grant the script write permission.
To uninstall, run the script again with the
sudo bash math-with-slack.sh -u
The code injected by the script might be overwritten when you update the Slack app. If your 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 or it might find the wrong installation. In such cases, you need to specify the location of Slack's
app.asar.unpacked/src/static folder as a parameter:
sudo bash math-with-slack.sh /My_Apps/Slack.app/Contents/Resources/app.asar.unpacked/src/static
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 servers for rendering.
Thanks to past contributors: