GladTeX is a utility for creating images of mathematics equations. This page describes a special version of GladTeX for Windows created by Erik Neumann, first released September 2004. See also Displaying Math on the Web.

Here is an example of an equation produced by gladTeX. To see how this equation is created in gladTeX, see Displaying Math on the Web.

\sum_{k=1}^\infty \frac{1}{k^2} = \frac{\pi^2}{6}

This version of gladTeX is different from gladTeX 0.3 in the following ways:

• Now works under Windows XP.
However, this version probably ONLY works under Windows until I or someone attempts to make this version work both under Unix and Windows (not a difficult job, but I don't have a Unix system to test it with).
• Avoids re-creating equation images that already exist.
This vastly speeds up the running time of gladTeX, especially if you are making changes to the source page which don't affect existing equations. Briefly, here's how it works: the LaTeX equation is written to a .tex file in the same directory where the .png file is created. When gladTeX is asked to render a certain LaTeX expression, it first scans all the available .tex files to see if that expression has already been rendered. If so, it just uses the existing .png file with the same name.
• Improved how inline equation images are aligned with text.
GladTeX originally used the vertical centering of images to effect alignment with the text -- gladTex would resize the image to add blank space above or below so it would align. This version instead uses a CSS vertical-align style attribute in the <IMG> tag like this:
<IMG style="vertical-align: -13px; margin: 0;" width="20" height="30">
With this attribute, we no longer need to make the image larger with blank space. This keeps the spacing between lines of text more compact.
• Names equation images to correspond to the HTML document they are from.
This helps me to keep track of what equation goes with what HTML document. Note that currently the 'avoid re-creating an image' code might find existing files that 'belong' to a different page. (It would be fairly simple to add an option to prevent that behavior).
• Adds alt property to <img> tags.
The alt property specifies a text equivalent for an image, which is important for visually impaired users, or for display on alternate devices or text-only browsers. The alt property is required under HTML 4.01. This version of GladTeX automatically adds the LaTeX form of the equation as the alt property. You can see the alt text by hovering your mouse over the equation image in many browsers.
• Only supports PNG, not GIF (at present).
I decided that PNG was good enough, and didn't try to get the GIF code to work.
• Double-quotes not allowed in LaTeX expressions.
This is because of how I am using grep to search for existing files. Since Windows command-line arguments are wrapped in double-quotes, we pass the LaTeX expression wrapped in double-quotes. So, a double-quote in the LaTeX expression would break that part of the process. This is not a big problem since double-quotes are pretty much not used in LaTeX anyway! (LaTeX requires use of two single quotes like '' or back quotes  instead). If you really need a double quote you can use \\symbol{34} instead. (Note that this limitation could be eliminated by writing the search argument to a file instead of passing it via the command-line).

Get the two files (that are part of this software release):

    eqn2img.exe  (compiled for Windows OS)


and put them somewhere that can be found by the Windows command line. You can get these files from ftp://www.MyPhysicsLab.com/gladtex/. In addition you will need the following:

With this version of gladTeX, libpng is part of eqn2img.exe, so you don't need to install libpng on your own.

Before trying to use gladTeX, you should be able to run latex on a simple .tex file, and turn it into a .dvi file (try viewing it with a .dvi viewer like Yap which is part of MikTeX). You should also be able to give the commands listed above (perl, latex, dvips, grep, gswin32c) at the command line.

## Usage

Put

    <eq>...latex code here....</eq>


in your .html file. But rename it to have the .htex extension. Then invoke gladtex by:

    perl gladtex.pl [options] myfile.htex


where [options] are described in gladtex.pl.

For inline equations use

    <eq inline=1>...latex code here...</eq>


This will result in special processing so that the equation image lines up with the other text on the line.

## Source Code

The perl file gladtex.pl is a perl text file. The source code for eqn2img.c is provided at ftp://www.MyPhysicsLab.com/gladtex/ in case you want to try to build it yourself. There are some additional .h and .c files:

• getopt.c is code for a command line parser.
• direct.h header is for directory operations like _chdir (direct.h comes with Visual C++ and is not included here)
• png.h is the header for libpng (comes with libpng and is not included here).

You will need to obtain libpng and zlib if you want to compile eqn2img.c. This is rather involved when using VisualC++ on Windows, see the accompanying file 'libpng notes.txt' for more information.

## Changes to eqn2img

I've made various changes to eqn2img.c so that it compiles and works on Windows. In addition some other changes I made were:

• Added the -i option to specify when an equation is inline with the text. Those equations are handled specially. They result in the <img> tag having a style="vertical-align" property so that they line up with the other text on that line. (In the old version of eqn2img this was done by increasing the size of the image, so that align=middle property would line it up, but that resulted in large spaces between lines of text).
• Added the -e option to specify the equation on the command line.
• No longer deletes the .tex file that is created. It is used by gladtex to see if a .png image can be reused.
• Automatically adds the LaTeX version of the equation as the alt text for the <img> tag.

This web page was first published September 2004.

previous next