Photo by Antoine Dautry on Unsplash

Writing Math (LaTeX) Formulas in Medium

Matteo Capitani

--

Introduction

I have looked for an easy solution to publish mathematical formula on Medium. As I use Markdown (and Jupyter notebooks) for my daily work, it is natural for me to use a solution like Markdium that works smoothly for embedding code.

For mathematical equations, however, the solution is not that easy. For example, the following procedure will not lead to a rendered formula. As I am not a Mac user, also the recommendation in this Medium article are not relevant for me.

The way I considered rely on saving the images in SVG and converting the images in PNG (currently, Medium does not support SVG for images).

The procedure

As a first step, I downloaded and installed Visual Studio Code. While there are many other alternative Markdown editors, Visual Studio come with many useful plugins. Specifically, I installed the plugin Math to Image. From the Extension tabs in Visual Studio Code:

Installing the plugin in Visual Studio Code.

After that, in a tab with a Markdown file opened, to convert the formula into a SVG file a right click is all that is required:

Rendering the equation in a SVG file.

The file is saved in the folder (for my machine)

C:\Users\matteo\AppData\Local\Programs\Microsoft VS Code\svg

As Medium does not currently support SVG, I convert the image into PNG using inkscape. From a linux terminal (in my case, a WSL terminal) it is simply (using the Stackoverflow post here):

where xiD9cdtbVh.svgis the input and xiD9cdtbVh.png the output. Without any input parameter, the result of importing the image into Medium is the following:

--

--

Matteo Capitani

Data Scientist, Mathematician and Physicist by Education