# How to export an equation as an image without background?

For example, if we have a equation on a file like:

\documentclass[12pt]{standalone}
\usepackage{varwidth}

\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{amsmath, amssymb, graphics, setspace}
\newcommand{\mathsym}[1]{{}}
\newcommand{\unicode}[1]{{}}
\newcounter{mathematicapage}

\begin{document}
\begin{varwidth}{50in}
\begin{equation*}
P\left(H_h|E_e\right)=\frac{P\left(E_e|H_h\right)P\left(H_h\right)}{P\left(E_e\right)}
\end{equation*}
\end{varwidth}
\end{document}


How export it as a png image, without background? (Just the equation, without white background).

(I'd like a full comand to do this, compiling the .tex file and getting a png image as output)

I need this to generate equation images to a presentation.

• A Suggestion: You migth want to prepare your presentation using beamer package and save yourself from the hassle :) Nov 21, 2011 at 22:15
• @percusse Unfortunally I need to use MSOffice apps to do this presentation. I'd like to learn beamer but now I can't. My advisor would like a MSOffice presentation =/ so I'm searching for a solution using equations without background...Anyway thanks about the suggestion. Nov 21, 2011 at 22:20
• Maybe this answer helps: tex.stackexchange.com/questions/3/compiling-documents-online/… Nov 21, 2011 at 22:30
• @GarouDan: I corrected a typo in your MWE. It appears that you had what appears to be the same typo in an earlier question, so please test your MWE before submitting them here. Nov 21, 2011 at 23:48

Use convert from from ImageMagick:

pdflatex formula.tex
convert -density 300 formula.pdf -quality 90 formula.png


Here is the resulting PNG file:

This solutions is from TeX to image over command line, which you should see as this will allow you to specify the formula on the command line.

• convert --version Version: ImageMagick 6.5.7-8 2010-12-02 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC Features: OpenMP I tried convert -transparent-color white -density 300 5.pdf -quality 90 5.png and convert -density 300 5.pdf -transparent-color white -quality 90 5.png. But I got the same results... =/ Nov 21, 2011 at 23:30
• Seems that you version is much older: convert --version yields: Version: ImageMagick 6.6.9-3 2011-04-04 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC Features: . So perhaps try downloading the latest version. Nov 21, 2011 at 23:42
• @PeterGrill Thanks so much. I have installed the new ImageMagick and it works fine. Thx. Nov 22, 2011 at 0:57
• If you find yourself doing this sort of conversion via ImageMagick a lot, a very useful wrapper is tex2im Nov 22, 2011 at 3:36
• If you have an older version of ImageMagick, you may need to add the option -transparent-color white to also have a transparent background.
– user63097
Nov 3, 2018 at 17:04

The following works for me:

1. Compile to dvi using latex (not pdflatex!).

By the way, you have a typo in your example: should be P\left(H_h|E_e\right)=\frac{P\left(E_e|H_h\right)P\left(H_h\right)}{P\left(E_e\right)}

2. Use dvipng:

dvipng -bg transparent -o myfile.png myfile.dvi

• this works fine. Thanks. But maybe, because of this question and this discussion I need to use pdflatex, can we use it? I tried PeterGrill solution but didn't worked, even inserting the -transparent-color white as you said. Nov 21, 2011 at 22:40
• You are right: -transparent-color does not work. It seems newer version of convert understand -alpha transparent, but mine, unfortunately, does not. There are other methods listed here: imagemagick.org/Usage/masking, but neither works for me :( Nov 21, 2011 at 22:53
• @Looks like in this link we cant convert a white background in a transparent one. I tried several thing as there explain but nothing works. Have you had sucess? (Tried this -alpha transparent too) Nov 21, 2011 at 23:33

I need this to generate equation images to a presentation.

I use an online latex equation editor.

It has a rich user interface that helps writing the equation and it renders in real time. Use the export menu to download the image as an svg, png, pdf or gif formats. It provides the code to embed the equation in HTML and others. I can also create a link that will show your equation, here is your equation.

• This might not be the best, but it's a valid answer to the question. I don't understand the down vote.
– Katu
Dec 20, 2015 at 16:21

I use mathurl

it'll allow you to save your equations as .png

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Apr 3, 2016 at 16:11
• The resolution is poor...
– zyy
Dec 26, 2020 at 4:06