1

I would like to make .png images of equations. To achive that I use pdflatex + pdfcrop + convert. But it takes more than 3 seconds on my computer to process simple $$E=mc^2$$. But I will generate dozens of images and I would like to do it as fast as possible.

pdfcrop is really slow and now I am trying to fit equation into page to except crop from my cycle. I use this:

\documentclass[landscape]{report}
\usepackage{amsmath} 
\usepackage{graphicx}

\begin{document}
\thispagestyle{empty}

\begin{equation*}
\resizebox{1.0\linewidth}{!} 
{
    $ E = mc^2 $
}
\end{equation*}

\end{document}

pdflatex produces this: 1

So, it's a lot of blank space around the equation. Moreover, I would like to use latex instead of pdflatex because it's faster. But latex ignores resizebox environment. So, my questions are: Is it possible to

1) Make pdflatex scale equation to entire page?

2) Similar but using latex?

3) Or maybe there is another way to produce images of equations?

1

I sometimes also need a picture of a LaTeX equation. For this, I use the following tex file equation.tex:

\documentclass{standalone}

\begin{document}
$\displaystyle  E = m\,c^2$
\end{document}

Since it uses the standalone class, no pdfcrop is required and the resulting PDF contains your equation only, and nothing else, no borders, nothing. In the same folder as the equation.tex I also have a Makefile as follows

.PHONY: all clean

equation.pdf: equation.tex
    pdflatex --interaction=nonstopmode equation.tex
    convert -background white -alpha remove -density 600 equation.pdf equation.png

clean:
    --@rm -rf *.aux *.log *.lof *.bak *.loa *.log *.lot *.bbl
    --@rm -rf *.blg *.dvi *.out *.brf *.thm *.toc *.idx *.ilg *.ind
    --@rm -rf *eps-converted-to.pdf *.gnuplot *.tps
    --@rm -rf *.nav *.snm *.vrb *.lol *.tmp *.synctex *.synctex.gz
    --@rm -rf *.xwm *.pdf

and if you run the make command inside this directory, it produces the PDF with the equation and converts it to PNG. Note that on Windows, you need to enter the full path to the convert tool, e.g.

c:\programs\ImageMagick-6.8.5\bin\convert -background white -alpha remove -density 600 equation.pdf equation.png

On my box, this PDF creation and the conversion to PDF runs pretty fast. I would say less than 1/2 sec, and not 3 sec.

The above shown mwe produces this png file:

equation

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.