TeX to GIF converter for Web documents

When preparing technical documents for the World-Wide Web, there's frequently a need to include equations in the text. Since HTML doesn't provide direct support for mathematical typesetting, equations must be included as inline images. If you use TeX or LaTeX to write conventional documents, you already know how to format equations in those languages. Wouldn't it be nice to painlessly use TeX equations in your Web documents?

If you want to convert an entire LaTeX document into HTML, use LaTeX2HTML, by Nikos Drakos. But if you just want to typeset some equations for a new Web document, it's cumbersome to first write your document in LaTeX, convert it into HTML, then add links and additional functionality in the HTML text. Also, it's nice to be able to control the size of an equation image and the resolution with which it's rendered equation-by-equation; this isn't possible with a bulk document translator such as LaTeX2HTML.

Textogif is a simple Perl program which uses the same software tools employed by LaTeX2HTML to compile individual equations in short LaTeX files into GIF images suitable for embedding in Web documents. You can obtain the program as a GZIP compressed Unix shell archive:

To use textogif, write your equation (or anything else you can typeset with LaTeX) in a file like:


    \bf     % Formulae images often look better in boldface, but
            % the choice is up to you.
    \int H(x,x')\psi(x')dx' = -\frac{\hbar^2}{2m}\frac{d^2}{dx^2}

The "\pagestyle{empty}" is required to avoid generating a huge image with a page number at the bottom. Then (assuming you have all the software described below installed properly), you can simply say:
    textogif filename ...
to compile filename.tex to filename.gif, an interlaced, transparent background GIF file ready to use an an inline image. You can specify the base name, for example, "schrod", rather than the full name of the TeX file ("schrod.tex"), and use wild cards to process multiple files. TeX requires, however, that all files have an extension of ".tex". A sample IMG tag, including the image width and height is printed on standard error, for example:
    <img src="schrod.gif" width=529 height=56>
Here's what you'll see when you include the image for the equation:

(Equation image)

GIF files created by textogif are interlaced to permit incremental display by browsers which provide that capability, and have a transparent background so they'll look good regardless of the background on which they're placed.

Command line options

Command line options allow you to control the size of the image generated for the equation and the degree of antialiasing used to avoid jagged edges in the text.

-dpi nnn

The -dpi option is followed by an integer which controls the size of the generated image by giving the "dots per inch" for the image. The default of 150 creates images of reasonable size for most browsers, for example:
(Equation image)

Larger values create larger images. A value specification of "-dpi 300" would double the size of the equation to:
(Equation image)

while "-dpi 75" would create an image half the size of the default:
(Equation image)

Smaller images like this often look better if set in bold face type. The LaTeX command "\bf" within the displaymath environment produces the more readable:
(Equation image)

-res n.nn

The -res option is followed by a floating point number which specifies the degree of antialiasing used to smooth characters in the image. The specification is given in terms of the size of the actual output image divided by the size of the original image used to produce it. The default value, 0.25, produces an image with four times the desired dots per inch, then scales it, smoothing jagged edges in the process.

Smaller values for "-res" produce greater smoothing, but at the cost of increased memory and disc space requirements as the image is being generated. If your system's resources are insufficient to create an image, increase the value of "-res" until it can be successfully processed. Larger values of "-res" reduce the antialiasing and yield rougher contours in the text. A value of 1.0 disables antialiasing entirely. Here is the same equation processed with different "-res" settings.

(Equation image)           -res 0.25

(Equation image)           -res 0.5

(Equation image)           -res 1.0

Software Prerequisites

Textogif is a small Perl program which relies upon the following software to do the real work. You'll need to have all the following packages properly installed on your system in order to use Textogif. The version numbers are those I had installed on my machine when I developed this program; later versions should work OK as long as they're upwardly compatible with those cited. Given the number of Unix-specific dirty tricks employed by Textogif, it is extremely unlikely it will work under other operating systems without modifications.
    Perl        4.0 Patch level 36
    TeX         3.141 (C version d)
    LaTeX2e     patch level 3
    dvips       dvipsk 5.521a
    Ghostscript 2.6.1 (5/28/93)
    pstoppm.ps  (version supplied with Ghostscript 2.6.1)
    Netpbm      1 March 1994

Download textogif software

by John Walker