I'm referring to the Slack website and not the Slack desktop program or phone application, as indicated by the slack tag. Stack Exchange Network Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
- I'm referring to the Slack website and not the Slack desktop program or phone application, as indicated by the slack tag. Stack Exchange Network Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
- Renders LaTeX math formulas in Slack. Similar to the Chrome extension math-with-slackb, except this plugin uses the KaTeX library instead of MathJax for better compatibility with the latest version of Slack.
Render Latex In Slack
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:
Writing Latex In Slack
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:
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 !
Latex In Slack
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 Send Code
If you liked this post, you can share it with your followers or follow me on Twitter!