summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/ontarget/ontarget-makessense.tex
blob: e0a635285d95873d8709f602a9ae7d1f41ceb934 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
% language=us runpath=texruns:manuals/ontarget

\startcomponent ontarget-makessense

\environment ontarget-style

\startchapter[title={But this does}]

In \LUAMETATEX\ one can do a lot on \LUA, like what I will discuss next, but
because it is somewhat fundamental it became a core feature of the engine. It was
also quite easy to implement. It has to do with packaging. \footnote {I actually
did prototype it in \LUA\ first but wanted a more natural integration in the
end.}

The box constructors in traditional \TEX\ accept two keywords: \type {to} for
setting an exact width and \type {spread} for specifying additional width. In
\LUAMETATEX\ we have some more like \type {shift} (a traditional \TEX\ concept),
\type {orientation}, \type {xmove}, \type {xoffset}, \type {ymove} and \type
{yoffset} for absolute positioning, \type {anchor(s)}, \type {target} and \type
{source} for relative positioning, \type {axis} and \type {class} for usage in
\math, \type {delay} for leader like boxes, the multiple \type {attr} key for
setting attributes, a special subtype directive \type {container} and \type
{direction} for controlling bidirectional typesetting, and \type {reverse} for
reversing content. The latest addition: \type {adapt} is there for controlling
and freezing glue.

So, in addition to the width related keys \type {to} and \type {spread} we have
\type {adapt} that drives wo what width the box will be typeset. \footnote {For
the moment this keyword only has effect for horizontal boxes.} The keyword is
followed by a scale values between -1000 and 1000 where a negative value enforces
shrink and a positive value stretch. The following table shows the effects:

\startbuffer
\starttabulate
    \Test{}
    \Test{to      4cm}
    \Test{to      \hsize}
    \Test{spread  1cm}
    \Test{spread -1cm}
    \Test{adapt -1000}
    \Test{adapt  -750}
    \Test{adapt  -500}
    \Test{adapt     0}
    \Test{adapt   500}
    \Test{adapt   750}
    \Test{adapt  1000}
\stoptabulate
\stopbuffer

\def\Test#1{%
    \NC
        \type {#1}
    \NC
        \showglyphs
        \ruledhbox#1{Here are just some words so that we can see what happens.}%
    \NC \NR
}

\getbuffer

When a box is typeset the natural glue width is used but when the required width
exceeds the natural width the glue stretch components kick in. With a negative
spread the shrink is used but you can get underflows. The \type {adapt} feature
freezes the glue and it removes the stretch and shrink after applying it to the
glue width with the given scale factor. So, in order to get the minimum width you
use \type {adapt -1000}.

\def\Test#1{%
    \NC
        \type {#1}
    \NC
        \medmuskip 4mu plus 2mu minus 2mu\relax
        \showmakeup[mathglue]%
        \showglyphs
        \ruledhbox#1{$ x + x + a = 2x + a$\hss}%
    \NC \NR
}

The reason why I decided to add this feature is that when experimenting with math
alignments I wanted to be able to see what shrink could be achieved. \footnote
{At that time Mikael and I were experimenting with consistent spacing in math
alignments.} The next example shows this:

\getbuffer

Once we had this new feature it made sense to add support for it to \type
{\framed}, one of the oldest macros that got extended over time:

\startbuffer
\inframed[adaptive=1000] {Just some words}
\inframed[adaptive=500]  {Just some words}
\inframed[adaptive=0]    {Just some words}
\inframed[adaptive=-500] {Just some words}
\inframed[adaptive=-1000]{Just some words}
\stopbuffer

\typebuffer

This renders as:

\startlinecorrection \getbuffer \stoplinecorrection

Once we have it there other mechanisms can benefit from it, for instance natural
tables. But keep in mind that spaces are fixed in there so there is only the
expected result if glue has stretch or shrink.

\stopchapter

\stopcomponent