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: 0MathType for the Mac 1.x (this format is not described here) 1MathType for the Mac 2.x and MathType for Windows 1.x 2MathType 3.x and Equation Editor 1.x 3Equation Editor 3.x (this format is not described here) 4MathType 3.5 5MathType 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 descriptionvalue 0 MTEF version2 1 generating platform0 for Mac, 1 for Windows 2 generating product0 for MathType, 1 for Equation Editor 3 product version3 4 product subversion0 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: initial SIZE record PILE or LINE record contents of PILE or LINE END record 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 end of MTEF, pile, line, embellishment list, or template 1 LINE line (slot) record 2 CHAR character record 3 TMPL template record 4 PILE pile (vertical stack of lines) record 5 MATRIX matrix record 6 EMBELL character embellishment (e.g. hat, prime) record 7 RULER ruler (tab-stop location) record 8 FONT font name record 9 SIZE general size record 10 FULL full size record 11 SUB subscript size record 12 SUB2 sub-subscript size record 13 SYM symbol size record 14 SUBSYM 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 Option flag values for LINE and PILE records: 0x2 xfRULER RULER record follows LINE or PILE record 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: valuesymbol 1fnTEXT 2fnFUNCTION 3fnVARIABLE 4fnLCGREEK 5fnUCGREEK 6fnSYMBOL 7fnVECTOR 8fnNUMBER 9fnUSER1 10fnUSER2 11fnMTEXTRA 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: tag (2) [nudge] if xfLMOVE is set [typeface] typeface value (see FONT below) + 128 [character] character value (encoding depends on typeface) [embellishment list] if xfEMBELL is set (embellishments) 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: 0fixed-size integral; 1the integral expands vertically to fit its contents. Fence template option field values (fence alignment): 0center fence on math axis, place math axis of contents on math axis of containing line (default); 1center fence on contents, place math axis of contents on math axis of containing line; 2center 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: 1left justification 2centered 3right justification 4relational operator alignment 5decimal point alignment Vertical alignment: 0alignment with baseline of top line 1alignment with baseline of center line 2alignment with baseline of bottom line 3vertical 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 descriptionclass 0 tmANGLE angle bracketsParBoxClass variation symboldescription 0 tvBANGLEboth left and right 1 tvLANGLEleft only 2 tvRANGLEright only 1 tmPAREN parenthesesParBoxClass variation symboldescription 0 tvBPARENboth left and right 1 tvLPARENleft only 2 tvRPARENright only 2 tmBRACE braces (curly brackets)ParBoxClass variation symboldescription 0 tvBBRACEboth left and right 1 tvLBRACEleft only 2 tvRBRACEright only 3 tmBRACK square bracketsParBoxClass variation symboldescription 0 tvBBRACKboth left and right 1 tvLBRACKleft only 2 tvRBRACKright only 4 tmBAR vertical barsParBoxClass variation symboldescription 0 tvBBARboth left and right 1 tvLBARleft only 2 tvRBARright only 5 tmDBAR double vertical barsParBoxClass variation symboldescription 0 tvBDBARboth left and right 1 tvLDBARleft only 2 tvRDBARright only 6 tmFLOOR floor bracketsParBoxClass 7 tmCEILING ceiling bracketsParBoxClass 8 tmLBLB left brace, left braceParBoxClass 9 tmRBRB right brace, right braceParBoxClass 10 tmRBLB right brace, left braceParBoxClass 11 tmLBRP left brace, right parenthesisParBoxClass 12 tmLPRB left parenthesis, right braceParBoxClass 13 tmROOT radicalRootBoxClass variation symboldescription 0 tvSQROOTsquare root 1 tvNTHROOTnth root 14 tmFRACT fractionsFracBoxClass variation symboldescription 0 tvFFRACTfull-size slots 1 tvPFRACTsubscript-size slots (piece fraction) 15 tmSCRIPT subscript/superscriptScrBoxClass variation symboldescription 0 tvSUPERsuperscript 1 tvSUBsubscript 2 tvSUBSUPboth 16 tmUBAR underbarBarBoxClass variation symboldescription 0 tvSUBARsingle underbar 1 tvDUBARdouble underbar 17 tmOBAR overbarBarBoxClass variation symboldescription 0 tvSOBARsingle overbar 1 tvDOBARdouble overbar 18 tmLARROW left-pointing arrowArroBoxClass variation symboldescription 0 tvLTARROWbox on top 1 tvLBARROWbox on bottom 19 tmRARROW right-pointing arrowArroBoxClass variation symboldescription 0 tvRTARROWbox on top 1 tvRBARROWbox on bottom 20 tmBARROW left- and right-pointing arrowArroBoxClass variation symboldescription 0 tvBTARROWbox on top 1 tvBBARROWbox on bottom 21 tmSINT single integralBigOpBoxClass variation symboldescription 0 tvNSINTno limits 1 tvLSINTlower limit only 2 tvBSINTboth limits 3 tvNCINTcontour, no limits 4 tvLCINTcontour, lower limit only 22 tmDINT double integralBigOpBoxClass variation symboldescription 0 tvNDINTno limits 1 tvLDINTlower limit only 2 tvNAINTarea, no limits 3 tvLAINTarea, lower limit only 23 tmTINT triple integralBigOpBoxClass variation symboldescription 0 tvNTINTno limits 1 tvLTINTlower limit only 2 tvNVINTvolume, no limits 3 tvLVINTvolume, lower limit only 24 tmSSINT single summation-style integralBigOpBoxClass variation symboldescription 0 tvBSSINTboth limits 1 tvLSSINTlower limit only 2 tvLCSINTcontour, lower limit only 25 tmDSINT double summation-style integralBigOpBoxClass variation symboldescription 0 tvLASINTarea, lower limit only 1 tvLDSINTlower limit only 26 tmTSINT triple summation-style integralBigOpBoxClass variation symboldescription 0 tvLVSINTvolume, lower limit only 1 tvLTSINTlower limit only 27 tmUHBRACE upper horizontal braceHBrBoxClass 28 tmLHBRACE lower horizontal braceHBrBoxClass 29 tmSUM summationBigOpBoxClass variation symboldescription 0 tvLSUMlower only 1 tvBSUMboth upper and lower limits 2 tvNSUMno limits 30 tmISUM summation (integral-style limits)BigOpBoxClass variation symboldescription 0 tvLISUMlower only 1 tvBISUMboth upper and lower limits 31 tmPROD productBigOpBoxClass variation symboldescription 0 tvLPRODlower only 1 tvBPRODboth upper and lower limits 2 tvNPRODno limits 32 tmIPROD product (integral-style limits)BigOpBoxClass variation symboldescription 0 tvLIPRODlower only 1 tvBIPRODboth upper and lower limits 33 tmCOPROD coproductBigOpBoxClass variation symboldescription 0 tvLCOPRODlower only 1 tvBCOPRODboth upper and lower limits 2 tvNCOPRODno limits 34 tmICOPROD coproduct (integral-style limits)BigOpBoxClass variation symboldescription 0 tvLICOPRODlower only 1 tvBICOPRODboth upper and lower limits 35 tmUNION unionBigOpBoxClass variation symboldescription 0 tvLUNIONlower only 1 tvBUNIONboth upper and lower limits 2 tvNUNIONno limits 36 tmIUNION union (integral-style limits)BigOpBoxClass variation symboldescription 0 tvLIUNIONlower only 1 tvBIUNIONboth upper and lower limits 37 tmINTER intersectionBigOpBoxClass variation symboldescription 0 tvLINTERlower only 1 tvBINTERboth upper and lower limits 2 tvNINTERno limits 38 tmIINTER intersection (integral-style limits)BigOpBoxClass variation symboldescription 0 tvLIINTERlower only 1 tvBIINTERboth upper and lower limits 39 tmLIM limitLimBoxClass variation symboldescription 0 tvULIMupper limit 1 tvLLIMlower limit 2 tvBLIMboth upper and lower limits 40 tmLDIV long divisionLDivBoxClass variation symboldescription 0 tvLDIVWwith upper slot 1 tvLDIVWOwithout upper slot 41 tmSLFRACT slash fractionsSlashBoxClass variation symboldescription 0 tvSLFNORMnormal 1 tvSLFBASEslots on baseline 2 tvSLFSUBsubscript-sized slots 42 tmINTOP big integral-style operatorsBigOpBoxClass variation symboldescription 0 tvUINTOPupper limit 1 tvLINTOPlower limit 2 tvBINTOPboth upper and lower limits 43 tmSUMOP big summation-style operatorsBigOpBoxClass variation symboldescription 0 tvUSUMOPupper limit 1 tvLSUMOPlower limit 2 tvBSUMOPboth upper and lower limits 44 tmLSCRIPT leading sub- and superscriptsScrBoxClass variation symboldescription 0 tvLSUPERsuperscript 1 tvLSUBsubscript 2 tvLSUBSUPsubscript and superscript 45 tmDIRAC Dirac deltaDiracBoxClass variation symboldescription 0 tvBDIRACboth left and right slots 1 tvLDIRACleft slot only 2 tvRDIRACright slot only 46 tmUARROW under arrowVectorBoxClass variation symboldescription 0 tvLUARROWleft-pointing 1 tvRUARROWright-pointing 2 tvDUARROWdouble-headed (left and right) 47 tmOARROW over arrowVectorBoxClass variation symboldescription 0 tvLOARROWleft-pointing 1 tvROARROWright-pointing 2 tvDOARROWdouble-headed (left and right) 48 tmOARC over arcArcBoxClass 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 Back to MathType SDK intro page Table of Contents Abstract Introduction Header MTEF Byte Stream Record Details Template Selectors and Variations Template Subobject Order