ontarget-makessense.tex /size: 3813 b    last modification: 2024-01-16 10:21
1% language=us runpath=texruns:manuals/ontarget
2
3\startcomponent ontarget-makessense
4
5\environment ontarget-style
6
7\startchapter[title={But this does}]
8
9In \LUAMETATEX\ one can do a lot on \LUA, like what I will discuss next, but
10because it is somewhat fundamental it became a core feature of the engine. It was
11also quite easy to implement. It has to do with packaging. \footnote {I actually
12did prototype it in \LUA\ first but wanted a more natural integration in the
13end.}
14
15The box constructors in traditional \TEX\ accept two keywords: \type {to} for
16setting an exact width and \type {spread} for specifying additional width. In
17\LUAMETATEX\ we have some more like \type {shift} (a traditional \TEX\ concept),
18\type {orientation}, \type {xmove}, \type {xoffset}, \type {ymove} and \type
19{yoffset} for absolute positioning, \type {anchor(s)}, \type {target} and \type
20{source} for relative positioning, \type {axis} and \type {class} for usage in
21\math, \type {delay} for leader like boxes, the multiple \type {attr} key for
22setting attributes, a special subtype directive \type {container} and \type
23{direction} for controlling bidirectional typesetting, and \type {reverse} for
24reversing content. The latest addition: \type {adapt} is there for controlling
25and freezing glue.
26
27So, in addition to the width related keys \type {to} and \type {spread} we have
28\type {adapt} that drives wo what width the box will be typeset. \footnote {For
29the moment this keyword only has effect for horizontal boxes.} The keyword is
30followed by a scale values between -1000 and 1000 where a negative value enforces
31shrink and a positive value stretch. The following table shows the effects:
32
33\startbuffer
34\starttabulate
35    \Test{}
36    \Test{to      4cm}
37    \Test{to      \hsize}
38    \Test{spread  1cm}
39    \Test{spread -1cm}
40    \Test{adapt -1000}
41    \Test{adapt  -750}
42    \Test{adapt  -500}
43    \Test{adapt     0}
44    \Test{adapt   500}
45    \Test{adapt   750}
46    \Test{adapt  1000}
47\stoptabulate
48\stopbuffer
49
50\def\Test#1{%
51    \NC
52        \type {#1}
53    \NC
54        \showglyphs
55        \ruledhbox#1{Here are just some words so that we can see what happens.}%
56    \NC \NR
57}
58
59\getbuffer
60
61When a box is typeset the natural glue width is used but when the required width
62exceeds the natural width the glue stretch components kick in. With a negative
63spread the shrink is used but you can get underflows. The \type {adapt} feature
64freezes the glue and it removes the stretch and shrink after applying it to the
65glue width with the given scale factor. So, in order to get the minimum width you
66use \type {adapt -1000}.
67
68\def\Test#1{%
69    \NC
70        \type {#1}
71    \NC
72        \medmuskip 4mu plus 2mu minus 2mu\relax
73        \showmakeup[mathglue]%
74        \showglyphs
75        \ruledhbox#1{$ x + x + a = 2x + a$\hss}%
76    \NC \NR
77}
78
79The reason why I decided to add this feature is that when experimenting with math
80alignments I wanted to be able to see what shrink could be achieved. \footnote
81{At that time Mikael and I were experimenting with consistent spacing in math
82alignments.} The next example shows this:
83
84\getbuffer
85
86Once we had this new feature it made sense to add support for it to \type
87{\framed}, one of the oldest macros that got extended over time:
88
89\startbuffer
90\inframed[adaptive=1000] {Just some words}
91\inframed[adaptive=500]  {Just some words}
92\inframed[adaptive=0]    {Just some words}
93\inframed[adaptive=-500] {Just some words}
94\inframed[adaptive=-1000]{Just some words}
95\stopbuffer
96
97\typebuffer
98
99This renders as:
100
101\startlinecorrection \getbuffer \stoplinecorrection
102
103Once we have it there other mechanisms can benefit from it, for instance natural
104tables. But keep in mind that spaces are fixed in there so there is only the
105expected result if glue has stretch or shrink.
106
107\stopchapter
108
109\stopcomponent
110
111