summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/details/details-snappingheads.tex
blob: 26f4dfbc4bf5e3780701bd43d4bccf9e0861f37d (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
% language=uk

\environment details-environment

\startcomponent details-snappingheads

\startchapter[title={Snapping heads}]

The grid snapper in \MKIV\ is quite different from the one in \MKII. For not too
complex layouts the old grid snapper was quite ok, but the new one should be a
bit more robust. In the old situation the running text was assumed to fit on the
grid and the normal baseline skip should do the job in combination with the grid
aware spacing features and placement mechanisms like tables and figures.

Snapping on a fixed grid is sort of counter intuitive in \TEX\ because it has an a
advanced spacing model with glue. Publishers however love grids so we do need to
support it. Of course when complex layouts are involved in a later stage of
document preparation the grid is often abandoned. This manual uses the grid but I
personally never use the grid. There are better ways to make your document look
good and often a grid snapped document doesn't look that great anyway, because
all elements should somehow fit in multiples of the line height.

The \MKIV\ snapper does more analysis and therefore can compensate for the more
nasty cases. Of course it can still fail but we hope to fix those cases when we
run into them. Grids are controlled by keywords or a combination of them.

\starttabulate[|tCT{blue}||]
\NC none             \NC don't enlarge \NC \NR
\NC halfline         \NC enlarge by halfline/halfline \NC \NR
\NC line             \NC enlarge by line/line \NC \NR
\NC strut            \NC enlarge by ht/dp (default) \NC \NR
\NC first            \NC align to top line \NC \NR
\NC last             \NC align to bottom line \NC \NR
\NC mindepth         \NC round depth down \NC \NR
\NC maxdepth         \NC round depth up \NC \NR
\NC minheight        \NC round height down \NC \NR
\NC maxheight        \NC round height up \NC \NR
\NC local            \NC use local interline space \NC \NR
\NC offset:-3tp      \NC vertical shift within box \NC \NR
\NC bottom:lines     \NC \NC \NR
\NC top:lines        \NC \NC \NR
\NC box              \NC centers a box rounded upwards (box:.5 -> tolerance) \NC \NR
\NC min              \NC centers a box rounded downwards \NC \NR
\NC max              \NC centers a box rounded upwards \NC \NR
\stoptabulate

We combine these directives in so called grid options:

\starttyping
\definegridsnapping [normal]   [maxheight,maxdepth,strut]
\definegridsnapping [standard] [maxheight,maxdepth,strut]
\definegridsnapping [yes]      [maxheight,maxdepth,strut]

\definegridsnapping [strict]   [maxdepth:0.8,maxheight:0.8,strut]
\definegridsnapping [tolerant] [maxdepth:1.2,maxheight:1.2,strut]
\definegridsnapping [math]     [maxdepth:1.05,maxheight:1.05,strut]

\definegridsnapping [top]      [minheight,maxdepth,strut]
\definegridsnapping [bottom]   [maxheight,mindepth,strut]
\definegridsnapping [both]     [minheight,mindepth,strut]

\definegridsnapping [broad]    [maxheight,maxdepth,strut,0.8]
\definegridsnapping [fit]      [maxheight,maxdepth,strut,1.2]

\definegridsnapping [first]    [first]
\definegridsnapping [last]     [last]
\definegridsnapping [high]     [minheight,maxdepth,none]
\definegridsnapping [one]      [minheight,mindepth]
\definegridsnapping [low]      [maxheight,mindepth,none]
\definegridsnapping [none]     [none]
\definegridsnapping [line]     [line]
\definegridsnapping [strut]    [strut]
\definegridsnapping [box]      [box]
\definegridsnapping [min]      [min]
\definegridsnapping [max]      [max]

\definegridsnapping [middle]   [maxheight,maxdepth]
\stoptyping

As you can see, keys like \type {maxdepth} can take a criterium as extra detail,
separated by a colon. These options look obscure and often you need to trial and
error a bit to get what you want. This is no real problem because most cases are
handles automatically. Only headings and structuring elements that exceed a
line height might need some treatment. For instance you might want to be more
tolerant for (fractions of) a point overflow or when you know that always a blank
follows you can decide to limit the height of some element to a line. Some of
the options, like \type {math} and \type {middle} are used internally.

On the next pages we show how the \type {maxheight} and \type {maxdepth}
fractions work on a sample line.

\page

\bgroup
    \page
    \enabledirectives[visualizers.fraction=.5]
    \dostepwiserecurse {0} {10} {1} {
        \edef\one{\ifnum#1=10 10\else0.#1\fi}
        \dostepwiserecurse {0} {10} {1} {
            \edef\two{\ifnum##1=10 10\else0.##1\fi}
            \definegridsnapping [test:\one:\two][maxdepth:\one,maxheight:\two,strut]
            \par
                \blackrule[height=1pt,depth=1pt,width=\textwidth,color=green]
            \par
            \par
                \snaptogrid[test:\one:\two]
                    \ruledhbox{\backgroundline[red]{\white\bf maxdepth:\one,maxheight:\two}}
            \par
        }
    }
    \par
    \blackrule[height=1pt,depth=1pt,width=\textwidth,color=green]
    \par
    \page
    \enabledirectives[visualizers.fraction]
\egroup

Next we show some of the options in action. For practical reasons we start a new
page each time. The sample is input as:

\startbuffer
\bf                             none \par
\bfb \hskip2cm                  none \par
\bfd \hskip6cm                  none \par
\bf                             test \par
\bfb \hskip2cm                  test \par
\bfd \hskip6cm                  test \par
\bf                             grid \par
\bfb \hskip2cm                  grid \par
\bfd \hskip6cm                  grid \par
\bf                      \strut strut \par
\bfb \hskip2cm           \strut strut \par
\bfd \hskip6cm           \strut strut \par
\bfb \hskip2cm \setstrut \strut setstrut \par
\bfd \hskip6cm \setstrut \strut setstrut \par
\stopbuffer

\typebuffer

\unexpanded\def\SampleGrid#1%
  {\page
   \section{Grid snapping method \quotation{#1}}
    This is just a line to start with but next we %
    show what method \type {#1} does. \par
    \start
    \setuplayout[grid=#1] % the demo value
    \showstruts
    \getbuffer
    \stop
    And here we end the demo.
    \setuplayout[grid=yes] % the document default
    \page}

\SampleGrid{normal}
\SampleGrid{strict}
\SampleGrid{tolerant}
\SampleGrid{top}
\SampleGrid{bottom}
\SampleGrid{both}
\SampleGrid{broad}
\SampleGrid{fit}
\SampleGrid{first}
\SampleGrid{last}
\SampleGrid{high}
\SampleGrid{one}
\SampleGrid{low}
\SampleGrid{none}
\SampleGrid{line}
\SampleGrid{strut}
\SampleGrid{box}
\SampleGrid{min}
\SampleGrid{max}
\SampleGrid{middle}

We now come to the topic of this chapter: snapping heads. The problem with
section heads is that they often exceed the line height. Even worse, they can
be more than one line high.

The next pages show some ways to control snapping around heads. The result can be
confusing, even when we use a font that we assume behaves like a regular style.
For instance in Latin Modern the bold style has larger heights and depths than
the regular style and even 0.1pt can force the snapper to add a line. The
examples use that font.

The grid option of \type {setuphead} normally takes one keyword that refers to
the local snapper. However, the result gets then snapped again. This is because
the local snapper can use a different line height. Historically the local snapper is
the default but you can force global snapping by prefixing with the \type
{global} keyword. The next table summarizes the ways you can control snapping:

\starttabulate
\NC \type {(nothing)}  \NC local snapping plus global snapping \NC \NR
\NC \type {local}      \NC local snapping plus global snapping \NC \NR
\NC \type {foo}        \NC local \type {foo} snapping cf.\ font style plus global snapping \NC \NR
\NC \type {local:foo}  \NC local \type {foo} snapping cf.\ font style plus global snapping  \NC \NR
\NC \type {global}     \NC global snapping \NC \NR
\NC \type {global:foo} \NC global \type {foo} snapping \NC \NR
\stoptabulate

\startbuffer[demo]
\setuppapersize
  [A5][A5]

\setuplayout
  [grid=yes,
   width=middle,
   height=middle,
   backspace=1cm,
   topspace=2mm,
   lines=38,
   bottomspace=2mm,
   footer=0cm,
   header=4mm,
   headerdistance=5mm]

\definehead
  [MyHead]
  [subsubsubject]
  [style=\tf,
   textstyle=,
   numberstyle=,
   before=,
   after=]

\showgrid

\starttext

\starttexdefinition TestHead #1
    \page
    \setupheadertexts[\type{#1}]
    \setuphead[MyHead][grid={#1},style=\tf,interlinespace=]
    \MyHead{some head 1.1}
    \hskip1cm line following 1.1
    \MyHead{some head 1.2}
    \hskip1cm line following 1.2
    \MyHead{some head 1.3a\par some head 1.3b}
    \hskip1cm line following 1.3
    \setuphead[MyHead][grid={#1},style=\bf,interlinespace=]
    \MyHead{some head 2.1}
    \hskip1cm line following 2.1
    \MyHead{some head 2.2}
    \hskip1cm line following 2.2
    \MyHead{some head 2.3a\par some head 2.3b}
    \hskip1cm line following 2.3
    \setuphead[MyHead][grid=,style=\bf,interlinespace=4ex]
    \MyHead{some head 3.1}
    \hskip1cm line following 3.1
    \MyHead{some head 3.2}
    \hskip1cm line following 3.2
    \MyHead{some head 3.3a\par some head 3.3b}
    \hskip1cm line following 3.3
    \setuphead[MyHead][grid={#1},style=\bfb,interlinespace=]
    \MyHead{some head 4.1}
    \hskip1cm line following 4.1
    \MyHead{some head 4.2}
    \hskip1cm line following 4.2
    \page
\stoptexdefinition

\TestHead{yes}
\TestHead{tolerant}
\TestHead{global:tolerant}

\stoptext
\stopbuffer

\typebuffer

\placefigure[page]{}{\typesetbuffer[demo][page=1,background=color,backgroundcolor=white,width=\textwidth]}
\placefigure[page]{}{\typesetbuffer[demo][page=2,background=color,backgroundcolor=white,width=\textwidth]}
\placefigure[page]{}{\typesetbuffer[demo][page=3,background=color,backgroundcolor=white,width=\textwidth]}

\stopchapter

\stopcomponent