Latex In Slack



The latex is a sticky, milky and white colloid drawn off by making incisions in the bark and collecting the fluid in vessels in a process called 'tapping'. The latex then is refined into rubber that is ready for commercial processing. In major areas, latex is allowed to coagulate in the collection cup. Slack is an out-of-game platform for team communication. EVE University uses Slack for communication within each of the campuses, communities, and other teams. The various University campuses have channels set up in their respective slack applications for different purposes. Version 0.2 Toolbar actions: bold, italic, underline, align left, align center, align right; Color settings page; Sections folding; Version 0.1.1 Fixed syntax highlighting (better BNF and Flex rules). Restart Slack (quit and relaunch); refreshing no longer works; I contacted Slack support and was told to use ⌘+R to do a quick refresh and reset the mode from overwrite to insert. From Slack support team: Thanks for writing in about this! We've seen this occur on Mac computers recently as well, and the good news is there is an easy way to.

I just joined a new Slack workspace, and was growing weary of using the codecogs equation editor just to paste in an image of some latex math into Slack.
It took a bit of effort, but I thought I would document the process for anyone who is curious.

You need:
– Slack, obviously
– A Linux server, accessible from anywhere
– Familiarity with some command line

Slack insert code block

Writing Latex In Slack

I have a digital ocean droplet hosting this webpage, running Ubuntu 16.04.

Slack

First, SSH into your server.

Second, you will probably need an updated version of node.

Third, get mathslax ready.

Fourth, navigate to slack chat -> Workspace name -> Customize slack -> Apps -> Search for Slash Commands, install that integration.
Go to Custom Integrations -> Slash Commands ->Add Configuration
Enter some settings:

yourServerName should be your webpage name; e.g., mine is srmart.in

yourConfiguredPortNumber should be the port that the mathslax server will listen on. E.g., 7777

Slack math

Write down or copy the Token that is generated for you.

Fifth, in your SSH session or server, create a simple script for launching the mathslax server

Save that to /usr/local/bin/tex.sh, and mark as executable

Sixth, move mathslax to a location. I did not follow best practices; this should probably be in /opt, /usr/share, or some other directory, but whatever.

Slack math

Latex In Slack Definition

Finally, create a systemd services script, and place it in /etc/systemd/system/mathslax.service

Then:

You may need to enable the port in your firewall. If using UFW, then it’s simply sudo ufw allow yourConfiguredPortNumber

In slack, you can then type:

And get an image of those three aligned sampling statements.

Part two. The bot method.

On your server,

Create a file /usr/local/bin/texbot.sh with:

Create a file /etc/systemd/system/SlackLateX.service with:

Go to your slack chat workspace -> Apps -> Install Slack bots -> Add configuration:

Copy the API token, paste it into /usr/local/bin/SlackLateX/secret.txt

Then simply invite latexbot into the channel, and start the bot sudo systemctl start SlackLateX

Latex In Slack

Now you can type $pi$ to get a rendering of the pi symbol (or any other latex equation). This method improves upon the first method because it’s channel-specific, and you can edit latex code, which will re-render.

Implementing nice looking plots in a (LaTeX) document was harder than expected. I use R (through Rstudio) combined with ggplot2 (Grammar of Graphics plot) to plot my data and wanted a convenient way to insert my plots into Latex documents. I use something similar with Inkscape. It automatically sets the right font, properly writes Latex symbols and respects the proper font sizes.

The best solution I found is using the tikzDevice package for R and the tikz (available in the pgf package) package from LaTeX. TikZ plots will consist of vectors that will directly be coded into the LaTeX document so that there is no loss in image quality.First you need to install tikzDevice in R through install.packages('tikzDevice'). For the following example to work, you will also need to install ggplot2.Once you have both R packages, you can use this Rscript as an example:

The output provided by this script in R looks like this:

As you can see, the LaTeX codes are clearly visible. The font is R’s default font for now. If you check the folder where you sourced your file, you will find a test.tex file(you can check its content for this specific case by clicking on it) which contains the plot information as vectors. Every line, word or symbol is included as latex instructions in this .tex file.You should now create a .tex (any name will do) in the same folder your plot_test.tex file is in and use this simple LaTeX code to implement the image in it:

Latex In Slack

The result should look like this. As you can see, LaTeX symbols are now properly written, the font is also similar to the rest of the document and the plot can be inserted in your LaTeX document !

A problem you might still have: the font size of the plot title and axis legend and their positions.You can easily modify the sizes using the rel() function to scale the font size of each element. To modify the position of the axis legends or title plot, you can use the vjust and hjust parameters for vertical and horizontal positioning. R will not prepare your plot for the LaTeX font and sizes, so you will probably need to move the title and axis titles or they will probably touch the plot itsel at some point (visible in the previous LaTeX plot). To correct it, use something similar to this:

Slack Code Text

If you liked this post, you can share it with your followers or follow me on Twitter!