MathType MTEF v.4 (MathType 3.5)
Abstract
This document describes MTEF, the binary equation format used by MathType 3.5 (all platforms). MTEF is embedded in OLE equation objects produced by MathType, as well as in all the file formats in which MathType can save equations. The methods used by MathType to embed this information in such files are described in a separate document. See How MTEF is Stored in Files and Objects.
Introduction
This document describes the binary equation format used by MathType 3.5 (all platforms). Although MTEF is not the most friendly medium for defining equations, there have been so many requests for this information, we decided to publish it anyway. We must warn the reader that it is not an easy format to understand and, more importantly, MathType is not at all forgiving in its processing of it. This means that if you send MathType MTEF with errors, it might crash. At a minimum, you will get an equation with formatting problems. Also, it is a binary format. This means that you can't use character strings to represent equations and it makes creating MTEF a little harder with programming languages like Visual Basic.
How MathType stores an equation description in an OLE equation object, a file, or on the clipboard is not described here. Please see the document on MathType MTEF Storage for more information on this subject.
Header
MTEF version history:
MTEF data exists in the following versions:
0 | MathType for the Mac 1.x (this format is not described here) |
1 | MathType for the Mac 2.x and MathType for Windows 1.x |
2 | MathType 3.x and Equation Editor 1.x |
3 | Equation Editor 3.x (this format is not described here) |
4 | MathType 3.5 |
5 | MathType 4.0 and later |
Version 2 differs from version 1 only in the format of the header.
MTEF header (version 1):
The version 1 header consists of a single byte version number. This number is 1 if the MTEF was generated on the Mac or 101 if it was generated by the Windows version.
MTEF header (version 2 and later):
The version 2 header consists of a 5-byte header:
byte | description | value |
---|---|---|
0 | MTEF version | 2 |
1 | generating platform | 0 for Mac, 1 for Windows |
2 | generating product | 0 for MathType, 1 for Equation Editor |
3 | product version | 3 |
4 | product subversion | 0 |
MTEF Byte Stream
This section describes the actual MTEF data following the header. MTEF data consists of a series of records. Each record starts with a tag byte containing the record type and some flag bits. The overall structure is:
Most MTEF values are bytes. Word values (16-bit) are written low-order byte followed by high-order byte. All dimensional values are expressed in MathType’s internal units, 32nds of a point (A point is 1/72 inch).
Tag byte structure:
Each tag byte consists of a record type in the low-order 4 bits and option flags in the high-order 4 bits. The following record types are used:
value | symbol | description |
---|---|---|
0 | end of MTEF, pile, line, embellishment list, or template | |
1 | line (slot) record | |
2 | character record | |
3 | template record | |
4 | pile (vertical stack of lines) record | |
5 | matrix record | |
6 | character embellishment (e.g. hat, prime) record | |
7 | ruler (tab-stop location) record | |
8 | font name record | |
9 | general size record | |
10 | full size record | |
11 | subscript size record | |
12 | sub-subscript size record | |
13 | symbol size record | |
14 | sub-symbol size record |
Option values:
The option flag values are record-dependent:
value | symbol | description |
---|---|---|
Option flag values for all equation structure records: | ||
0x8 | xfLMOVE | nudge values follow tag |
Option flag values for CHAR records: | ||
0x1 | xfAUTO | character is a candidate for function recognition |
0x2 | xfEMBELL | character is followed by an embellishment list |
Option flag values for LINE records: | ||
0x1 | xfNULL | line is a placeholder only |
0x4 | xfLSPACE | line spacing value follows tag |
0x2 | xfRULER |
Nudge values:
LINE, CHAR, TMPL, PILE, MATRIX, and EMBELL records may store the result of nudging (small offsets applied by the user). A nudged record has the xfLMOVE flag (0x8) set in the tag byte and the tag byte is followed immediately by the nudge offset. The nudge offset consists of either two bytes or six, depending on the amount of offset. If -128 < dx < +128 and -128 < dy < +128, then the offsets are stored as two bytes, dx followed by dy, where each value is biased by 128. Otherwise, two bytes of 128 are stored, followed by the (unbiased) offsets, dx and dy, stored as 16-bit values.
Typeface values:
CHAR records contain a typeface value (biased by 128). If the value is positive, it represents one of MathType’s styles:
value | symbol |
---|---|
1 | fnTEXT |
2 | fnFUNCTION |
3 | fnVARIABLE |
4 | fnLCGREEK |
5 | fnUCGREEK |
6 | fnSYMBOL |
7 | fnVECTOR |
8 | fnNUMBER |
9 | fnUSER1 |
10 | fnUSER2 |
11 | fnMTEXTRA |
If the value is negative, it represents an explicit font as specified by a FONT record.
Object lists:
LINE, CHAR, TMPL, PILE, MATRIX, and RULER records are followed by object lists that define contents of each equation structure. Each object list contains a sequence of records of any type and terminated by an END record. In a special case for LINE records, if there are no objects in the list, the xfNULL flag will be set in the tag byte and the object list is omitted entirely (i.e. no END record). Although there are no restrictions made by the MTEF format on what record types may occur in any particular list, the user interface prevents certain things from happening. For example, the object list defining the contents of a pile contains only LINE records.
Record Details
END record (0):
Contains just the tag byte. No flags are defined.
LINE record (1):
Consists of:
tag (1)
[nudge] if xfLMOVE is set
[line spacing] if xfLSPACE is set
[RULER record] if xfRULER is set
object list contents of line (a single pile, characters and templates, or nothing)
The line spacing value, if present, is the distance between the baseline of this line and the line above it.
CHAR record (2):
Consists of:
Associated with every font is an encoding (a one-to-one mapping between character value and glyph; e.g. ASCII). The character represented by the character value is determined according to the encoding of the typeface value. The encodings used by MathType are documented by Wiris Tech Note #9.
TMPL record (3):
Consists of:
tag (3)
[nudge] if xfLMOVE is set
[selector] template selector code
[variation] template variation code
[options] template-specific options
[subobject list] either a single character (e.g. sigma in a summation) and/or lines
The template selector and variation codes determine the class of the template and various properties of the template, such as which subobjects can be deleted by the user (see Template Selectors and Variations for a list). The class of a template determines the order and meaning of each of its subobjects (see Template Subobject Order).
The template-specific options field is only used for integrals and fence templates:
Integral template option field values: | |
0 | fixed-size integral; |
1 | the integral expands vertically to fit its contents. |
Fence template option field values (fence alignment): | |
0 | center fence on math axis, place math axis of contents on math axis of containing line (default); |
1 | center fence on contents, place math axis of contents on math axis of containing line; |
2 | center fence on contents, center contents on math axis of containing line. |
PILE record (4):
Consists of:
tag (4)
[nudge] if xfLMOVE is set
[halign] horizontal alignment
[valign] vertical alignment
[RULER record] if xfRULER is set
[object list] list of lines contained by the pile
Horizontal alignment:
1 | left justification |
2 | centered |
3 | right justification |
4 | relational operator alignment |
5 | decimal point alignment |
Vertical alignment:
0 | alignment with baseline of top line |
1 | alignment with baseline of center line |
2 | alignment with baseline of bottom line |
3 | vertical centering |
MATRIX record (5):
Consists of:
tag (5)
[nudge] if xfLMOVE is set
[valign] vertical alignment of matrix within container
[h_just] horizontal alignment within columns
[v_just] vertical alignment within columns
[rows] number of rows
[cols] number of columns
[row_parts] row partition line types
[col_parts] column partition line types
[object list] list of lines, one for each element of the matrix, in order from left-to-right and top-to-bottom
The values for valign, h_just, and v_just are described in PILE above.
The row partition line type list consists of two-bit values for each possible partition line (one more than the number of rows), rounded out to the nearest byte. Each value determines the line style of the corresponding partition line (0 for none, 1 for solid, 2 for dashed, or 3 for dotted). Similarly for the column partition lines.
EMBELL record (6):
Consists of:
tag (6)
[nudge] if xfLMOVE is set
[embell] embellishment type
The embellishment types are:
value | symbol | description |
---|---|---|
2 | embDOT | single dot |
3 | embDDOT | double dot |
4 | embTDOT | triple dot |
5 | embPRIME | single prime |
6 | embDPRIME | double prime |
7 | embBPRIME | backwards prime (left of character) |
8 | embTILDE | tilde |
9 | embHAT | hat (circumflex) |
10 | embNOT | diagonal slash through character |
11 | embRARROW | right arrow |
12 | embLARROW | left arrow |
13 | embBARROW | double-headed arrow |
14 | embR1ARROW | right single-barbed arrow |
15 | embL1ARROW | left single-barbed arrow |
16 | embMBAR | mid-height horizontal bar |
17 | embOBAR | over-bar |
18 | embTPRIME | triple prime |
19 | embFROWN | over-arc, concave downward |
20 | embSMILE | over-arc, concave upward |
RULER record (7):
Consists of:
tag (7)
[n_stops] number of tab-stops
[tab-stop list] tab-stops in order from left-to-right
Each tab stop is described by a tab-stop type (0 for left, 1 for center, 2 for right, 3 for equal, 4 for decimal), followed by a 16-bit offset from the left end of the slot or pile with which it is associated.
FONT record (8):
Consists of:
tag (8)
[tface] typeface number
[style] 1 for italic and/or 2 for bold
[name] font name (null-terminated)
This record associates a typeface number with an explicit font and style. The typeface number is the negative (which makes it positive) of the typeface value (unbiased) that appears in CHAR records that might follow a given FONT record. For example, a 3 in the FONT record corresponds to 125 (-3 + 128) in the CHAR record.
SIZE record (9):
Consists of one of the following cases:
if lsize < 0 (explicit point size):
tag (9)
101
-lsize (16 bits)
else if –128 < dsize < +128:
tag (9)
lsize
dsize + 128
else: (large delta)
tag (9)
100
lsize
dsize (16 bits)
Sizes in MathType are represented as a pair of values, lsize and dsize. Lsize stands for "logical size", dsize for "delta size". If it is negative, it is an explicit point size (in 32nds of a point) negated and dsize is ignored. Otherwise, lsize is one of the following typesize values and dsize is a delta from that size:
value | symbol | description |
---|---|---|
0 | szFULL | full |
1 | szSUB | subscript |
2 | szSUB2 | sub-subscript |
3 | szSYM | symbol |
4 | szSUBSYM | sub-symbol |
5 | szUSER1 | user 1 |
6 | szUSER2 | user 2 |
TYPESIZE records (10-14):
Consists of:
tag (10-14)
These records are just short ways of specifying a simple typesize where dsize is zero. The tag value represents an lsize + 10. So if the tag value is 10, it means equation content following it will be Full size (szFULL), tag value 11 means szSUB, and so on.
Template Selectors and Variations
This section shows the selector and variation codes for all the templates. The symbols shown here are internal identifiers in MathType and are for reference only. The class names can be used to determine the order of subobjects in the list following the template tag (see Template Subobject Order).
selector | symbol | description | class |
---|---|---|---|
0 | tmANGLE | angle brackets | ParBoxClass |
::: | variation | symbol | description |
::: | 0 | tvBANGLE | both left and right |
::: | 1 | tvLANGLE | left only |
::: | 2 | tvRANGLE | right only |
1 | tmPAREN | parentheses | ParBoxClass |
::: | variation | symbol | description |
::: | 0 | tvBPAREN | both left and right |
::: | 1 | tvLPAREN | left only |
::: | 2 | tvRPAREN | right only |
2 | tmBRACE | braces (curly brackets) | ParBoxClass |
::: | variation | symbol | description |
::: | 0 | tvBBRACE | both left and right |
::: | 1 | tvLBRACE | left only |
::: | 2 | tvRBRACE | right only |
3 | tmBRACK | square brackets | ParBoxClass |
::: | variation | symbol | description |
::: | 0 | tvBBRACK | both left and right |
::: | 1 | tvLBRACK | left only |
::: | 2 | tvRBRACK | right only |
4 | tmBAR | vertical bars | ParBoxClass |
::: | variation | symbol | description |
::: | 0 | tvBBAR | both left and right |
::: | 1 | tvLBAR | left only |
::: | 2 | tvRBAR | right only |
5 | tmDBAR | double vertical bars | ParBoxClass |
::: | variation | symbol | description |
::: | 0 | tvBDBAR | both left and right |
::: | 1 | tvLDBAR | left only |
::: | 2 | tvRDBAR | right only |
6 | tmFLOOR | floor brackets | ParBoxClass |
7 | tmCEILING | ceiling brackets | ParBoxClass |
8 | tmLBLB | left brace, left brace | ParBoxClass |
9 | tmRBRB | right brace, right brace | ParBoxClass |
10 | tmRBLB | right brace, left brace | ParBoxClass |
11 | tmLBRP | left brace, right parenthesis | ParBoxClass |
12 | tmLPRB | left parenthesis, right brace | ParBoxClass |
13 | tmROOT | radical | RootBoxClass |
::: | variation | symbol | description |
::: | 0 | tvSQROOT | square root |
::: | 1 | tvNTHROOT | nth root |
14 | tmFRACT | fractions | FracBoxClass |
::: | variation | symbol | description |
::: | 0 | tvFFRACT | full-size slots |
::: | 1 | tvPFRACT | subscript-size slots (piece fraction) |
15 | tmSCRIPT | subscript/superscript | ScrBoxClass |
::: | variation | symbol | description |
::: | 0 | tvSUPER | superscript |
::: | 1 | tvSUB | subscript |
::: | 2 | tvSUBSUP | both |
16 | tmUBAR | underbar | BarBoxClass |
::: | variation | symbol | description |
::: | 0 | tvSUBAR | single underbar |
::: | 1 | tvDUBAR | double underbar |
17 | tmOBAR | overbar | BarBoxClass |
::: | variation | symbol | description |
::: | 0 | tvSOBAR | single overbar |
::: | 1 | tvDOBAR | double overbar |
18 | tmLARROW | left-pointing arrow | ArroBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLTARROW | box on top |
::: | 1 | tvLBARROW | box on bottom |
19 | tmRARROW | right-pointing arrow | ArroBoxClass |
::: | variation | symbol | description |
::: | 0 | tvRTARROW | box on top |
::: | 1 | tvRBARROW | box on bottom |
20 | tmBARROW | left- and right-pointing arrow | ArroBoxClass |
::: | variation | symbol | description |
::: | 0 | tvBTARROW | box on top |
::: | 1 | tvBBARROW | box on bottom |
21 | tmSINT | single integral | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvNSINT | no limits |
::: | 1 | tvLSINT | lower limit only |
::: | 2 | tvBSINT | both limits |
::: | 3 | tvNCINT | contour, no limits |
::: | 4 | tvLCINT | contour, lower limit only |
22 | tmDINT | double integral | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvNDINT | no limits |
::: | 1 | tvLDINT | lower limit only |
::: | 2 | tvNAINT | area, no limits |
::: | 3 | tvLAINT | area, lower limit only |
23 | tmTINT | triple integral | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvNTINT | no limits |
::: | 1 | tvLTINT | lower limit only |
::: | 2 | tvNVINT | volume, no limits |
::: | 3 | tvLVINT | volume, lower limit only |
24 | tmSSINT | single summation-style integral | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvBSSINT | both limits |
::: | 1 | tvLSSINT | lower limit only |
::: | 2 | tvLCSINT | contour, lower limit only |
25 | tmDSINT | double summation-style integral | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLASINT | area, lower limit only |
::: | 1 | tvLDSINT | lower limit only |
26 | tmTSINT | triple summation-style integral | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLVSINT | volume, lower limit only |
::: | 1 | tvLTSINT | lower limit only |
27 | tmUHBRACE | upper horizontal brace | HBrBoxClass |
28 | tmLHBRACE | lower horizontal brace | HBrBoxClass |
29 | tmSUM | summation | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLSUM | lower only |
::: | 1 | tvBSUM | both upper and lower limits |
::: | 2 | tvNSUM | no limits |
30 | tmISUM | summation (integral-style limits) | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLISUM | lower only |
::: | 1 | tvBISUM | both upper and lower limits |
31 | tmPROD | product | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLPROD | lower only |
::: | 1 | tvBPROD | both upper and lower limits |
::: | 2 | tvNPROD | no limits |
32 | tmIPROD | product (integral-style limits) | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLIPROD | lower only |
::: | 1 | tvBIPROD | both upper and lower limits |
33 | tmCOPROD | coproduct | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLCOPROD | lower only |
::: | 1 | tvBCOPROD | both upper and lower limits |
::: | 2 | tvNCOPROD | no limits |
34 | tmICOPROD | coproduct (integral-style limits) | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLICOPROD | lower only |
::: | 1 | tvBICOPROD | both upper and lower limits |
35 | tmUNION | union | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLUNION | lower only |
::: | 1 | tvBUNION | both upper and lower limits |
::: | 2 | tvNUNION | no limits |
36 | tmIUNION | union (integral-style limits) | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLIUNION | lower only |
::: | 1 | tvBIUNION | both upper and lower limits |
37 | tmINTER | intersection | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLINTER | lower only |
::: | 1 | tvBINTER | both upper and lower limits |
::: | 2 | tvNINTER | no limits |
38 | tmIINTER | intersection (integral-style limits) | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLIINTER | lower only |
::: | 1 | tvBIINTER | both upper and lower limits |
39 | tmLIM | limit | LimBoxClass |
::: | variation | symbol | description |
::: | 0 | tvULIM | upper limit |
::: | 1 | tvLLIM | lower limit |
::: | 2 | tvBLIM | both upper and lower limits |
40 | tmLDIV | long division | LDivBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLDIVW | with upper slot |
::: | 1 | tvLDIVWO | without upper slot |
41 | tmSLFRACT | slash fractions | SlashBoxClass |
::: | variation | symbol | description |
::: | 0 | tvSLFNORM | normal |
::: | 1 | tvSLFBASE | slots on baseline |
::: | 2 | tvSLFSUB | subscript-sized slots |
42 | tmINTOP | big integral-style operators | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvUINTOP | upper limit |
::: | 1 | tvLINTOP | lower limit |
::: | 2 | tvBINTOP | both upper and lower limits |
43 | tmSUMOP | big summation-style operators | BigOpBoxClass |
::: | variation | symbol | description |
::: | 0 | tvUSUMOP | upper limit |
::: | 1 | tvLSUMOP | lower limit |
::: | 2 | tvBSUMOP | both upper and lower limits |
44 | tmLSCRIPT | leading sub- and superscripts | ScrBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLSUPER | superscript |
::: | 1 | tvLSUB | subscript |
::: | 2 | tvLSUBSUP | subscript and superscript |
45 | tmDIRAC | Dirac delta | DiracBoxClass |
::: | variation | symbol | description |
::: | 0 | tvBDIRAC | both left and right slots |
::: | 1 | tvLDIRAC | left slot only |
::: | 2 | tvRDIRAC | right slot only |
46 | tmUARROW | under arrow | VectorBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLUARROW | left-pointing |
::: | 1 | tvRUARROW | right-pointing |
::: | 2 | tvDUARROW | double-headed (left and right) |
47 | tmOARROW | over arrow | VectorBoxClass |
::: | variation | symbol | description |
::: | 0 | tvLOARROW | left-pointing |
::: | 1 | tvROARROW | right-pointing |
::: | 2 | tvDOARROW | double-headed (left and right) |
48 | tmOARC | over arc | ArcBoxClass |
Template Subobject Order
The following list shows the order of subobjects for each template class:
ArcBoxClass vector notation
main slot
ArroBoxClass expanding arrows
main slot
arrow character
BarBoxClass over-bars and under-bars
main slot
BigOpBoxClass integrals, summations, products, etc.
main slot (summand, integrand)
upper slot
lower slot
large operator character
DiracBoxClass three-part bracket structure
left slot
right slot
left angle bracket (optional)
vertical bar
right angle bracket (optional)
FracBoxClass fractions with a horizontal bar
numerator slot
denominator slot
HBrBoxClass horizontal expanding braces
main slot
small slot
brace character
LDivBoxClass long division
dividend slot
quotient slot
LimBoxClass limits
main slot
lower slot
upper slot
ParBoxClass parenthesized or bracketed slots
main slot
left fence character (optional)
right fence character (optional)
RootBoxClass radical sign
main slot
radicand slot
ScrBoxClass subscripts and superscripts
subscript slot
superscript slot
SlashBoxClass fractions with a diagonal bar
numerator slot
denominator slot
VectorBoxClass box with upper or lower arrow
main slot
<a><button>Back to MathType SDK intro page</button></a> |