# How to export a equation as a 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 :) – percusse Nov 21 '11 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. – GarouDan Nov 21 '11 at 22:20
Maybe this answer helps: tex.stackexchange.com/questions/3/compiling-documents-online/… – Count Zero Nov 21 '11 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. – Peter Grill Nov 21 '11 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.

-
Would this make the background transparent? Id add the option -transparent-color white to convert. – Boris Nov 21 '11 at 22:31
@Boris: It seems to. See image. – Peter Grill Nov 21 '11 at 22:41
@PeterGrill The Gwenview here open your image without background as I need. But here, when I try generate it I get one with a white background (I had corrected the {). I tried the example on your link and I got the same result, a white background image. What's the problem? – GarouDan Nov 21 '11 at 22:51
I used this code and runned this commands:pdflatex 5.tex , convert -density 300 5.pdf -quality 90 5.png and I got this image. Very strange. – GarouDan Nov 21 '11 at 22:57
@GarouDan: Not sure. Try adding -transparent-color white as suggested b Boris. Maybe different versions of convert? I get the same results with or without that option. – Peter Grill Nov 21 '11 at 23:21

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. – GarouDan Nov 21 '11 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 :( – Boris Nov 21 '11 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) – GarouDan Nov 21 '11 at 23:33

I need this to generate equation images to a presentation.

I use an online latex equation editor that has the option to download it as .gif.

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