Skip to content

YingzhouLi/math-with-slack

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rendered math (MathJax) with Slack's desktop client

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:

  • You can write both inline- and display-style equations.
  • You can edit equations after you've posted them.
  • Nothing is sent to external servers for rendering.

The downside is that equations are not rendered for team members without the MathJax injection.

Math Slack Example

How do I install it?

Get and run the script. Restart the Slack client. You're done!

Getting the script

In the following instructions, replace any {repo_name} in commands by the current GitHub username of this repo.

Mac and Linux

Run the following in a terminal:

curl -OL https://raw.githubusercontent.com/{repo_name}/math-with-slack/master/math-with-slack.py
sudo python math-with-slack.py

Windows

You need to exit your Slack before the installation. Then there are two ways to install math-with-slack on Windows.

  1. Ubuntu subsystem

    git clone https://github.com/{repo_name}/math-with-slack
    cd math-with-slack
    sudo python math-with-slack.py
  2. Windows PowerShell

    Download math-with-slack as a zip file and unzip it.

    cd path\to\math-with-slack
    python math-with-slack.py

If multiple versions of Slack are found on your computer, you will be asked to select one from them.

python math-with-slack.py
Several verisons of Slack were installed.
 0: /mnt/c/Users/***/AppData/Local/slack/app-4.9.0/resources/app.asar (default)
 1: /mnt/c/Users/***/AppData/Local/slack/app-4.8.0/resources/app.asar
Please select a version (#/Stop): 1

You can either enter the number indicating one of the listed versions or type Enter to select the first one.

Currently, we only support Slack installed from Slack installer. If your Slack is installed through Microsoft Store, math-with-slack is not able to modifiy files in WindowsApps folder hence not able to embedded our script.

Package and software managers

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.

MathJax versions and URLs

The default MathJax is of version 3.0.5 and downloaded from https://registry.npmjs.org/mathjax/-/mathjax-3.0.5.tgz, which is a registry of npmjs.

The script also works with other versions of MathJax 3 and we list a table of versions that we have tested and the corresponding URLs.

Version URLs File Size
3.0.5 https://registry.npmjs.org/mathjax/-/mathjax-3.0.5.tgz
https://r.cnpmjs.org/mathjax/-/mathjax-3.0.5.tgz
4.4 MB
3.0.4 https://registry.npmjs.org/mathjax/-/mathjax-3.0.4.tgz
https://r.cnpmjs.org/mathjax/-/mathjax-3.0.4.tgz
4.4 MB
3.0.1 https://registry.npmjs.org/mathjax/-/mathjax-3.0.1.tgz
https://r.cnpmjs.org/mathjax/-/mathjax-3.0.1.tgz
6.3 MB
3.0.0 https://registry.npmjs.org/mathjax/-/mathjax-3.0.0.tgz
https://r.cnpmjs.org/mathjax/-/mathjax-3.0.0.tgz
6.3 MB

Some URLs works better for certain areas. You can use any URL in the table to install math-with-slack.

cd path\to\math-with-slack
python math-with-slack.py --mathjax-url=https://r.cnpmjs.org/mathjax/-/mathjax-3.0.5.tgz

Uninstall

To uninstall, run the script again with the -u flag:

python math-with-slack.py -u

Updating Slack

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 Slack cannot be found

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 file as a parameter:

python math-with-slack.py --app-file=/My_Apps/Slack.app/Contents/Resources/app.asar
python math-with-slack.py --app-file=c:/Users/yourusername/AppData/Local/slack/app-4.7.0/resources/app.asar

How do I get my math rendered?

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).

How does it work?

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.

Can I contribute?

Yes, please. Just add an issue or a pull request.

Thanks to past contributors:

Inspiration

This comment by jouni was extremely helpful. So was this snippet by etihwnad.

About

Rendered math (MathJax) with Slack's desktop client

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%