Tags

, , ,

If you’re giving a presentation, for example, and you want to use animations and transitions so don’t want to write it entirely in LaTeX. You may want to still use LaTeX to get well-formatted equations in your presentation. These need to be included as pictures as most presentation programs don’t natively support LaTeX.

This guide will tell you how to use LaTeX to create standalone pictures of equations for use in anything, from presentations to websites. Update: I have now written a bash script to do the same as this, but easier to use and better, explanation in this blog post.


The LaTeX Source
You will need a stripped down version of the page, because the only thing you want visible is the equation. The template you will want is:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\pagestyle{empty}
\begin{equation*}
%Equation goes here
\end{equation*}
\end{document}

To explain, you want to use the article class. You need to load the amsmath package to give access to equation* environment which you need to use to remove the equation number. Finally \pagestyle{empty} removes any page number.

Colour schemes
Depending on the colour scheme of your presentation, you may want to use a different text or background colour. For this you need to add to your preamble this:

\usepackage[usenames,dvipsnames]{color}

Which will allow you to use pre-defined named colours. You then need to tell LaTeX what colour to use for what. For example, for white on black you need:

\pagecolor{black}
\textcolor{white}

You can substitute these colours for any in the list of known colours.

Compiling into an eps file
As with any LaTeX file, there is a compilation process. To get a picture of the equation only, the process is a bit different to normal. I discovered this compilation method thanks to this article. Compile the LaTeX file to dvi like normal:

latex input.tex

This will give you a full page with just the equation on it. Then, we want a picture the size of the equation as the output. We use dvips just like we do to go to ps then to pdf, but this time we are converting to eps. You want to use this code:

dvips -E -o output.eps input.dvi

Specifying the extension of the output makes dvips output to eps not ps. The -E part specifies that the bounding box is tight, meaning that the picture is only as big as the equation rather than a whole page.

Automating the process
You can put the above commands in a bash script just like a normal LaTeX compilation script. In this guide I will tell you how to use Kile to automate the process. See my previous post about using Kile. In the settings, there’s a build section. This is where you need to add some things.

Create a new tool, and tell it to copy all settings from the DVItoPS tool. It should be a convert tool run outside of Kile. Call it something helpful like DVItoCroppedEPS. Then you need to add the settings.
The command should be:

dvips

The options should be:

-E -o '%S.eps' '%S.dvi'

The program will then replace %S with your filename, so now dvips will get the correct filenames with the correct extensions.

Secondly create a new tool and tell it to copy quickbuild. It should be a sequence of tools. Call it something useful like compile-equation-picture. Add to the sequence the standard LaTeX compile tool (not pdfLaTeX). Then add the tool you just created above. Finally choose the menu in which this create-equation-picture tool should appear.

One click on the tool should take your equation.tex and make an equation.eps picture.

Using your equation picture
While eps is a format that is fairly widely supported, some programs can’t directly use it. If you need to you can then use your favourite picture editing program to convert it into a format that you can use.

Advertisements