Writing Mathematics on Medium

Cihan Soylu
2 min readJul 11, 2019

--

Photo by Antoine Dautry on Unsplash

Recently I have struggled with writing an article on Medium that has lots of mathematical equations and symbols. I came up with two methods which may make things a little bit easier. Depending on the amount of equations you have in your article you can do two things:

1- Turn the whole article into png images and embed into Medium.

2- Create a png image for each equation in your article and embed them in between the text on Medium.

The steps for these two methods are very similar. The differences are pointed out in each step.

Note: I have tried the following on MacOS. Some of the steps may require adjustment on a different operating system.

Step 1: For the first method, simply type your article in latex and create a pdf version of your article. For the second method, type each equation in your article in latex such that each equation is in a separate page in the resulting pdf. You need to get rid of the page numbers for the step 2. So use \pagenumbering{gobble} on your latex file.

Step 2: Crop the pdf using pdfcrop. First open the terminal and go to the directory containing the pdf file. Then run the following command.

pdfcrop filename.pdf

Replace filename with your file name. This command will create a new pdf file named filename-crop.pdf. This is the cropped version of the original pdf.

Step 3: Convert the cropped pdf file into png format using the `convert` command from ImageMagick. Convert command comes with various command line options. For details see the documentation.

 convert -density 600 -quality 95 filename-crop.pdf filename.png

This command will create a png file for each page in the cropped pdf file. For example, if the pdf file has 3 pages, then the following png files will be created in the same directory:

filename-0.png
filename-1.png
filename-2.png

Depending on the options you provided and the number of pages, this may take a while.

Step 4: Add these png files on Medium as if you are adding any other image. If you are using the first method, you simply add all the images in the right order. If you are using the second method, then start writing your article on Medium editor and embed the equations as images when you need them.

The biggest downside of first method is that the text will be embedded in images and so can not be highlighted.

The problem with the second method is typing the symbols within the text. For this the easiest way is to use chrome with tex-to-unicode extension. This will let you type most standard math symbols.

Here is an example article using the first method.

Hope this was helpful.

--

--

Cihan Soylu

Interested in all things machine learning and mathematics.