MathType 5 SDK
Extracting Baseline Info from a GIF File

Last Updated: September 15, 2001

Products: MathType (all platforms)

MathType (version 2.0 and later) inserts a comment describing the distance in points from the bottom of the frame rectangle to the baseline of the equation. For example:

This information can be made use of by page layout, word processor, or HTML editing programs to ensure proper alignment of the equation baseline with that of a text line in which it is pasted.

Starting with MathType 5.0 for Windows, baseline data is embedded into a GIF file as an Application Extension Record. Earlier versions of MathType do not embed this data.

The Application Extension Record consists of a 14-byte header (Application Extension Descriptor), followed by the MTEF data. The header contains:

Byte Introducer = 0x21;
Byte ExtensionLabel = 0xFF;
Byte BlockSize = 0x0B;
Byte ApplicationId[8] = "MathType";
Byte AuthenticationCode[3] = "002";

The data follows this header and is written as a series of blocks each containing 255 bytes or less. Each block starts with a single byte count followed by the data. The end is marked as a block with length 0.

The header is unique enough that the easiest way to extract the data might be to scan the file for the 14-byte header, then expect the MTEF data blocks to follow. Properly decoding the GIF records isn't that hard either, but obviously requires you read the GIF specification.

The actual baseline data is stored within the data part of the Application Extension Record as three 16-bit integer values:

     Word BaselineDelta;
     Word LeftSideBearing;
     Word RightSideBearing;

Each of these values is written as two bytes, with the low-order byte first. Each value represents a distance in pixels. The BaselineDelta is measured as in the picture above. The LeftSideBearing and RightSideBearing values are for future use and are currently both zero.

MathType's internal equation data format, MTEF, is also stored in the GIF file using a similar Application Extension Record as described above, but with an AuthenticationCode of "001". For details, see How MTEF is Stored in Files and Objects.

See also:

Extracting Baseline Info from PICT Data (Macintosh)
Extracting Baseline Info from WMF (MS Windows)
Extracting Baseline Info from EPS Files
How MTEF is Stored in Files and Objects

Copyright ©2000-2002 by Design Science, Inc. All rights reserved.