Home > latex > LaTeX formula to image (PNG)

## LaTeX formula to image (PNG)

Problem

With LaTeX you produce a nice formula that you would like to crop and convert to an image.

Solution

Let’s see the following simple LaTeX source:

\documentclass{article}
\pagestyle{empty}

\begin{document}
$a^2+b^2=c^2$
\end{document}


Save it as file.tex and execute “latex file.tex“, which will produce a DVI output (file.dvi). The image conversion is done the following way:

dvipng -T tight -x 1200 -z 9 file.dvi -o file.png


Result:

Ref.: I saw this conversion technique in justinvh’s Markdown-LaTeX project. If your goal is to include LaTeX formulae in HTML, try his script.

Categories: latex Tags: , ,
1. April 19, 2011 at 10:28

This website is so great :)

• April 19, 2011 at 10:29

Thank you SO much! :)

2. April 19, 2011 at 10:40

thanks so much. Outstanding site, by the way :)

• April 19, 2011 at 10:42

Thank you guys. And I just complained the other day that I get no feedbacks :)

3. April 19, 2011 at 23:03

Nice tip !
How to create an image of difficult formula in five seconds :)

Thanx.