details-floatingaround.tex /size: 36 Kb    last modification: 2023-12-21 09:43
1% language=us
2
3\environment details-environment
4
5\startcomponent details-floatingaround
6
7\startchapter[title={Floating around}]
8
9\index {floats}
10
11Graphics, tables and alike are often treated as floating bodies. This means that
12when such a body does not fit on the current page, it will be moved to the next
13one. In the examples we will use figures, but much of what we demonstrate here
14applies to all floats.
15
16A side float is a float which placement one way or another depends on the text
17that follows it. In its simplest form, the text flows around it, for instance in:
18
19\startbuffer
20\placefigure[left,none]{caption}{\framed[height=1cm]{graphic}}
21\stopbuffer
22
23\typebuffer
24
25The first keyword of such a call is treated as a placement directive, so this
26figure will be placed left. The \type {none} directive nils the caption.
27
28\getbuffer \fakewords{60}{80}
29
30When the figure does not fit on the page, a page break is issued. A figure can
31span multiple paragraphs. When a next graphic is placed the previous figure will
32be padded if needed. First an example of multiple paragraphs.
33
34\getbuffer \fakewords{30}{40} \par \fakewords{30}{40}
35
36Multiple floats in a row will lead to padding. The amount of padding is a
37combination of empty lines and the normal white space following the float. The
38visual quality of the result depends on the graphic itself.
39
40\start \tracesidefloatstrue
41
42\getbuffer \fakewords{30}{40}
43
44\getbuffer \fakewords{30}{40} \fakewords{30}{40}
45
46\stop
47
48Here we show the baseline of the first paragraph after the float as well as the
49filler. The whitespace around a graphic also depends on the inter|-|paragraph
50whitespace. As with many automated mechanisms, compromises are made. A one point
51smaller figure may result in an extra empty line.
52
53Later we will demonstrate a lot of tuning options, but first we give a few more
54examples. Most of the tuning options can be driven by keywords as well as
55(global) settings.
56
57\startbuffer
58\placefigure
59  [left,nonumber]
60  {caption} {\framed[height=1cm]{graphic}}
61\stopbuffer
62
63\typebuffer
64
65The \type {nonumber} keyword suppresses the label and figure number. You can do
66this for all figures with
67
68\starttyping
69\setupcaption[figure][number=no]
70\stoptyping
71
72The previous placement command results in the following side float.
73
74\getbuffer \fakewords{80}{100}
75
76Another handy keyword is \type {none}.
77
78\startbuffer
79\placefigure
80  [left,none]{quoting knuth}
81  {\framed[height=1cm]{graphic}}
82\stopbuffer
83
84\typebuffer \getbuffer \fakewords{80}{100}
85
86Control over spacing is exercised by means of the keywords \type {high}, \type
87{low} and \type {fit}.
88
89\startbuffer
90\placefigure
91  [left,none,high]{}
92  {\framed[height=1cm]{graphic}}
93\stopbuffer
94
95\typebuffer \getbuffer \fakewords{80}{100}
96
97\startbuffer
98\placefigure
99  [left,none,high,low]{}
100  {\framed[height=1cm]{graphic}}
101\stopbuffer
102
103\typebuffer \getbuffer \fakewords{80}{100}
104
105\startbuffer
106\placefigure
107  [left,none,fit]{}
108  {\framed[height=1cm]{graphic}}
109\stopbuffer
110
111\typebuffer \getbuffer \fakewords{80}{100}
112
113In the examples so far, we saw additional spacing around the graphic. We will now
114(for a while) disable the surrounding whitespace.
115
116\startbuffer
117\setupfloat
118  [figure]
119  [sidespacebefore=none,
120   sidespaceafter=none]
121\stopbuffer
122
123\typebuffer
124
125With these settings a simple left placement looks as follows. The top of the side
126float aligns with the maximum height of a line.
127
128\start \getbuffer \tracesidefloatstrue
129
130\startbuffer
131\placefigure
132  [left,none]
133  {} {\framed[height=1cm]{graphic}}
134\stopbuffer
135
136\typebuffer \getbuffer \fakewords{30}{40} \par \stop
137
138You can change the alignment by setting the \type {sidealign} variable, for
139instance:
140
141\starttyping
142\setupfloat
143  [figure]
144  [sidealign=line]
145\stoptyping
146
147The three keywords \type {height}, \type {line} and \type {depth} can also be
148passed directly:
149
150\startbuffer
151\placefigure
152  [left,none,height]{}
153  {\framed[height=1cm]{graphic}}
154\stopbuffer
155
156\typebuffer
157
158The three alignments disable the spacing before the float and show up as follows.
159
160\bgroup \tracesidefloatstrue \getbuffer \fakewords{30}{40} \par \egroup
161
162\startbuffer
163\placefigure
164  [left,none,line]{}
165  {\framed[height=1cm]{graphic}}
166\stopbuffer
167
168\bgroup \tracesidefloatstrue \getbuffer \fakewords{30}{40} \par \egroup
169
170\startbuffer
171\placefigure
172  [left,none,depth]{}
173  {\framed[height=1cm]{graphic}}
174\stopbuffer
175
176\bgroup \tracesidefloatstrue \getbuffer \fakewords{30}{40} \par \egroup
177
178So far the floats took up space in the main text body area. In addition to the
179\type {left} (or \type {right}) directive we can use \type {inner} or \type
180{outer} to force left or right placement depending in the spread.
181
182Instead of spoiling paper in the text areas, we can use the margin and edges:
183\type {leftmargin} and \type {leftedge}, \type {rightmargin} and \type
184{rightedge}, but also \type {innermargin} and \type {outermargin}, \type
185{inneredge} and \type {outeredge}.
186
187The next couple of pages we will highlight the margins and edges so that we can
188see what happens.
189
190\setupbackgrounds [text] [leftedge]    [background=color]
191\setupbackgrounds [text] [rightedge]   [background=color]
192\setupbackgrounds [text] [leftmargin]  [background=color]
193\setupbackgrounds [text] [rightmargin] [background=color]
194
195\startbuffer
196\placefigure
197  [leftmargin,none]
198  {} {\framed{!}}
199\stopbuffer
200
201\typebuffer \getbuffer \fakewords{30}{40}
202
203\startbuffer
204\placefigure
205  [leftmargin,none]
206  {} {\framed[width=1cm]{!}}
207\stopbuffer
208
209\typebuffer \getbuffer \fakewords{30}{40}
210
211\startbuffer
212\placefigure
213  [leftmargin,none]
214  {} {\framed[width=1.5cm]{!}}
215\stopbuffer
216
217\typebuffer \getbuffer \fakewords{30}{40}
218
219The placement directives can be combined with setting distance and width
220parameters, thereby not only opening a world of possibilities, but also creating
221confusion. Therefore, we will illustrate these features by cloning floats.
222
223\startbuffer
224\definefloat
225  [marginfigure]
226  [figure]
227
228\setupfloat
229  [marginfigure]
230  [leftmargindistance=-\leftmargintotal,
231   default={left,none,low}]
232\stopbuffer
233
234\typebuffer \getbuffer
235
236The definition command clones figure into a new class of figures. There are two
237ways to use such a float :
238
239\starttyping
240\placefloat
241  [marginfigure]
242  {} {\framed[width=1.5cm]{!}}
243\stoptyping
244
245or directly:
246
247\startbuffer
248\placemarginfigure
249  {} {\framed[width=1.5cm]{!}}
250\stopbuffer
251
252\typebuffer
253
254Both placement calls will result in a figure sticking into the margin.
255
256\getbuffer \fakewords{30}{40}
257
258By manipulating the margin distance, you can align graphics to vertical grid
259lines, like the edge:
260
261\startbuffer
262\definefloat
263  [edgefigure]
264  [figure]
265
266\setupfloat
267  [edgefigure]
268  [leftmargindistance=-\innercombitotal,
269   default={left,none,low,high}]
270\stopbuffer
271
272\typebuffer \getbuffer
273
274The \type {\innercombitotal} is one of the many available dimensions. This
275measure is the combined width of the margin and edge.
276
277\startbuffer
278\placeedgefigure
279  {} {\framed[width=1.5cm]{!}}
280\stopbuffer
281
282\typebuffer \getbuffer \fakewords{30}{40}
283
284\startbuffer
285\placeedgefigure
286  {} {\framed[width=\innercombitotal]{!}}
287\stopbuffer
288
289\typebuffer \getbuffer \fakewords{30}{40}
290
291You need to be aware of the fact that the margins and edges are not related to
292the backspace and cut space settings. When you set up a layout, you need to think
293of the right page as starting point. In a double sided layout, the margins are
294swapped in the page composition stage. Unless you explicitly go to a left or
295right page, you don't know if your left margin will be swapped or not.
296
297For this reason \CONTEXT\ provides the inner and outer margin|/|edge dimensions.
298These are automatically synchronized when the float is constructed. So, if you
299want to automatically adapt the float placement and width to the current left
300margin in a double sided document, you can use the inner dimensions.
301
302\starttabulate[||||]
303\NC dimension                  \NC left page
304                               \NC right page                 \NC\NR
305\NC \type{\outermarginwidth}   \NC \type{\leftmarginwidth}
306                               \NC \type{\rightmarginwidth}   \NC\NR
307\NC \type{\innermarginwidth}   \NC \type{\rightmarginwidth}
308                               \NC \type{\leftmarginwidth}    \NC\NR
309\NC \type{\outermargindistance}\NC \type{\leftmargindistance}
310                               \NC \type{\rightmargindistance}\NC\NR
311\NC \type{\innermargindistance}\NC \type{\rightmargindistance}
312                               \NC \type{\leftmargindistance} \NC\NR
313\stoptabulate
314
315Similar dimensions are available for the edges. You can save yourself some
316calculations by using the following dimensions:
317
318\starttabulate[|||||]
319\NC \type{\leftmargintotal}  \NC left  margin width \NC + \NC left  margin distance \NC\NR
320\NC \type{\rightmargintotal} \NC right margin width \NC + \NC right margin distance \NC\NR
321\NC \type{\innermargintotal} \NC inner margin width \NC + \NC inner margin distance \NC\NR
322\NC \type{\outermargintotal} \NC outer margin width \NC + \NC outer margin distance \NC\NR
323\stoptabulate
324
325As you may expect, the edge totals are available as well, which leave a few more
326totals, namely the combinations of margin and edge.
327
328\starttabulate[|||]
329\NC \type{\leftsidetotal}   \NC left  margin width \NC + \NC left  edge total \NC\NR
330\NC \type{\rightsidetotal}  \NC right margin width \NC + \NC right edge total \NC\NR
331\TB
332\NC \type{\innersidetotal}  \NC inner margin width \NC + \NC inner edge total \NC\NR
333\NC \type{\outersidetotal}  \NC outer margin width \NC + \NC outer edge total \NC\NR
334\TB
335\NC \type{\leftcombitotal}  \NC left  margin total \NC + \NC left  edge total \NC\NR
336\NC \type{\rightcombitotal} \NC right margin total \NC + \NC right edge total \NC\NR
337\TB
338\NC \type{\innercombitotal} \NC inner margin total \NC + \NC inner edge total \NC\NR
339\NC \type{\outercombitotal} \NC outer margin total \NC + \NC outer edge total \NC\NR
340\stoptabulate
341
342Adaptive back- and cutspace dimensions are also available:
343
344\starttabulate[|||||]
345\NC \type{\innerspacewidth} \NC adaptive backspace \NC\NR
346\NC \type{\outerspacewidth} \NC adaptive cutspace  \NC\NR
347\stoptabulate
348
349There is one drawback in using the inner and outer dimensions: if you also change
350the height of the float dynamically, you may end up in a kind of loop because a
351page break may occur at a non||expected place.
352
353While negative values move float into the margin, positive values will move the
354float into the text. It will be of no surprise that you can also set the right
355margin distance. Keep in mind that this distance is not related to the text
356margin, but to the float margin.
357
358\startbuffer
359\setupfloat
360  [edgefigure]
361  [leftmargindistance=-\outercombitotal,
362   rightmargindistance=-\outercombitotal,
363   default={outer,none,low,high}]
364\stopbuffer
365
366\typebuffer \getbuffer
367
368The locations \type {inner} and \type {outer} change with the left or right page.
369
370\startbuffer
371\placeedgefigure
372  {} {\framed[width=\outercombitotal]{!}}
373\stopbuffer
374
375\typebuffer \getbuffer \fakewords{30}{40}
376
377\startbuffer
378\placeedgefigure
379  {} {\framed[width=8cm]{!}}
380\stopbuffer
381
382\typebuffer \getbuffer \fakewords{30}{40}
383
384As a result of manipulating the floats margin settings, the side floats can start
385in the margin (or edge). You should not confuse this with margin floats, i.e.\
386side floats that are explicitly placed in the margins.
387
388\startbuffer
389\placefigure[leftmargin,none]
390  {} {\framed{!}}
391\stopbuffer
392
393\typebuffer \getbuffer \fakewords{30}{40}
394
395\startbuffer
396\placefigure[leftmargin,none]
397  {} {\framed[width=.5cm]{!}}
398\stopbuffer
399
400\typebuffer \getbuffer \fakewords{30}{40}
401
402\startbuffer
403\placefigure[leftmargin,none]
404  {} {\framed[width=1.5cm]{!}}
405\stopbuffer
406
407\typebuffer \getbuffer \fakewords{30}{40}
408
409\startbuffer
410\placefigure[leftmargin,none]
411  {} {\framed[width=5cm]{!}}
412\stopbuffer
413
414\typebuffer \getbuffer \fakewords{30}{40}
415
416The margin side floats align to the margin and the edge floats to the edge. This
417way you can create bleeding figures.
418
419\startbuffer
420\placefigure[leftedge,none]
421  {} {\framed{!}}
422\stopbuffer
423
424\typebuffer \getbuffer \fakewords{30}{40}
425
426There are situations where you don't know the dimensions in advance. In order to
427prevent unwanted side effects, for instance part of a graphic disappearing
428outside the page boundary, \CONTEXT\ provides a few options. The most crude one
429is setting the \type {criterium}, as in:
430
431\starttyping
432\setupfloat
433  [figure]
434  [criterium=.25\textwidth]
435\stoptyping
436
437This will automatically turn figures that are wider than 25\% of the text width
438into normal floats instead of side floats. But let's not fall back on that
439feature now.
440
441You can use \type {maxwidth} and \type {minwidth} variables to control the
442placement in more detail. The exact result depends on the settings of \type
443{location}. By default we center, but you can set the location to \type {left} or
444\type {right} to achieve a different alignment.
445
446\startbuffer
447\definefloat
448  [midmarginfigure]
449  [figure]
450
451\setupfloat
452  [midmarginfigure]
453  [minwidth=\leftmarginwidth,
454   default={leftmargin,none}]
455\stopbuffer
456
457\typebuffer \getbuffer
458
459You can use \type {maxwidth} and \type {minwidth} variables to control the
460placement in more detail. The exact result depends on the settings of \type
461{location}. By default we center, but you can set the location to \type {left} or
462\type {right} to achieve a different alignment.
463
464\startbuffer
465\placemidmarginfigure
466  {} {\framed[width=1.5cm]{!}}
467\stopbuffer
468
469\typebuffer \getbuffer \fakewords{30}{40}
470
471The meaning of \type {maxwidth} depends on the kind of float. First we place a
472left float with a width smaller than \type {maxwidth}.
473
474\start
475
476\startbuffer
477\setupfloat[figure][maxwidth=2cm]
478\stopbuffer
479
480\typebuffer \getbuffer
481
482\startbuffer
483\placefigure[left,none]{}{\framed[width=1cm]{!}}
484\stopbuffer
485
486\typebuffer \getbuffer \fakewords{30}{40}
487
488When the width exceeds the maxwidth, the float will be centered. This is because
489we have no reference alignment point.
490
491\startbuffer
492\placefigure[left,none]{}{\framed[width=5cm]{!}}
493\stopbuffer
494
495\typebuffer \getbuffer \fakewords{30}{40}
496
497In margin floats, the \type {maxwidth} settings have a different result. First we
498place a small graphic.
499
500\startbuffer
501\setupfloat[figure][maxwidth=\leftmarginwidth]
502\stopbuffer
503
504\typebuffer \getbuffer
505
506\startbuffer
507\placefigure[leftmargin,none]{}{\framed[width=1cm]{!}}
508\stopbuffer
509
510\typebuffer \getbuffer \fakewords{30}{40}
511
512Because the left and right margin of this document are the same |<|the edges
513differ|>| we don't need to use inner and outer dimensions.
514
515\startbuffer
516\setupfloat[figure][maxwidth=\leftmarginwidth]
517\stopbuffer
518
519\typebuffer \getbuffer
520
521A wider than \type {maxwidth} graphic will behave like a mixture of a margin and
522text side float. Watch how we align the float to the margin.
523
524\startbuffer
525\placefigure[leftmargin,none]{}{\framed[width=5cm]{!}}
526\stopbuffer
527
528\typebuffer \getbuffer \fakewords{30}{40}
529
530\stop
531
532Instead of setting the width you can give \type {hanging} a try. The next
533examples demonstrate this.
534
535\startbuffer
536\placefigure[leftmargin,hanging,none]{}{\framed[width=5cm]{!}}
537\stopbuffer
538
539\typebuffer \getbuffer \fakewords{30}{40}
540
541\startbuffer
542\placefigure[left,hanging,none]{}{\framed[width=5cm]{!}}
543\stopbuffer
544
545\typebuffer \getbuffer \fakewords{30}{40}
546
547You can move down|/|up margin floats with the \type {\movesidefloat} macro. Such
548shifts come in handy when you have multiple side floats near to each other.
549
550\startbuffer
551\movesidefloat [+2*line]
552\placemidmarginfigure {} {\framed{!}}
553\stopbuffer
554
555\typebuffer \getbuffer \fakewords{30}{40}
556
557Given the default placement template, this is equivalent to the following
558command. Watch out, a simple \type {line} has a different effect (alignment).
559
560\starttyping
561\placemidmarginfigure
562  [leftmargin,none,+2*line]
563  {} {\framed{!}}
564\stoptyping
565
566Another nice keyword is \type {long}:
567
568\startbuffer
569\placefigure
570  [leftmargin,none,long]
571  {} {\framed[height=2cm,width=2cm]{!}}
572
573Watch how we move down. The effect is that we skip over the margin figure.
574
575\placefigure
576  [leftmargin,none]
577  {} {\framed[height=1cm,width=2cm]{!}}
578\stopbuffer
579
580\typebuffer \getbuffer \fakewords{30}{40}
581
582\startbuffer
583\placefigure
584  [leftmargin,none]
585  {} {\framed[height=2cm,width=2cm]{!}}
586
587Do we clash or not?
588
589\placefigure
590  [leftmargin,none]
591  {} {\framed[height=2cm,width=2cm]{!}}
592
593Did we clash or not?
594\stopbuffer
595
596\typebuffer \getbuffer
597
598There are a few macros that can be of help with solving clashes in side floats:
599
600\starttabulate
601\NC \tex {flushsidefloats} \NC
602    This macro moves down as much as is needed to separate the side floats of
603    each other. \NC \NR
604\NC \tex {forgetsidefloats} \NC
605    this macro kind of forgets that a side float is in progress. \NC \NR
606\stoptabulate
607
608Use these macros with care. If you change the dimensions of the graphic and|/|or
609content involved, reconsider the use of these directives.
610
611The next couple of spreads we will demonstrate some example definitions. These
612placements are taken from one of the styles we made for typesetting a series of
613school math books which illustrations and tables all over the pages.
614
615First we fine tune the spacing around side floats and verbatim text.
616
617\startbuffer[setupa]
618\setupfloats
619  [sidespacebefore=none,
620   sidespaceafter=depth]
621
622\setuptyping
623  [margin=]
624\stopbuffer
625
626\typebuffer[setupa]
627
628The placements have rather verbose names. In this case the word \quote {edge} is
629used to identify bleeding floats (with an cut||off margin of 3mm). The \quote
630{text} floats are side floats positioned in the main text flow.
631
632\startbuffer[setupb]
633\definefloat [marginfigure]       [marginfigures]       [figure]
634\definefloat [middlemarginfigure] [middlemarginfigures] [figure]
635\definefloat [middlefigure]       [middlefigures]       [figure]
636\definefloat [textfigure]         [textfigures]         [figure]
637\definefloat [leftfigure]         [leftfigures]         [figure]
638\definefloat [rightfigure]        [rightfigures]        [figure]
639\definefloat [bleedfigure]        [bleedfigures]        [figure]
640\stopbuffer
641
642\typebuffer[setupa]
643
644Watch how we define fall backs for too wide content (\type
645{criterium} as well as use \type {maxwidth} to manipulate
646the placement of content that falls off the margins.
647
648The black rules are set up with:
649
650\startbuffer[setupc]
651\setupblackrules[color=tred,depth=0pt,height=1.5cm]
652\stopbuffer
653
654\typebuffer[setupc]
655
656\page[left]
657
658\startbuffer[series]
659
660\startbuffer
661\setupfloat
662  [marginfigure]
663  [criterium=.5\textwidth,
664   maxwidth=\rightmarginwidth,
665   default={outermargin,none}]
666\stopbuffer
667
668\getbuffer \typebuffer
669
670\startbuffer
671\placemarginfigure{}{\blackrule[width=.25cm]}
672\stopbuffer
673
674\getbuffer \typebuffer \flushsidefloats
675
676\startbuffer
677\placemarginfigure{}{\blackrule[width=.5cm]}
678\stopbuffer
679
680\getbuffer \typebuffer \flushsidefloats
681
682\startbuffer
683\placemarginfigure{}{\blackrule[width=1cm]}
684\stopbuffer
685
686\getbuffer \typebuffer \flushsidefloats
687
688\startbuffer
689\placemarginfigure{}{\blackrule[width=2cm]}
690\stopbuffer
691
692\getbuffer \typebuffer \flushsidefloats
693
694\startbuffer
695\placemarginfigure{}{\blackrule[width=4cm]}
696\stopbuffer
697
698\getbuffer \typebuffer \flushsidefloats
699
700\startbuffer
701\placemarginfigure{}{\blackrule[width=8cm]}
702\stopbuffer
703
704\getbuffer \typebuffer \flushsidefloats
705
706\startbuffer
707\placemarginfigure{}{\blackrule[width=16cm]}
708\stopbuffer
709
710\getbuffer \typebuffer \flushsidefloats
711
712\stopbuffer
713
714{\getbuffer[setupa,setupb,setupc,series]} \page
715{\getbuffer[setupa,setupb,setupc,series]} \page
716
717\startbuffer[series]
718
719\startbuffer
720\setupfloat
721  [middlemarginfigure]
722  [minwidth=\rightmarginwidth,
723   criterium=\backspace,
724   location=middle,
725   default={outermargin,none}]
726\stopbuffer
727
728\getbuffer \typebuffer
729
730\startbuffer
731\placemiddlemarginfigure{}{\blackrule[width=.25cm]}
732\stopbuffer
733
734\getbuffer \typebuffer \flushsidefloats
735
736\startbuffer
737\placemiddlemarginfigure{}{\blackrule[width=.5cm]}
738\stopbuffer
739
740\getbuffer \typebuffer \flushsidefloats
741
742\startbuffer
743\placemiddlemarginfigure{}{\blackrule[width=1cm]}
744\stopbuffer
745
746\getbuffer \typebuffer \flushsidefloats
747
748\startbuffer
749\placemiddlemarginfigure{}{\blackrule[width=2cm]}
750\stopbuffer
751
752\getbuffer \typebuffer \flushsidefloats
753
754\startbuffer
755\placemiddlemarginfigure{}{\blackrule[width=4cm]}
756\stopbuffer
757
758\getbuffer \typebuffer \flushsidefloats
759
760\startbuffer
761\placemiddlemarginfigure{}{\blackrule[width=8cm]}
762\stopbuffer
763
764\getbuffer \typebuffer \flushsidefloats
765
766\startbuffer
767\placemiddlemarginfigure{}{\blackrule[width=16cm]}
768\stopbuffer
769
770\getbuffer \typebuffer \flushsidefloats
771
772\stopbuffer
773
774{\getbuffer[setupa,setupb,setupc,series]} \page
775{\getbuffer[setupa,setupb,setupc,series]} \page
776
777\startbuffer[series]
778
779\startbuffer
780\setupfloat
781  [middlefigure]
782  [default={here,none}]
783\stopbuffer
784
785\getbuffer \typebuffer
786
787\startbuffer
788\placemiddlefigure{}{\blackrule[width=.25cm]}
789\stopbuffer
790
791\getbuffer \typebuffer
792
793\startbuffer
794\placemiddlefigure{}{\blackrule[width=.5cm]}
795\stopbuffer
796
797\getbuffer \typebuffer
798
799\startbuffer
800\placemiddlefigure{}{\blackrule[width=1cm]}
801\stopbuffer
802
803\getbuffer \typebuffer
804
805\startbuffer
806\placemiddlefigure{}{\blackrule[width=2cm]}
807\stopbuffer
808
809\getbuffer \typebuffer
810
811\startbuffer
812\placemiddlefigure{}{\blackrule[width=4cm]}
813\stopbuffer
814
815\getbuffer \typebuffer
816
817\startbuffer
818\placemiddlefigure{}{\blackrule[width=8cm]}
819\stopbuffer
820
821\getbuffer \typebuffer
822
823%\startbuffer
824%\placemiddlefigure{}{\blackrule[width=16cm]}
825%\stopbuffer
826%
827%\getbuffer \typebuffer
828
829\stopbuffer
830
831{\getbuffer[setupa,setupb,setupc,series]} \page
832{\getbuffer[setupa,setupb,setupc,series]} \page
833
834\startbuffer[series]
835
836\startbuffer
837\setupfloat
838  [textfigure]
839  [criterium=.5\textwidth,
840   default={outer,none}]
841\stopbuffer
842
843\getbuffer \typebuffer
844
845\startbuffer
846\placetextfigure{}{\blackrule[width=.25cm]}
847\stopbuffer
848
849\getbuffer \typebuffer
850
851\startbuffer
852\placetextfigure{}{\blackrule[width=.5cm]}
853\stopbuffer
854
855\getbuffer \typebuffer
856
857\startbuffer
858\placetextfigure{}{\blackrule[width=1cm]}
859\stopbuffer
860
861\getbuffer \typebuffer
862
863\startbuffer
864\placetextfigure{}{\blackrule[width=2cm]}
865\stopbuffer
866
867\getbuffer \typebuffer
868
869\startbuffer
870\placetextfigure{}{\blackrule[width=4cm]}
871\stopbuffer
872
873\getbuffer \typebuffer
874
875\startbuffer
876\placetextfigure{}{\blackrule[width=8cm]}
877\stopbuffer
878
879\getbuffer \typebuffer
880
881\startbuffer
882\placetextfigure{}{\blackrule[width=16cm]}
883\stopbuffer
884
885\getbuffer \typebuffer
886
887\stopbuffer
888
889{\getbuffer[setupa,setupb,setupc,series]} \page
890{\getbuffer[setupa,setupb,setupc,series]} \page
891
892\startbuffer[series]
893
894\startbuffer
895\setupfloat
896  [leftfigure]
897  [criterium=.5\textwidth,
898   default={left,none}]
899\stopbuffer
900
901\getbuffer \typebuffer
902
903\startbuffer
904\placeleftfigure{}{\blackrule[width=.25cm]}
905\stopbuffer
906
907\getbuffer \typebuffer \flushsidefloats
908
909\startbuffer
910\placeleftfigure{}{\blackrule[width=.5cm]}
911\stopbuffer
912
913\getbuffer \typebuffer \flushsidefloats
914
915\startbuffer
916\placeleftfigure{}{\blackrule[width=1cm]}
917\stopbuffer
918
919\getbuffer \typebuffer \flushsidefloats
920
921\startbuffer
922\placeleftfigure{}{\blackrule[width=2cm]}
923\stopbuffer
924
925\getbuffer \typebuffer \flushsidefloats
926
927\startbuffer
928\placeleftfigure{}{\blackrule[width=4cm]}
929\stopbuffer
930
931\getbuffer \typebuffer \flushsidefloats
932
933\startbuffer
934\placeleftfigure{}{\blackrule[width=8cm]}
935\stopbuffer
936
937\getbuffer \typebuffer \flushsidefloats
938
939\startbuffer
940\placeleftfigure{}{\blackrule[width=16cm]}
941\stopbuffer
942
943\getbuffer \typebuffer \flushsidefloats
944
945\stopbuffer
946
947{\getbuffer[setupa,setupb,setupc,series]} \page
948{\getbuffer[setupa,setupb,setupc,series]} \page
949
950\startbuffer[series]
951
952\startbuffer
953\setupfloat
954  [rightfigure]
955  [criterium=.5\textwidth,
956   default={right,none}]
957\stopbuffer
958
959\getbuffer \typebuffer
960
961\startbuffer
962\placerightfigure{}{\blackrule[width=.25cm]}
963\stopbuffer
964
965\getbuffer \typebuffer \flushsidefloats
966
967\startbuffer
968\placerightfigure{}{\blackrule[width=.5cm]}
969\stopbuffer
970
971\getbuffer \typebuffer \flushsidefloats
972
973\startbuffer
974\placerightfigure{}{\blackrule[width=1cm]}
975\stopbuffer
976
977\getbuffer \typebuffer \flushsidefloats
978
979\startbuffer
980\placerightfigure{}{\blackrule[width=2cm]}
981\stopbuffer
982
983\getbuffer \typebuffer \flushsidefloats
984
985\startbuffer
986\placerightfigure{}{\blackrule[width=4cm]}
987\stopbuffer
988
989\getbuffer \typebuffer \flushsidefloats
990
991\startbuffer
992\placerightfigure{}{\blackrule[width=8cm]}
993\stopbuffer
994
995\getbuffer \typebuffer \flushsidefloats
996
997\startbuffer
998\placerightfigure{}{\blackrule[width=16cm]}
999\stopbuffer
1000
1001\getbuffer \typebuffer \flushsidefloats
1002
1003\stopbuffer
1004
1005{\getbuffer[setupa,setupb,setupc,series]} \page
1006{\getbuffer[setupa,setupb,setupc,series]} \page
1007
1008\startbuffer[series]
1009
1010\startbuffer
1011\setupfloat
1012  [bleedfigure]
1013  [criterium=.5\textwidth,
1014   leftmargindistance=-1mm,
1015   rightmargindistance=-1mm,
1016   default={backspace,none}]
1017\stopbuffer
1018
1019\getbuffer \typebuffer
1020
1021\startbuffer
1022\placebleedfigure{}{\blackrule[width=.25cm]}
1023\stopbuffer
1024
1025\getbuffer \typebuffer \flushsidefloats
1026
1027\startbuffer
1028\placebleedfigure{}{\blackrule[width=.5cm]}
1029\stopbuffer
1030
1031\getbuffer \typebuffer \flushsidefloats
1032
1033\startbuffer
1034\placebleedfigure{}{\blackrule[width=1cm]}
1035\stopbuffer
1036
1037\getbuffer \typebuffer \flushsidefloats
1038
1039\startbuffer
1040\placebleedfigure{}{\blackrule[width=2cm]}
1041\stopbuffer
1042
1043\getbuffer \typebuffer \flushsidefloats
1044
1045\startbuffer
1046\placebleedfigure{}{\blackrule[width=4cm]}
1047\stopbuffer
1048
1049\getbuffer \typebuffer \flushsidefloats
1050
1051\startbuffer
1052\placebleedfigure{}{\blackrule[width=8cm]}
1053\stopbuffer
1054
1055\getbuffer \typebuffer \flushsidefloats
1056
1057\startbuffer
1058\placebleedfigure{}{\blackrule[width=16cm]}
1059\stopbuffer
1060
1061\getbuffer \typebuffer \flushsidefloats
1062
1063\stopbuffer
1064
1065{\getbuffer[setupa,setupb,setupc,series]} \page
1066{\getbuffer[setupa,setupb,setupc,series]} \page
1067
1068\startbuffer[series]
1069
1070\startbuffer
1071\setupfloat
1072  [bleedfigure]
1073  [criterium=.5\textwidth,
1074   leftmargindistance=-1mm,
1075   rightmargindistance=-1mm,
1076   default={cutspace,none}]
1077\stopbuffer
1078
1079\getbuffer \typebuffer
1080
1081\startbuffer
1082\placebleedfigure{}{\blackrule[width=.25cm]}
1083\stopbuffer
1084
1085\getbuffer \typebuffer \flushsidefloats
1086
1087\startbuffer
1088\placebleedfigure{}{\blackrule[width=.5cm]}
1089\stopbuffer
1090
1091\getbuffer \typebuffer \flushsidefloats
1092
1093\startbuffer
1094\placebleedfigure{}{\blackrule[width=1cm]}
1095\stopbuffer
1096
1097\getbuffer \typebuffer \flushsidefloats
1098
1099\startbuffer
1100\placebleedfigure{}{\blackrule[width=2cm]}
1101\stopbuffer
1102
1103\getbuffer \typebuffer \flushsidefloats
1104
1105\startbuffer
1106\placebleedfigure{}{\blackrule[width=4cm]}
1107\stopbuffer
1108
1109\getbuffer \typebuffer \flushsidefloats
1110
1111\startbuffer
1112\placebleedfigure{}{\blackrule[width=8cm]}
1113\stopbuffer
1114
1115\getbuffer \typebuffer \flushsidefloats
1116
1117\startbuffer
1118\placebleedfigure{}{\blackrule[width=16cm]}
1119\stopbuffer
1120
1121\getbuffer \typebuffer \flushsidefloats
1122
1123\stopbuffer
1124
1125{\getbuffer[setupa,setupb,setupc,series]} \page
1126{\getbuffer[setupa,setupb,setupc,series]} \page
1127
1128\page
1129
1130\setupbackgrounds [text] [leftedge]    [background=]
1131\setupbackgrounds [text] [rightedge]   [background=]
1132\setupbackgrounds [text] [leftmargin]  [background=]
1133\setupbackgrounds [text] [rightmargin] [background=]
1134
1135At \CONTEXT\ and Bacho\TEX meetings it is now a tradition that Harald König and I
1136spend some time on figuring out what happens with border cases and interfences
1137with user intervention. As it's hard to nail down I decided to add some more
1138tracing and control. So, the remainder of this chapter is dedicated to Harald.
1139
1140We will now demonstrate some features in a way that makes it possible to
1141compare to the simple default case. Options can be passed as keywords:
1142
1143\starttyping
1144\placefigure
1145  [left,...]
1146  [fig:whatever]
1147  {caption}
1148  {content}
1149\stoptyping
1150
1151or as settings:
1152
1153\starttyping
1154\startplacefigure
1155  [default={left,...},
1156   title=caption,
1157   reference=fig:whatever]
1158
1159    content
1160
1161\stopplacefigure
1162\stoptyping
1163
1164It is important to realize that all that spacing can interfere with additional
1165hard coded corrections at the users end. We don't show the effects of \type
1166{sidespacebefore} and \type {sidespaceafter}, the two general vertical spacing
1167hooks. These are currently set to {\tttf \rootfloatparameter {sidespacebefore}}
1168and {\tttf \rootfloatparameter {sidespaceafter}} respectively. The \type
1169{sidealign} parameter is always winning from a keyword doing the same.
1170
1171The last few examples demonstrate that you can define an instance. Often that's
1172the best way to deal with special cases in a consistent way. For instance:
1173
1174\starttyping
1175\definefloat
1176  [LeftTwo]
1177  [figure]
1178
1179\setupfloat
1180  [LeftTwo]
1181  [default=left,
1182   sidealign=line]
1183\stoptyping
1184
1185First we show some keyword variant, next some parameter driven versions.
1186
1187\def\SampleKeyword#1%
1188  {\setbuffer[foo]
1189     \useMPlibrary[dum]
1190     \setupbodyfont[dejavu]
1191     \setuplayout[page]
1192     \placefigure[left]{}{\externalfigure[dummy]} \samplefile{sapolsky} \samplefile{sapolsky}
1193     \placefigure[#1]  {}{\externalfigure[dummy]} \samplefile{sapolsky} \samplefile{sapolsky}
1194   \endbuffer
1195   \framed
1196     [background=color,backgroundcolor=white,offset=overlay]
1197     {\scale
1198        [width=.45\textwidth]
1199        {\typesetbuffer[foo]}}}
1200
1201\def\SampleSettings#1#2#3%
1202  {\setbuffer[foo]
1203     \useMPlibrary[dum]
1204     \setupbodyfont[dejavu]
1205     \setuplayout[page]
1206     \definefloat[#1][figure]
1207     \setupfloat[#1][default=left]
1208     \definefloat[#2][figure]
1209     \setupfloat[#2][#3]
1210     \startplacefloat[#1] \externalfigure[dummy] \stopplacefloat \samplefile{sapolsky} \samplefile{sapolsky}
1211     \startplacefloat[#2] \externalfigure[dummy] \stopplacefloat \samplefile{sapolsky} \samplefile{sapolsky}
1212   \endbuffer
1213   \framed
1214     [background=color,backgroundcolor=white,offset=overlay]
1215     {\scale
1216        [width=.45\textwidth]
1217        {\typesetbuffer[foo]}}}
1218
1219\startbuffer[LeftOne]
1220\definefloat[LeftOne][figure]
1221
1222\setupfloat
1223  [LeftOne]
1224  [default=left]
1225\stopbuffer
1226
1227\startbuffer[LeftTwo]
1228\definefloat[LeftTwo][figure]
1229
1230\setupfloat
1231  [LeftTwo]
1232  [default=left,
1233   sidealign=line]
1234\stopbuffer
1235
1236\startbuffer[LeftThree]
1237\definefloat[LeftThree][figure]
1238
1239\setupfloat
1240  [LeftThree]
1241  [default={left,2*line}]
1242\stopbuffer
1243
1244\startbuffer[LeftFour]
1245\definefloat[LeftFour][figure]
1246
1247\setupfloat
1248  [LeftFour]
1249  [default={left},
1250   topoffset=5pt]
1251\stopbuffer
1252
1253\startbuffer[LeftFive]
1254\definefloat[LeftFive][figure]
1255
1256\setupfloat
1257  [LeftFive]
1258  [default={left},
1259   bottomoffset=5pt,
1260   topoffset=5pt]
1261\stopbuffer
1262
1263\startlinecorrection
1264\startcombination[2*2]
1265    {\SampleKeyword{left,high}}     {\type{left,high}}
1266    {\SampleKeyword{left,low}}      {\type{left,low}}
1267    {\SampleKeyword{left,high,low}} {\type{left,high,low}}
1268    {\SampleKeyword{left,fit}}      {\type{left,fit}}
1269\stopcombination
1270\stoplinecorrection
1271
1272\startlinecorrection
1273\startcombination[2*2]
1274    {\SampleKeyword{left,halfline}} {\type{left,halfline}}
1275    {\SampleKeyword{left,height}}   {\type{left,height}}
1276    {\SampleKeyword{left,depth}}    {\type{left,depth}}
1277    {\SampleKeyword{left,grid}}     {\type{left,grid}}
1278\stopcombination
1279\stoplinecorrection
1280
1281\startlinecorrection
1282\startcombination[2*2]
1283    {\SampleKeyword{left,line}}     {\type{left,line}}
1284    {\SampleKeyword{left,1*line}}   {\type{left,1*line}}
1285    {\SampleKeyword{left,2*line}}   {\type{left,2*line}}
1286    {\SampleKeyword{left,3*line}}   {\type{left,3*line}}
1287\stopcombination
1288\stoplinecorrection
1289
1290\startlinecorrection
1291\startcombination[2*2]
1292    {\SampleSettings{LeftOne}{LeftTwo}  {default={left,line}}}
1293                                        {\typ{default={left,line}}}
1294    {\SampleSettings{LeftOne}{LeftThree}{default={left,2*line}}}
1295                                        {\typ{default={left,2*line}}}
1296    {\SampleSettings{LeftOne}{LeftFour} {default=left,topoffset=5pt}}
1297                                        {\typ{default=left, topoffset=5pt}}
1298    {\SampleSettings{LeftOne}{LeftFive} {default=left, topoffset=5pt, bottomoffset=5pt}}
1299                                        {\typ{default=left, topoffset=5pt, bottomoffset=5pt}}
1300\stopcombination
1301\stoplinecorrection
1302
1303There is some tracing built in but as this mechanism is rather complex it only
1304gives an idea about what is going on. Here is an example:
1305
1306\startbuffer[one]
1307\enabletrackers[floats.anchoring]
1308
1309\showframe
1310
1311\setupfloat
1312  [sidespacebefore=big,
1313   sidespaceafter=big]
1314
1315\starttext
1316    \dorecurse{10}{
1317        \placefigure[left]{#1.1}{}
1318        a small sentence \par
1319        \placefigure[left]{#1.2}{}
1320        a small sentence \par
1321        \input klein \par
1322    }
1323\stoptext
1324\stopbuffer
1325
1326\typebuffer[one]
1327
1328In \in {figure} [fig:side:one:1] and \in {figure} [fig:side:one:2] you see the
1329first two pages of the typeset result.
1330
1331The anchor to the text is showed in orange and an optional shift in red. The content
1332is in green and a depth compensation in magenta. Dummy lines added for proper
1333spacing as well as progressing beyond a previous float are in blue.
1334
1335\startplacefigure[title={Side float tracing example 1, page 1.},reference=fig:side:one:1]
1336    \scale[width=\textwidth]{\typesetbuffer[one][page=1]}
1337\stopplacefigure
1338
1339\startplacefigure[title={Side float tracing example 1, page 2.},reference=fig:side:one:2]
1340    \scale[width=\textwidth]{\typesetbuffer[one][page=2]}
1341\stopplacefigure
1342
1343A second example that uses different settings is shown in \in {figure}
1344[fig:side:two:1] and \in {figure} [fig:side:two:2].
1345
1346\startbuffer[two]
1347\enabletrackers[floats.anchoring]
1348
1349\setupfloat
1350  [sidespacebefore=,
1351   sidespaceafter=big,
1352   step=small]
1353
1354\showframe
1355
1356\starttext
1357    \dorecurse{10}{
1358        \placefigure[left]{#1.1}{}
1359        a small sentence \par
1360        \placefigure[left]{#1.2}{}
1361        a small sentence \par
1362        \input klein \par
1363    }
1364\stoptext
1365\stopbuffer
1366
1367\typebuffer[two]
1368
1369\startplacefigure[title={Side float tracing example 2, page 1.},reference=fig:side:two:1]
1370   \framed
1371      [background=color,backgroundcolor=white,offset=overlay]
1372      {\scale[width=\textwidth]{\typesetbuffer[two][page=1]}}
1373\stopplacefigure
1374
1375\startplacefigure[title={Side float tracing example 2, page 2.},reference=fig:side:two:2]
1376   \framed
1377      [background=color,backgroundcolor=white,offset=overlay]
1378      {\scale[width=\textwidth]{\typesetbuffer[two][page=2]}}
1379\stopplacefigure
1380
1381\startbuffer[three]
1382\usemodule[simulate]
1383
1384\setuplayout
1385  [tight]
1386
1387\setupbodyfont
1388  [dejavu]
1389
1390\enabletrackers
1391  [floats.anchoring]
1392
1393\setupfloats
1394  [sidethreshold=.5\strutdp, % default, use "old" for previous implementation
1395   step=small]
1396
1397\definemeasure[MyHeight][3cm]
1398\definemeasure[MyWidth] [3cm]
1399
1400% \setupheadertexts
1401%   [width=\measure{MyWidth}\quad height=\measure{MyHeight}]
1402
1403\unexpanded\def\FakeWords#1%
1404  {\simulatewords
1405     [n=#1,m=#1,min=1,max=5,hyphen=no,color=text,line=yes,random=1234]}
1406
1407\starttext
1408
1409\startbuffer
1410    \FakeWords{100}\par
1411    \placefigure
1412        [left] {oeps}
1413        {\framed[width=\measure{MyWidth},height=\measure{MyHeight}]{}}
1414    \FakeWords  {2}\par
1415    \FakeWords  {3}\par
1416    \FakeWords  {5}\par
1417    \FakeWords  {4}\par
1418    \FakeWords{200}\par
1419    \placefigure
1420        [left] {oeps}
1421        {\framed[width=\measure{MyWidth},height=\measure{MyHeight}]{}}
1422    \FakeWords{200}\par
1423\stopbuffer
1424
1425\dostepwiserecurse {\number\dimexpr3cm} {\number\dimexpr4cm} {\number\dimexpr0.25cm} {
1426    \definemeasure[MyWidth][#1sp]
1427    \dostepwiserecurse {\number\dimexpr3cm} {\number\dimexpr4cm} {\number\dimexpr0.25cm} {
1428        \definemeasure[MyHeight][##1sp]
1429        \start
1430            \setupwhitespace[none]
1431            \getbuffer \page
1432        \stop
1433        \start
1434            \setupwhitespace[big]
1435            \getbuffer \page
1436        \stop
1437    }
1438}
1439\stoptext
1440\stopbuffer
1441
1442Progressing next to a side float and determining how many lines to indent is a
1443somewhat complex mechamism because many factors play a role and spacing can
1444interfere badly. The decision about the number of lines to hang is to some extend
1445controllable but there are cases when you need to steer it (for instance by
1446scaling an image). In the next overviews we see the result of the following
1447somewhat complex setup:
1448
1449\typebuffer[three]
1450
1451The \type {step} parameter controls how we fill up the space when we need to
1452progress beyond it for instance because another float shows up or because we
1453issue a \type {\flushsidefloats}. Its value can be \type {big}, \type {medium} or
1454\type {small} and defaults to \type {small} which gives of enough precision. The
1455\type {sidethreshold} parameter controls the number of lines that we hang around
1456the float. Here we only show the consequence of the the threshold. A larger
1457threshold result in mode whitespace below the side float. You can zoom in to see
1458what happens at the bottom of the float (or run the examples yourself).
1459
1460\def\ShowSample#1%
1461  {\framed
1462     [background=color,backgroundcolor=white,offset=overlay]
1463     {\scale
1464        [width=\dimexpr(\textwidth-2\emwidth)/3\relax]
1465        {\typesetbuffer[three][page=#1]}}}
1466
1467\startplacefigure[title={The working of default step and side threshold (no whitespace.},reference=fig:side:three:1]
1468    \startcombination[3*3]
1469        {\ShowSample {1}} {} {\ShowSample {3}} {} {\ShowSample {5}} {}
1470        {\ShowSample {7}} {} {\ShowSample {9}} {} {\ShowSample {9}} {}
1471        {\ShowSample{11}} {} {\ShowSample{13}} {} {\ShowSample{15}} {}
1472    \stopcombination
1473\stopplacefigure
1474
1475\startplacefigure[title={The working of default step and side threshold (whitespace).},reference=fig:side:three:2]
1476    \startcombination[3*3]
1477        {\ShowSample {2}} {} {\ShowSample {4}} {} {\ShowSample {6}} {}
1478        {\ShowSample {8}} {} {\ShowSample{10}} {} {\ShowSample{12}} {}
1479        {\ShowSample{12}} {} {\ShowSample{14}} {} {\ShowSample{15}} {}
1480    \stopcombination
1481\stopplacefigure
1482
1483\stopchapter
1484
1485\stopcomponent
1486