ps to gif

In January, 1998

This page is written to help members of our community (current users of the math machines) create web pages containing gifs duplicating the contents of previously generated postscript pages. This need is especially acute in math because html does not display math well now, and extensions to html to help this situation won't appear soon.

Postscript output is usually easy to get. TeX (via dvips) and programs such as gnuplot, xfig, Maple, etc. can produce Postscript files. But many browsers used by our students can't create an image from a Postscript file. All the usual web browsers do display gifs, however. What follows describes how to construct a sequence of web pages with gifs for each page of a Postscript file.

I've tried to document the use of the program carefully. I've made hundreds of web pages using this process without substantial difficulty.


There are certainly other approaches to handling the difficulties of putting math notation and pictures on the web. One is the use of the program latex2html which is available on our system as /usr/local/latex2html without, however, substantial documentation. Harri Ojanen has used it and you can observe an example. Note the rather large number of gif's needed for this method of transmitting mathematics. The pictures are quite interesting, however!


The perl script htmlize-ps discussed here was originally written by Larry Greenfield, and has been changed by me in very minor ways.

Before beginning

I'll assume you have a directory called frog which contains an index page called frog_index.html. The frog directory has various subdirectories which are listed below.

gifs This directory contains gifs which will be used to help viewers navigate between the web pages to be created. I list here the gifs I use. If you don't use these gifs and this directory structure, htmlize-ps should be changed.

gifstuff This is the directory where I put html pages and gifs made by the procedure described below.

psstuff I use this directory to store the original Postscript files to be copied during the procedure to be described below. You may wish to have these files accessible from the index page frog_index.html named above if you wish, for those who can access Postscript through their browsers. Postscript images and printouts seem superior to their gif companions.

I assume that the directory frog/gifstuff contains a copy of the program htmlize-ps and a copy of the file, a Postscript file which when printed or previewed is four pages long.

Your system must be notified that htmlize-ps is a program -- that it is "executable". So be sure to write (in the directory holding the copy):

chmod u+x htmlize-ps

The program htmlize-ps needs three parameters or arguments. Here is how it is used on a command line:

htmlize-ps ../frog_index.html "An essay about toads"

The first phrase is the program name. It must be followed by a space and then the name of the Postscript file to be converted. Follow this in turn by another space and write the backlink, the web page to which you wish viewers to be returned when they are done with reading your page. Then follow this by another space and the title of the web page(s) to be created. Any title with spaces must be enclosed by quotation marks.

The copy of htmlize-ps which is provided contains the line

$blname = "Back to S. Greenfield's teaching page";
A title for your backlink should be substituted in this file between the quotation marks. For example, a line which might be suitable here is
$blname = "Back to the frog homepage";

An actual record

Below is a verbatim record of one use of the program with comments interpolated. I started with an TeX file, as I usually do when writing course material. What appeared on the screen is in this font with comments written in the standard font.
./              ../             htmlize-ps*     toad.tex
A list of the files present before we begin working.
fermat>tex toad.tex
This is TeX, C Version 3.141
(toad.tex [1] [2] [3] [4] )
Output written on toad.dvi (4 pages, 17616 bytes).
Transcript written on toad.log.
I TeXed the toad file, and TeX reported that the output was 4 pages long.
fermat>dvips toad.dvi -o
This is dvips 5.528 Copyright 1986, 1994 Radical Eye Software
' TeX output 1998.01.27:1749' ->
. [1] [2] [3] [4] 
The program dvips takes the dvi output and changes it into Postscript. If pictures had been included in the TeX file, dvips would report additional information.
fermat>htmlize-ps ../frog_index.html "An essay about toads"
This is the command line for the actual transformation.
Generating ppm files...
Changing ppm to gif & removing ppm 1...ppmtogif: computing colormap...
ppmtogif: 2 colors found
page 2...ppmtogif: computing colormap...
ppmtogif: 2 colors found
page 3...ppmtogif: computing colormap...
ppmtogif: 2 colors found
page 4...ppmtogif: computing colormap...
ppmtogif: 2 colors found
Making HTML: page 4...done.
The program may take a while to run. The ppm files described are an intermediate stage -- yet another graphical format for files!
./              toad-1.gif      toad-2.html     toad-4.gif      toad.log
../             toad-1.html     toad-3.gif      toad-4.html
htmlize-ps*     toad-2.gif      toad-3.html     toad.dvi        toad.tex
This is a list of the files present when we've finished. I clean up by removing the files I don't need. Again, I usually keep a copy of in the directory psstuff. If generated one page of output instead of four, the resulting files would be named toad-1.html and toad-1.gif.
fermat>rm toad.log toad.tex toad.dvi
./              toad-1.gif      toad-2.html     toad-4.gif
../             toad-1.html     toad-3.gif      toad-4.html
htmlize-ps*     toad-2.gif      toad-3.html     
We're left with lots of files!

If the file frog_index.html has the proper link to the web page toad-1.html (as <a href="gifstuff/toad-1.html">...</a>) then readers will be led along from the first page through the fourth. I've just tested this whole process several times with Postscript files of varying sizes. It failed once: one of the gifs produced was flawed. When rerun, things worked fine. The process is intricate and uses some large, complicated programs (most notably, ghostscript).

Certainly this is close to a kludge (on-line dictionary definition: 1. an ill-assorted collection of poorly matching parts. 2. [Computing] a machine, system, or program that has been badly put together.), but it works, now. A Unix hacker could increase the efficiency of the whole process with another macro or two. The future will bring more efficient methods to display math. But, again, this works now!


The permissions on your web pages must be set properly. Thus the world should be able to read the html and gif files. The following instruction given in the directory gifstuff will insure that happens:
fermat>chmod a+r *.html *.gif
The world should also have access to your gifstuff directory and other directories. Therefore, go "up" to the directory frog and write
fermat>chmod a+rx gifstuff gifs psstuff

Maintained by and last modified 1/28/98.