Word 2007 equations are written in RTF with control words that start with
\m. They mirror the Office Open XML math elements (OMML): deleting the
leading m gives the OMML element name, so \mf is
<m:f>. All of them are new in the RTF 1.9.1 specification, which flags them as added for Word
2007. Properties are
set in two ways: with a number, as in \msty2, or with a small group holding
a word, as in {\mtype skw}, copied from OMML’s
<m:type m:val="skw"/>. Switches written as groups take
on or off.
Math zones
A math zone is a stretch of text in which math typography applies. A zone that
fills a whole paragraph is a display zone, shown on its own lines; one with other
text before or after it (other than \par) is inline and set more
compactly, like TeX’s $ and $$.
{\mmath {\*\moMath …}{\mmathPict …}} inline zone
{\mmath{\*\moMathPara{\moMathParaPr …}{\*\moMath …}+}{\mmathPict …}} display zone
Each {\*\moMath …} is one equation; in a math paragraph each starts on a
new line. {\mmathPict …} holds pictures of the equation (a
\shppict and a \nonshppict) for readers that skip the
ignorable \moMath group. A text paragraph may hold several math
paragraphs separated by lines of ordinary text.
<mathzone> '{' \mmath (<mathpara> | <mathinline>) <mathpict>? '}'
<mathpara> '{\*' \moMathPara <mathparaprops>? <oMath>+ '}'
<mathparaprops> '{' \moMathParaPr \mjcN? '}'
<mathinline> <oMath>
<oMath> '{\*' \moMath \fN (<mathobject> | <r>)* '}'
<r> '{' \mr (\mnor | \mscrN \mstyN)? \mlit? <char>* <u>* '}'
<mathPict> '{' \mmathPict '{\*' \shppict <pict> '}{' \nonshppict <pict> '}}'
The \fN in \moMath should not be needed, since
\mmathFontN gives the default, but Word 2007 needs it.
The skewed fraction a/b, which OMML writes as <m:f><m:fPr><m:type
m:val="skw"/></m:fPr><m:num>…</m:num><m:den>…</m:den></m:f>,
is in RTF:
{\mf{\mfPr{\mctrlPr}{\mtype skw}}
{\mnum\u-10187?\u-9138?}
{\mden\u-10187?\u-9137?}}
The pairs of \u escapes are UTF-16 surrogates for the math italic
letters U+1D44E and U+1D44F. The properties group, with its {\mctrlPr}
even when empty, must be present for the text to take the surrounding character
formatting. Word itself writes such letters as {\mr\mscr0\msty2 a}.
Surrogate pairs must be inside a math object group or a {\mr …} run.
Document math properties
<mathprops> '{\*' \mmathPr <mathPr>* '}'
<mathPr> \mbrkBinN | \mbrkBinSubN | \mdefJcN | \mdispDefN | \minterSpN | \mintLimN |
\mintraSpN | \mlMarginN | \mmathFontN | \mnaryLimN | \mpostSpN | \mpreSpN |
\mrMarginN | \msmallFracN | \mwrapIndentN | \mwrapRightN
| Control word | Meaning |
|---|---|
\*\mmathPr | The document’s math properties. |
\mmathFontN | Default math font: index N in the font table. |
\mbrkBinN | Line break at a binary operator: 0 or missing before the operator, 1 after it, 2 the operator is repeated at the end of one line and the start of the next. |
\mbrkBinSubN | With repeated operators, a minus sign at a break: 0 or missing − before and after, 1 + before and − after, 2 − before and + after. |
\mdefJcN | Default alignment of display zones: 1 or missing centred as a group (equations left-aligned within a block that is centred), 2 centred, 3 left, 4 right. |
\mdispDefN | 1 (default): use the math margins, alignment and wrapping settings instead of the paragraph’s; 0: use the paragraph settings. |
\mlMarginN, \mrMarginN | Left and right math margins in twips, added to the paragraph’s. |
\mwrapIndentN | Indent of wrapped equation lines, in twips; default 1440 (1 inch). |
\mwrapRightN | 1: right-align wrapped lines instead of indenting them. |
\mintLimN | Integral limits when built up from linear form in display mode: 0 or missing to the right of the sign, 1 above and below. |
\mnaryLimN | The same for other n-ary operators: 0 to the right, 1 above and below. |
\msmallFracN | 1: fractions in display math at script size; 0 (default) text size. |
\minterSpN | Space between equations in a display math paragraph, twips (default 0; not written by Word 2007). |
\mintraSpN | Space between consecutive display math paragraphs, twips (default 0; not written by Word 2007). |
\mpreSpN, \mpostSpN | Space before and after a math paragraph, twips (default 0; not supported by Word 2007). |
\mdiffStyN | Style of the differential ⅆ and U+2145–U+2149: 0 or missing math italic, 1 upright, 2 open-face italic. Word 2007 ignores it. |
Math objects
Each object group holds its properties group, then its arguments.
| Object | Syntax | Meaning |
|---|---|---|
\macc | {\macc <accPr> <e>} | Accent: a base and a combining mark. |
\mbar | {\mbar <barPr> <e>} | Overbar or underbar. |
\mborderBox | {\mborderBox <borderBoxPr> <e>} | A border round an equation. |
\mbox | {\mbox <boxPr> <e>} | Groups parts of an equation. |
\md | {\md <dPr> <e>+} | Delimiters (brackets, braces, bars) round one or more elements, with separators between them. |
\meqArr | {\meqArr <eqArrPr> <e>+} | Equation array: equations aligned as a unit, with alignment points inside. |
\mf | {\mf <fPr> <num> <den>} | Fraction (also used for stacks with no bar). |
\mfunc | {\mfunc <funcPr> <fname> <e>} | Function application, such as sin x. |
\mgroupChr | {\mgroupChr <groupChrPr> <e>} | A stretched character above or below, such as a brace. |
\mlimLow | {\mlimLow <limLowPr> <lim> <e>} | Text with smaller text below, such as lim over n→∞. (The grammar writes \mlimlow.) |
\mlimUpp | {\mlimUpp <limUppPr> <lim> <e>} | Text with smaller text above. |
\mm | {\mm <mPr> <mr>+} | Matrix of rows (no brackets: put it inside \md for those). |
\mnary | {\mnary <naryPr> <sub> <sup> <e>} | n-ary operator (integral, sum, product, union…) with limits. |
\mphant | {\mphant <phantPr> <e>} | Phantom: adds the space of its content without showing it, or hides part of a glyph from spacing. |
\mrad | {\mrad <radPr> <deg> <e>} | Radical with optional degree (the grammar leaves out <deg>; the argument list includes it). |
\msPre | {\msPre <sPrePr> <sub> <sup> <e>} | Subscript and superscript before the base. |
\msSub | {\msSub <sSubPr> <sub> <e>} | Subscript. |
\msSubSup | {\msSubSup <sSubSupPr> <sub> <sup> <e>} | Subscript and superscript. |
\msSup | {\msSup <sSupPr> <sup> <e>} | Superscript. |
Arguments and runs
| Control word | Meaning |
|---|---|
\me | Base element of every object except the fraction. |
\mnum, \mden | Numerator and denominator of a fraction. |
\mdeg | Degree of a radical (the 3 of a cube root); optional, a square root if missing. |
\mlim | Limit of \mlimLow or \mlimUpp. |
\mfName | Function name of \mfunc. |
\msub, \msup | Subscript and superscript arguments (also the limits of n-ary objects). |
\margPr | Argument properties: {\margSz N}, the size or script level; 1 is the next larger size. Only text, script and script-script sizes exist. |
\mr | A run of math text. (The grammar shows matrix rows as <mr> too; the word list names the matrix row \mmr.) |
\mrPr | Run properties group. |
\mnor | Normal text: no math italic or math spacing, and no automatic build-up. |
\mlit | Literal characters: no operator or build-up meaning. |
\mscrN | Alphabet: 0 roman, 1 script, 2 fraktur, 3 double-struck, 4 sans-serif, 5 monospace. With \msty, limited to the combinations Unicode has as math alphanumerics (UTR #25 §2.1). |
\mstyN | 0 upright, 1 bold, 2 italic, 3 bold italic. |
\mbrkN | Manual line break at the start of this box or run in a display zone; the new line aligns with the (N + 1)th operator of the first line. |
\mctrlPr | Character formatting of the object’s own characters (n-ary operator, fraction bar, grouping character), as differences from the paragraph’s; goes in every properties group. |
Object properties
| Group | May contain |
|---|---|
\maccPr | {\mchr c} (the accent; default U+0302), \mctrlPr |
\mbarPr | {\mpos top|bot} (default bot, underbar), \mctrlPr |
\mborderBoxPr | {\mhideTop on}, \mhideBot, \mhideLeft, \mhideRight (hide an edge; shown by default); \mstrikeH, \mstrikeV, \mstrikeBLTR, \mstrikeTLBR (horizontal, vertical, bottom-left to top-right and top-left to bottom-right strike lines; off by default) |
\mboxPr | \mopEmu (the box acts as one operator: a break point and alignment point), \maln (for an operator emulator: an alignment point), \mnoBreak (no line break inside), \mdiff (a differential, with its spacing), \mbrkN |
\mdPr | {\mbegChr c} (default (), {\mendChr c} (default )), {\msepChr c} (default |), {\mgrow on}, {\mshp match|centered} (delimiters fit the content’s height or are centred on it; default centered) |
\meqArrPr | {\mbaseJc …}, {\mmaxDist on} (spread to the width of the page, column or cell), {\mobjDist on} (spread to the array’s width), \mrSpN, \mrSpRuleN |
\mfPr | {\mtype bar|lin|skw|nobar}: stacked (default), linear a/b, skewed, stacked with no bar |
\mfuncPr, \mlimLowPr, \mlimUppPr, \msPrePr, \msSubPr, \msSupPr | \mctrlPr only |
\msSubSupPr | {\malnScr on} (align sub- and superscript with each other instead of kerning them to the base; off by default) |
\mgroupChrPr | {\mchr c} (default U+23DF), {\mpos top|bot}, {\mvertJc top|bot} (which edge of the object sits on the baseline) |
\mmPr | {\mbaseJc top|bot} (default centre; the specification’s example also writes center), \mcGpN, \mcGpRuleN, \mcSpN, \mmcs (columns), {\mplcHide on} (hide empty placeholders), \mrSpN, \mrSpRuleN |
\mmcs, \mmc, \mmcPr | Matrix columns: each \mmc has \mmcPr with {\mcount n} (how many columns it describes) and {\mmcJc left|center|right} (default centre). The grammar calls the latter \mmjc. |
\mmr | One row of a matrix. |
\mnaryPr | {\mchr c} (the operator; default U+222B ∫), {\mgrow on} (grow to the operand’s height), {\mlimLoc undovr|subsup} (limits above and below, or to the right), {\msubHide on}, {\msupHide on} |
\mphantPr | {\mshow off} (hide the content; shown by default), {\mzeroWid on}, {\mzeroAsc on}, {\mzeroDesc on} (count no width, ascent or descent), {\mtransp on} (the content’s spacing class, such as an operator, still counts) |
\mradPr | {\mdegHide on} (hide the degree; off by default) |
\moMathParaPr | \mjcN: alignment of the math paragraph, 1 or missing centred as a group, 2 centred, 3 left, 4 right |
\mrSpRuleN, \mcGpRuleN | Gap between rows (or columns) |
|---|---|
| 0 (default) | Single line (one em for columns) |
| 1 | 1.5 lines |
| 2 | 2 lines |
| 3 | Exactly \mrSpN (\mcGpN) twips |
| 4 | \mrSpN (\mcGpN) half lines |
\mcSpN is the minimum gap between the edges of adjacent matrix
columns (default 0).
Control words are case-sensitive. The specification’s control word index spells
some of these words differently from its math section: \mdispdefN,
\mlimloc, \mlimlowPr, \mlimupp,
\mlimuppPr and \mmaxdist, against
\mdispDefN, \mlimLoc, \mlimLowPr,
\mlimUpp, \mlimUppPr and \mmaxDist in the
definitions.
Source
Microsoft, Rich Text Format (RTF) Specification, version 1.9.1, 19 March 2008,
section “Mathematics” (Syntax, Math Objects, Math Object Arguments, Math RTF Control
Words) and Appendix B; the PDF copy Microsoft keeps for its Open Specifications
(officeprotocoldoc.z19.web.core.windows.net/files/Archive_References/[MSFT-RTF].pdf),
read in full for this page.