15

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.

  • 3
    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
19

Use convert from from ImageMagick:

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

Here is the resulting PNG file:

enter image description here

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... =/ – GarouDan Nov 21 '11 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. – Peter Grill Nov 21 '11 at 23:42
  • @PeterGrill Thanks so much. I have installed the new ImageMagick and it works fine. Thx. – GarouDan Nov 22 '11 at 0:57
  • If you find yourself doing this sort of conversion via ImageMagick a lot, a very useful wrapper is tex2im – Paul M. Nov 22 '11 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. – nbro Nov 3 '18 at 17:04
6

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
2

I use mathurl

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

1

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 Dec 20 '15 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.