math-features.tex /size: 8021 b    last modification: 2021-10-28 13:50
1% language=us runpath=texruns:manuals/math
2
3\environment math-layout
4
5\usemodule[fonts-features]
6
7\startcomponent math-features
8
9\startchapter[title=Features]
10
11\startsection[title=Default features]
12
13Math fonts are loaded in so called basemode, which gives them a traditional
14treatment in the engine. However, we do support features in basemode too, so
15setting them can influence what gets passed to \TEX. Also, in math mode, some
16font features (like \type {dtls} and stylistic alternates) are applied
17dynamically.
18
19The default \type {mathematics} feature set is as follows:
20
21\showfeatureset[name=mathematics]
22
23We don't discuss the exact meaning of these options here because normally you
24don't have to deal with them. If a math font demands something special, the place
25to deal with it is the related font goodie file.
26
27This feature set is the parent of two other sets: \type {mathematics-l2r} and
28\type {mathematics-r2l}:
29
30\showfeatureset[name=mathematics-l2r]
31
32This one is the same as the parent but the right|-|to|-|left variant is
33different:
34
35\showfeatureset[name=mathematics-r2l]
36
37Eventually we need size related feature sets and again we define a parent and
38direction specific ones: \type {math-text}, \type {math-script} and \type
39{math-scriptscript}.
40
41\showfeatureset[name=math-text]
42\showfeatureset[name=math-script]
43\showfeatureset[name=math-scriptscript]
44
45The left|-|to|-|right sets \type {math-*-l2r} are:
46
47\showfeatureset[name=math-text-l2r]
48\showfeatureset[name=math-script-l2r]
49\showfeatureset[name=math-scriptscript-l2r]
50
51The right|-|to|-|left sets \type {math-*-r2l} are:
52
53\showfeatureset[name=math-text-r2l]
54\showfeatureset[name=math-script-r2l]
55\showfeatureset[name=math-scriptscript-r2l]
56
57There are a few extra sets defined but these are meant for testing or virtual
58math fonts. The reason for showing these sets is to make clear that the number of
59features is minimal and that math is a real script indeed.
60
61The \type {kern} features is questionable. In traditional \TEX\ there are kerns
62indeed but in \OPENTYPE\ math kerns are not used that way because a more advanced
63kerning feature is present (and that one is currently always enabled). We used to
64set the following but these make no sense.
65
66\starttyping
67liga=yes, % (traditional) ligatures
68tlig=yes, % tex ligatures, like -- and ---
69trep=yes, % tex replacements, like the ' quote
70\stoptyping
71
72Math fonts normally have no ligatures and supporting the \TEX\ specific ones can
73actually be annoying. So, in todays \CONTEXT\ these are no longer enabled. Just
74consider the following:
75
76\startbuffer
77$- \kern0pt -   \kern 0pt \mathchar"2D$
78$- \kern0pt --  \kern 0pt \mathchar"2D \mathchar"2D$
79$- \kern0pt --- \kern 0pt \mathchar"2D \mathchar"2D \mathchar"2D$
80\stopbuffer
81
82\typebuffer
83
84The \type {-} is mapped onto a minus sign and therefore several in succession
85become multiple minus signs. The \type {\mathchar"2D} will remain the character
86with that slot in the font so there we will see a hyphen. If we would enable the
87\type {tlig} feature several such characters would be combined into an endash or
88emdash. So how do we get these than? Because getting a hyphen directly involves a
89command, the same is true for its longer relatives: \type {\endash} and \type
90{\emdash}.
91
92\startlines
93\getbuffer
94\stoplines
95
96As convenience we have defined a special \type {\mathhyphen} command. Watch the
97fact that a text hyphen in math mode is a minus in math! As comparison we also
98show the plus sign.
99
100\starttabulate[||c|c|]
101\BC command            \BC math          \BC text        \NC \NR
102\TB
103\NC \type{\mathhyphen} \NC $\mathhyphen$ \NC \mathhyphen \NC \NR
104\NC \type{\texthyphen} \NC $\texthyphen$ \NC \texthyphen \NC \NR
105\NC \type{-}           \NC $-$           \NC -           \NC \NR
106\NC \type{+}           \NC $+$           \NC +           \NC \NR
107\NC \type{\endash}     \NC $\endash$     \NC \endash     \NC \NR
108\NC \type{\emdash}     \NC $\emdash$     \NC \emdash     \NC \NR
109\stoptabulate
110
111\stoptabulate
112
113\stopsection
114
115\startsection[title=Stylistic alternates]
116
117    {\em todo}
118
119\stopsection
120
121\startsection[title=Dotless variants]
122
123    {\em todo}
124
125\stopsection
126
127\startsection[title=Script kerning]
128
129Text in math is somewhat special. First of all, a math font is not a text fonts
130because the characters and glyphs have a different purpose. Text features are
131normally not present (and often not even wanted). Anyway, you can force a text
132font, but that doesn't mean you will get for instance kerning. You can force a
133box which in turn will trigger font processing, but then you normally loose the
134script related size properties. So we end up with some juggling possibly combined
135with user intervention, and that is what the \type {\text} macro does.
136
137But still there is the kern between a variable and its subscript to consider,
138something that normally is dealt with with staircase kerns, an \OPENTYPE\ math
139speciality. But, as we progress over the math list, and we bind a subscript to a
140variable, that subscript can be anything: a simple character, or more characters
141(a list) or something wrapped in a box. There is simply no universal solution
142that we can hard code because sometimes you don't want that special kerning. This
143is why in \LUATEX\ the integer variable \type {\mathscriptboxmode} controls the
144way this is dealt with.
145
146\starttabulate[|l|p|]
147\NC \type {0} \NC forget about kerning \NC \NR
148\NC \type {1} \NC kern math sub lists with a valid glyph (default in the engine) \NC \NR
149\NC \type {2} \NC also kern math sub boxes that have a valid glyph (default in \CONTEXT) \NC \NR
150\NC \type {3} \NC only kern math sub boxes with a boundary node present \NC \NR
151\stoptabulate
152
153Here we show some examples of how this parameter controls kerning. Watch the
154difference between a simple font switch and a text wrapped in a box. There are
155differences between fonts: some fonts have kerns, some don't. When present kerns
156are passed to the engine without further user intervention.
157
158\startbuffer[1]
159    $T_{\tf fluff}$
160\stopbuffer
161
162\startbuffer[2]
163    $T_{\text{fluff}}$
164\stopbuffer
165
166\startbuffer[3]
167    $T_{\text{\boundary1 fluff}}$
168\stopbuffer
169
170\unexpanded\def\Show#1#2#3%
171  {\doifelsenothing{#3}
172     {\typeinlinebuffer[#1]}
173     {\doifelse{#3}{-}
174        {\type{mode #2}}
175        {\switchtobodyfont[#3,big]\setstrut\strut\showfontkerns\showglyphs\mathscriptboxmode#2\relax\inlinebuffer[#1]}}}
176
177% \starttabulate[|lT|c|c|c|c|c|]
178%     \NC          \NC \Show{1}{0}{}         \NC\Show{1}{1}{}         \NC \Show{2}{1}{}         \NC \Show{2}{2}{}         \NC \Show{3}{3}{}         \NC \NR
179%     \NC          \NC \Show{1}{0}{-}        \NC\Show{1}{1}{-}        \NC \Show{2}{1}{-}        \NC \Show{2}{2}{-}        \NC \Show{3}{3}{-}        \NC \NR
180%     \NC modern   \NC \Show{1}{0}{modern}   \NC\Show{1}{1}{modern}   \NC \Show{2}{1}{modern}   \NC \Show{2}{2}{modern}   \NC \Show{3}{3}{modern}   \NC \NR
181%     \NC lucidaot \NC \Show{1}{0}{lucidaot} \NC\Show{1}{1}{lucidaot} \NC \Show{2}{1}{lucidaot} \NC \Show{2}{2}{lucidaot} \NC \Show{3}{3}{lucidaot} \NC \NR
182%     \NC pagella  \NC \Show{1}{0}{pagella}  \NC\Show{1}{1}{pagella}  \NC \Show{2}{1}{pagella}  \NC \Show{2}{2}{pagella}  \NC \Show{3}{3}{pagella}  \NC \NR
183%     \NC cambria  \NC \Show{1}{0}{cambria}  \NC\Show{1}{1}{cambria}  \NC \Show{2}{1}{cambria}  \NC \Show{2}{2}{cambria}  \NC \Show{3}{3}{cambria}  \NC \NR
184%     \NC dejavu   \NC \Show{1}{0}{dejavu}   \NC\Show{1}{1}{dejavu}   \NC \Show{2}{1}{dejavu}   \NC \Show{2}{2}{dejavu}   \NC \Show{3}{3}{dejavu}   \NC \NR
185% \stoptabulate
186
187\def\ShowMore#1#2%
188  {\subsubject{\Show{#1}{#2}{} (\Show{#1}{#2}{-})}
189   \starttabulate[|lT|c|c|c|c|c|]
190     \NC modern   \NC \Show{#1}{#2}{modern}   \NC \NR
191     \NC lucidaot \NC \Show{#1}{#2}{lucidaot} \NC \NR
192     \NC pagella  \NC \Show{#1}{#2}{pagella}  \NC \NR
193     \NC cambria  \NC \Show{#1}{#2}{cambria}  \NC \NR
194     \NC dejavu   \NC \Show{#1}{#2}{dejavu}   \NC \NR
195   \stoptabulate}
196
197\ShowMore{1}{0}
198\ShowMore{1}{1}
199\ShowMore{2}{1}
200\ShowMore{2}{2}
201\ShowMore{3}{3}
202
203\stopsection
204
205\stopchapter
206
207\stopcomponent
208