OpenType Math Illuminated

Ulrik Vieth Vaihinger Straße 69 70567 Stuttgart Germany ulrik dot vieth (at) arcor dot de

Abstract In recent years, we have seen the development of new TEX engines, X TE EX and LuaTEX, adopting OpenType technology for providing support. While there are already plenty of OpenType text available for use, both from the TEX community and from commercial font suppliers, there is little support for OpenType math fonts so far. Ironically, it was left to to develop a de facto standard for OpenType math font information and to provide the first reference implementation of a full-featured OpenType math font. In order to develop the much-needed math support for Latin Modern and TEX Gyre fonts, it will be crucially important to develop a good understanding of the internals of OpenType math tables, much as it is necessary to develop a good understanding of Appendix G and TEX’s \fontdimen parameters to develop math support for traditional TEX fonts. In this paper, we try to help improve the understanding of OpenType math internals, summarizing the parameters of OpenType math fonts as well as illustrating the similarities and differences between traditional TEX math fonts and OpenType math fonts.

1 Background on OpenType math Ironically, it was left to Microsoft to develop the first system to offer support for Unicode math. In recent years, the TEX community has been go- ing through a phase of very significant developments. When Microsoft introduced support for math type- Among the most important achievements, we have setting in Office 2007 [1,2], they extended the Open- Type font format and commissioned the design of seen the development of new TEX engines, X TE EX Math [3] as a reference implementation of and LuaTEX, providing support for Unicode and OpenType font technology. At about the same time a full-featured OpenType math font. we have also seen the development of new font dis- Fortunately for us, Microsoft was smart enough to borrow from the best examples of math typeset- tributions, Latin Modern and TEX Gyre, provided simultaneously in Type 1 format as a set of 8-bit ting technology, thus many concepts of OpenType font encodings as well as in OpenType format. math are not only derived from the model of TEX, but also go beyond T X and introduce extensions or Together these developments have enabled TEX E users to keep up with current trends in the publish- generalizations of familiar concepts. While OpenType math is officially still consid- ing industry, providing users of the new TEX engines with a comprehensive set of free OpenType fonts ered experimental, it is quickly becoming a de facto and enabling them to take advantage of the many standard, as it has already been widely deployed to offerings by commercial font suppliers. millions of installations of Microsoft Office 2007 and As far as text typesetting is concerned, support it is also being been adopted by other projects such as the FontForge [4] font editor or independent font for OpenType font technology in the new TEX - gines is already very advanced, supporting not only designs such as Asana Math [5]. traditional typographic features of Latin alphabets, Most importantly, support for OpenType math but also addressing the very complex and challeng- has already been implemented or is currently being ing requirements of . implemented in the new TEX engines, thus adopting However, when it comes to math typesetting, OpenType math for the development of the much- needed Unicode math support for Latin Modern and one of the traditional strongholds of TEX, support for Unicode and OpenType math is only just begin- TEX Gyre obviously seems to be most promising ning to take shape. choice of technology.

Preprint: Proceedings of the BachoTEX 2009 conference 1001 Ulrik Vieth

2 Design and quality of math fonts In the following sections, we will discuss some When it comes to developing math fonts, designing of these parameters in more detail, illustrating the the shapes is only part of the job. Another similarities and differences between traditional TEX part, which is equally important, is to adjust the math fonts and OpenType math fonts. glyph metrics of individual and to set up the 4 Parameters of OpenType math fonts global parameters affecting various aspects of glyph positioning in math typesetting. The parameters of the OpenType MATH table play As we have discussed at previous conferences, a similar role as TEX’s \fontdimen parameters, con- the quality of math typesetting crucially depends trolling various aspects of math typesetting, such as on the fine-tuning of these parameters. Developing the placement of limits on big operators, the place- a good understanding of these parameters will there- ment of numerators and denominators in , fore become an important prerequisite to support or the placement of superscripts and subscripts. the development of new math fonts. While a number of parameters are specified in T X through the \fontdimen parameters of math In the case of traditional TEX math fonts, we E have to deal with the many \fontdimen parameters fonts, there are other parameters which are defined which have been analyzed in Bogusław Jackowski’s by built-in rules of TEX’s math typesetting engine. paper Appendix G Illuminated and a follow-up paper In many such cases, additional parameters have been by the present author [6,7]. introduced in the OpenType MATH table, making it In the case of OpenType math fonts, we need to possible to specify all the relevant parameters in the develop a similar understanding of the various tables math font without relying on built-in rules of any and parameters and how the concepts of OpenType particular typesetting engine. In view of the conference motto, it is interest- math relate to the concepts of TEX. ing to note that the two new TEX engines, X TE EX 3 Overview of the OpenType font format and LuaTEX, have taken a very different approach The OpenType font format [8] was developed jointly how to support the additional parameters of Open- by Adobe and Microsoft, based on elements of the Type math fonts: While X TE EX has retained TEX’s earlier PostScript and TrueType font formats by the original math typesetting engine and uses an inter- same vendors. The overall structure of OpenType nal mapping to set up \fontdimen parameters from fonts consists of a number of tables, some of which OpenType parameters [10], LuaTEX has introduced are required while others are optional [9]. an of TEX’s math typesetting engine [11], In the case of OpenType math, the extension of which will allow to take full advantage of most of 1 the font format essentially consists of adding another the additional OpenType parameters. optional table, the so-called MATH table, contain- For font designers developing OpenType math ing all the information related to math typesetting. fonts, it may be best to supply all of the additional Since it is an optional table, it would be interpreted OpenType parameters in order to make their fonts only by software which knows about it (such as the as widely usable as possible with any typesetting engine, not necessarily limited to any specific one of new TEX engines or Microsoft Office 2007), while it would be ignored by other software. the new TEX engines. Unlike a database table, which has a very rigid In the following sections, we will take a closer format, an OpenType font table can have a fairly look at the various groups of OpenType parameters, complex structure, combining a variety of different organized in a similar way as they are presented to kinds of information in the same table. In the case font designers in the FontForge font editor, but not of the OpenType MATH table, we have the following necessarily in the same order. kinds of information: We will use the figures from [6,7] as a visual clue to illustrate how the various parameters are de- • a number of global parameters specific to math fined in TEX, while summarizing the similarities and typesetting (similar to T X’s many \fontdimen E differences between OpenType parameters and TEX parameters of Appendix G) parameters in tabular form. • instructions for vertical and horizontal variants and/or constructions (similar to T X’s charlists E 1 More precisely, while X TE EX only provides access to the and extensible recipes) OpenType parameters as additional \fontdimens, LuaTEX • additional glyph metric information specific to uses an internal data structure based on the combined set of OpenType and TEX parameters, making it possible to supply math mode (such as italic corrections, accent missing values which are not supported in either OpenType placement, or ) math fonts or traditional TEX math fonts.

1002 Preprint: Proceedings of the BachoTEX 2009 conference OpenType Math Illuminated

ξ13 4.2 Stretch Stacks δ/2 Stretch stacks are a new feature in OpenType math ξ11 ≥ξ9 fonts, which do not have a direct correspondence in TEX. They can be understood in terms of material Z stacked above or below stretchable elements such as overbraces, underbraces or long arrows. In TEX, such elements were typically handled at the macro level and effectively treated in the same way as limits on big operators. In LuaTEX, such elements will be implemented by new primitives using either the new OpenType ≥ξ10 parameters for stretch stacks (as shown in table2) δ/2 ξ12 or the parameters for limits on big operators when

M=1 ξ using traditional T X math fonts. 13 E

Figure 1:TEX font metric parameters affecting the placement of limits above or below big operators. OpenType parameter TEX parameter StretchStackTopShiftUp ξ11 StretchStackGapAboveMin ξ9 4.1 Limits on big operators StretchStackGapBelowMin ξ10 In TEX math fonts, there are five parameters con- StretchStackBottomShiftDown ξ12 trolling the placement of limits on big operators (see figure1), which are denoted as ξ9 to ξ13 using the Table 2: Correspondence of font metric parameters notation of Appendix G. between OpenType and TEX related to stretch stacks. Two of them control the default position of the limits (ξ10 and ξ12), two of them control the inside gap (ξ9 and ξ11), while the final one controls the 4.3 Overbars and Underbars outside gap above and below the limits (ξ ). 13 In T X math fonts, there are no specific parameters In OpenType math fonts, the MATH table con- E related to the placement of overlines and underlines. tains only four parameters controlling the placement Instead, there is only one parameter controlling the of limits on big operators. Those four parameters default rule thickness (ξ ), which is used in a number have a direct correspondence to T X’s parameters 8 E of different situations where other parameters are (as shown in table1), while the remaining one has expressed in multiples of the rule thickness. no correspondence and is effectively set to zero.2 In OpenType math fonts, a different approach was taken, introducing extra parameters for each OpenType parameter TEX parameter purpose, even supporting different sets of parame- UpperLimitBaselineRiseMin ξ11 ters for overlines and underlines. Thus the MATH UpperLimitGapMin ξ9 table contains the following parameters related to LowerLimitGapMin ξ10 overlines and underlines (as shown in table3), which only have an indirect correspondence in T X. LowerLimitBaselineDropMin ξ12 E (no correspondence) ξ13 OpenType parameter T X parameter Table 1: Correspondence of font metric parameters E between OpenType and TEX affecting the placement OverbarExtraAscender (= ξ8) of limits above or below big operators. OverbarRuleThickness (= ξ8) OverbarVerticalGap (= 3 ξ8) 2 Considering the approach taken in other circumstances, UnderbarVerticalGap (= 3 ξ8) it is very likely that if there were any such correspondence, UnderbarRuleThickness (= ξ8) there might actually be two parameters in OpenType instead UnderbarExtraDescender (= ξ8) of only one, such as UpperLimitExtraAscender and LowerLimitExtraDescender. In LuaTEX’s internal data structures, there are actually two parameters for this purpose, which are either initialized from Table 3: Correspondence of font metric parameters TEX’s parameter ξ13 when using TEX math fonts or set to between OpenType and TEX affecting the placement zero when using OpenType math fonts. of overlines and underlines.

Preprint: Proceedings of the BachoTEX 2009 conference 1003 Ulrik Vieth

0 0 σ8 styles D,D σ8 styles D,D ϕ 0 0 σ9 other styles σ10 other styles 3ξ8 styles D,D ϕ 7ξ8 styles D,D ϕ ξ8 other styles 3ξ8 other styles 0 0 σ11 styles D,D σ11 styles D,D σ12 other styles σ12 other styles

Figure 2:TEX font metric parameters affecting the Figure 3:TEX’s boundary conditions affecting the placement of numerators and denominators in regular placement of numerators and denominators in regular and generalized fractions. and generalized fractions.

It is interesting to note that the introduction As shown in table4, there is a correspondence of additional parameters in OpenType math fonts for all TEX parameters, but this correspondence isn’t provides for greater flexibility of the font designer necessarily unique when the same TEX parameter is to adjust the values for best results. used for multiple purposes in fractions and stacks. While TEX’s built-in rules always use a fixed Obviously, font designers of OpenType math fonts multiplier of the rule thickness regardless of its size, should be careful about choosing the values of Open- OpenType math fonts can compensate for a larger Type parameters in a consistent way. rule thickness by using a smaller multiplier. An example can be found when inspecting the OpenType parameter T X parameter parameter values of Cambria Math: In relative terms E the inside gap is only about 2.5 times rather than FractionNumeratorDisplayStyleShiftUp σ8 3 times the rule thickness, while the latter (at about FractionNumeratorShiftUp σ9 0.65 pt compared to 0.4 pt) is quite a bit larger than FractionNumeratorDisplayStyleGapMin (= 3 ξ8) in typical TEX fonts. FractionNumeratorGapMin (= ξ8) Obviously, making use of the individual Open- FractionRuleThickness (= ξ8) Type parameters (as in LuaT X) instead of relying E FractionDenominatorDisplayStyleGapMin (= 3 ξ8) on T X’s built-in rules (as in X T X) would more E E E FractionDenominatorGapMin (= ξ ) closely reflect the intention of the font designer. 8 FractionDenominatorDisplayStyleShiftDown σ11 4.4 Fractions and Stacks FractionDenominatorShiftDown σ12 In TEX math fonts, there are five parameters control- StackTopDisplayStyleShiftUp σ8 ling the placement of numerators and denominators StackTopShiftUp σ10 (see figure2), which are denoted as σ8 to σ12 using StackDisplayStyleGapMin (= 7 ξ8) the notation of Appendix G. StackGapMin (= 3 ξ8) Four of them apply to regular fractions, either StackBottomDisplayStyleShiftDown σ11 in display style (σ and σ ) or in text style and 8 11 StackBottomShiftDown σ12 below (σ9 and σ12), while the remaining one applies to the special case of generalized fractions when the Table 4: Correspondence of font metric parameters bar is absent (σ10). between OpenType and TEX affecting the placement Besides those specific parameters, there are also of numerators and denominators. a number of parameters which are based on built-in rules of TEX’s math typesetting engine, expressed Analyzing the font parameters of Cambria Math in multiples of the rule thickness (ξ8), such as the once again shows how the introduction of additional thickness of the fraction rule or the inside gap above parameters increases the flexibility of the designer and below the fraction rule (see figure3). to adjust the parameters for best results: In relative In OpenType math fonts, a different approach terms, FractionDisplayStyleGapMin is only about 2 times was once again taken, introducing a considerable rather than 3 times the rule thickness. Similarly, number of additional parameters for each purpose. StackDisplayStyleGapMin is only about 4.5 times rather Thus the MATH table contains 9 parameters related than 7 times the rule thickness. In absolute terms, to regular fractions and 6 more parameters related however, both parameters are about the same order to generalized fractions (also known as stacks). of magnitude as in typical TEX fonts.

1004 Preprint: Proceedings of the BachoTEX 2009 conference OpenType Math Illuminated

σ13 σ14 σ15 4 5 σ5 1 σ16 4 σ5 σ17

σ↑18

4ξ8 4 4ξ8 5 σ5

σ↓19

Figure 4:TEX font metric parameters affecting the Figure 5:TEX font metric parameters affecting the placement of superscripts and subscripts on a simple placement of superscripts and subscripts in cases of character or a boxed subformula. resolving collisions.

4.5 Superscripts and Subscripts Besides those specific parameters, there are also In TEX math fonts, there are seven parameters con- a number of parameters which are based on TEX’s trolling the placement of superscripts and subscripts built-in rules, expressed in multiples of the x-height (see figure4), which are denoted as σ13 to σ19 using (σ5) or the rule thickness (ξ8), most of them related the notation of Appendix G. to resolving collisions between superscripts and sub- Three of them apply to superscripts, either in scripts or adjusting the position when a superscript display style (σ13), in text style and below (σ14), or or subscript becomes too big (see figure5). in cramped style (σ15), while the other two apply to In OpenType math fonts, we once again find the placement of subscripts, either with or without a number of additional parameters for each specific a superscript (σ16 and σ17). purpose, as shown in table5. Finally, there are two more parameters which It is interesting to note that some of the usual apply to superscripts and subscripts on a boxed sub- distinctions made in TEX were apparently omitted in formula (σ18 and σ19), which also apply to limits the OpenType MATH table, as there is no specific attached to big operators with \nolimits. value for the superscript position in display style, nor are there any differences in subscript position in the presence or absence of superscripts. OpenType parameter TEX parameter While it is not clear why there is no correspon-

SuperscriptShiftUp σ13, σ14 dence for these parameters, it is quite possible that there was a conscious design decision to omit them, SuperscriptShiftUpCramped σ15 perhaps to avoid inconsistencies in alignment. SubscriptShiftDown σ16, σ17 SuperscriptBaselineDropMax σ18 4.6 Radicals SubscriptBaselineDropMin σ19 In T X math fonts, there are no specific parameters 1 E SuperscriptBottomMin (= 4 σ5) related to typesetting radicals. Instead, the relevant 4 SubscriptTopMax (= 5 σ5) parameters are based on built-in rules of TEX’s math SubSuperscriptGapMin (= 4 ξ8) typesetting engine, expressed in multiples of the rule 4 thickness (ξ ) or the x-height (σ ). SuperscriptBottomMaxWithSubscript (= 5 σ5) 8 5 SpaceAfterScript \scriptspace To be precise, there are even more complica- tions involved [6], as the height of the fraction rule is Table 5: Correspondence of font metric parameters actually taken from the height of the fraction glyph between OpenType and TEX affecting the placement rather than the default rule thickness to account for of superscripts and subscripts. effects of pixel rounding in bitmap fonts.

Preprint: Proceedings of the BachoTEX 2009 conference 1005 Ulrik Vieth

In OpenType math fonts, we once again find a 4.7 General parameters number of additional parameters for each purpose, The final group of OpenType parameters combines a as shown in table6. mixed bag of parameters for various purposes. Some of them have a straight-forward correspondence in OpenType parameter TEX parameter TEX (such as the math axis position), while others do not have any correspondence at all. As shown in RadicalExtraAscender (= ξ8) table7, there are some very noteworthy parameters RadicalRuleThickness (= ξ8) 1 in this group, which deserve some further explana- RadicalDisplayStyleVerticalGap (= ξ8 + 4 σ5) 1 tions in the following . RadicalVerticalGap (= ξ8 + 4 ξ8) RadicalKernBeforeDegree e. g. 5/18 OpenType parameter TEX parameter RadicalKernAfterDegree e. g. 10/18 em ScriptPercentScaleDown e. g. 70–80 % RadicalDegreeBottomRaisePercent e. g. 60 % ScriptScriptPercentScaleDown e. g. 50–60 % Table 6: Correspondence of font metric parameters DisplayOperatorMinHeight ?? (e. g. 12–15 pt) between OpenType and TEX affecting the placement (no correspondence) σ20 (e. g. 20–24 pt) of radicals. DelimitedSubFormulaMinHeight σ21 (e. g. 10–12 pt) AxisHeight σ22 (axis height) While there is a correspondence for all of the AccentBaseHeight σ5 (x-height) parameters built into TEX’s typesetting algorithms, FlattenedAccentBaseHeight ?? (capital height) it is interesting to note that OpenType math has MathLeading unused also introduced some additional parameters related √ MinConnectorOverlap unused to the placement of the degree of an n th root ( n x ), which is usually handled at the macro level in TEX’s Table 7: Correspondence of font metric parameters format files plain. or latex.ltx: between OpenType and TEX affecting some general \newbox\rootbox aspects of math typesetting. \def\root#1\of{% \setbox\rootbox \hbox{$\m@th\scriptscriptstyle{#1}$}% (Script)ScriptPercentScaleDown \mathpalette\r@@t} These OpenType parameters represent the font sizes \def\r@@t#1#2{% of the first and second level script fonts relative to \setbox\z@\hbox{$\m@th#1\sqrtsign{#2}$}% the base font. In TEX math fonts, these parameters \dimen@=\ht\z@ \advance\dimen@-\dp\z@ do not have a correspondence in the font metrics. \mkern5mu\raise.6\dimen@\copy\rootbox Instead they are usually specified at the macro level \mkern-10mu\box\z@} when a family of math fonts is loaded. As shown in the listing, the definition of the \root If a font family provides multiple design sizes macro contains a number of hard-coded parameters, (as in ), font loading of math fonts such as a positive kern before the box containing in TEX might look like the following, using different the degree and negative kern thereafter, expressed in design sizes, each at their natural size: multiples of the font-specific math unit. In addition, \newfam\symbols there is also a raise factor expressed relative to the \textfont\symbols=cmsy10 size of the box containing the radical sign. \scriptfont\symbols=cmsy7 Obviously, the extra OpenType parameters re- \scriptscriptfont\symbols=cmsy5 lated to the degree of radicals correspond directly to If a font family does not provide multiple design the parameters used internally in the \root macro, sizes (as in MathTime), font loading of math fonts making it possible to supply a set of font-specific will use scaled-down versions of the base font: values instead of using hard-coded values expressed \newfam\symbols in multiples of font-specific units. \textfont\symbols=mtsy10 at 10pt In LuaTEX, this approach has been taken one \scriptfont\symbols=mtsy10 at 7.6pt step further, introducing a new \Uroot primitive as \scriptscriptfont\symbols=mtsy10 at 6pt an extension of the \Uradical primitive, making it The appropriate scaling factors depend on the font possible to replace the processing at the macro level design, but are usually defined in macro packages by processing at the algorithmic level in LuaTEX’s or in format files using higher-level macros such as extended math typesetting engine [11]. \DeclareMathSizes in LATEX.

1006 Preprint: Proceedings of the BachoTEX 2009 conference OpenType Math Illuminated

In OpenType math fonts, it will be possible to As a result, we will typically get 10 pt or 12 pt package optical design variants for script sizes into delimiters in text style and 18 pt or 24 pt delimiters a single font by using OpenType feature selectors to in display style. For typical settings, the delimiters address the design variants and using scaling factors only have to cover 90 % of the required size and they as specified in the MATH table.3 may fall short by at most 5 pt. The corresponding code for font loading of full- If a generalized fraction with delimiters is coded featured OpenType math fonts in new TEX engines like the following might look like the following: $ {n \atopwithdelims() k} $ \newfam\symbols the contents will be treated as a delimited fraction, \textfont\symbols="CambriaMath" and in this case the size of delimiters will depend on \scriptfont\symbols="CambriaMath:+ssty0" scaled the \fontdimen parameters σ20 and σ21 applicable \scriptscriptfont\symbols="CambriaMath:+ssty1" in either display style or text style. scaled As a result, regardless of the contents, we will If the font provides optical design variants for some always get 10 pt delimiters in text style and 24 pt letters and symbols, they will be substituted using delimiters in display style, even if 18 pt delimiters the +ssty0 or +ssty1 feature selectors, but the scal- would be big enough in the standard case. ing factor of (Script)ScriptPercentScaleDown will be applied While DelimitedSubFormulaMinHeight may be the best in any case regardless of substitutions. choice of OpenType parameters to supply a value for TEX’s \fontdimen parameters related to delimited DisplayOperatorMinHeight fractions, it will be insufficient by itself to represent This OpenType parameter represents the minimum a distinction between display style and text style values needed in T X. (Unless we simply assume a size of big operators in display style. While TEX E only supports two sizes of operators, which are used factor, such as σ20 = 2 σ21.) in text style and display style, OpenType can sup- In the absence of a better solution, it may be port multiple sizes of big operators and it needs an best to simply avoid using \atopwithdelims with additional parameter to determine the smallest size OpenType math fonts in the new TEX engines and to use in display style. to redefine user-level macros (such as \choose) in For font designers, it should be easy to set this terms of \left and \right delimiters. parameter based on the design size of big operators, e. g. using 14 pt for display style operators combined (Flattened)AccentBaseHeight with 10 pt for text style operators. These OpenType parameters affect the placement of math accents and are closely related to design parameters of the font design. DelimitedSubFormulaMinHeight While T X assumes that accents are designed This OpenType parameter represents the minimum E to fit on top of base glyphs which do not exceed size of delimited subformulas and it might also be the x-height (σ ) and adjusts the vertical position of applied to the special case of delimited fractions. 5 accents accordingly, OpenType provides a separate To illustrate the significance, some explanations parameter for this purpose, which doesn’t have to may be necessary to out the difference between match the x-height of the font, but plays a similar the usual case of fractions with delimiters and the role with respect to accent placement. special case of delimited fractions. In addition to that, OpenType has introduced If a generalized fraction with delimiters is coded another mechanism to replace accents by flattened like the following accents if the size of the base glyph exceeds a certain $ \left( {n \atop k} \right) $ size, which is most likely related to the height of the contents will be treated as a standard case of a capital letters. At the time of writing, support for generalized fraction, and the size of delimiters will flattened accents has not yet been implemented in be determined by taking into account the effects the new TEX engines, but it is being considered for of \delimiterfactor and \delimitershortfall LuaTEX version 0.40 [11]. as set up in the format file. In view of these developments, font designers are well advised to supply a complete set of values 3 As discussed in [12], there are many issues to consider for all the OpenType math parameters since new regarding the development of OpenType math fonts besides T X engines working on implementing full support setting up the font parameters. One such issue is the question E of font organization regarding the inclusion of optical design for OpenType math may start using them sooner variants into the base font. rather than later.

Preprint: Proceedings of the BachoTEX 2009 conference 1007 Ulrik Vieth

So far, we have discussed only one aspect of In OpenType math, these concepts have been the information contained in the OpenType MATH extended, so it would be possible to have multiple table, focusing on the global parameters which corre- sizes of display style operators as well as extensible spond to TEX’s \fontdimen parameters or to built- versions of operators, if desired. in rules of TEX’s math typesetting algorithms. While LuaTEX has already implemented most Besides those global parameters, there are other of the new features of OpenType math, it has not data structures in the OpenType MATH table, which yet addressed additional sizes of big operators, and are also important to consider, as we will discuss in it is not clear how that would be done. the following sections. Most likely, this would require some changes to the semantics of math markup at the user level, so 5 Instructions for vertical and horizontal that operators would be defined to apply to a scope variants and constructions of a subformula, which could then be measured to The concepts of vertical and horizontal variants and determine the required size of operators. constructions in OpenType math are obviously very In addition, such a change might also require similar to TEX’s concepts of charlists and extensible adding new parameters to decide when an opera- recipes. However, there are some subtle differences tor is big enough, similar to the role of the parame- regarding when and how these concepts are applied ters \delimiterfactor and \delimitershortfall in the math typesetting algorithms. in the case of big delimiters. In TEX, charlists and extensible recipes are only used in certain situations when typesetting elements 5.2 Horizontal variants and constructions such as big operators, big delimiters, big radicals or Wide accents When typesetting wide math ac- wide accents. In OpenType math fonts, these con- cents TEX uses charlists to switch to the next-larger cepts have been extended and generalized, allowing horizontal variants, but it doesn’t support extensible them to be used also for other stretchable elements recipes for horizontal constructions. such as long arrows or over- and underbraces. As a result, math accents in traditional TEX fonts cannot grow beyond a certain maximum size, 5.1 Vertical variants and constructions and stretchable horizontal elements of arbitrary size Big delimiters When typesetting big delimiters have to be implemented using other mechanisms, or radicals TEX uses charlists to switch to the next- such as alignments at the macro level. larger vertical variants, optionally followed by exten- In OpenType math, these concepts have been sible recipes for vertical constructions. In OpenType extended, making it possible to introduce extensible math, these concepts apply in the same way. versions of wide math accents (or similar elements), It is customary to provide at least four fixed-size if desired. In addition, new mechanisms for bottom variants, using a progression of sizes such as 12 pt, accents have also been added, complementing the 18 pt, 24 pt, 30 pt, before switching to an extensible existing mechanisms for top accents. version, but there is no requirement for that other than compatibility and user expectations.4 Over- and underbraces When typesetting some Font designers are free to provide any number stretchable elements such as over- and underbraces, of additional or intermediate sizes, but in TEX they TEX uses an alignment construction at the macro used to be limited by constraints such as 256 glyphs level to get an extensible brace of the required size, per 8-bit font table and no more than 16 different which is then typeset as a math operator with upper heights and depths in TFM files. In OpenType math or lower limits attached. fonts, they are no longer subject to such restrictions, While it would be possible to define extensible and in the example of Cambria Math big delimiters over- and underbraces in OpenType math fonts as are indeed provided in seven sizes. extensible versions of math accents, the semantics of math accents aren’t well suited to handle upper Big operators When typesetting big operators or lower limits attached to those elements. In LuaT X, new primitives \Uoverdelimiter TEX uses the charlist mechanism to switch from text E style to display style operators, but only once. There and \Uunderdelimiter have been added as a new is no support for multiple sizes of display operators, concept to represent stretchable horizontal elements nor are there extensible versions. which may have upper or lower limits attached. The placement of these limits is handled similar to limits 4 At the macro level these sizes can be accessed by using on big operators in terms of so-called ‘stretch stacks’ \big (12 pt), \Big (18 pt), \bigg (24 pt), \Bigg (30 pt). as discussed earlier in section 4.2.

1008 Preprint: Proceedings of the BachoTEX 2009 conference OpenType Math Illuminated

Long arrows In TEX math fonts, long horizontal Setting up vertical or horizontal constructions arrows are constructed at the macro level by over- is slightly more complicated, as it also requires some lapping the glyphs of short arrows and suitable ex- additional information which pieces are of fixed size tension modules (such as − or =). Similarly, arrows and which are extensible, such as with hooks or tails are constructed by overlapping integral : integralbt:0 uni23AE:1 integraltp:0 the glyphs of regular arrows and suitable glyphs for or the hooks or tails. arrowboth : In OpenType math fonts, all such constructions arrowleft.left:0 uni23AF:1 arrowright.right:0 can be defined at the font level in terms of horizontal It is interesting to note that some of the building constructions rather than relying on the macro level. blocks (such as uni23AE or uni23AF) have Unicode However, in most cases such constructions will also slots by themselves, while others have to placed in contain an extensible part, making the resulting long the private use area, using private glyph names such arrows strechable as well. as glyph.left, glyph.mid, or glyph.right. In LuaTEX, stretchable long arrows can also be Moreover, vertical or horizontal constructions defined using the new primitives \Uoverdelimiter may also contain multiple extensible parts, such as as discussed in the case of over- and underbraces. in the example of over- and underbraces, where the The placement of limits on such elements more or left, middle, and right parts are of fixed size while less corresponds to using macros such as \stackrel the extensible part appears twice on either side. to stack text on top of a relation symbol. 6 Additional glyph metric information 5.3 Encoding of variants and constructions Besides the global parameters and the instructions In traditional TEX math fonts, glyphs are addressed for vertical and horizontal variants and construc- by a slot number in a font-specific output encoding. tions, there is yet another kind of information stored Each variant glyph in a charlist and each building in the OpenType MATH table, containing additions block in an extensible recipe needs to have a slot of to the font metrics of individual glyphs. its own in the font table. However, only the entry In traditional TEX math fonts, the file format of points to the charlists need to be encoded at the TFM fonts only provides a limited number of fields macro level and these entry points in a font-specific to store font metric information. As a workaround, input encoding do not even have to coincide with certain fields which are needed in math mode only the slot numbers in the output encoding. are stored in rather non-intuitive way by overloading In OpenType math fonts, the situation is some- fields for other purposes [13]. what different. The underlying input encoding is For example, the nominal width of a glyph is assumed to consist of Unicode characters. However used to store the subscript position, while the italic these Unicode codes are internally mapped to font correction is used to indicate the horizontal offset programs using glyph names, which can be either between the subscript and superscript position. symbolic (such as summation or integral) or purely As a result, the nominal width doesn’t represent technical (such as uni2345 or glyph3456). the actual width of the glyph and the accent position With few exceptions, most of the variant glyphs may turn out incorrect. As a secondary correction, and building blocks cannot be allocated in standard fake kern pairs with a so-called skewchar are used to Unicode slots, so these glyphs have to be mapped to store an offset to the accent position. the private use area with font-specific glyph names. In OpenType math fonts, all such non-intuitive In Cambria Math, variant glyphs use suffix names ways of storing information can be avoided by using (such as glyph.vsize or glyph.hsize), while additional data fields for glyph-specific font metric other fonts such as Asana Math use different names information in the MATH table. (such as glyphbig or glyphwide). For example, the horizontal offset of the optical For font designers developing OpenType math center of a glyph is stored in a top_accent table, so fonts, setting up vertical or horizontal variants is any adjustments to the placement of math accents pretty straight-forward, such as can be expressed in a straight-forward way instead summation : summation.vsize1 summation.vsize2 ... of relying on kern pairs with a skewchar. integral : integral.vsize1 integral.vsize2 ... Similarly, the italic correction is no longer used or for the offset between superscripts and subscripts. Instead, the position of indices can be expressed tildecomb : tildecomb.hsize1 tildecomb.hsize2 more specifically in a math_kern array, representing provided that the variant glyphs use suffix names. cut-ins at each corner of the glyphs.

Preprint: Proceedings of the BachoTEX 2009 conference 1009 Ulrik Vieth

7 Summary and conclusions [6] Bogusław Jackowski: Appendix G Illuminated. In this paper, we have tried to help improve the Proceedings of the 16th EuroTEX Conference understanding of the internals of OpenType math 2006, Debrecen, Hungary. fonts. We have done this in order to contribute to http://www.gust.org.pl/projects/e-foundry/ the much-needed development of math support for math-support/tb87jackowski. Latin Modern and TEX Gyre fonts. [7] Ulrik Vieth: Understanding the æsthetics of In the previous sections, we have discussed the math typesetting. Biuletyn GUST, 5–12, 2008. parameters of the OpenType MATH table in great Proceedings of the 16th BachoTEX Conference detail, illustrating the similarities and differences be- 2008, Bachotek, Poland. tween traditional TEX math fonts and OpenType http://www.gust.org.pl/projects/e-foundry/ math fonts. However, we have covered other aspects math-support/vieth2008.pdf of OpenType math fonts only superficially, as it is [8] Microsoft Typography: OpenType specifica- impossible to cover everything in one paper. tion. Version 1.5, May 2008. For a more extensive overview of the features http://www.microsoft.com/typography/otspec/ and functionality of OpenType math fonts as well [9] Yannis Haralambous: Fonts and Encodings. as a discussion of the resulting challenges to font O’Reilly Media, 2007. ISBN 0-596-10242-9 developers, readers are also referred to [12]. http://oreilly.com/catalog/9780596102425/ In view of the conference motto, it is interesting [10] Will Robertson: The unicode-math package. to note that recent versions of LuaTEX have started Version 0.3b, August 2008. to provide a full-featured implementation of Open- http://scripts.sil.org/svn-public/xetex/ Type math support in LuaTEX and Context [14, 15], TRUNK/texmf/source/xelatex/unicode-math/ which differs significantly from the implementation unicode-math.pdf of OpenType math support in X T X[10]. In this E E [11] Taco Hoekwater: LuaT X Reference Manual. paper, we have pointed out some of these differences, E Version 0.37, 31 March 2009. but further discussions of this topic are beyond of http://www.luatex.org/svn/trunk/manual/ the scope of this paper. luatexref-t.pdf Acknowledgments [12] Ulrik Vieth: Do we need a ‘Cork’ math font The author once again wishes to thank Bogusław encoding? TUGboat, 29(3), 426–434, 2008. Jackowski for permission to reproduce and adapt the Proceedings of the TUG 2008 Annual Meeting, figures from his paper Appendix G Illuminated [6]. Cork, Ireland. In addition, the author also wishes to acknowledge https://www.tug.org/members/TUGboat/tb29-3/ feedback and suggestions from Taco Hoekwater and tb93vieth.pdf Hans Hagen regarding the state of OpenType math [13] Ulrik Vieth: Math Typesetting: The Good, support in LuaTEX. The Bad, The Ugly. MAPS, 26, 207–216, 2001. Proceedings of the 12th EuroTEX Conference References 2001, Kerkrade, Netherlands. [1] Murray Sargent III: Math in Office Blog. http://www.ntg.nl/maps/26/27.pdf http://blogs.msdn.com/murrays/default.aspx [14] Taco Hoekwater: Math extensions in LuaTEX. [2] Murray Sargent III: High-quality editing and these proceedings display of mathematical text in Office 2007. [15] Hans Hagen: Unicode math in Context Mk IV. http://blogs.msdn.com/murrays/archive/2006/ these proceedings 09/13/752206.aspx [3] John Hudson, Ross Mills: Mathematical Type- setting: Mathematical and scientific typeset- ting solutions from Microsoft. Promotional Booklet, Microsoft, 2006. http://www.tiro.com/projects/ [4] George Williams: FontForge. Math typesetting information. http://fontforge.sourceforge.net/math.html [5] Apostolos Syropoulos: Asana Math. www.ctan.org/tex-archive/fonts/Asana-Math/

1010 Preprint: Proceedings of the BachoTEX 2009 conference