fix getsup (HH)
[luatex.git] / manual / luatex-math.tex
blobb19f5823f6adc679862ea599517428e195e59fbb
1 % language=uk
3 \environment luatex-style
4 \environment luatex-logos
6 \startcomponent luatex-math
8 \startchapter[reference=math,title={Math}]
10 The handling of mathematics in \LUATEX\ differs quite a bit from how \TEX82 (and
11 therefore \PDFTEX) handles math. First, \LUATEX\ adds primitives and extends some
12 others so that \UNICODE\ input can be used easily. Second, all of \TEX82's
13 internal special values (for example for operator spacing) have been made
14 accessible and changeable via control sequences. Third, there are extensions that
15 make it easier to use \OPENTYPE\ math fonts. And finally, there are some
16 extensions that have been proposed or considered in the past that are now added
17 to the engine.
19 \section{The current math style}
21 It is possible to discover the math style that will be used for a formula in an
22 expandable fashion (while the math list is still being read). To make this
23 possible, \LUATEX\ adds the new primitive: \type {\mathstyle}. This is a \quote
24 {convert command} like e.g. \type {\romannumeral}: its value can only be read,
25 not set.
27 \subsection{\type {\mathstyle}}
29 The returned value is between 0 and 7 (in math mode), or $-1$ (all other modes).
30 For easy testing, the eight math style commands have been altered so that the can
31 be used as numeric values, so you can write code like this:
33 \starttyping
34 \ifnum\mathstyle=\textstyle
35 \message{normal text style}
36 \else \ifnum\mathstyle=\crampedtextstyle
37 \message{cramped text style}
38 \fi \fi
39 \stoptyping
41 Sometimes you won't get what you expect so a bit of explanation might help to
42 understand what happens. When math is parsed and expanded it gets turned into a
43 linked list. In a second pass the formula will be build. This has to do with the
44 fact that in order to determine the automatically chosen sizes (in for instance
45 fractions) following content can influence preceding sizes. A side effect of this
46 is for instance that one cannot change the definition of a font family (and
47 thereby reusing numbers) because the number that got used is stored and used in
48 the second pass (so changing \type {\fam 12} mid|-|formula spoils over to
49 preceding use of that family).
51 The style switching primitives like \type {\textstyle} are turned into nodes so
52 the styles set there are frozen. The \type {\mathchoice} primitive results in
53 four lists being constructed of which one is used in the second pass. The fact
54 that some automatic styles are not yet known also means that the \type
55 {\mathstyle} primitive expands to the current style which can of course be
56 different from the one really used. It's a snapshot of the first pass state. As a
57 consequence in the following example you get a style number (first pass) typeset
58 that can actually differ from the used style (second pass). In the case of a math
59 choice used ungrouped, the chosen style is used after the choice too, unless you
60 group.
62 \startbuffer[1]
63 [a:\mathstyle]\quad
64 \bgroup
65 \mathchoice
66 {\bf \scriptstyle (x:d :\mathstyle)}
67 {\bf \scriptscriptstyle (x:t :\mathstyle)}
68 {\bf \scriptscriptstyle (x:s :\mathstyle)}
69 {\bf \scriptscriptstyle (x:ss:\mathstyle)}
70 \egroup
71 \quad[b:\mathstyle]\quad
72 \mathchoice
73 {\bf \scriptstyle (y:d :\mathstyle)}
74 {\bf \scriptscriptstyle (y:t :\mathstyle)}
75 {\bf \scriptscriptstyle (y:s :\mathstyle)}
76 {\bf \scriptscriptstyle (y:ss:\mathstyle)}
77 \quad[c:\mathstyle]\quad
78 \bgroup
79 \mathchoice
80 {\bf \scriptstyle (z:d :\mathstyle)}
81 {\bf \scriptscriptstyle (z:t :\mathstyle)}
82 {\bf \scriptscriptstyle (z:s :\mathstyle)}
83 {\bf \scriptscriptstyle (z:ss:\mathstyle)}
84 \egroup
85 \quad[d:\mathstyle]
86 \stopbuffer
88 \startbuffer[2]
89 [a:\mathstyle]\quad
90 \begingroup
91 \mathchoice
92 {\bf \scriptstyle (x:d :\mathstyle)}
93 {\bf \scriptscriptstyle (x:t :\mathstyle)}
94 {\bf \scriptscriptstyle (x:s :\mathstyle)}
95 {\bf \scriptscriptstyle (x:ss:\mathstyle)}
96 \endgroup
97 \quad[b:\mathstyle]\quad
98 \mathchoice
99 {\bf \scriptstyle (y:d :\mathstyle)}
100 {\bf \scriptscriptstyle (y:t :\mathstyle)}
101 {\bf \scriptscriptstyle (y:s :\mathstyle)}
102 {\bf \scriptscriptstyle (y:ss:\mathstyle)}
103 \quad[c:\mathstyle]\quad
104 \begingroup
105 \mathchoice
106 {\bf \scriptstyle (z:d :\mathstyle)}
107 {\bf \scriptscriptstyle (z:t :\mathstyle)}
108 {\bf \scriptscriptstyle (z:s :\mathstyle)}
109 {\bf \scriptscriptstyle (z:ss:\mathstyle)}
110 \endgroup
111 \quad[d:\mathstyle]
112 \stopbuffer
114 \typebuffer[1]
116 % \typebuffer[2]
118 This gives:
120 \blank $\displaystyle \getbuffer[1]$ \blank
121 \blank $\textstyle \getbuffer[1]$ \blank
123 Using \type {\begingroup} \unknown\ \type {\endgroup} instead gives:
125 \blank $\displaystyle \getbuffer[2]$ \blank
126 \blank $\textstyle \getbuffer[2]$ \blank
128 This might look wrong but it's just a side effect of \type {\mathstyle} expanding
129 to the current (first pass) style and the number being injected in the list that
130 gets converted in the second pass. It all makes sense and it illustrates the
131 importance of grouping. In fact, the math choice style being effective afterwards
132 has advantages. It would be hard to get it otherwise.
134 \subsection{\type {\Ustack}}
136 There are a few math commands in \TEX\ where the style that will be used is not
137 known straight from the start. These commands (\type {\over}, \type {\atop},
138 \type {\overwithdelims}, \type {\atopwithdelims}) would therefore normally return
139 wrong values for \type {\mathstyle}. To fix this, \LUATEX\ introduces a special
140 prefix command: \type {\Ustack}:
142 \starttyping
143 $\Ustack {a \over b}$
144 \stoptyping
146 The \type {\Ustack} command will scan the next brace and start a new math group
147 with the correct (numerator) math style.
149 \section{Unicode math characters}
151 Character handling is now extended up to the full \UNICODE\ range (the \type {\U}
152 prefix), which is compatible with \XETEX.
154 The math primitives from \TEX\ are kept as they are, except for the ones that
155 convert from input to math commands: \type {mathcode}, and \type {delcode}. These
156 two now allow for a 21-bit character argument on the left hand side of the equals
157 sign.
159 Some of the new \LUATEX\ primitives read more than one separate value. This is
160 shown in the tables below by a plus sign in the second column.
162 The input for such primitives would look like this:
164 \starttyping
165 \def\overbrace{\Umathaccent 0 1 "23DE }
166 \stoptyping
168 The altered \TEX82 primitives are:
170 \starttabulate[|l|l|r|c|l|r|]
171 \NC \bf primitive \NC \bf min \NC \bf max \NC \kern 2em \NC \bf min \NC \bf max \NC \NR
172 \NC \type {\mathcode} \NC 0 \NC 10FFFF \NC = \NC 0 \NC 8000 \NC \NR
173 \NC \type {\delcode} \NC 0 \NC 10FFFF \NC = \NC 0 \NC FFFFFF \NC \NR
174 \stoptabulate
176 The unaltered ones are:
178 \starttabulate[|l|l|r|]
179 \NC \bf primitive \NC \bf min \NC \bf max \NC \NR
180 \NC \type {\mathchardef} \NC 0 \NC 8000 \NC \NR
181 \NC \type {\mathchar} \NC 0 \NC 7FFF \NC \NR
182 \NC \type {\mathaccent} \NC 0 \NC 7FFF \NC \NR
183 \NC \type {\delimiter} \NC 0 \NC 7FFFFFF \NC \NR
184 \NC \type {\radical} \NC 0 \NC 7FFFFFF \NC \NR
185 \stoptabulate
187 For practical reasons \type {\mathchardef} will silently accept values larger
188 that \type {0x8000} and interpret it as \type {\Umathcharnumdef}. This is needed
189 to satisfy older macro packages.
191 The following new primitives are compatible with \XETEX:
193 % somewhat fuzzy:
195 \starttabulate[|l|l|r|c|l|r|]
196 \NC \bf primitive \NC \bf min \NC \bf max \NC \kern 2em \NC \bf min \NC \bf max \NC \NR
197 \NC \type {\Umathchardef} \NC 0+0+0 \NC 7+FF+10FFFF\rlap{\high{1}} \NC \NC \NC \NC \NR
198 \NC \type {\Umathcharnumdef}\rlap{\high{5}} \NC -80000000 \NC 7FFFFFFF\rlap{\high{3}} \NC \NC \NC \NC \NR
199 \NC \type {\Umathcode} \NC 0 \NC 10FFFF \NC = \NC 0+0+0 \NC 7+FF+10FFFF\rlap{\high{1}} \NC \NR
200 \NC \type {\Udelcode} \NC 0 \NC 10FFFF \NC = \NC 0+0 \NC FF+10FFFF\rlap{\high{2}} \NC \NR
201 \NC \type {\Umathchar} \NC 0+0+0 \NC 7+FF+10FFFF \NC \NC \NC \NC \NR
202 \NC \type {\Umathaccent} \NC 0+0+0 \NC 7+FF+10FFFF\rlap{\high{2,4}} \NC \NC \NC \NC \NR
203 \NC \type {\Udelimiter} \NC 0+0+0 \NC 7+FF+10FFFF\rlap{\high{2}} \NC \NC \NC \NC \NR
204 \NC \type {\Uradical} \NC 0+0 \NC FF+10FFFF\rlap{\high{2}} \NC \NC \NC \NC \NR
205 \NC \type {\Umathcharnum} \NC -80000000 \NC 7FFFFFFF\rlap{\high{3}} \NC \NC \NC \NC \NR
206 \NC \type {\Umathcodenum} \NC 0 \NC 10FFFF \NC = \NC -80000000 \NC 7FFFFFFF\rlap{\high{3}} \NC \NR
207 \NC \type {\Udelcodenum} \NC 0 \NC 10FFFF \NC = \NC -80000000 \NC 7FFFFFFF\rlap{\high{3}} \NC \NR
208 \stoptabulate
210 Specifications typically look like:
212 \starttyping
213 \Umathchardef\xx="1"0"456
214 \Umathcode 123="1"0"789
215 \stoptyping
217 Note 1: The new primitives that deal with delimiter|-|style objects do not set up a
218 \quote {large family}. Selecting a suitable size for display purposes is expected
219 to be dealt with by the font via the \type {\Umathoperatorsize} parameter (more
220 information can be found in a following section).
222 Note 2: For these three primitives, all information is packed into a single
223 signed integer. For the first two (\type {\Umathcharnum} and \type
224 {\Umathcodenum}), the lowest 21 bits are the character code, the 3 bits above
225 that represent the math class, and the family data is kept in the topmost bits
226 (This means that the values for math families 128--255 are actually negative).
227 For \type {\Udelcodenum} there is no math class. The math family information is
228 stored in the bits directly on top of the character code. Using these three
229 commands is not as natural as using the two- and three|-|value commands, so
230 unless you know exactly what you are doing and absolutely require the speedup
231 resulting from the faster input scanning, it is better to use the verbose
232 commands instead.
234 Note 3: The \type {\Umathaccent} command accepts optional keywords to control
235 various details regarding math accents. See \in {section} [mathacc] below for
236 details.
238 New primitives that exist in \LUATEX\ only (all of these will be explained
239 in following sections):
241 \starttabulate[|l|l|l|l|]
242 \NC \bf primitive \NC \bf value range (in hex) \NC \NR
243 \NC \type {\Uroot} \NC 0+0--FF+10FFFF$^2$ \NC \NR
244 \NC \type {\Uoverdelimiter} \NC 0+0--FF+10FFFF$^2$ \NC \NR
245 \NC \type {\Uunderdelimiter} \NC 0+0--FF+10FFFF$^2$ \NC \NR
246 \NC \type {\Udelimiterover} \NC 0+0--FF+10FFFF$^2$ \NC \NR
247 \NC \type {\Udelimiterunder} \NC 0+0--FF+10FFFF$^2$ \NC \NR
248 \stoptabulate
250 \section{Cramped math styles}
252 \LUATEX\ has four new primitives to set the cramped math styles directly:
254 \starttyping
255 \crampeddisplaystyle
256 \crampedtextstyle
257 \crampedscriptstyle
258 \crampedscriptscriptstyle
259 \stoptyping
261 These additional commands are not all that valuable on their own, but they come
262 in handy as arguments to the math parameter settings that will be added shortly.
264 In Eijkhouts \quotation {\TEX\ by Topic} the rules for handling styles in scripts
265 are described as follows:
267 \startitemize
268 \startitem
269 In any style superscripts and subscripts are taken from the next smaller style.
270 Exception: in display style they are in script style.
271 \stopitem
272 \startitem
273 Subscripts are always in the cramped variant of the style; superscripts are only
274 cramped if the original style was cramped.
275 \stopitem
276 \startitem
277 In an \type {..\over..} formula in any style the numerator and denominator are
278 taken from the next smaller style.
279 \stopitem
280 \startitem
281 The denominator is always in cramped style; the numerator is only in cramped
282 style if the original style was cramped.
283 \stopitem
284 \startitem
285 Formulas under a \type {\sqrt} or \type {\overline} are in cramped style.
286 \stopitem
287 \stopitemize
289 In \LUATEX\ one can set the styles in more detail which means that you sometimes
290 have to set both normal and cramped styles to get the effect you want. If we
291 force styles in the script using \type {\scriptstyle} and \type {\crampedscriptstyle}
292 we get this:
294 \startbuffer[demo]
295 \starttabulate
296 \NC default \NC $b_{x=xx}^{x=xx}$ \NC \NR
297 \NC script \NC $b_{\scriptstyle x=xx}^{\scriptstyle x=xx}$ \NC \NR
298 \NC crampedscript \NC $b_{\crampedscriptstyle x=xx}^{\crampedscriptstyle x=xx}$ \NC \NR
299 \stoptabulate
300 \stopbuffer
302 \getbuffer[demo]
304 Now we set the following parameters
306 \startbuffer[setup]
307 \Umathordrelspacing\scriptstyle=30mu
308 \Umathordordspacing\scriptstyle=30mu
309 \stopbuffer
311 \typebuffer[setup]
313 This gives:
315 \start\getbuffer[setup,demo]\stop
317 But, as this is not what is expected (visually) we should say:
319 \startbuffer[setup]
320 \Umathordrelspacing\scriptstyle=30mu
321 \Umathordordspacing\scriptstyle=30mu
322 \Umathordrelspacing\crampedscriptstyle=30mu
323 \Umathordordspacing\crampedscriptstyle=30mu
324 \stopbuffer
326 \typebuffer[setup]
328 Now we get:
330 \start\getbuffer[setup,demo]\stop
332 \section{Math parameter settings}
334 In \LUATEX, the font dimension parameters that \TEX\ used in math typesetting are
335 now accessible via primitive commands. In fact, refactoring of the math engine
336 has resulted in many more parameters than were accessible before.
338 \starttabulate
339 \NC \bf primitive name \NC \bf description \NC \NR
340 \NC \type {\Umathquad} \NC the width of 18 mu's \NC \NR
341 \NC \type {\Umathaxis} \NC height of the vertical center axis of
342 the math formula above the baseline \NC \NR
343 \NC \type {\Umathoperatorsize} \NC minimum size of large operators in display mode \NC \NR
344 \NC \type {\Umathoverbarkern} \NC vertical clearance above the rule \NC \NR
345 \NC \type {\Umathoverbarrule} \NC the width of the rule \NC \NR
346 \NC \type {\Umathoverbarvgap} \NC vertical clearance below the rule \NC \NR
347 \NC \type {\Umathunderbarkern} \NC vertical clearance below the rule \NC \NR
348 \NC \type {\Umathunderbarrule} \NC the width of the rule \NC \NR
349 \NC \type {\Umathunderbarvgap} \NC vertical clearance above the rule \NC \NR
350 \NC \type {\Umathradicalkern} \NC vertical clearance above the rule \NC \NR
351 \NC \type {\Umathradicalrule} \NC the width of the rule \NC \NR
352 \NC \type {\Umathradicalvgap} \NC vertical clearance below the rule \NC \NR
353 \NC \type {\Umathradicaldegreebefore}\NC the forward kern that takes place before placement of
354 the radical degree \NC \NR
355 \NC \type {\Umathradicaldegreeafter} \NC the backward kern that takes place after placement of
356 the radical degree \NC \NR
357 \NC \type {\Umathradicaldegreeraise} \NC this is the percentage of the total height and depth of
358 the radical sign that the degree is raised by; it is
359 expressed in \type {percents}, so 60\% is expressed as the
360 integer $60$ \NC \NR
361 \NC \type {\Umathstackvgap} \NC vertical clearance between the two
362 elements in a \type {\atop} stack \NC \NR
363 \NC \type {\Umathstacknumup} \NC numerator shift upward in \type {\atop} stack \NC \NR
364 \NC \type {\Umathstackdenomdown} \NC denominator shift downward in \type {\atop} stack \NC \NR
365 \NC \type {\Umathfractionrule} \NC the width of the rule in a \type {\over} \NC \NR
366 \NC \type {\Umathfractionnumvgap} \NC vertical clearance between the numerator and the rule \NC \NR
367 \NC \type {\Umathfractionnumup} \NC numerator shift upward in \type {\over} \NC \NR
368 \NC \type {\Umathfractiondenomvgap} \NC vertical clearance between the denominator and the rule \NC \NR
369 \NC \type {\Umathfractiondenomdown} \NC denominator shift downward in \type {\over} \NC \NR
370 \NC \type {\Umathfractiondelsize} \NC minimum delimiter size for \type {\...withdelims} \NC \NR
371 \NC \type {\Umathlimitabovevgap} \NC vertical clearance for limits above operators \NC \NR
372 \NC \type {\Umathlimitabovebgap} \NC vertical baseline clearance for limits above operators \NC \NR
373 \NC \type {\Umathlimitabovekern} \NC space reserved at the top of the limit \NC \NR
374 \NC \type {\Umathlimitbelowvgap} \NC vertical clearance for limits below operators \NC \NR
375 \NC \type {\Umathlimitbelowbgap} \NC vertical baseline clearance for limits below operators \NC \NR
376 \NC \type {\Umathlimitbelowkern} \NC space reserved at the bottom of the limit \NC \NR
377 \NC \type {\Umathoverdelimitervgap} \NC vertical clearance for limits above delimiters \NC \NR
378 \NC \type {\Umathoverdelimiterbgap} \NC vertical baseline clearance for limits above delimiters \NC \NR
379 \NC \type {\Umathunderdelimitervgap} \NC vertical clearance for limits below delimiters \NC \NR
380 \NC \type {\Umathunderdelimiterbgap} \NC vertical baseline clearance for limits below delimiters \NC \NR
381 \NC \type {\Umathsubshiftdrop} \NC subscript drop for boxes and subformulas \NC \NR
382 \NC \type {\Umathsubshiftdown} \NC subscript drop for characters \NC \NR
383 \NC \type {\Umathsupshiftdrop} \NC superscript drop (raise, actually) for boxes and subformulas \NC \NR
384 \NC \type {\Umathsupshiftup} \NC superscript raise for characters \NC \NR
385 \NC \type {\Umathsubsupshiftdown} \NC subscript drop in the presence of a superscript \NC \NR
386 \NC \type {\Umathsubtopmax} \NC the top of standalone subscripts cannot be higher than this
387 above the baseline \NC \NR
388 \NC \type {\Umathsupbottommin} \NC the bottom of standalone superscripts cannot be less than
389 this above the baseline \NC \NR
390 \NC \type {\Umathsupsubbottommax} \NC the bottom of the superscript of a combined super- and subscript
391 be at least as high as this above the baseline \NC \NR
392 \NC \type {\Umathsubsupvgap} \NC vertical clearance between super- and subscript \NC \NR
393 \NC \type {\Umathspaceafterscript} \NC additional space added after a super- or subscript \NC \NR
394 \NC \type {\Umathconnectoroverlapmin}\NC minimum overlap between parts in an extensible recipe \NC \NR
395 \stoptabulate
397 Each of the parameters in this section can be set by a command like this:
399 \starttyping
400 \Umathquad\displaystyle=1em
401 \stoptyping
403 they obey grouping, and you can use \type {\the\Umathquad\displaystyle} if
404 needed.
406 \section{Skips around display math}
408 The injection of \type {\abovedisplayskip} and \type {\belowdisplayskip} is not
409 symmetrical. An above one is always inserted, also when zero, but the below is
410 only inserted when larger than zero. Especially the later makes it sometimes hard
411 to fully control spacing. Therefore \LUATEX\ comes with a new directive: \type
412 {\mathdisplayskipmode}. The following values apply:
414 \starttabulate
415 \NC 0 \NC normal \TEX\ behaviour: always above, only below when larger than zero \NC \NR
416 \NC 1 \NC always \NC \NR
417 \NC 2 \NC only when not zero \NC \NR
418 \NC 3 \NC never, not even when not zero \NC \NR
419 \stoptabulate
421 \section{Font-based Math Parameters}
423 While it is nice to have these math parameters available for tweaking, it would
424 be tedious to have to set each of them by hand. For this reason, \LUATEX\
425 initializes a bunch of these parameters whenever you assign a font identifier to
426 a math family based on either the traditional math font dimensions in the font
427 (for assignments to math family~2 and~3 using \TFM|-|based fonts like \type
428 {cmsy} and \type {cmex}), or based on the named values in a potential \type
429 {MathConstants} table when the font is loaded via Lua. If there is a \type
430 {MathConstants} table, this takes precedence over font dimensions, and in that
431 case no attention is paid to which family is being assigned to: the \type
432 {MathConstants} tables in the last assigned family sets all parameters.
434 In the table below, the one|-|letter style abbreviations and symbolic tfm font
435 dimension names match those using in the \TeX book. Assignments to \type
436 {\textfont} set the values for the cramped and uncramped display and text styles,
437 \type {\scriptfont} sets the script styles, and \type {\scriptscriptfont} sets
438 the scriptscript styles, so we have eight parameters for three font sizes. In the
439 \TFM\ case, assignments only happen in family~2 and family~3 (and of course only
440 for the parameters for which there are font dimensions).
442 Besides the parameters below, \LUATEX\ also looks at the \quote {space} font
443 dimension parameter. For math fonts, this should be set to zero.
445 \start
447 \switchtobodyfont[8pt]
449 \starttabulate[|l|l|l|p|]
450 \NC \bf variable \NC \bf style \NC \bf default value opentype \NC \bf default value tfm \NC \NR
451 \NC \type {\Umathaxis} \NC -- \NC AxisHeight \NC axis_height \NC \NR
452 \NC \type {\Umathoperatorsize} \NC D, D' \NC DisplayOperatorMinHeight \NC $^6$ \NC \NR
453 \NC \type {\Umathfractiondelsize} \NC D, D' \NC FractionDelimiterDisplayStyleSize$^9$ \NC delim1 \NC \NR
454 \NC \NC T, T', S, S', SS, SS' \NC FractionDelimiterSize$^9$ \NC delim2 \NC \NR
455 \NC \type {\Umathfractiondenomdown} \NC D, D' \NC FractionDenominatorDisplayStyleShiftDown \NC denom1 \NC \NR
456 \NC \NC T, T', S, S', SS, SS' \NC FractionDenominatorShiftDown \NC denom2 \NC \NR
457 \NC \type {\Umathfractiondenomvgap} \NC D, D' \NC FractionDenominatorDisplayStyleGapMin \NC 3*default_rule_thickness \NC \NR
458 \NC \NC T, T', S, S', SS, SS' \NC FractionDenominatorGapMin \NC default_rule_thickness \NC \NR
459 \NC \type {\Umathfractionnumup} \NC D, D' \NC FractionNumeratorDisplayStyleShiftUp \NC num1 \NC \NR
460 \NC \NC T, T', S, S', SS, SS' \NC FractionNumeratorShiftUp \NC num2 \NC \NR
461 \NC \type {\Umathfractionnumvgap} \NC D, D' \NC FractionNumeratorDisplayStyleGapMin \NC 3*default_rule_thickness \NC \NR
462 \NC \NC T, T', S, S', SS, SS' \NC FractionNumeratorGapMin \NC default_rule_thickness \NC \NR
463 \NC \type {\Umathfractionrule} \NC -- \NC FractionRuleThickness \NC default_rule_thickness \NC \NR
464 \NC \type {\Umathskewedfractionhgap} \NC -- \NC SkewedFractionHorizontalGap \NC math_quad/2 \NC \NR
465 \NC \type {\Umathskewedfractionvgap} \NC -- \NC SkewedFractionVerticalGap \NC math_x_height \NC \NR
466 \NC \type {\Umathlimitabovebgap} \NC -- \NC UpperLimitBaselineRiseMin \NC big_op_spacing3 \NC \NR
467 \NC \type {\Umathlimitabovekern} \NC -- \NC 0$^1$ \NC big_op_spacing5 \NC \NR
468 \NC \type {\Umathlimitabovevgap} \NC -- \NC UpperLimitGapMin \NC big_op_spacing1 \NC \NR
469 \NC \type {\Umathlimitbelowbgap} \NC -- \NC LowerLimitBaselineDropMin \NC big_op_spacing4 \NC \NR
470 \NC \type {\Umathlimitbelowkern} \NC -- \NC 0$^1$ \NC big_op_spacing5 \NC \NR
471 \NC \type {\Umathlimitbelowvgap} \NC -- \NC LowerLimitGapMin \NC big_op_spacing2 \NC \NR
472 \NC \type {\Umathoverdelimitervgap} \NC -- \NC StretchStackGapBelowMin \NC big_op_spacing1 \NC \NR
473 \NC \type {\Umathoverdelimiterbgap} \NC -- \NC StretchStackTopShiftUp \NC big_op_spacing3 \NC \NR
474 \NC \type {\Umathunderdelimitervgap} \NC-- \NC StretchStackGapAboveMin \NC big_op_spacing2 \NC \NR
475 \NC \type {\Umathunderdelimiterbgap} \NC-- \NC StretchStackBottomShiftDown \NC big_op_spacing4 \NC \NR
476 \NC \type {\Umathoverbarkern} \NC -- \NC OverbarExtraAscender \NC default_rule_thickness \NC \NR
477 \NC \type {\Umathoverbarrule} \NC -- \NC OverbarRuleThickness \NC default_rule_thickness \NC \NR
478 \NC \type {\Umathoverbarvgap} \NC -- \NC OverbarVerticalGap \NC 3*default_rule_thickness \NC \NR
479 \NC \type {\Umathquad} \NC -- \NC <font_size(f)>$^1$ \NC math_quad \NC \NR
480 \NC \type {\Umathradicalkern} \NC -- \NC RadicalExtraAscender \NC default_rule_thickness \NC \NR
481 \NC \type {\Umathradicalrule} \NC -- \NC RadicalRuleThickness \NC <not set>$^2$ \NC \NR
482 \NC \type {\Umathradicalvgap} \NC D, D' \NC RadicalDisplayStyleVerticalGap \NC (default_rule_thickness+\crlf
483 (abs(math_x_height)/4))$^3$ \NC \NR
484 \NC \NC T, T', S, S', SS, SS' \NC RadicalVerticalGap \NC (default_rule_thickness+\crlf
485 (abs(default_rule_thickness)/4))$^3$ \NC \NR
486 \NC \type {\Umathradicaldegreebefore} \NC -- \NC RadicalKernBeforeDegree \NC <not set>$^2$ \NC \NR
487 \NC \type {\Umathradicaldegreeafter} \NC -- \NC RadicalKernAfterDegree \NC <not set>$^2$ \NC \NR
488 \NC \type {\Umathradicaldegreeraise} \NC -- \NC RadicalDegreeBottomRaisePercent \NC <not set>$^{2,7}$ \NC \NR
489 \NC \type {\Umathspaceafterscript} \NC -- \NC SpaceAfterScript \NC script_space$^4$ \NC \NR
490 \NC \type {\Umathstackdenomdown} \NC D, D' \NC StackBottomDisplayStyleShiftDown \NC denom1 \NC \NR
491 \NC \NC T, T', S, S', SS, SS' \NC StackBottomShiftDown \NC denom2 \NC \NR
492 \NC \type {\Umathstacknumup} \NC D, D' \NC StackTopDisplayStyleShiftUp \NC num1 \NC \NR
493 \NC \NC T, T', S, S', SS, SS' \NC StackTopShiftUp \NC num3 \NC \NR
494 \NC \type {\Umathstackvgap} \NC D, D' \NC StackDisplayStyleGapMin \NC 7*default_rule_thickness \NC \NR
495 \NC \NC T, T', S, S', SS, SS' \NC StackGapMin \NC 3*default_rule_thickness \NC \NR
496 \NC \type {\Umathsubshiftdown} \NC -- \NC SubscriptShiftDown \NC sub1 \NC \NR
497 \NC \type {\Umathsubshiftdrop} \NC -- \NC SubscriptBaselineDropMin \NC sub_drop \NC \NR
498 \NC \type {\Umathsubsupshiftdown} \NC -- \NC SubscriptShiftDownWithSuperscript$^8$ \NC \NC \NR
499 \NC \NC \NC \quad\ or SubscriptShiftDown \NC sub2 \NC \NR
500 \NC \type {\Umathsubtopmax} \NC -- \NC SubscriptTopMax \NC (abs(math_x_height * 4) / 5) \NC \NR
501 \NC \type {\Umathsubsupvgap} \NC -- \NC SubSuperscriptGapMin \NC 4*default_rule_thickness \NC \NR
502 \NC \type {\Umathsupbottommin} \NC -- \NC SuperscriptBottomMin \NC (abs(math_x_height) / 4) \NC \NR
503 \NC \type {\Umathsupshiftdrop} \NC -- \NC SuperscriptBaselineDropMax \NC sup_drop \NC \NR
504 \NC \type {\Umathsupshiftup} \NC D \NC SuperscriptShiftUp \NC sup1 \NC \NR
505 \NC \NC T, S, SS, \NC SuperscriptShiftUp \NC sup2 \NC \NR
506 \NC \NC D', T', S', SS' \NC SuperscriptShiftUpCramped \NC sup3 \NC \NR
507 \NC \type {\Umathsupsubbottommax} \NC -- \NC SuperscriptBottomMaxWithSubscript \NC (abs(math_x_height * 4) / 5) \NC \NR
508 \NC \type {\Umathunderbarkern} \NC -- \NC UnderbarExtraDescender \NC default_rule_thickness \NC \NR
509 \NC \type {\Umathunderbarrule} \NC -- \NC UnderbarRuleThickness \NC default_rule_thickness \NC \NR
510 \NC \type {\Umathunderbarvgap} \NC -- \NC UnderbarVerticalGap \NC 3*default_rule_thickness \NC \NR
511 \NC \type {\Umathconnectoroverlapmin} \NC -- \NC MinConnectorOverlap \NC 0$^5$ \NC \NR
512 \stoptabulate
514 \stop
516 Note 1: \OPENTYPE\ fonts set \type {\Umathlimitabovekern} and \type
517 {\Umathlimitbelowkern} to zero and set \type {\Umathquad} to the font size of the
518 used font, because these are not supported in the \type {MATH} table,
520 Note 2: Traditional \TFM\ fonts do not set \type {\Umathradicalrule} because
521 \TEX82\ uses the height of the radical instead. When this parameter is indeed not
522 set when \LUATEX\ has to typeset a radical, a backward compatibility mode will
523 kick in that assumes that an oldstyle \TEX\ font is used. Also, they do not set
524 \type {\Umathradicaldegreebefore}, \type {\Umathradicaldegreeafter}, and \type
525 {\Umathradicaldegreeraise}. These are then automatically initialized to
526 $5/18$quad, $-10/18$quad, and 60.
528 Note 3: If \TFM\ fonts are used, then the \type {\Umathradicalvgap} is not set
529 until the first time \LUATEX\ has to typeset a formula because this needs
530 parameters from both family~2 and family~3. This provides a partial backward
531 compatibility with \TEX82, but that compatibility is only partial: once the \type
532 {\Umathradicalvgap} is set, it will not be recalculated any more.
534 Note 4: When \TFM\ fonts are used a similar situation arises with respect to
535 \type {\Umathspaceafterscript}: it is not set until the first time \LUATEX\ has
536 to typeset a formula. This provides some backward compatibility with \TEX82. But
537 once the \type {\Umathspaceafterscript} is set, \type {\scriptspace} will never
538 be looked at again.
540 Note 5: Traditional \TFM\ fonts set \type {\Umathconnectoroverlapmin} to zero
541 because \TEX82\ always stacks extensibles without any overlap.
543 Note 6: The \type {\Umathoperatorsize} is only used in \type {\displaystyle}, and
544 is only set in \OPENTYPE\ fonts. In \TFM\ font mode, it is artificially set to
545 one scaled point more than the initial attempt's size, so that always the \quote
546 {first next} will be tried, just like in \TEX82.
548 Note 7: The \type {\Umathradicaldegreeraise} is a special case because it is the
549 only parameter that is expressed in a percentage instead of as a number of scaled
550 points.
552 Note 8: \type {SubscriptShiftDownWithSuperscript} does not actually exist in the
553 \quote {standard} \OPENTYPE\ math font Cambria, but it is useful enough to be
554 added.
556 Note 9: \type {FractionDelimiterDisplayStyleSize} and \type
557 {FractionDelimiterSize} do not actually exist in the \quote {standard} \OPENTYPE\
558 math font Cambria, but were useful enough to be added.
560 \section{Nolimit correction}
562 There are two extra math parameters \type {\Umathnolimitsupfactor} and \type
563 {\Umathnolimitsubfactor} that were added to provide some control over how limits
564 are spaced (for example the position of super and subscripts after integral
565 operators). They relate to an extra parameter \type {\mathnolimitsmode}. The half
566 corrections are what happens when scripts are placed on above and below. The
567 problem with italic corrections is that officially that correction italic is used
568 for above|/|below placement while advanced kerns are used for placement at the
569 right end. The question is: how often is this implemented, and if so, does the
570 kerns assume correction too. Anyway, with this parameter one can control it.
572 \starttabulate[|l|ck1|ck1|ck1|ck1|ck1|ck1|]
574 \NC \mathnolimitsmode0 $\displaystyle\int\nolimits^0_1$
575 \NC \mathnolimitsmode1 $\displaystyle\int\nolimits^0_1$
576 \NC \mathnolimitsmode2 $\displaystyle\int\nolimits^0_1$
577 \NC \mathnolimitsmode3 $\displaystyle\int\nolimits^0_1$
578 \NC \mathnolimitsmode4 $\displaystyle\int\nolimits^0_1$
579 \NC \mathnolimitsmode8000 $\displaystyle\int\nolimits^0_1$
580 \NC \NR
582 \NC \bf mode
583 \NC \tttf 0
584 \NC \tttf 1
585 \NC \tttf 2
586 \NC \tttf 3
587 \NC \tttf 4
588 \NC \tttf 8000
589 \NC \NR
590 \NC \bf superscript
591 \NC 0
592 \NC font
593 \NC 0
594 \NC 0
595 \NC +ic/2
596 \NC 0
597 \NC \NR
598 \NC \bf subscript
599 \NC -ic
600 \NC font
601 \NC 0
602 \NC -ic/2
603 \NC -ic/2
604 \NC 8000ic/1000
605 \NC \NR
606 \stoptabulate
608 When the mode is set to one, the math parameters are used. This way a macro
609 package writer can decide what looks best. Given the current state of fonts in
610 \CONTEXT\ we currently use mode 1 with factor 0 for the superscript and 750 for
611 the subscripts. Positive values are used for both parameters but the subscript
612 shifts to the left. A \type {\mathnolimitsmode} larger that 15 is considered to
613 be a factor for the subscript correction. This feature can be handy when
614 experimenting.
616 \section{Math spacing setting}
618 Besides the parameters mentioned in the previous sections, there are also 64 new
619 primitives to control the math spacing table (as explained in Chapter~18 of the
620 \TEX book). The primitive names are a simple matter of combining two math atom
621 types, but for completeness' sake, here is the whole list:
623 \starttwocolumns
624 \starttyping
625 \Umathordordspacing
626 \Umathordopspacing
627 \Umathordbinspacing
628 \Umathordrelspacing
629 \Umathordopenspacing
630 \Umathordclosespacing
631 \Umathordpunctspacing
632 \Umathordinnerspacing
633 \Umathopordspacing
634 \Umathopopspacing
635 \Umathopbinspacing
636 \Umathoprelspacing
637 \Umathopopenspacing
638 \Umathopclosespacing
639 \Umathoppunctspacing
640 \Umathopinnerspacing
641 \Umathbinordspacing
642 \Umathbinopspacing
643 \Umathbinbinspacing
644 \Umathbinrelspacing
645 \Umathbinopenspacing
646 \Umathbinclosespacing
647 \Umathbinpunctspacing
648 \Umathbininnerspacing
649 \Umathrelordspacing
650 \Umathrelopspacing
651 \Umathrelbinspacing
652 \Umathrelrelspacing
653 \Umathrelopenspacing
654 \Umathrelclosespacing
655 \Umathrelpunctspacing
656 \Umathrelinnerspacing
657 \Umathopenordspacing
658 \Umathopenopspacing
659 \Umathopenbinspacing
660 \Umathopenrelspacing
661 \Umathopenopenspacing
662 \Umathopenclosespacing
663 \Umathopenpunctspacing
664 \Umathopeninnerspacing
665 \Umathcloseordspacing
666 \Umathcloseopspacing
667 \Umathclosebinspacing
668 \Umathcloserelspacing
669 \Umathcloseopenspacing
670 \Umathcloseclosespacing
671 \Umathclosepunctspacing
672 \Umathcloseinnerspacing
673 \Umathpunctordspacing
674 \Umathpunctopspacing
675 \Umathpunctbinspacing
676 \Umathpunctrelspacing
677 \Umathpunctopenspacing
678 \Umathpunctclosespacing
679 \Umathpunctpunctspacing
680 \Umathpunctinnerspacing
681 \Umathinnerordspacing
682 \Umathinneropspacing
683 \Umathinnerbinspacing
684 \Umathinnerrelspacing
685 \Umathinneropenspacing
686 \Umathinnerclosespacing
687 \Umathinnerpunctspacing
688 \Umathinnerinnerspacing
689 \stoptyping
690 \stoptwocolumns
692 These parameters are of type \type {\muskip}, so setting a parameter can be done
693 like this:
695 \starttyping
696 \Umathopordspacing\displaystyle=4mu plus 2mu
697 \stoptyping
699 They are all initialized by \type {initex} to the values mentioned in the table
700 in Chapter~18 of the \TEX book.
702 Note 1: for ease of use as well as for backward compatibility, \type
703 {\thinmuskip}, \type {\medmuskip} and \type {\thickmuskip} are treated
704 especially. In their case a pointer to the corresponding internal parameter is
705 saved, not the actual \type {\muskip} value. This means that any later changes to
706 one of these three parameters will be taken into account.
708 Note 2: Careful readers will realise that there are also primitives for the items
709 marked \type {*} in the \TEX book. These will not actually be used as those
710 combinations of atoms cannot actually happen, but it seemed better not to break
711 orthogonality. They are initialized to zero.
713 \section[mathacc]{Math accent handling}
715 \LUATEX\ supports both top accents and bottom accents in math mode, and math
716 accents stretch automatically (if this is supported by the font the accent comes
717 from, of course). Bottom and combined accents as well as fixed-width math accents
718 are controlled by optional keywords following \type {\Umathaccent}.
720 The keyword \type {bottom} after \type {\Umathaccent} signals that a bottom accent
721 is needed, and the keyword \type {both} signals that both a top and a bottom
722 accent are needed (in this case two accents need to be specified, of course).
724 Then the set of three integers defining the accent is read. This set of integers
725 can be prefixed by the \type {fixed} keyword to indicate that a non-stretching
726 variant is requested (in case of both accents, this step is repeated).
728 A simple example:
730 \starttyping
731 \Umathaccent both fixed 0 0 "20D7 fixed 0 0 "20D7 {example}
732 \stoptyping
734 If a math top accent has to be placed and the accentee is a character and has a
735 non-zero \type {top_accent} value, then this value will be used to place the
736 accent instead of the \type {\skewchar} kern used by \TEX82.
738 The \type {top_accent} value represents a vertical line somewhere in the
739 accentee. The accent will be shifted horizontally such that its own \type
740 {top_accent} line coincides with the one from the accentee. If the \type
741 {top_accent} value of the accent is zero, then half the width of the accent
742 followed by its italic correction is used instead.
744 The vertical placement of a top accent depends on the \type {x_height} of the
745 font of the accentee (as explained in the \TEX book), but if value that turns out
746 to be zero and the font had a \type {MathConstants} table, then \type
747 {AccentBaseHeight} is used instead.
749 The vertical placement of a bottom accent is straight below the accentee, no
750 correction takes place.
752 Possible locations are \type {top}, \type {bottom}, \type {both} and \type
753 {center}. When no location is given \type {top} is assumed. An additional
754 parameter \type {fraction} can be specified followed by a number; a value of for
755 instance 1200 means that the criterium is 1.2 times the width of the nucleus. The
756 fraction only applies to the stepwise selected shapes and is mostly meant for the
757 \type {overlay} location. It also works for the other locations but then it
758 concerns the width.
760 \section{Math root extension}
762 The new primitive \type {\Uroot} allows the construction of a radical noad
763 including a degree field. Its syntax is an extension of \type {\Uradical}:
765 \starttyping
766 \Uradical <fam integer> <char integer> <radicand>
767 \Uroot <fam integer> <char integer> <degree> <radicand>
768 \stoptyping
770 The placement of the degree is controlled by the math parameters \type
771 {\Umathradicaldegreebefore}, \type {\Umathradicaldegreeafter}, and \type
772 {\Umathradicaldegreeraise}. The degree will be typeset in \type
773 {\scriptscriptstyle}.
775 \section{Math kerning in super- and subscripts}
777 The character fields in a \LUA|-|loaded \OPENTYPE\ math font can have a \quote
778 {mathkern} table. The format of this table is the same as the \quote {mathkern}
779 table that is returned by the \type {fontloader} library, except that all height
780 and kern values have to be specified in actual scaled points.
782 When a super- or subscript has to be placed next to a math item, \LUATEX\ checks
783 whether the super- or subscript and the nucleus are both simple character items.
784 If they are, and if the fonts of both character items are \OPENTYPE\ fonts (as
785 opposed to legacy \TEX\ fonts), then \LUATEX\ will use the \OPENTYPE\ math
786 algorithm for deciding on the horizontal placement of the super- or subscript.
788 This works as follows:
790 \startitemize
791 \startitem
792 The vertical position of the script is calculated.
793 \stopitem
794 \startitem
795 The default horizontal position is flat next to the base character.
796 \stopitem
797 \startitem
798 For superscripts, the italic correction of the base character is added.
799 \stopitem
800 \startitem
801 For a superscript, two vertical values are calculated: the bottom of the
802 script (after shifting up), and the top of the base. For a subscript, the two
803 values are the top of the (shifted down) script, and the bottom of the base.
804 \stopitem
805 \startitem
806 For each of these two locations:
807 \startitemize
808 \startitem
809 find the math kern value at this height for the base (for a subscript
810 placement, this is the bottom_right corner, for a superscript
811 placement the top_right corner)
812 \stopitem
813 \startitem
814 find the math kern value at this height for the script (for a
815 subscript placement, this is the top_left corner, for a superscript
816 placement the bottom_left corner)
817 \stopitem
818 \startitem
819 add the found values together to get a preliminary result.
820 \stopitem
821 \stopitemize
822 \stopitem
823 \startitem
824 The horizontal kern to be applied is the smallest of the two results from
825 previous step.
826 \stopitem
827 \stopitemize
829 The math kern value at a specific height is the kern value that is specified by the
830 next higher height and kern pair, or the highest one in the character (if there is no
831 value high enough in the character), or simply zero (if the character has no math kern
832 pairs at all).
834 \section{Scripts on horizontally extensible items like arrows}
836 The primitives \type {\Uunderdelimiter} and \type {\Uoverdelimiter} allow the
837 placement of a subscript or superscript on an automatically extensible item and
838 \type {\Udelimiterunder} and \type {\Udelimiterover} allow the placement of an
839 automatically extensible item as a subscript or superscript on a nucleus. The
840 input:
842 % these produce radical noads .. in fact the code base has the numbers wrong for
843 % quite a while, so no one seems to use this
845 \startbuffer
846 $\Uoverdelimiter 0 "2194 {\hbox{\strut overdelimiter}}$
847 $\Uunderdelimiter 0 "2194 {\hbox{\strut underdelimiter}}$
848 $\Udelimiterover 0 "2194 {\hbox{\strut delimiterover}}$
849 $\Udelimiterunder 0 "2194 {\hbox{\strut delimiterunder}}$
850 \stopbuffer
852 \typebuffer will render this:
854 \blank \startnarrower \getbuffer \stopnarrower \blank
856 The vertical placements are controlled by \type {\Umathunderdelimiterbgap}, \type
857 {\Umathunderdelimitervgap}, \type {\Umathoverdelimiterbgap}, and \type
858 {\Umathoverdelimitervgap} in a similar way as limit placements on large operators.
859 The superscript in \type {\Uoverdelimiter} is typeset in a suitable scripted style,
860 the subscript in \type {\Uunderdelimiter} is cramped as well.
862 These primitives accepts an option \type {width} specification. When used the
863 also optional keywords \type {left}, \type {middle} and \type {right} will
864 determine what happens when a requested size can't be met (which can happen when
865 we step to successive larger variants).
867 An extra primitive \type {\Uhextensible} is available that can be used like this:
869 \startbuffer
870 $\Uhextensible width 10cm 0 "2194$
871 \stopbuffer
873 \typebuffer This will render this:
875 \blank \startnarrower \getbuffer \stopnarrower \blank
877 Here you can also pass options, like:
879 \startbuffer
880 $\Uhextensible width 1pt middle 0 "2194$
881 \stopbuffer
883 \typebuffer This gives:
885 \blank \startnarrower \getbuffer \stopnarrower \blank
887 \LUATEX\ internally uses a structure that supports \OPENTYPE\ \quote
888 {MathVariants} as well as \TFM\ \quote {extensible recipes}. In most cases where
889 font metrics are involved we have a different code path for traditional fonts end
890 \OPENTYPE\ fonts.
892 \section {Extracting values}
894 You can extract the components of a math character. Say that we have defined:
896 \starttyping
897 \Umathcode 1 2 3 4
898 \stoptyping
900 then
902 \starttyping
903 [\Umathcharclass1] [\Umathcharfam1] [\Umathcharslot1]
904 \stoptyping
906 will return:
908 \starttyping
909 [2] [3] [4]
910 \stoptyping
912 These commands are provides as convenience. Before they came available you could
913 do the following:
915 \starttyping
916 \def\Umathcharclass{\directlua{tex.print(tex.getmathcode(token.scan_int())[1])}}
917 \def\Umathcharfam {\directlua{tex.print(tex.getmathcode(token.scan_int())[2])}}
918 \def\Umathcharslot {\directlua{tex.print(tex.getmathcode(token.scan_int())[3])}}
919 \stoptyping
921 \section{fractions}
923 The \type {\abovewithdelims} command accepts a keyword \type {exact}. When issued
924 the extra space relative to the rule thickness is not added. One can of course
925 use the \type {\Umathfraction..gap} commands to influence the spacing. Also the
926 rule is still positioned around the math axis.
928 \starttyping
929 $$ { {a} \abovewithdelims() exact 4pt {b} }$$
930 \stoptyping
932 The math parameter table contains some parameters that specify a horizontal and
933 vertical gap for skewed fractions. Of course some guessing is needed in order to
934 implement something that uses them. And so we now provide a primitive similar to the
935 other fraction related ones but with a few options so that one can influence the
936 rendering. Of course a user can also mess around a bit with the parameters
937 \type {\Umathskewedfractionhgap} and \type {\Umathskewedfractionvgap}.
939 The syntax used here is:
941 \starttyping
942 { {1} \Uskewed / <options> {2} }
943 { {1} \Uskewedwithdelims / () <options> {2} }
944 \stoptyping
946 where the options can be \type {noaxis} and \type {exact}. By default we add half
947 the axis to the shifts and by default we zero the width of the middle character.
948 For Latin Modern The result looks as follows:
950 \def\ShowA#1#2#3{$x + { {#1} \Uskewed / #3 {#2} } + x$}
951 \def\ShowB#1#2#3{$x + { {#1} \Uskewedwithdelims / () #3 {#2} } + x$}
953 \start
954 \switchtobodyfont[modern]
955 \starttabulate[||||||]
956 \NC \NC
957 \ShowA{a}{b}{} \NC
958 \ShowA{1}{2}{} \NC
959 \ShowB{a}{b}{} \NC
960 \ShowB{1}{2}{} \NC
962 \NC \type{exact} \NC
963 \ShowA{a}{b}{exact} \NC
964 \ShowA{1}{2}{exact} \NC
965 \ShowB{a}{b}{exact} \NC
966 \ShowB{1}{2}{exact} \NC
968 \NC \type{noaxis} \NC
969 \ShowA{a}{b}{noaxis} \NC
970 \ShowA{1}{2}{noaxis} \NC
971 \ShowB{a}{b}{noaxis} \NC
972 \ShowB{1}{2}{noaxis} \NC
974 \NC \type{exact noaxis} \NC
975 \ShowA{a}{b}{exact noaxis} \NC
976 \ShowA{1}{2}{exact noaxis} \NC
977 \ShowB{a}{b}{exact noaxis} \NC
978 \ShowB{1}{2}{exact noaxis} \NC
980 \stoptabulate
981 \stop
983 \section {Last lines}
985 There is a new primitive to control the overshoot in the calculation of the
986 previous line in mid|-|paragraph display math. The default value is 2 times
987 the em width of the current font:
989 \starttyping
990 \predisplaygapfactor=2000
991 \stoptyping
993 If you want to have the length of the last line independent of math i.e.\ you don't
994 want to revert to a hack where you insert a fake display math formula in order to
995 get the length of the last line, the following will often work too:
997 \starttyping
998 \def\lastlinelength{\dimexpr
999 \directlua {tex.sprint (
1000 (nodes.dimensions(node.tail(tex.lists.page_head).list))
1001 )}sp
1002 \relax}
1003 \stoptyping
1005 \section {Other Math changes}
1007 \subsection {Verbose versions of single-character math commands}
1009 \LUATEX\ defines six new primitives that have the same function as
1010 \type {^}, \type {_}, \type {$}, and \type {$$}:
1012 \starttabulate[|l|l|l|l|]
1013 \NC \bf primitive \NC \bf explanation \NC \NR
1014 \NC \type {\Usuperscript} \NC Duplicates the functionality of \type {^} \NC \NR
1015 \NC \type {\Usubscript} \NC Duplicates the functionality of \type {_} \NC \NR
1016 \NC \type {\Ustartmath} \NC Duplicates the functionality of \type {$}, % $
1017 when used in non-math mode. \NC \NR
1018 \NC \type {\Ustopmath} \NC Duplicates the functionality of \type {$}, % $
1019 when used in inline math mode. \NC \NR
1020 \NC \type {\Ustartdisplaymath} \NC Duplicates the functionality of \type {$$}, % $$
1021 when used in non-math mode. \NC \NR
1022 \NC \type {\Ustopdisplaymath} \NC Duplicates the functionality of \type {$$}, % $$
1023 when used in display math mode. \NC \NR
1024 \stoptabulate
1026 The \type {\Ustopmath} and \type {\Ustopdisplaymath} primitives check if the current
1027 math mode is the correct one (inline vs.\ displayed), but you can freely intermix
1028 the four mathon|/|mathoff commands with explicit dollar sign(s).
1030 \subsection{Allowed math commands in non-math modes}
1032 The commands \type {\mathchar}, and \type {\Umathchar} and control sequences that
1033 are the result of \type {\mathchardef} or \type {\Umathchardef} are also
1034 acceptable in the horizontal and vertical modes. In those cases, the \type
1035 {\textfont} from the requested math family is used.
1037 \section{Math surrounding skips}
1039 Inline math is surrounded by (optional) \type {\mathsurround} spacing but that is fixed
1040 dimension. There is now an additional parameter \type {\mathsurroundskip}. When set to a
1041 non|-|zero value (or zero with some stretch or shrink) this parameter will replace
1042 \type {\mathsurround}. By using an additional parameter instead of changing the nature
1043 of \type {\mathsurround}, we can remain compatible. In the meantime a bit more
1044 control has been added via \type {\mathsurroundmode}. This directive can take 6 values
1045 with zero being the default behaviour.
1047 \start
1049 \def\OneLiner#1#2%
1050 {\NC #1
1051 % \NC \ruledhbox{\mathsurroundmode#1\relax\hsize 100pt x$x$x}
1052 % \NC \ruledhbox{\mathsurroundmode#1\relax\hsize 100pt x $x$ x}
1053 \NC \dontleavehmode\inframed[align=normal,offset=0pt,frame=off]{\mathsurroundmode#1\relax\hsize 100pt x$x$x}
1054 \NC \dontleavehmode\inframed[align=normal,offset=0pt,frame=off]{\mathsurroundmode#1\relax\hsize 100pt x $x$ x}
1055 \NC #2
1056 \NC \NR}
1058 \startbuffer
1059 \mathsurround 10pt
1060 \mathsurroundskip20pt
1061 \stopbuffer
1063 \typebuffer \getbuffer
1065 \starttabulate[|Tc|c|c|pl|]
1067 \BC mode \BC \type {x$x$x} \BC \type {x $x$ x} \BC effect \NC \NR
1069 \OneLiner{0}{obey \type {\mathsurround} when \type {\mathsurroundskip} is 0pt}
1070 \OneLiner{1}{only add skip to the left}
1071 \OneLiner{2}{only add skip to the right}
1072 \OneLiner{3}{add skip to the left and right}
1073 \OneLiner{4}{ignore the skip setting, obey \type {\mathsurround}}
1074 \OneLiner{5}{disable all spacing around math}
1075 \OneLiner{6}{only apply \type {\mathsurroundskip} when also spacing}
1076 \OneLiner{7}{only apply \type {\mathsurroundskip} when no spacing}
1078 \stoptabulate
1080 \stop
1082 Method six omits the surround glue when there is (x)spacing glue present while
1083 method seven does the opposite, the glue is only applied when there is (x)space
1084 glue present too. Anything more fance, like checking the begining or end of a
1085 paragraph (or edges of a box) would not be robust anyway. If you want that you
1086 can write a callback that runs over a list and analyzes a paragraph. Actually, in
1087 that case you could also inject glue (or set the properties of a math node)
1088 explicitly. So, these modes are in practice mostly useful for special purposes
1089 and experiments (they originate in a tracker item). Keep in mind that this glue
1090 is part of the math node and not always treated as normal glue: it travels with
1091 the begin and end math nodes. Also, method 6 and 7 will zero the skip related
1092 fields in a node when applicable in the first occasion that checks them
1093 (linebreaking or packaging).
1095 % \section{Math todo}
1097 % The following items are still todo.
1099 % \startitemize
1100 % \startitem
1101 % Pre-scripts.
1102 % \stopitem
1103 % \startitem
1104 % Multi-story stacks.
1105 % \stopitem
1106 % \startitem
1107 % Flattened accents for high characters (maybe).
1108 % \stopitem
1109 % \startitem
1110 % Better control over the spacing around displays and handling of equation numbers.
1111 % \stopitem
1112 % \startitem
1113 % Support for multi|-|line displays using \MATHML\ style alignment points.
1114 % \stopitem
1115 % \stopitemize
1117 \subsection {Delimiters: \type{\Uleft}, \type {\Umiddle} and \type {\Uright}}
1119 Normally you will force delimiters to certain sizes by putting an empty box or
1120 rule next to it. The resulting delimiter will either be a character from the
1121 stepwise size range or an extensible. The latter can be quite differently
1122 positioned that the characters as it depends on the fit as well as the fact if
1123 the used characters in the font have depth or height. Commands like (plain \TEX
1124 s) \type {\big} need use this feature. In \LUATEX\ we provide a bit more control
1125 by three variants that supporting optional parameters \type {height}, \type
1126 {depth} and \type {axis}. The following example uses this:
1128 \startbuffer
1129 \Uleft height 30pt depth 10pt \Udelimiter "0 "0 "000028
1130 \quad x\quad
1131 \Umiddle height 40pt depth 15pt \Udelimiter "0 "0 "002016
1132 \quad x\quad
1133 \Uright height 30pt depth 10pt \Udelimiter "0 "0 "000029
1134 \quad \quad \quad
1135 \Uleft height 30pt depth 10pt axis \Udelimiter "0 "0 "000028
1136 \quad x\quad
1137 \Umiddle height 40pt depth 15pt axis \Udelimiter "0 "0 "002016
1138 \quad x\quad
1139 \Uright height 30pt depth 10pt axis \Udelimiter "0 "0 "000029
1140 \stopbuffer
1142 \typebuffer
1144 \startlinecorrection
1145 \ruledhbox{\mathematics{\getbuffer}}
1146 \stoplinecorrection
1148 The keyword \type {exact} can be used as directive that the real dimensions
1149 should be applied when the criteria can't be met which can happen when we're
1150 still stepping through the successively larger variants. When no dimensions are
1151 given the \type {noaxis} command can be used to prevent shifting over the axis.
1153 You can influence the final class with the keyword \type {class} which will
1154 influence the spacing.
1156 \subsection{Fixed scripts}
1158 We have three parameters that are used for this fixed anchoring:
1160 \starttabulate[|l|l|]
1161 \NC $d$ \NC \type {\Umathsubshiftdown} \NC \NR
1162 \NC $u$ \NC \type {\Umathsupshiftup} \NC \NR
1163 \NC $s$ \NC \type {\Umathsubsupshiftdown} \NC \NR
1164 \stoptabulate
1166 When we set \type {\mathscriptsmode} to a value other than zero these are used
1167 for calculating fixed positions. This is something that is needed for instance
1168 for chemistry. You can manipulate the mentioned variables to achive different
1169 effects.
1171 \def\SampleMath#1%
1172 {$\mathscriptsmode#1\mathupright CH_2 + CH^+_2 + CH^2_2$}
1174 \starttabulate[|c|c|c|l|]
1175 \NC \bf mode \NC \bf down \NC \bf up \NC \NC \NR
1176 \NC 0 \NC dynamic \NC dynamic \NC \SampleMath{0} \NC \NR
1177 \NC 1 \NC $d$ \NC $u$ \NC \SampleMath{1} \NC \NR
1178 \NC 2 \NC $s$ \NC $u$ \NC \SampleMath{2} \NC \NR
1179 \NC 3 \NC $s$ \NC $u + s - d$ \NC \SampleMath{3} \NC \NR
1180 \NC 4 \NC $d + (s-d)/2$ \NC $u + (s-d)/2$ \NC \SampleMath{4} \NC \NR
1181 \NC 5 \NC $d$ \NC $u + s - d$ \NC \SampleMath{5} \NC \NR
1182 \stoptabulate
1184 The value of this parameter obeys grouping but applies to the whole current
1185 formula.
1187 % if needed we can put the value in stylenodes but maybe more should go there
1189 \subsection {Tracing}
1191 Because there are quite some math related parameters and values, it is possible
1192 to limit tracing. Only when \type {tracingassigns} and|/|or \type
1193 {tracingrestores} are set to~2 or more they will be traced.
1195 \subsection {Math options}
1197 The logic in the math engine is rather complex and there are often no universal
1198 solutions (read: what works out well for one font, fails for another). Therefore
1199 some variations in the implementation will be driven by options for which a new
1200 primitive \type {\mathoption} has been introduced (so that we don't end up with
1201 many new commands). The approach of options also permits us to see what effect a
1202 specific solution has.
1204 \subsubsection {\type {\mathoption old}}
1206 This option was introduced for testing purposes when the math engine got split
1207 code paths and it forces the engine to treat new fonts as old ones with respect
1208 to italic correction etc. There are no guarantees given with respect to the final
1209 result and unexpected side effects are not seens as bugs as they relate to font
1210 properties.
1212 \startbuffer
1213 \mathoption old 1
1214 \stopbuffer
1216 The \type {oldmath} boolean flag in the \LUA\ font table is the official way to
1217 force old treatment as it's bound to fonts.
1219 \subsubsection {\type {\mathoption noitaliccompensation}}
1221 This option compensates placement for characters with a built|-|in italic
1222 correction.
1224 \startbuffer
1225 {\showboxes\int}\quad
1226 {\showboxes\int_{|}^{|}}\quad
1227 {\showboxes\int\limits_{|}^{|}}
1228 \stopbuffer
1230 \typebuffer
1232 Gives (with computer modern that has such italics):
1234 \startlinecorrection[blank]
1235 \switchtobodyfont[modern]
1236 \startcombination[nx=2,ny=2,distance=5em]
1237 {\mathoption noitaliccompensation 0\relax \mathematics{\getbuffer}}
1238 {\nohyphens\type{0:inline}}
1239 {\mathoption noitaliccompensation 0\relax \mathematics{\displaymath\getbuffer}}
1240 {\nohyphens\type{0:display}}
1241 {\mathoption noitaliccompensation 1\relax \mathematics{\getbuffer}}
1242 {\nohyphens\type{1:inline}}
1243 {\mathoption noitaliccompensation 1\relax \mathematics{\displaymath\getbuffer}}
1244 {\nohyphens\type{1:display}}
1245 \stopcombination
1246 \stoplinecorrection
1248 \subsubsection {\type {\mathoption nocharitalic}}
1250 When two characters follow each other italic correction can interfere. The
1251 following example shows what this option does:
1253 \startbuffer
1254 \catcode"1D443=11
1255 \catcode"1D444=11
1256 \catcode"1D445=11
1257 P( PP PQR
1258 \stopbuffer
1260 \typebuffer
1262 Gives (with computer modern that has such italics):
1264 \startlinecorrection[blank]
1265 \switchtobodyfont[modern]
1266 \startcombination[nx=2,ny=2,distance=5em]
1267 {\mathoption nocharitalic 0\relax \mathematics{\getbuffer}}
1268 {\nohyphens\type{0:inline}}
1269 {\mathoption nocharitalic 0\relax \mathematics{\displaymath\getbuffer}}
1270 {\nohyphens\type{0:display}}
1271 {\mathoption nocharitalic 1\relax \mathematics{\getbuffer}}
1272 {\nohyphens\type{1:inline}}
1273 {\mathoption nocharitalic 1\relax \mathematics{\displaymath\getbuffer}}
1274 {\nohyphens\type{1:display}}
1275 \stopcombination
1276 \stoplinecorrection
1278 \subsubsection {\type {\mathoption useoldfractionscaling}}
1280 This option has been introduced as solution for tracker item 604 for fuzzy cases
1281 around either or not present fraction related settings for new fonts.
1283 \stopchapter
1285 \stopcomponent