Making Nice Images of Equations in Windows

If you already know LaTeX, there is a quick and easy way to make images that you can paste into many different Windows applications such as PowerPoint.
For the following technique to work, it will be necessary to install MikTeX.

Now, if the details are not what you are interested in and you would like to get on with it,  I have made files available.  To get them to work the idea is simple.   Download the files I have made available.  Put them all in the same directory.  Edit body.txt and double click the batch file (.bat).  The body.txt file that I have provided contains the text:

$\frac{a}{b}$

Double clicking makeLaTeXImage.bat produces the image of the fraction \displaystyle\frac{a}{b} which is called tmp1.png

The code is set up to produce images with a transparent background to make it conducive to pasting into documents with different colored backgrounds.

To change the image generated, change the text in body.txt

One modification to the images produced that I can anticipate an average user needing is a modification in the default resolution.  This can be done by editing the following line of the batch file in your text editor:

dvipng -D 200 tmp.dvi -T tight -bg transparent

Here, 200 means 200 dpi.  You can change this to whatever dpi you need.  For instance,

dvipng -D 600 tmp.dvi -T tight -bg transparent

gives 600 dpi.

Details:

preamble.txt

\documentclass[12pt]{article}

\usepackage{amssymb}
\usepackage{color}
\usepackage{amsfonts}

\pagestyle{empty}
\begin{document}

This section contains the needed packages.  You may have to modify it depending on the packages needed.

body.txt

$\frac{a}{b}$

This section contains the LaTeX text.   You need to modify this file.

postamble.txt

\end{document}

This section contains the end of the document and is mostly irrelevant.

makeLaTeXImage.bat

copy /b /y preamble.txt+body.txt+postamble.txt tmp.tex
texi2dvi tmp.tex
dvipng -D 200 tmp.dvi -T tight -bg transparent
del /f /q tmp.aux
del /f /q tmp.dvi
del /f /q tmp.tex
del /f /q tmp.log

copy /b /y preamble.txt+body.txt+postamble.txt tmp.tex

/b copy in binary mode
/y copy without asking for confirmation

texi2dvi tmp.tex

This converts the TeX file to DVI.

dvipng -D 200 tmp.dvi -T tight -bg transparent

-bg transparent make the background transparent
-T tight                  Cropped to only include the equation with very little border.
-D 100                   output resolution, 100 dpi

This generates tmp1.png which is where the image of the equation is stored.

One response to “Making Nice Images of Equations in Windows

  1. Warren Lockhart

    Thank you very much, this saved me some time. I have a suggestion from the experience of using your script – because the dollar signs indicate inline latex, the fraction part shrinks to the height of stuff on the other side of an equal sign. Two solutions are 1) include package amsmath and use \dfrac instead of \frac, or 2) use \displaystyle after the first dollar. I tried to use \begin{equation} and \end{equation} in your preamble and postamble files, but this does not seem to work (complains about missing dollar), so the two solutions above seem best.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s