strc-flt.mkvi /size: 98 Kb    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=strc-flt,
3%D        version=2008.10.20,
4%D          title=\CONTEXT\ Structure Macros,
5%D       subtitle=Float Numbering,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D This module will be redone with conditionals and everythings
15
16\writestatus{loading}{ConTeXt Structure Macros / Float Numbering}
17
18\registerctxluafile{strc-flt}{}
19
20\unprotect
21
22% todo: a keyword for this (and then a settings->hash for speed)
23%
24% \setuplayout[width=middle,backspace=3cm]
25%
26% \appendtoks
27%     \settrue\inhibitmargindata
28% \to \everyinsidefloat
29%
30% \starttext
31%     \dorecurse{20}{
32%         \par \inleft{\red\infofont<#1>} \par
33%         \placefigure[leftmargin]{}{\framed[height=1cm,width=2cm]{}}
34%       % \placefigure{#1}{\framed[height=1cm,width=2cm]{}}
35%         \par line #1.1 \par line #1.2 \par
36%     }
37% \stoptext
38
39% todo: delay caption creation and make setups for each method instead
40%       so that we can have a list of methods and redo them as we can
41%       keep the list or even better: recreate it
42%
43% todo: strc_floats_analyze_variables_two could trigger a setup
44%       and we could have nofmethods of them
45%
46% todo: move variables from page-flt to strc-flt
47%
48% todo: p_name etc
49%
50% todo: less globals!
51%
52% todo: do all options in lua
53
54%D This module is being converted into a mkvi one.
55%D
56%D - rename macros
57%D - get rid of dead code
58%D - less gobal mess
59%D - more mkiv-ish
60
61\installcorenamespace{float}
62\installcorenamespace{floatbuilder}
63\installcorenamespace{floatcaption}
64\installcorenamespace{floatframed}
65
66\installframedcommandhandler \??float        {float}        \??float
67\installframedcommandhandler \??floatcaption {floatcaption} \??floatcaption
68\installframedcommandhandler \??floatframed  {floatframed}  \??floatframed
69
70\let\setupfloats  \setupfloat
71\let\setupcaption \setupfloatcaption
72\let\setupcaptions\setupfloatcaption
73
74\unexpanded\def\dohandlenextfloatindent
75  {\useindentnextparameter\floatparameter
76   \dorechecknextindentation}
77
78\setupcaptions
79  [\c!location=\v!bottom,
80   \c!grid=,
81   \c!before=, % not used (yet)
82   \c!inbetween={\blank[\v!medium]},
83   \c!after=, % not used (yet)
84   \c!spacebefore=,
85   \c!spaceinbetween=, % replaces fuzzy inbetween dual usage
86   \c!spaceafter=,
87   \c!width=\v!fit,
88   \c!minwidth=\v!fit, % id est: the width of the floatbox in some cases
89   \c!headstyle=\v!bold,
90   \c!headcolor=,
91   \c!leftmargin=\zeropoint,
92   \c!rightmargin=\zeropoint,
93   \c!outermargin=\zeropoint,
94   \c!innermargin=\zeropoint,
95   \c!setups=,
96   \c!style=\v!normal,
97   \c!color=,
98   \c!textstyle=,
99   \c!textcolor=,
100   \c!align=,
101   \c!number=\v!yes,
102   \c!offset=\v!overlay,
103   \c!frame=\v!off,
104 % \c!expansion=,
105 % \c!prefix=,
106 % \c!prefixconnector=,
107 % \c!way=,
108 % \c!prefixsegments=,
109 % \c!way=,
110 % \c!blockway=,
111 % \c!sectionnumber=,
112 % \c!separator=,
113 % \c!starter=,
114 % \c!stopper=,
115   \c!suffixseparator=, % currently rather hard coded
116   \c!suffix=\floatcaptionsuffix,
117   \c!distance=\emwidth, % plus .5\emwidth minus .25\emwidth
118   \c!conversion=\v!numbers,
119   \c!maxwidth=\hsize,
120   \c!command=]
121
122% we can comment some of these
123
124\setupfloats
125  [\c!location=\v!middle,
126   \c!width=8\lineheight,
127   \c!height=6\lineheight,
128   \c!offset=\v!overlay,
129   \c!frame=\v!off,
130   \c!strut=\v!no,
131   \c!radius=.5\bodyfontsize,
132   \c!corner=\v!rectangular,
133   \c!grid=,
134  %\c!background=,
135  %\c!backgroundcolor=,
136   \c!backgroundoffset=\!!zeropoint,
137  %\c!topframe=,
138  %\c!bottomframe=,
139  %\c!leftframe=,
140  %\c!rightframe=,
141   \c!frameoffset=\!!zeropoint,
142  %\c!before=,
143  %\c!after=,
144   \c!spacebefore=\v!big,
145   \c!spaceafter=\v!big,
146   \c!sidespacebefore=\rootfloatparameter\c!spacebefore,
147   \c!sidespaceafter=\rootfloatparameter\c!spaceafter,
148   \c!sidespaceinbetween=\rootfloatparameter\c!spacebefore,
149   \c!spacebeforeside=, % extra, not part of, can be used to add whitespace before text
150   \c!spaceafterside=,  % idem
151   \c!sidealign=\v!normal,
152   \c!textmethod=\ifgridsnapping2\else0\fi, % 0=raw 1=safe (.99pg) 2=tight (-1pt) % THIS WILL CHANGE
153   \c!sidemethod=\ifgridsnapping2\else1\fi, % 0=raw 1=safe (.99pg) 2=tight (-1pt) % THIS WILL CHANGE
154   \c!indentnext=\v!no,
155   \c!margin=\emwidth,
156   \c!method=1,
157   \c!cache=\v!yes, % when no, then intermediate flush
158   \c!leftmargin=\zeropoint,  % displacement in 'normal floats'
159   \c!rightmargin=\zeropoint, % idem
160   \c!innermargin=\zeropoint, % idem
161   \c!outermargin=\zeropoint, % idem
162   \c!leftmargindistance=\zeropoint,
163   \c!rightmargindistance=\floatparameter\c!leftmargindistance,
164   \c!step=\v!small, % the flush side float step (big, medium, small : always depth)
165   \c!ntop=2,
166   \c!nbottom=0,
167   \c!nlines=4, % used?
168   \c!topoffset=\zeropoint,
169   \c!bottomoffset=\zeropoint,
170   \c!freeregion=\v!yes,
171  %\c!local=,
172  %\c!bottombefore=, % e.g. \vfill
173  %\c!bottomafter=,
174  %\c!default=, % default location
175   \c!sidethreshold=.5\strutdp, % set to "old" to check with old method
176   \c!numbering=\v!yes,
177   \c!compress=\v!yes, % when possible pack floats when flushing
178   \c!compressdistance=\emwidth]
179
180\setupfloatframed
181  [\c!frame=\v!off,
182   \c!offset=\v!overlay,
183   \c!strut=\v!no]
184
185\appendtoks
186    \doifelse{\floatparameter\c!compress}\v!yes\settrue\setfalse\c_page_floats_pack_flushed
187    \d_page_floats_compress_distance\floatparameter\c!compressdistance\relax
188\to \everysetupfloat
189
190%D We need to do it again here:
191
192\setupfloat
193  [\c!compress=\v!yes, % when possible pack floats when flushing
194   \c!compressdistance=\emwidth]
195
196%D Individial settings:
197
198\installcounterassociation{floatcaption}
199
200\appendtoks
201    \let\currentfloat\currentfloatcaption % ?
202    \synchronizefloatcaptioncounters
203\to \everysetupfloatcaption
204
205\appendtoks
206    \let\currentfloat\currentfloatcaption % ?
207    \synchronizefloatcaptioncounters
208\to \everydefinefloatcaption
209
210%D Definitions:
211
212\let\strc_floats_define_saved\definefloat
213
214\unexpanded\overloaded\def\definefloat
215  {\dotripleempty\strc_floats_define}
216
217\def\strc_floats_define[#1][#2][#3]% name+plural+parent | name+parent+settings
218  {\ifthirdargument
219     \doifassignmentelse{#3}
220       {\strc_floats_define_b[#1][#2][#3]}%
221       {\strc_floats_define_a[#1][#2][#3]}%
222   \else\ifsecondargument
223     \doifelsecommandhandler\??float{#2}%
224       {\strc_floats_define_a[#1][#1][#2]}%
225       {\strc_floats_define_c[#1][#2]}%
226   \else
227     \strc_floats_define_c[#1][#1]%
228   \fi\fi}
229
230\def\strc_floats_define_a[#1][#2][#3]% name names parent
231  {\definefloatcaption[#1][#3]%
232   \definefloatframed[#1][#3]%
233   \definecounter[#1][#3]%
234   \definelist[#1][#3]%
235   \copylabeltext[#1=#3]%
236   \strc_floats_define_saved[#1][#3]%
237   \strc_floats_define_commands{#1}{#2}}
238
239\def\strc_floats_define_b[#1][#2][#3]% name parent settings
240  {\definefloatcaption[#1][#2]%
241   \definefloatframed[#1][#2]%
242   \definecounter[#1][#2]%
243   \definelist[#1][#2]%
244   \copylabeltext[#1=#2]%
245   \strc_floats_define_saved[#1][#2][#3]%
246   \strc_floats_define_commands{#1}{#1}}
247
248\def\strc_floats_define_c[#1][#2]% name names
249  {\registerfloatcaptioncounter{#1}%
250   \definefloatcaption[#1]%
251   \definefloatframed[#1]%
252   \definecounter[#1]%
253   \definelist[#1]%
254   \presetlabeltext[#1=\Word{#1}~]%
255   \presetheadtext[#2=\Word{#2}]%
256   \strc_floats_define_saved[#1]%
257   \strc_floats_define_commands{#1}{#2}}
258
259\def\strc_floats_define_commands#1#2%
260  {\setuvalue         {\e!place\e!listof#2}{\dodoubleempty\strc_lists_place[#1]}% call will change
261   \setuvalue      {\e!complete\e!listof#2}{\dotripleempty\strc_lists_complete_indeed[#1][#2]}% call will change
262   \setuevalue                 {\e!place#1}{\strc_floats_place{#1}}%
263   \setuevalue         {\e!start\e!place#1}{\strc_floats_start_place{#1}}%
264   \setuevalue          {\e!stop\e!place#1}{\strc_floats_stop_place}%
265   \setuevalue          {\e!start#1\e!text}{\strc_floats_start_text{#1}}%
266   \setuevalue           {\e!stop#1\e!text}{\strc_floats_stop_text}%
267   % these will become obsolete:
268   \setuevalue               {\e!reserve#1}{\strc_floats_reserve{#1}}%
269   \setuevalue{\e!start\e!reserve#1\e!text}{\strc_floats_start_reserve_text{#1}}%
270   \setuevalue {\e!stop\e!reserve#1\e!text}{\strc_floats_stop_reserve_text}}
271
272%D Fallback float body:
273
274\unexpanded\def\strc_floats_place_empty_box % \inheritedfloatframed
275  {\framed
276     [\c!frame=\v!on,
277      \c!width=\rootfloatparameter\c!width,
278      \c!height=\rootfloatparameter\c!height,
279      \c!location=\v!normal,
280      \c!offset=\rootfloatparameter\c!offset]%
281     {\getmessage\m!floatblocks{12}\empty}}
282
283%D Data. We can generalize this to lists.
284
285\newif\ifnofloatcaption
286\newif\ifnofloatnumber
287\newif\ifemptyfloatcaption
288
289\installstructurelistprocessor\s!float{\usestructurelistprocessor{number+title}}
290
291\unexpanded\def\thecurrentfloatnumbersuffix
292  {\doifsomething{\floatcaptionparameter\c!suffix}
293     {\floatcaptionparameter\c!suffixseparator
294      \floatcaptionparameter\c!suffix
295      \floatcaptionparameter\c!suffixstopper}}
296
297\unexpanded\def\thecurrentfloatnumber
298  {\ifnofloatcaption \else \ifnofloatnumber \else
299     \ifx\currentfloatnumber\relax\else
300       \namedtaggedlabeltexts
301         \t!floatlabel \currentfloat
302         \t!floatnumber\currentfloat
303         {\begstrut
304          \floatcaptionparameter\c!numbercommand
305            {\clf_savedlistprefixednumber{\currentfloat}\currentfloatnumber\relax
306             \thecurrentfloatnumbersuffix}%
307          \endstrut}%
308     \fi
309   \fi \fi}
310
311\unexpanded\def\thecurrentfloatcaption
312  {\ifnofloatcaption \else \ifemptyfloatcaption \else
313     \ifx\currentfloatnumber\relax\else
314       \dostarttagged\t!floattext\empty
315       \begstrut
316       \floatcaptionparameter\c!textcommand
317         {\clf_savedlisttitle{\currentfloat}\numexpr\currentfloatnumber\relax}%
318       \endstrut
319       \dostoptagged
320     \fi
321   \fi \fi}
322
323%D Captions.
324
325\let\floatcaptionsuffix\empty % an optional suffix
326\let\floatcaptionnumber\empty % a logical counter
327
328% For a while these were placeholders:
329%
330%D \starttyping
331%D \unexpanded\def\placefloatcaption{\dodoubleempty\strc_floats_place_caption}
332%D \unexpanded\def\setfloatcaption  {\dodoubleempty\strc_floats_set_caption}
333%D
334%D \def\strc_floats_place_caption[#tag][#reference]#caption{[not supported]}
335%D \def\strc_floats_set_caption  [#tag][#reference]#caption{[not supported]}
336%D
337%D \unexpanded\def\placefloatcaptiontext     [#tag]{[not suported yet]}
338%D \unexpanded\def\placefloatcaptionnumber   [#tag]{[not suported yet]}
339%D \unexpanded\def\placefloatcaptionreference[#tag]{[not suported yet]}
340%D \stoptyping
341%D
342%D because in \MKII\ we had:
343%D
344%D \starttyping
345%D \let\placefloatlabel         \placefloatcaption
346%D \let\placefloatlabeltext     \placefloatcaptiontext
347%D \let\placefloatlabelreference\placefloatcaptionreference
348%D \stoptyping
349%D
350%D But as it was never advertised we don't provide it in \MKIV. However, at some
351%D point HvdM wanted this:
352%D
353%D \starttyping
354%D \placefigure                     {labeltext-1}  {\externalfigure[figure-1]}
355%D \placefloatcaption[figure][title={labeltext-2}]  \externalfigure[figure-2]
356%D \placefigure                     {labeltext-3}  {\externalfigure[figure-3]}
357%D \stoptyping
358%D
359%D So there you have it:
360
361\unexpanded\def\placefloatcaption
362  {\dotripleempty\strc_floats_place_caption}
363
364\def\strc_floats_place_caption[#category][#settings][#userdata]%
365  {\ifsecondargument
366     % we need at least a category and title
367     \dontleavehmode
368     \bgroup
369     \edef\currentfloat{#category}%
370     \let\currentfloatcaption\currentfloat
371     \resetfloatcaptionparameter\c!reference
372     \resetfloatcaptionparameter\c!title
373     \resetfloatcaptionparameter\c!marking
374     \resetfloatcaptionparameter\c!list
375     \resetfloatcaptionparameter\c!bookmark
376     \setupcurrentfloatcaption[#settings]%
377     \edef\currentfloatcounter{\namedcounterparameter\currentfloat\s!name}%
378     \iftrialtypesetting\strc_counters_save\currentfloatcounter\fi
379     \strc_counters_increment\currentfloatcounter
380     \strc_counters_register_component
381       \s!float
382       \setupcurrentfloatcaption
383       \floatcaptionparameter
384       \detokenizedfloatcaptionparameter
385       \relax
386       \relax
387       \relax
388       [\s!name=\currentfloat,
389        \s!counter=\currentfloatcounter,%
390        \s!hascaption=\v!yes,%
391        \s!hasnumber=\v!yes,%
392        \s!hastitle=\v!yes]%
393       [#userdata]%
394     \glet\previousfloatnumber    \m_strc_counters_last_registered_index
395     \glet\currentfloatnumber     \m_strc_counters_last_registered_index
396     \glet\currentfloatattribute  \m_strc_counters_last_registered_attribute
397     \glet\currentfloatsynchronize\m_strc_counters_last_registered_synchronize
398     %
399   % \iflocation
400   %    \c_attr_destination\currentfloatattribute\relax
401   % \fi
402     \currentfloatsynchronize
403     \strc_floats_make_complete_caption
404     %
405     \iftrialtypesetting\strc_counters_restore\currentfloatcounter\fi
406     \egroup
407   \fi}
408
409\newbox  \b_strc_floats_caption
410\newbox  \b_strc_floats_content
411\newdimen\d_strc_floats_caption_height
412\newdimen\d_strc_floats_caption_depth
413
414\def\strc_floats_make_complete_caption
415  {\doifsomething{\floatcaptionparameter\c!spacebefore}{\blank[\floatcaptionparameter\c!spacebefore]}%
416   \strc_floats_make_complete_caption_before
417   \synchronizedisplaydirection % temp hack, till we have a proper model
418   \noindent
419   \gdef\lastcaptiontag{\strut\thecurrentfloatnumber}% was xdef ... needs checking
420   \begingroup
421     \ifnofloatcaption
422       \global\d_strc_floats_caption_height\zeropoint
423       \global\d_strc_floats_caption_depth \zeropoint
424     \else
425       \usefloatcaptionstyleandcolor\c!style\c!color
426       \clf_doifelselisthastitle{\currentfloat}\numexpr\currentfloatnumber\relax
427         \donothing
428         \emptyfloatcaptiontrue
429       \ifnofloatnumber \else \ifnofloatcaption \else
430         \ifemptyfloatcaption
431           \hbox{\usefloatcaptionstyleandcolor\c!headstyle\c!headcolor\thecurrentfloatnumber}%
432         \else
433           \doifelsenothing{\floatcaptionparameter\c!spaceinbetween}
434             {\scratchskip\floatcaptionparameter\c!distance\relax
435              \setbox\scratchbox\hbox
436                {\usefloatcaptionstyleandcolor\c!headstyle\c!headcolor
437                 \thecurrentfloatnumber
438                 \floatcaptionparameter\c!headseparator
439                 \dotfskip\scratchskip}%
440              \doifelse{\floatcaptionparameter\c!hang}\v!yes
441                 {\leftskip\wd\scratchbox
442                  \llap{\box\scratchbox}}
443                 {\unhbox\scratchbox}%
444               \emergencystretch.5\scratchskip}
445             {\hbox{\usefloatcaptionstyleandcolor\c!headstyle\c!headcolor\thecurrentfloatnumber}%
446              \blank[\floatcaptionparameter\c!spaceinbetween]}%
447         \fi
448       \fi \fi
449       \usefloatcaptionstyleandcolor\c!textstyle\c!textcolor
450       \global\d_strc_floats_caption_height\strutheight
451       \global\d_strc_floats_caption_depth \strutdepth
452       \thecurrentfloatcaption\endgraf
453     \fi
454   \endgroup
455   \strc_floats_make_complete_caption_after
456   \doifsomething{\floatcaptionparameter\c!spaceafter}{\blank[\floatcaptionparameter\c!spaceafter]}}
457
458%let\strc_floats_make_complete_caption_before\relax
459\let\strc_floats_make_complete_caption_after \relax
460
461\def\strc_floats_make_complete_caption_before
462  {\doifelseframed\floatcaptionparameter\strc_floats_make_complete_caption_before_indeed\relax}
463
464\def\strc_floats_make_complete_caption_before_indeed
465  {\edef\m_strc_align{\floatcaptionparameter\c!align}%
466   \edef\m_strc_strut{\floatcaptionparameter\c!strut}%
467   \letfloatcaptionparameter\c!align\v!normal
468   \letfloatcaptionparameter\c!strut\v!no
469   \inheritedfloatcaptionframed
470   \bgroup
471   \letfloatcaptionparameter\c!align\m_strc_align
472   \letfloatcaptionparameter\c!strut\m_strc_strut
473   \let\strc_floats_make_complete_caption_after\egroup}
474
475% \definefloat  [figure-1] [figure]
476% \definefloat  [figure-2] [figure]
477% \setupfloat   [figure-1] [location=left,leftmargin=10mm]
478% \setupfloat   [figure-2] [location=left,leftmargin=-5mm]
479% \setupcaption [figure-1] [align=flushleft]
480% \setupcaption [figure-2] [align=flushleft,leftmargin=15mm]
481%
482% \startsetups somefigure
483%     \ifdim\wd\nextbox>\textwidth
484%         \placefloat[figure-2][][]{}{\box\nextbox}
485%     \else
486%         \placefloat[figure-1][][]{}{\box\nextbox}
487%     \fi
488% \stopsetups
489%
490% \unexpanded\def\setupswithbox[#1]{\dowithnextbox{\setups[#1]}\vbox}
491%
492% test \setupswithbox[somefigure]{\framed[width=3cm]                         {}} test
493% test \setupswithbox[somefigure]{\framed[width=\dimexpr\textwidth+3cm\relax]{}} test
494
495% temporary removed ... was not applied systematically
496%
497% \def\dosetcaptionthings
498%   {\usesetupsparameter\floatcaptionparameter}
499
500\def\strc_floats_check_caption_content
501  {\ifnofloatcaption
502   \else
503     \setbox\b_strc_floats_caption\hbox
504       {\settrialtypesetting
505        \notesenabledfalse
506        \strc_floats_make_complete_caption}%
507     % new, \placefigure{\xmlfirst{#1}{somecaption}}{} passes earlier empty check
508     % so here we misuse the scratch box; actually this means that the previous
509     % test can go away (some day, when i redo this module)
510     \ifzeropt\wd\b_strc_floats_caption
511       \global\emptyfloatcaptiontrue
512       \ifnofloatnumber
513         \global\nofloatcaptiontrue
514       \fi
515     \else
516       \global\emptyfloatcaptionfalse
517       \setbox\b_strc_floats_caption\hpack{\hskip\leftskip\box\b_strc_floats_caption}%
518     \fi
519   \fi}
520
521%D We can do this ...
522%D
523%D \starttyping
524%D \newcount\c_strc_floats_n
525%D
526%D \definedataset[\s!float][\c!delay=\v!yes]
527%D
528%D \let\strc_float_realpage\realpageno
529%D
530%D \def\strc_float_save_data
531%D   {\setdataset[\s!float][\number\c_strc_floats_n][]}
532%D
533%D \def\strc_float_load_data % precedes save !
534%D   {\global\advance\c_strc_floats_n\plusone
535%D    \xdef\strc_float_realpage{\datasetvariable\s!float{\number\c_strc_floats_n}\s!page}%
536%D    \ifx\strc_float_realpage\empty
537%D      \glet\strc_float_realpage\realpageno % \realfolio
538%D    \fi}
539%D \stoptyping
540%D
541%D ... but this is more efficient:
542
543\definepagestate[\s!float][\c!delay=\v!yes]
544
545\newcount\c_strc_floats_n
546
547\let\strc_float_realpage\realpageno
548
549\def\strc_float_save_data
550  {\setpagestate[\s!float][\number\c_strc_floats_n]}
551
552\def\strc_float_load_data % precedes save !
553  {\global\advance\c_strc_floats_n\plusone
554   \xdef\strc_float_realpage{\pagestaterealpage\s!float{\number\c_strc_floats_n}}%
555   \ifx\strc_float_realpage\empty
556    \glet\strc_float_realpage\realpageno % \realfolio
557   \fi}
558
559%D test case:
560%D
561%D \starttyping
562%D \setupfloat[figure][criterium=\marginwidth,fallback=bottom]
563%D \dorecurse{3}{
564%D     \chapter{test}
565%D     \placefigure[bottom]{1}{\framed{bottom}}
566%D     test
567%D     \placetable[bottom]{1}{\framed{table}}
568%D     test
569%D     \placetable{2}{\framed{table}}
570%D     test
571%D     \placefigure[left]{2}{\framed{left but way too wide}}
572%D     \input tufte
573%D     \placefigure[left]{3}{\framed{left but ok}}
574%D     \input tufte }
575%D \stoptyping
576
577% A complication is that we may have to handle a pagebreak
578% first, which in turn may issue a (postponed) float.
579% Therefore we may not trust on variable assignments before
580% we're really dealing with the float. Some day I'll root out
581% the global settings.
582
583\let\lastplacedfloat\empty
584
585\def\strc_floats_set_current_tag#tag%
586  {\edef\currentfloat{#tag}%
587   \ifx\currentfloat\empty
588     \let\currentfloat\v!figure % a bit of a hack
589   \fi
590   \doifelsecommandhandler\??float\currentfloat
591     \donothing
592     {\writestatus\m!floatblocks{unknown float type '\currentfloat'}%
593      \let\currentfloat\v!figure}% also a hack
594   \glet\lastplacedfloat\currentfloat
595   \let\m_strc_floats_saved_userdata\empty
596   \let\currentfloatcaption\currentfloat}
597
598\let\askedfloatmethod \empty
599\let\askedfloatoptions\empty
600
601\def\strc_floats_reset_variables
602  {\global\emptyfloatcaptionfalse
603   \global\nofloatcaptionfalse
604   \global\nofloatnumberfalse
605   \glet\askedfloatmethod \empty
606   \glet\askedfloatoptions\empty}
607
608% place
609
610\let\floatlabel         \empty
611\let\floatcolumn        \empty
612\let\floatrow           \empty
613\let\floatlocation      \empty
614\let\floatlocationmethod\empty
615
616\def\strc_floats_analyze_location
617  {% more will be moved here
618   \let\floatlabel \empty
619   \let\floatcolumn\empty
620   \let\floatrow   \empty
621   %
622   \edef\floatcaptionlocation{\floatcaptionparameter\c!location}%
623   %
624   \setfloatmethodvariables\floatlocation}
625
626\unexpanded\def\strc_floats_place#tag%
627  {\flushnotes
628   \page_otr_command_flush_side_floats % here !
629   \strc_floats_begin_group
630   \strc_floats_set_current_tag{#tag}%
631   \dodoubleempty\strc_floats_place_indeed}
632
633\newtoks\c_floats_every_table_float
634
635\appendtoks
636    \edef\floatlocation{\v!force,\v!always,\floatlocation}%
637    \setupfloat[\c!spacebefore=\v!none,\c!spaceafter=\v!none]%
638\to \c_floats_every_table_float
639
640\ifdefined\dotagregisterfloat \else \let\dotagregisterfloat\gobbletwoarguments \fi
641
642\def\strc_floats_place_indeed[#location][#reference]#caption%
643  {\strc_floats_reset_variables
644   \xdef\askedfloatoptions{#location}%
645   \edef\floatlocation{#location}%
646   \ifx\floatlocation\empty
647     \edef\floatlocation{\floatparameter\c!default}% beware of a clash between alignment locations
648   \fi
649   \ifintable
650     \the\c_floats_every_table_float
651   \fi
652   \strc_floats_analyze_location
653   % todo: use \lets
654   \setupcurrentfloatcaption[\c!reference={#reference},\c!title={#caption},\c!marking=,\c!list=,\c!bookmark=]%
655   \doifelseinset\v!split\floatlocation\strc_floats_place_next_box_split\strc_floats_place_next_box_normal}
656
657\unexpanded\def\placefloat
658  {\flushnotes
659   \page_otr_command_flush_side_floats % here !
660   \strc_floats_begin_group
661   \dotripleempty\strc_floats_place_float}
662
663\def\strc_floats_place_float[#tag]%
664  {\strc_floats_set_current_tag{#tag}%
665   \strc_floats_place_indeed}
666
667% start-stop
668
669% \startplacefigure[title=oeps][subtitle=whatever]
670%     \framed[width=10cm,height=5cm]{\floatuserdataparameter{subtitle}}
671% \stopplacefigure
672
673\installcorenamespace{floatuserdata}
674
675\installsetuponlycommandhandler \??floatuserdata {floatuserdata}
676
677\let\m_strc_floats_saved_userdata\empty % todo: reset this in non start|stop cases
678
679\unexpanded\def\strc_floats_start_place#tag%
680  {\flushnotes
681   \page_otr_command_flush_side_floats % here !
682   \strc_floats_begin_group
683   \strc_floats_set_current_tag{#tag}%
684   \dodoubleempty\strc_floats_start_place_indeed}
685
686%D We abuse the settings to pick up some float parameters too which makes it
687%D messy.
688
689\def\strc_floats_start_place_indeed[#settings][#userdata]%
690  {\strc_floats_reset_variables
691   % save
692   \edef\m_location    {\floatcaptionparameter\c!location}%
693   \edef\m_topoffset   {\floatcaptionparameter\c!topoffset}%
694   \edef\m_bottomoffset{\floatcaptionparameter\c!bottomoffset}%
695   \edef\m_freeregion  {\floatcaptionparameter\c!freeregion}%
696   % preset
697   \letfloatcaptionparameter        \c!location     \empty
698   \setexpandedfloatcaptionparameter\c!topoffset   {\floatparameter\c!topoffset}%
699   \setexpandedfloatcaptionparameter\c!bottomoffset{\floatparameter\c!bottomoffset}%
700   \setexpandedfloatcaptionparameter\c!freeregion  {\floatparameter\c!freeregion}%
701   \letfloatcaptionparameter        \c!reference    \empty
702   \letfloatcaptionparameter        \c!title        \empty
703   \letfloatcaptionparameter        \c!marking      \empty
704   \letfloatcaptionparameter        \c!list         \empty
705   \letfloatcaptionparameter        \c!bookmark     \empty
706   % pickup
707   \setupcurrentfloatcaption[#settings]%
708   \ifsecondargument
709     \setupcurrentfloatuserdata[#userdata]%
710     \def\m_strc_floats_saved_userdata{#userdata}%
711   \else
712     \let\m_strc_floats_saved_userdata\empty
713   \fi
714   % check
715   \edef\floatlocation{\floatcaptionparameter\c!location}%
716   \ifx\floatlocation\empty
717      \edef\floatlocation{\floatparameter\c!default}%
718   \fi
719   % inherit
720   \setexpandedfloatparameter\c!topoffset   {\floatcaptionparameter\c!topoffset}%
721   \setexpandedfloatparameter\c!bottomoffset{\floatcaptionparameter\c!bottomoffset}%
722   \setexpandedfloatparameter\c!freeregion  {\floatcaptionparameter\c!freeregion}%
723   % restore
724   \letfloatcaptionparameter\c!location    \m_location
725   \letfloatcaptionparameter\c!topoffset   \m_topoffset
726   \letfloatcaptionparameter\c!bottomoffset\m_bottomoffset
727   \letfloatcaptionparameter\c!freeregion  \m_freeregion
728   %
729   \strc_floats_analyze_location
730   \doifelseinset\v!split\floatlocation\strc_floats_place_next_box_split\strc_floats_place_next_box_normal
731   \bgroup
732   \ignorespaces}
733
734\unexpanded\def\strc_floats_stop_place
735  {\removeunwantedspaces
736   \egroup}
737
738\unexpanded\def\startplacefloat
739  {\flushnotes
740   \page_otr_command_flush_side_floats % here !
741   \strc_floats_begin_group
742   \dotripleempty\strc_floats_start_place_float}
743
744\def\strc_floats_start_place_float[#tag]%
745  {\strc_floats_set_current_tag{#tag}%
746   \strc_floats_start_place_indeed}
747
748\let\stopplacefloat\strc_floats_stop_place
749
750% reserve
751
752\unexpanded\def\strc_floats_reserve#tag%
753  {\flushnotes
754   \page_otr_command_flush_side_floats % here !
755   \strc_floats_begin_group
756   \strc_floats_set_current_tag{#tag}%
757   \dotripleempty\strc_floats_reserve_indeed}
758
759\def\strc_floats_reserve_indeed[#settings][#location][#reference]#caption% maybe check for #settings
760  {\strc_floats_place_indeed[#location][#reference]{#caption}{\strc_floats_reserve_box{#settings}}}
761
762\def\strc_floats_reserve_box#settings%
763  {\begingroup
764   \setupcurrentfloat[\c!frame=\v!on,#settings]%
765   \inheritedfloatframed{}%
766   \endgroup}
767
768% text
769
770\unexpanded\def\strc_floats_start_text#tag%
771  {\flushnotes      % Here indeed?
772   \page_otr_command_flush_side_floats % Here indeed?
773   \strc_floats_begin_text_group
774   \strc_floats_set_current_tag{#tag}%
775   \dodoubleempty\strc_floats_start_text_indeed}
776
777\def\strc_floats_start_text_indeed[#location][#reference]%
778  {\strc_floats_place_indeed[\v!text,#location,\v!left][#reference]}
779
780\unexpanded\def\strc_floats_stop_text
781  {\strc_floats_stop_text_indeed}
782
783% reserved text
784
785\unexpanded\def\strc_floats_start_reserve_text#tag%
786  {\flushnotes
787   \page_otr_command_flush_side_floats
788   \strc_floats_begin_text_group
789   \strc_floats_set_current_tag{#tag}%
790   \dotripleempty\strc_floats_start_reserve_text_indeed}
791
792\def\strc_floats_start_reserve_text_indeed[#settings][#location][#reference]#caption%
793  {\strc_floats_place_indeed[\v!text,#location,\v!left][#reference]{#caption}{\strc_floats_reserve_box{#settings}}}
794
795\unexpanded\def\strc_floats_stop_reserve_text
796  {\strc_floats_stop_text_indeed}
797
798% special hack
799
800\def\strc_floats_begin_group     {\begingroup}
801\def\strc_floats_end_group       {\carryoverpar\endgroup}
802\def\strc_floats_end_split_group {\endgroup}
803\def\strc_floats_begin_text_group{\begingroup\let\strc_floats_end_group\relax}
804\def\strc_floats_end_text_group  {\endgroup}
805
806% implementation
807
808%setnewconstant\c_page_one_float_method  \zerocount % 0=raw 1=safe (.99) 2=tight (-1pt) / belongs in page-one
809\setnewconstant\c_strc_floats_rotation   \zerocount % 0 90 180 270
810\newconditional\c_strc_floats_par_float
811
812\ifdefined\page_margin_strc_floats_before    \else \let\page_margin_strc_floats_before   \relax \fi
813\ifdefined\page_margin_strc_floats_set_hsize \else \let\page_margin_strc_floats_set_hsize\relax \fi
814
815\def\flushfloatslist
816  {\v!left,\v!right,\v!inner,\v!outer,%
817   \v!backspace,\v!cutspace,%
818   \v!inleft,\v!inright,\v!inmargin,%
819   \v!leftmargin,\v!rightmargin,\v!leftedge,\v!rightedge,%
820   \v!innermargin,\v!outermargin,\v!inneredge,\v!outeredge,%
821   \v!text,\v!opposite}% \v!page
822
823\unexpanded\def\strc_floats_place_next_box_split
824  {\let\splitfloatfinalizer\strc_floats_end_split_group
825   \let\strc_floats_end_group\relax
826   \splitfloat{\strc_floats_place_next_box_normal}}
827
828\unexpanded\def\strc_floats_place_next_box_normal
829  {\ifconditional\c_page_floats_some_waiting
830     % this was \checkwaitingfloats spread all over
831     \doifelseinset\v!always\floatlocation
832       {\showmessage\m!floatblocks5\empty}
833       {\doifelsecommon\floatlocation\flushfloatslist\page_otr_command_flush_floats\donothing}%
834     % but which should be done before using box \floatbox
835   \fi
836   \page_margin_strc_floats_before % todo: each float handler gets a before
837   \global\insidefloattrue
838   \dostarttaggedchained\t!float\currentfloat\??float
839   \page_margin_strc_floats_set_hsize % todo: each float handler gets a set_hsize
840   \the\everyinsidefloat
841   \strc_floats_analyze_variables_one
842   \dostarttagged\t!floatcontent\empty
843   \dowithnextboxcontent
844     {\strc_floats_set_local_hsize
845      \floatparameter\c!inner
846      \postponenotes} % new
847     {\page_postprocessors_linenumbers_box\nextbox % for aditya
848      \dostoptagged
849      \strc_floats_finish_placement}
850     \vbox}
851
852%D \starttyping
853%D \definefloat
854%D   [one] [figure]
855%D   [default=right,
856%D    rightmargindistance=-20cm,
857%D    criterium=129pt,
858%D    fallback=rightmargin]
859%D
860%D \definefloat
861%D   [two] [figure]
862%D   [default=right,
863%D    rightmargindistance=-20cm,
864%D    criterium=129pt,
865%D    fallback=three]
866%D
867%D \definefloat
868%D   [three] [figure]
869%D   [default=rightmargin,
870%D    rightmargindistance=0cm]
871%D
872%D \placefloat[one]{}{\blackrule[width=30pt]}  \samplefile{tufte}
873%D \placefloat[one]{}{\blackrule[width=60pt]}  \samplefile{tufte}
874%D \placefloat[one]{}{\blackrule[width=90pt]}  \samplefile{tufte}
875%D \placefloat[one]{}{\blackrule[width=130pt]} \samplefile{tufte}
876%D \placefloat[two]{}{\blackrule[width=130pt]} \samplefile{tufte}
877%D \stoptyping
878
879\def\strc_floats_finish_placement
880  {\doifsomething{\floatparameter\c!criterium}
881     {\ifdim\wd\nextbox>\floatparameter\c!criterium\relax
882        \edef\forcedfloatmethod{\floatparameter\c!fallback}%
883        \ifx\forcedfloatmethod\empty \else
884          \doifelsecommandhandler\??float\forcedfloatmethod
885            {\let\currentfloat\forcedfloatmethod
886             \edef\floatlocation{\floatparameter\c!default}%
887             \let\forcedfloatmethod\floatlocation}
888            \donothing
889        \fi
890        \ifx\forcedfloatmethod\empty
891          \let\forcedfloatmethod\v!here
892        \fi
893      \fi}%
894   \strc_floats_check_extra_actions
895   \strc_floats_analyze_variables_two
896   \strc_floats_place_packaged_boxes
897   \dotagregisterfloat\askedfloatoptions\askedfloatmethod
898   \dostoptagged % tricky .... needs checking
899   % we need to carry over the par because of side floats
900   \global\d_page_sides_downshift \zeropoint
901   \global\d_page_sides_extrashift\zeropoint
902   \ifconditional\c_strc_floats_par_float
903     \doifinset\v!reset\floatlocation\page_sides_forget_floats
904     \doinhibitblank
905   \fi
906   \strc_floats_end_group}
907
908% nicer is a bunch of states and one loop that sets those states
909
910\newdimen\d_strc_floats_top
911\newdimen\d_strc_floats_bottom
912\newdimen\d_strc_floats_overflow
913
914% \def\strc_floats_calculate_skip#target#skip%
915%   {\begingroup
916%    \edef\askedfloatskip{\rootfloatparameter#skip}%
917%    \ifx\askedfloatskip\empty
918%      \global#target\zeropoint
919%    \else\ifx\askedfloatskip\v!none
920%      \global#target\zeropoint
921%    \else
922%      \setbox\scratchbox\vbox{\whitespace\blank[\askedfloatskip]}% todo: move whitespace inside blank
923%      \global#target\ht\scratchbox
924%    \fi\fi
925%    \endgroup}
926
927\def\strc_floats_calculate_skip#target#skip%
928  {\begingroup
929   \edef\p_blank{\rootfloatparameter#skip}%
930   \ifx\p_blank\v!nowhite
931     \edef\p_blank{-\v!white}%
932   \fi
933   \prerollblank[\p_blank]%
934   \global#target\prerolledblank
935   \endgroup}
936
937\def\strc_floats_analyze_variables_two
938  {\ifinsidecolumns
939     \global\setfalse\c_strc_floats_par_float
940   \else
941     \doifelsecommon\floatlocation\flushfloatslist
942       {\global\settrue \c_strc_floats_par_float}%
943       {\global\setfalse\c_strc_floats_par_float}%
944   \fi
945   % variable initializations
946   \global\d_page_sides_shift       \zeropoint
947   \global\d_page_sides_maximum     \zeropoint
948   \global\c_page_sides_align       \zerocount
949   \global\c_page_sides_tolerance   \zerocount
950   \global\c_page_sides_skipmode    \zerocount
951   \global\c_strc_floats_rotation   \zerocount
952   \global\d_page_sides_margin      \floatparameter\c!margin
953   \global\d_page_sides_leftshift   \floatparameter\c!leftmargindistance
954   \global\d_page_sides_rightshift  \floatparameter\c!rightmargindistance
955   \global\d_page_sides_topoffset   \floatparameter\c!topoffset
956   \global\d_page_sides_bottomoffset\floatparameter\c!bottomoffset
957   \global\c_page_sides_method      \floatparameter\c!sidemethod
958   \global\c_page_one_float_method  \floatparameter\c!textmethod
959   \global\c_page_floats_n_of_top   \rootfloatparameter\c!ntop
960   \global\c_page_floats_n_of_bottom\rootfloatparameter\c!nbottom
961   \global\d_strc_floats_overflow   \zeropoint
962   \ifconditional\c_strc_floats_par_float
963     \global\d_strc_floats_top        \zeropoint
964     \global\d_strc_floats_bottom     \zeropoint
965     \strc_floats_calculate_skip\d_page_sides_topskip   \c!sidespacebefore
966     \strc_floats_calculate_skip\d_page_sides_bottomskip\c!sidespaceafter
967     \strc_floats_calculate_skip\d_page_sides_midskip   \c!sidespaceinbetween
968     \strc_floats_calculate_skip\d_strc_floats_top      \c!spacebeforeside
969     \strc_floats_calculate_skip\d_strc_floats_bottom   \c!spaceafterside
970   \else
971     \global\d_page_sides_topskip     \zeropoint
972     \global\d_page_sides_bottomskip  \zeropoint
973     \strc_floats_calculate_skip\d_strc_floats_top   \c!spacebefore
974     \strc_floats_calculate_skip\d_strc_floats_bottom\c!spaceafter
975   \fi
976   % keyword handling
977   \ifconditional\c_strc_floats_par_float
978     \processaction
979       [\floatparameter\c!sidealign]
980       [\v!height=>\global\c_page_sides_align\plusone  ,%
981          \v!line=>\global\c_page_sides_align\plustwo  ,% (***)
982         \v!depth=>\global\c_page_sides_align\plusthree,%
983          \v!grid=>\global\c_page_sides_align\plusfour ,%
984      \v!halfline=>\global\c_page_sides_align\plusfive ]%
985     \ifcase\c_page_sides_align\relax % todo: optie v!lokaal => \else
986       \doifinset\v!height  \floatlocation{\global\c_page_sides_align\plusone  }%
987       \doifinset\v!line    \floatlocation{\global\c_page_sides_align\plustwo  }%
988       \doifinset\v!depth   \floatlocation{\global\c_page_sides_align\plusthree}%
989       \doifinset\v!grid    \floatlocation{\global\c_page_sides_align\plusfour }%
990       \doifinset\v!halfline\floatlocation{\global\c_page_sides_align\plusfive }% meant for 'none'
991     \fi
992     \doifinset\v!high        \floatlocation{\global\c_page_sides_skipmode \plusone  }%
993     \doifinset\v!low         \floatlocation{\global\c_page_sides_skipmode \plustwo  }%
994     \doifinset\v!fit         \floatlocation{\global\c_page_sides_skipmode \plusthree}%
995     \doifinset\v!tolerant    \floatlocation{\global\c_page_sides_tolerance\plusone  }%
996     \doifinset\v!verytolerant\floatlocation{\global\c_page_sides_tolerance\plustwo  }%
997   \else
998     \processallactionsinset
999       [\floatlocation]%
1000       [ 90=>\global\c_strc_floats_rotation\commalistelement\relax,%
1001        180=>\global\c_strc_floats_rotation\commalistelement\relax,%
1002        270=>\global\c_strc_floats_rotation\commalistelement\relax]%
1003   \fi
1004   \doifelseinset\v!nonumber\floatlocation
1005     {\global\nofloatnumbertrue}%
1006     {\doifelse{\floatcaptionparameter\c!number}\v!yes
1007        {\global\nofloatnumberfalse}%
1008        {\global\nofloatnumbertrue}}%
1009   \doifelseinset\v!none\floatlocation
1010     {\global\nofloatcaptiontrue}%
1011     {\global\nofloatcaptionfalse}%
1012   \doif{\floatcaptionparameter\c!number}\v!none % new
1013     {\global\nofloatcaptiontrue}%
1014   \doifinset\v!effective\floatlocation
1015     {\letfloatparameter       \c!leftmargin \effectiveleftskip
1016      \letfloatparameter       \c!rightmargin\effectiverightskip
1017      \letfloatcaptionparameter\c!leftmargin \effectiveleftskip
1018      \letfloatcaptionparameter\c!rightmargin\effectiverightskip}%
1019   \ifemptyfloatcaption \ifnofloatnumber
1020     \global\nofloatcaptiontrue
1021   \fi \fi}
1022
1023% documenteren in details
1024
1025\def\strc_floats_analyze_variables_one
1026  {\doifelse{\floatparameter\c!local}\v!yes\settrue\setfalse\c_page_floats_center_box_global % fout keyword
1027   \ifconditional\c_page_floats_center_box_global
1028     \settrue\c_page_floats_center_box_local
1029   \else
1030     \doifelseinset\v!local\floatlocation\settrue\setfalse\c_page_floats_center_box_local
1031   \fi
1032   \doifelse{\floatparameter\c!freeregion}\v!yes
1033     \settrue\setfalse\c_strc_floats_mark_as_free
1034   \doifnotcommon{\v!always,\v!here,\v!force}\floatlocation % ! ! ! ! ! !
1035     {\setfalse\c_page_floats_center_box_global
1036      \setfalse\c_page_floats_center_box_local}}
1037
1038\def\naturalfloatheight{\the\naturalfloatwd}
1039\def\naturalfloatwidth {\the\naturalfloatht}
1040\def\naturalfloatdepth {\the\naturalfloatdp}
1041
1042\def\floatcaptionheight{\the\floatcaptionwd}
1043\def\floatcaptionwidth {\the\floatcaptionht}
1044\def\floatcaptiondepth {\the\floatcaptiondp}
1045
1046\newdimen\naturalfloatwd
1047\newdimen\naturalfloatht
1048\newdimen\naturalfloatdp
1049
1050\newdimen\floatcaptionwd
1051\newdimen\floatcaptionht
1052\newdimen\floatcaptiondp
1053
1054\def\strc_floats_set_natural_dimensions#box%
1055  {\global\naturalfloatwd\wd#box\relax
1056   \global\naturalfloatht\ht#box\relax
1057   \global\naturalfloatdp\dp#box\relax}
1058
1059\def\strc_floats_set_caption_dimensions#box%
1060  {\global\floatcaptionwd\wd#box\relax
1061   \global\floatcaptionht\ht#box\relax
1062   \global\floatcaptiondp\dp#box\relax}
1063
1064\def\doifelsemainfloatbody
1065  {\ifinsidesplitfloat
1066     \ifconditional\splitfloatfirstdone
1067       \doubleexpandafter\secondoftwoarguments
1068     \else
1069       \doubleexpandafter\firstoftwoarguments
1070     \fi
1071   \else
1072     \expandafter\firstoftwoarguments
1073   \fi}
1074
1075\let\doifmainfloatbodyelse\doifelsemainfloatbody
1076
1077% todo: optional user pars
1078
1079\let\currentfloatattribute\empty % to be checked
1080
1081\def\floatcaptionattribute
1082  {\iflocation
1083      \ifx\currentfloatattribute\empty
1084        % safeguard, can be samepage too
1085      \else
1086       \ifnofloatcaption
1087       \else
1088         \ifinsidesplitfloat
1089            \ifconditional\splitfloatfirstdone
1090            \else
1091              attr \destinationattribute \currentfloatattribute
1092            \fi
1093         \else
1094           attr \destinationattribute \currentfloatattribute
1095         \fi
1096       \fi
1097     \fi
1098   \fi}
1099
1100\newconditional\usesamefloatnumber
1101
1102% \startplacefigure[location=here,reference=first, title=first, group=alpha,groupsuffix=.a]
1103%     \externalfigure[dummy][height=2cm]
1104% \stopplacefigure
1105% \startplacefigure[location=here,reference=second,title=second,group=alpha,groupsuffix=.b]
1106%     \externalfigure[dummy][height=2cm]
1107% \stopplacefigure
1108%
1109% uses:
1110
1111\def\strc_floats_group_index
1112  {\numexpr\clf_listgroupindex{\currentfloat}{\currentfloatgroup}\relax}
1113
1114%D A lightweight subnumber feature:
1115%D
1116%D \starttyping
1117%D \startplacefigure [location=none]
1118%D   \startsubfloatnumbering
1119%D     \startfloatcombination [nx=3]
1120%D       \startplacefigure [title=Left]   \externalfigure \stopplacefigure
1121%D       \startplacefigure [title=Middle] \externalfigure \stopplacefigure
1122%D       \startplacefigure [title=Right]  \externalfigure \stopplacefigure
1123%D     \stopfloatcombination
1124%D   \stopsubfloatnumbering
1125%D \stopplacefigure
1126%D \stoptyping
1127
1128\glet\currentsubfloatcounter\empty
1129
1130\unexpanded\def\startsubfloatnumbering
1131  {\glet\currentsubfloatcounter\s!unknown}
1132
1133\unexpanded\def\stopsubfloatnumbering
1134  {\strc_counters_reset_sub\currentsubfloatcounter\plustwo
1135   \glet\currentsubfloatcounter\empty}
1136
1137\defineconversionset[subfloats][number,characters]
1138
1139\setupcaptions
1140 %[figure]
1141  [\c!numberconversionset=subfloats]
1142
1143\def\strc_floats_place_packaged_boxes
1144  {\expandafter\strc_floats_place_packaged_boxes_indeed\expandafter{\m_strc_floats_saved_userdata}}
1145
1146\def\strc_floats_place_packaged_boxes_indeed#userdata%
1147  {\bgroup
1148   \ifconditional\usesamefloatnumber
1149     \glet\currentfloatnumber     \previousfloatnumber
1150     \glet\currentfloatattribute  \empty
1151     \glet\currentfloatsynchronize\relax
1152   \else
1153     \edef\currentfloatcounter{\namedcounterparameter\currentfloat\s!name}%
1154     \edef\currentfloatgroup  {\floatcaptionparameter\c!group}%
1155     \ifnofloatnumber \else \ifnofloatcaption \else
1156       \ifx\currentfloatgroup\empty
1157         % independent
1158         \iftrialtypesetting\strc_counters_save\currentfloatcounter\fi
1159         \ifx\empty\currentsubfloatcounter
1160           \strc_counters_increment\currentfloatcounter
1161           \strc_counters_reset_sub\currentfloatcounter\plustwo
1162         \else
1163           \ifcase\strc_counters_raw_sub\currentfloatcounter\plustwo\relax
1164             \strc_counters_increment\currentfloatcounter
1165             \strc_counters_reset_sub\currentfloatcounter\plustwo
1166           \fi
1167           \strc_counters_increment_sub\currentfloatcounter\plustwo
1168           \glet\currentsubfloatcounter\currentfloatcounter
1169         \fi         
1170       \else\ifcase\strc_floats_group_index
1171         % first in group
1172         \iftrialtypesetting\strc_counters_save\currentfloatcounter\fi
1173         \strc_counters_increment\currentfloatcounter
1174       \else
1175         % next in group
1176       \fi \fi
1177     \fi \fi
1178     % *1* as an alternative we could set counter parameters here if needed
1179     \strc_counters_register_component
1180       \s!float
1181       \setupcurrentfloatcaption
1182       \floatcaptionparameter
1183       \detokenizedfloatcaptionparameter
1184       \relax
1185       \relax
1186       \relax
1187       [\s!name=\currentfloat,% was c!name
1188        \s!counter=\currentfloatcounter,%
1189        \s!hascaption=\ifnofloatcaption \v!no\else\v!yes\fi,%
1190        \s!hasnumber=\ifnofloatnumber   \v!no\else\v!yes\fi,%
1191        \s!hastitle=\ifemptyfloatcaption\v!no\else\v!yes\fi]%
1192       [#userdata]%
1193     \glet\previousfloatnumber    \m_strc_counters_last_registered_index
1194     \glet\currentfloatnumber     \m_strc_counters_last_registered_index
1195     \glet\currentfloatattribute  \m_strc_counters_last_registered_attribute
1196     \glet\currentfloatsynchronize\m_strc_counters_last_registered_synchronize
1197   \fi
1198   %
1199   \iftrialtypesetting\else\global\setfalse\usesamefloatnumber\fi % one shot
1200   % check float box
1201   \strc_floats_set_natural_dimensions\nextbox
1202   \global\setbox\floatbox\vbox{\floatparameter\c!command{\box\nextbox}}% can be anything so no pack
1203   \strc_floats_set_natural_dimensions\floatbox
1204   \ifzeropt\htdp\floatbox
1205     \showmessage\m!floatblocks{11}\empty
1206     \global\setbox\floatbox\vpack
1207       {\dostarttagged\t!floatcontent\empty
1208        \strc_floats_place_empty_box
1209        \dostoptagged}%
1210   \fi
1211   % deal with lack of caption
1212   \global\setbox\floatbox\vpack \floatcaptionattribute
1213     {\doifelsemainfloatbody\currentfloatsynchronize\donothing
1214      \unvbox\floatbox
1215      \ifnofloatcaption
1216        \vss
1217      \fi}% gets rid of the depth (unless tabulate)
1218   \iftrialtypesetting\strc_counters_restore\currentfloatcounter\fi
1219   \egroup
1220   % place the float
1221   \strc_floats_set_box
1222   \strc_floats_get_box
1223   \global\insidefloatfalse}
1224
1225
1226\newdimen\availablefloatwidth
1227\newdimen\availablefloatheight
1228
1229\def\strc_floats_set_local_hsize
1230  {\ifconditional\c_page_floats_center_box_local
1231     % also available check here?
1232     \seteffectivehsize
1233     \hsize\localhsize
1234   \else
1235     \doifinset\v!margin\floatlocation % brr, really needed! see wm will be redone
1236       {\hsize\namedmarginblockparameter\empty\c!width}%
1237   \fi
1238   \edef\p_availablewidth {\floatparameter\c!availablewidth }%
1239   \edef\p_availableheight{\floatparameter\c!availableheight}%
1240   \availablefloatwidth \ifx\p_availablewidth \empty\hsize\else\p_availablewidth \relax\fi
1241   \availablefloatheight\ifx\p_availableheight\empty\vsize\else\p_availableheight\relax\fi}
1242
1243\ifdefined\everyinsidefloat \else \newevery \everyinsidefloat \relax \fi
1244
1245\appendtoks
1246    \everyinsidefloat\emptytoks % in case it's called earlier
1247    \strc_float_load_data
1248\to \everyinsidefloat
1249
1250\def\doifelserightpagefloat
1251  {\ifdoublesided
1252     \ifsinglesided
1253       \doubleexpandafter\firstoftwoarguments
1254     \else
1255       \doubleexpandafter\doifelseoddpagefloat
1256     \fi
1257   \else
1258     \expandafter\firstoftwoarguments
1259   \fi}
1260
1261\def\doifelseoddpagefloat
1262  {\ifodd\purenumber\strc_float_realpage\space
1263     \expandafter\firstoftwoarguments
1264   \else
1265     \expandafter\secondoftwoarguments
1266   \fi}
1267
1268\let\doifrightpagefloatelse\doifelserightpagefloat
1269\let\doifoddpagefloatelse  \doifelseoddpagefloat
1270
1271\appendtoks
1272    \overloaded\frozen\let\rightorleftpageaction\doifelserightpagefloat
1273\to \everyinsidefloat
1274
1275% \let\movesidefloat\gobbleoneargument
1276
1277% new : \place...[leftmargin,-2*line]; we need to catch fxtb:2*3
1278% watch out: line alone aligns on the line ! ! !
1279
1280\unexpanded\def\movesidefloat[#settings]% (-)n*line|x=,y=
1281  {\global\d_page_sides_downshift \zeropoint
1282   \global\d_page_sides_extrashift\zeropoint
1283   \doifelseassignment{#settings}%
1284     {\begingroup
1285      \setupcurrentfloat[\c!x=\zeropoint,\c!y=\zeropoint,#settings]%
1286      \ifgridsnapping
1287        \getnoflines{\floatparameter\c!y}%
1288        \global\d_page_sides_downshift\noflines\lineheight
1289      \else
1290        \global\d_page_sides_downshift\floatparameter\c!y
1291      \fi
1292      \global\d_page_sides_extrashift\floatparameter\c!x
1293      \endgroup}
1294     {\movedownsidefloat[#settings]}}
1295
1296\installcorenamespace{floatmovement}
1297
1298\setvalue{\??floatmovement \v!line}{\strc_floats_move_down_line+}
1299\setvalue{\??floatmovement+\v!line}{\strc_floats_move_down_line+}
1300\setvalue{\??floatmovement-\v!line}{\strc_floats_move_down_line-}
1301\setvalue{\??floatmovement \v!hang}{\strc_floats_move_down_hang\plusone}
1302\setvalue{\??floatmovement+\v!hang}{\strc_floats_move_down_hang\plusone}
1303\setvalue{\??floatmovement-\v!hang}{\strc_floats_move_down_hang\minusone}
1304
1305\setvalue{\??floatmovement-2*\v!line}{\strc_floats_move_down_line{-2}}
1306\setvalue{\??floatmovement+2*\v!line}{\strc_floats_move_down_line{2}}
1307\setvalue{\??floatmovement 2*\v!line}{\strc_floats_move_down_line{2}}
1308
1309\unexpanded\def\installfloatmovement#1#2{\setvalue{\??floatmovement#1}{#2}}
1310
1311\def\strc_floats_move_down#setting%
1312  {\begincsname\??floatmovement#setting\endcsname}
1313
1314\def\strc_floats_move_down_line#sign%
1315  {\if!!donea \else
1316     \global\d_page_sides_downshift\zeropoint
1317     \!!doneatrue
1318   \fi
1319   \global\advance\d_page_sides_downshift#sign\lineheight}
1320
1321\def\strc_floats_move_down_hang#lines%
1322  {\if!!doneb \else
1323     \global\c_page_sides_n_of_lines\zerocount
1324     \!!donebtrue
1325   \fi
1326   \global\advance\c_page_sides_n_of_lines#lines\relax}
1327
1328\unexpanded\def\movedownsidefloat[#settings]% already in core
1329  {\doifnotinstring{:}{#settings}
1330     {\begingroup
1331      \!!doneafalse
1332      \!!donebfalse
1333      \normalexpanded{\dorepeatwithcommand[#settings]}\strc_floats_move_down
1334      \endgroup}}
1335
1336\unexpanded\def\hangsidefloat[#number]%
1337  {\global\c_page_sides_n_of_lines#number\relax}
1338
1339\def\strc_floats_set_extra_action#rightpagelocation#leftpagelocation%
1340  {\rightorleftpageaction
1341     {\let\extrafloatlocation#rightpagelocation}%
1342     {\let\extrafloatlocation#leftpagelocation}}
1343
1344\let\extrafloatlocation\empty
1345
1346\installcorenamespace{extrafloataction}
1347
1348\setvalue{\??extrafloataction      \v!inner}#1{\strc_floats_set_extra_action\v!left       \v!right}
1349\setvalue{\??extrafloataction      \v!outer}#1{\strc_floats_set_extra_action\v!right      \v!left}
1350\setvalue{\??extrafloataction\v!innermargin}#1{\strc_floats_set_extra_action\v!leftmargin \v!rightmargin}
1351\setvalue{\??extrafloataction\v!outermargin}#1{\strc_floats_set_extra_action\v!rightmargin\v!leftmargin}
1352\setvalue{\??extrafloataction  \v!inneredge}#1{\strc_floats_set_extra_action\v!leftedge   \v!rightedge}
1353\setvalue{\??extrafloataction  \v!outeredge}#1{\strc_floats_set_extra_action\v!rightedge  \v!leftedge}
1354\setvalue{\??extrafloataction  \v!backspace}#1{\strc_floats_set_extra_action\v!backspace  \v!cutspace}
1355\setvalue{\??extrafloataction   \v!cutspace}#1{\strc_floats_set_extra_action\v!cutspace   \v!backspace}
1356%setvalue{\??extrafloataction     \v!margin}#1{\strc_floats_set_extra_action\v!cutspace   \v!backspace}
1357\setvalue{\??extrafloataction       \v!left}#1{\strc_floats_set_extra_action\v!left       \v!left}
1358\setvalue{\??extrafloataction      \v!right}#1{\strc_floats_set_extra_action\v!right      \v!right}
1359\setvalue{\??extrafloataction       \v!line}#1{} % only -n*line is handled (see ***)
1360\setvalue{\??extrafloataction    \s!unknown}#1{\movedownsidefloat[#1]}
1361
1362\def\strc_floats_check_extra_actions % less tracingthis way ....
1363  {\doifnotinset\v!text\floatlocation % fuzzy, text overloads left, since then it's a directive
1364     {\let\extrafloatlocation\empty
1365      % \d_page_sides_downshift will be reset afterwards, and can
1366      % already be set at this point
1367      \processcommacommand[\floatlocation]\strc_floats_check_extra_actions_step
1368      \ifx\extrafloatlocation\empty \else
1369        \edef\floatlocation{\extrafloatlocation,\floatlocation}%
1370        \setfloatmethodvariables\floatlocation
1371      \fi}}
1372
1373\def\strc_floats_check_extra_actions_step#step%
1374  {\csname\??extrafloataction
1375     \ifcsname\??extrafloataction#step\endcsname#step\else\s!unknown\fi
1376   \endcsname{#step}}
1377
1378% pas op, maxbreedte niet instellen als plaats=links/rechts
1379
1380\def\strc_floats_set_local_dimensions
1381  {\global\d_page_sides_shift  \zeropoint       % duplicate
1382   \global\d_page_sides_maximum\zeropoint\relax % duplicate
1383   \ifzeropt\d_page_sides_downshift\else
1384     \global\setbox\floatbox\vpack
1385       {\vskip\d_page_sides_downshift
1386        \nointerlineskip
1387        \box\floatbox}%
1388   \fi
1389   \edef\p_minwidth{\floatparameter\c!minwidth}%
1390   \ifx\p_minwidth\empty
1391     % nothing
1392   \else
1393     \scratchwidth\p_minwidth\relax
1394     \ifdim\wd\floatbox<\scratchwidth
1395       \strc_floats_realign_floatbox_horizontal_two
1396     \fi
1397   \fi
1398   % we can also support edges .. in that case no common but a fast loop
1399   \doifelseinset\v!hanging\floatlocation
1400     {\doifelsecommon{\v!inleft,\v!leftmargin}\floatlocation
1401        {\let\p_maxwidth\leftmarginwidth}%
1402        {\doifelsecommon{\v!inright,\v!rightmargin}\floatlocation
1403           {\let\p_maxwidth\rightmarginwidth}%
1404           {\edef\p_maxwidth{\floatparameter\c!maxwidth}}}}%
1405     {\edef\p_maxwidth{\floatparameter\c!maxwidth}}%
1406   \ifx\p_maxwidth\empty
1407     % nothing
1408   \else
1409     \scratchwidth\p_maxwidth\relax
1410     \ifdim\wd\floatbox>\scratchwidth
1411       \doifelsecommon{\v!inright,\v!rightmargin,\v!rightedge,\v!inleft,\v!leftmargin,\v!leftedge}\floatlocation
1412         {\global\d_page_sides_maximum\scratchwidth}
1413         {\doifelsecommon{\v!right,\v!left}\floatlocation
1414            \strc_floats_realign_floatbox_horizontal_one
1415            \strc_floats_realign_floatbox_horizontal_two}%
1416     \fi
1417   \fi}
1418
1419\def\strc_floats_realign_floatbox_horizontal_one
1420  {\global\setbox\floatbox\hpack to \scratchwidth
1421     {\doifnotinset\v!right\floatlocation\hss
1422      \box\floatbox
1423      \doifnotinset\v!left\floatlocation\hss}}
1424
1425\def\strc_floats_realign_floatbox_horizontal_two % why is this
1426  {\global\setbox\floatbox\hpack to \scratchwidth
1427     {\doifnot{\floatparameter\c!location}\v!left\hss
1428      \box\floatbox
1429      \doifnot{\floatparameter\c!location}\v!right\hss}}
1430
1431\unexpanded\def\placefloats
1432  {\page_otr_command_flush_floats}
1433
1434\unexpanded\def\betweenfloatblanko % assumes that spaceafter is present
1435  {\blank[\rootfloatparameter\c!spacebefore]} % or v!back,....
1436
1437% keep as old 1
1438%
1439% \unexpanded\def\doplacefloatbox % used elsewhere
1440%   {%\forgetall % NO
1441%    \whitespace
1442%    \blank[\rootfloatparameter\c!spacebefore]
1443%    \page_otr_command_flush_float_box
1444%    \blank[\rootfloatparameter\c!spaceafter]}
1445%
1446% keep as old 2
1447%
1448% \unexpanded\def\doplacefloatbox % used elsewhere
1449%   {%\forgetall % NO
1450%    \whitespace
1451%    \blank[\rootfloatparameter\c!spacebefore]
1452%    \nointerlineskip
1453%    \flushnotes % new per 2014-05-29 : todo: move them up in the mvl
1454%    \nointerlineskip
1455%    \page_otr_command_flush_float_box
1456%    \nointerlineskip
1457%    \blank[\rootfloatparameter\c!spaceafter]}
1458
1459\def\strc_floats_apply_skip#1%
1460  {\edef\m_space{\rootfloatparameter#1}%
1461   \ifx\m_space\empty \else\ifx\m_space\v!none \else
1462      \directvspacing\m_space
1463   \fi\fi}
1464
1465\unexpanded\def\doplacefloatbox % used elsewhere
1466  {%\forgetall % NO
1467   \whitespace
1468   \strc_floats_apply_skip\c!spacebefore
1469   \nointerlineskip
1470   \flushnotes % new per 2014-05-29 : todo: move them up in the mvl
1471   \nointerlineskip
1472   \page_otr_command_flush_float_box
1473 % \nointerlineskip % interferes with depth of caption
1474   \strc_floats_apply_skip\c!spaceafter}
1475
1476% test case:
1477%
1478% \placefigure[page,none]{}{\blackrule[width=\textwidth,height=0.9\textheight,color=green]}
1479% \placefigure[page,none]{}{\blackrule[width=\textwidth,height=1.0\textheight,color=green]}
1480% \placefigure[page,none]{}{\blackrule[width=\textwidth,height=1.1\textheight,color=green]}
1481
1482% the [#1] will go away
1483
1484\def\page_one_place_float_text % this macro should be defined elsewhere
1485  {%\checkwaitingfloats\floatlocationmethod
1486   % todo: check if #1 is indeed \floatlocation or maybe more
1487   \global\floatwidth    \wd\floatbox
1488   \global\floatheight   \ht\floatbox % forget about the depth
1489   \global\floattextwidth\dimexpr\hsize-\floatwidth-\rootfloatparameter\c!margin\relax
1490   \edef\floatlocation{\floatlocationmethod}% to be sure .. why
1491   \doifelseinset\v!tall\floatlocationmethod
1492     {\floattextheight\dimexpr\pagegoal-\pagetotal-\bigskipamount\relax % ugly, this bigskip
1493      \ifdim\floattextheight>\textheight
1494        \floattextheight\textheight
1495      \fi
1496      \boxmaxdepth\zeropoint\relax            % toegevoegd
1497      \ifdim\floattextheight<\floatheight
1498        \floattextheight\floatheight
1499      \fi
1500      \setbox\floattext\vbox to \floattextheight}
1501     {\setbox\floattext\vbox}%
1502   \bgroup
1503   \forgetall
1504   \setupblank
1505   \setupwhitespace % new, also needed for footnotes
1506   \blank[\v!disable]
1507   \hsize\floattextwidth
1508   \ignorespaces}
1509
1510\def\strc_floats_stop_text_indeed % todo
1511  {\egroup
1512   \doifnotinset\v!tall\floatlocation
1513     {\floattextheight\ifdim\ht\floattext<\floatheight\floatheight\else\ht\floattext\fi}%
1514   \setbox\floatbox\vpack to \floattextheight
1515     {\hsize\floatwidth
1516      \doifelseinset\v!both\floatlocation
1517        {\doifelseinset\v!low\floatlocation
1518           {\vfill\box\floatbox}
1519           {\doifelseinset\v!middle\floatlocation
1520              {\vfill\box\floatbox\vfill}
1521              {\box\floatbox\vfill}}}
1522        {\box\floatbox\vfill}}%
1523    \setbox\floattext\vpack to \floattextheight
1524     {\hsize\floattextwidth
1525      \doifelseinset\v!low\floatlocation
1526        {\vfill
1527         \box\floattext
1528         \doifinset\c!offset\floatlocation{\whitespace\blank}}
1529        {\doifelseinset\v!middle\floatlocation
1530           {\vfill
1531            \box\floattext
1532            \vfill}
1533           {\doifinset\v!offset\floatlocation{\whitespace\blank}%
1534            \box\floattext
1535            \vfill}}}%
1536   \doifelseinset\v!right\floatlocation
1537     {\setbox\floatbox\hpack to \hsize
1538        {\box\floattext
1539         \hfill
1540         \box\floatbox}}
1541     {\setbox\floatbox\hpack to \hsize
1542        {\box\floatbox
1543         \hfill
1544         \box\floattext}}%
1545   \baselinecorrection
1546   \whitespace
1547   \blank[\rootfloatparameter\c!spacebefore]%
1548   \doifnotinset\v!tall\floatlocation
1549     {\dp\floatbox\openstrutdepth}% dp\strutbox}%      % toegevoegd
1550   \box\floatbox
1551   \dostoptagged
1552   \blank[\rootfloatparameter\c!spaceafter]%
1553   \strc_floats_end_text_group
1554   \page_floats_report_total}
1555
1556\def\borderedfloatbox
1557  {\begingroup
1558   \setupcurrentfloat[\c!location=\v!normal,\c!width=\v!fit,\c!height=\v!fit]%
1559   \inheritedfloatframed{\box\floatbox}%
1560   \endgroup}
1561
1562% minwidth=fit,width=max : no overshoot, as wide as graphic
1563
1564% keep these as reference:
1565%
1566% \def\strc_floats_align_content_indeed
1567%   {\alignstrutmode\zerocount
1568%    \doifnotcommon\floatcaptionlocation{\v!outermargin,\v!innermargin,\v!leftmargin,\v!rightmargin}
1569%      {\shiftalignedline
1570%         {\floatparameter\c!leftmargin }{\floatparameter\c!rightmargin}%
1571%         {\floatparameter\c!innermargin}{\floatparameter\c!outermargin}}%
1572%    \alignedline{\floatparameter\c!location}\v!middle}
1573%
1574% \def\strc_floats_align_caption_indeed
1575%   {\alignstrutmode\zerocount
1576%    \shiftalignedline
1577%      {\floatcaptionparameter\c!leftmargin }{\floatcaptionparameter\c!rightmargin}%
1578%      {\floatcaptionparameter\c!innermargin}{\floatcaptionparameter\c!outermargin}%
1579%    \alignedline{\floatparameter\c!location}\v!middle}
1580%
1581% Test case:
1582%
1583% \setupfloats[location=left]
1584% \setupfloatcaption[width=max]
1585%
1586% \startfloatcombination
1587%     \placefigure{}{}
1588%     \placefigure{}{}
1589% \stopfloatcombination
1590
1591%D In a floatcombination we ignore the margins .. if that is ever needed we need another
1592%D state (instead of local).
1593
1594\def\strc_floats_align_indeed
1595  {\alignedline{\floatparameter\c!location}\v!middle}
1596
1597\def\strc_floats_shift_indeed#1%
1598  {\shiftalignedline{#1\c!leftmargin}{#1\c!rightmargin}{#1\c!innermargin}{#1\c!outermargin}}
1599
1600\def\strc_floats_align_content_indeed
1601  {\alignstrutmode\zerocount
1602   \ifx\forcedfloatmethod\v!local \else
1603     \doifnotcommon\floatcaptionlocation{\v!outermargin,\v!innermargin,\v!leftmargin,\v!rightmargin}
1604       {\strc_floats_shift_indeed\floatparameter}%
1605     \expandafter\strc_floats_align_indeed
1606   \fi}
1607
1608\def\strc_floats_align_caption_indeed
1609  {\alignstrutmode\zerocount
1610   \ifx\forcedfloatmethod\v!local
1611     \expandafter\strc_floats_align_indeed_local
1612   \else
1613     \strc_floats_shift_indeed\floatcaptionparameter
1614     \expandafter\strc_floats_align_indeed
1615   \fi}
1616
1617% \def\strc_floats_align_indeed_local#1%
1618%   {\begingroup
1619%    \hsize\wd\floatbox
1620%    \strc_floats_align_indeed{#1}%
1621%    \endgroup}
1622
1623\let\strc_floats_align_indeed_local\firstofoneargument
1624
1625\newdimen\d_strc_floats_content
1626\newdimen\d_strc_float_temp_height
1627\newdimen\d_strc_float_temp_width
1628
1629\newconditional\c_floats_adapt_to_caption_width
1630\newconditional\c_floats_store_minimal_package
1631
1632\def\captionminwidth {15\bodyfontsize} % can become parameter (but what name)
1633\def\captionovershoot{2\emwidth}       % can become parameter (but what name)
1634
1635\let\strc_floats_mark_pag_as_free\relax
1636
1637\def\strc_floats_set_page_variant
1638  {\bgroup
1639   \strc_floats_set_local_hsize
1640   \ifcase\c_strc_floats_rotation\else
1641     \swapdimens\hsize\vsize
1642   \fi
1643   \forgetall
1644   \postponenotes
1645   \dontcomplain
1646   \setbox\b_strc_floats_content\vpack{\borderedfloatbox}%
1647   \let\strc_floats_align_content\strc_floats_align_content_indeed
1648   \let\strc_floats_align_caption\strc_floats_align_caption_indeed
1649   \strc_floats_check_caption_content
1650   \d_strc_floats_content\wd\b_strc_floats_content
1651   \ifcase\floatparameter\c!method
1652     % nothing
1653   \or
1654     % automatic
1655     \ifnofloatcaption
1656       \strc_floats_prepare_no_caption
1657       \strc_floats_set_caption_dimensions\voidbox
1658      %\page_backgrounds_add_local_to_box\floatbox % was \doglobal but not needed
1659     \else
1660       % todo: installable maken, variant/method=auto vs macro
1661       \strc_floats_prepare_page_caption
1662      %\page_backgrounds_add_local_to_box\b_strc_floats_content
1663       \setbox\b_strc_floats_caption\hbox % text
1664         {\floatcaptionparameter\c!command{\box\b_strc_floats_caption}}%
1665       \strc_floats_set_caption_dimensions\b_strc_floats_caption
1666      %\moveboxontogrid\b_strc_floats_caption{\floatcaptionparameter\c!grid}\d_strc_floats_caption_height
1667      %\page_backgrounds_add_local_to_box\b_strc_floats_caption
1668       \strc_floats_build_box
1669     \fi
1670   \or
1671     % semi automatic
1672   \or
1673     % manual
1674   \fi
1675   \ifconditional\c_floats_store_minimal_package
1676      % nothing
1677   \else\ifcase\c_strc_floats_rotation
1678     \doifnotinset\v!margin\floatlocation % brr, really needed! see wm
1679       {\postcenterfloatbox\d_strc_floats_content
1680        \strc_floats_mark_pag_as_free}%
1681       % mark as free not done here
1682   \else
1683     \global\setbox\floatbox\vpack
1684       {\rotate[\c!rotation=\number\c_strc_floats_rotation]{\box\floatbox}}%
1685     \strc_floats_mark_pag_as_free
1686   \fi\fi
1687   \egroup}
1688
1689\def\strc_floats_prepare_no_caption
1690  {\global\setbox\floatbox\vpack % pas op als wd groter dan hsize
1691     {\ifinsidecolumns\ifdim\wd\b_strc_floats_content>\hsize
1692        \let\strc_floats_align_content\relax
1693      \fi\fi
1694      \strc_floats_align_content{\copy\b_strc_floats_content}}}
1695
1696\def\strc_floats_prepare_page_caption
1697  {\edef\p_strc_floats_caption_width   {\floatcaptionparameter\c!width}%
1698   \edef\p_strc_floats_caption_minwidth{\floatcaptionparameter\c!minwidth}%
1699   \edef\p_strc_floats_caption_align   {\floatcaptionparameter\c!align}%
1700   \dostarttagged\t!floatcaption\empty
1701   \doifcommonelse\floatcaptionlocation{\v!top,\v!bottom}
1702      {\strc_floats_prepare_page_caption_top_bottom}
1703      {\ifx\p_strc_floats_caption_width\v!fit
1704         \strc_floats_prepare_side_auto_caption
1705       \else\ifx\p_strc_floats_caption_width\v!max
1706         \strc_floats_prepare_side_auto_caption
1707       \else
1708         \strc_floats_prepare_side_width_caption
1709      \fi\fi}%
1710   \dostoptagged}
1711
1712\def\strc_floats_prepare_page_caption_top_bottom
1713  {\ifx\p_strc_floats_caption_width\v!fit
1714     \strc_floats_prepare_page_caption_top_bottom_fit_max
1715   \else\ifx\p_strc_floats_caption_width\v!max
1716     \strc_floats_prepare_page_caption_top_bottom_fit_max
1717   \else
1718     \strc_floats_prepare_side_width_caption % new, special effects (see icare)
1719   \fi\fi}
1720
1721\def\strc_floats_prepare_page_caption_top_bottom_fit_max
1722  {\ifx\p_strc_floats_caption_minwidth\v!fit
1723     \ifx\p_strc_floats_caption_width\v!max
1724       \strc_floats_prepare_stack_caption_max
1725     \else\ifdim\wd\b_strc_floats_caption>\wd\b_strc_floats_content % wider caption
1726       \ifx\p_strc_floats_caption_width\v!fit
1727         \strc_floats_prepare_stack_caption_auto
1728       \else
1729         \strc_floats_prepare_stack_caption_width
1730       \fi
1731     \else
1732       \strc_floats_prepare_stack_caption_min
1733     \fi\fi
1734  \else
1735    \strc_floats_prepare_stack_caption_fixed
1736  \fi}
1737
1738\def\strc_floats_caption_set_align
1739  {\edef\m_align{\v!reset\ifx\p_strc_floats_caption_align\empty\else,\fi\p_strc_floats_caption_align}%
1740   \doifinset\v!tolerant    \floatcaptionlocation{\edef\m_align{\m_align,\v!tolerant}}%
1741   \doifinset\v!verytolerant\floatcaptionlocation{\edef\m_align{\m_align,\v!verytolerant}}%
1742   \doifinset\v!stretch     \floatcaptionlocation{\edef\m_align{\m_align,\v!stretch}}%
1743   \setupalign[\m_align]}
1744
1745\def\strc_floats_prepare_side_auto_caption
1746  {\scratchdimen\dimexpr\hsize-\wd\b_strc_floats_content-\floatparameter\c!margin\relax
1747   \ifdim\wd\b_strc_floats_caption>\scratchdimen
1748     \ifdim\wd\b_strc_floats_caption<1.3\scratchdimen
1749       \scratchdimen0.8\scratchdimen
1750     \fi
1751   \fi
1752   \setbox\b_strc_floats_caption\vbox
1753     {\strc_floats_caption_set_align
1754      \hsize\scratchdimen
1755      \strc_floats_make_complete_caption}}
1756
1757\def\strc_floats_prepare_side_width_caption
1758  {\setbox\b_strc_floats_caption\vbox
1759     {\strc_floats_caption_set_align
1760      \hsize\floatcaptionparameter\c!width
1761      \strc_floats_make_complete_caption}}
1762
1763\def\strc_floats_prepare_stack_caption_fixed
1764  {\setbox\b_strc_floats_caption\vbox
1765     {\strc_floats_caption_set_align
1766      \hsize\floatcaptionparameter\c!minwidth % special effects
1767      \strc_floats_make_complete_caption}}
1768
1769\def\strc_floats_prepare_stack_caption_max
1770  {\setbox\b_strc_floats_caption\vbox
1771     {\strc_floats_caption_set_align
1772      \hsize\wd\b_strc_floats_content
1773      \strc_floats_make_complete_caption}}
1774
1775\def\strc_floats_prepare_stack_caption_width
1776  {\setbox\b_strc_floats_caption\vbox
1777     {\strc_floats_caption_set_align
1778      \hsize\floatcaptionparameter\c!width
1779      \strc_floats_make_complete_caption}}
1780
1781\def\strc_floats_prepare_stack_caption_min
1782  {\setbox\b_strc_floats_caption\vbox
1783     {\strc_floats_caption_set_align
1784      \hsize\wd\b_strc_floats_content
1785      \ifx\p_strc_floats_caption_align\empty
1786        \raggedcenter % on purpose overloads align !
1787      \fi
1788      \strc_floats_make_complete_caption}}
1789
1790\def\strc_floats_prepare_stack_caption_auto
1791  {\ifx\p_strc_floats_caption_align\empty \else
1792     \doifnotinset\v!middle\p_strc_floats_caption_align{\let\captionovershoot\!!zeropoint}%
1793   \fi
1794   \edef\captionhsize{\the\wd\b_strc_floats_content}%
1795   \scratchwidth\floatcaptionparameter\c!maxwidth\relax
1796   \ifconditional\c_floats_adapt_to_caption_width
1797     \let\captionminwidth \!!zeropoint
1798     \let\captionovershoot\!!zeropoint
1799   \fi
1800   \ifdim\captionhsize>\scratchwidth
1801     % float is wider than \hsize
1802     \setbox\b_strc_floats_caption\vbox
1803       {\settrialtypesetting
1804        \strc_floats_caption_set_align
1805        \hsize\scratchwidth
1806        \notesenabledfalse
1807        \strc_floats_make_complete_caption}%
1808     \ifdim\ht\scratchbox>\lineheight % more lines
1809       \setbox\b_strc_floats_caption\vbox
1810         {\strc_floats_caption_set_align
1811          \hsize\dimexpr\captionhsize-\captionovershoot\relax
1812          \ifdim\hsize<\captionminwidth\relax
1813            \hsize\scratchwidth
1814          \fi
1815          \strc_floats_make_complete_caption}%
1816     \else
1817       \setbox\b_strc_floats_caption\vbox
1818         {\strc_floats_caption_set_align
1819          \hsize\scratchwidth
1820          \strc_floats_make_complete_caption}%
1821     \fi
1822   \else
1823     % float is smaller of equal to \hsize
1824     \ifdim\captionhsize<\captionminwidth\relax
1825       \scratchdimen\captionminwidth % float smaller than min width
1826       \edef\captionhsize{\the\scratchdimen}%
1827% \ifconditional\c_floats_adapt_to_caption_width
1828%   \setbox\b_strc_floats_content\hpack to \captionhsize{\hss\box\b_strc_floats_content\hss}%
1829% \fi
1830     \fi
1831     \setbox\scratchbox\vbox     % test with overshoot
1832       {\settrialtypesetting
1833        \scratchdimen\dimexpr\captionhsize+\captionovershoot+3\emwidth\relax % 3em is an average word length
1834        \ifdim\scratchdimen<\hsize
1835          \hsize\scratchdimen
1836        \fi
1837        \notesenabledfalse
1838        \strc_floats_make_complete_caption}%
1839     \ifdim\ht\scratchbox>\lineheight
1840       % at least an average word longer than a line
1841       \setbox\b_strc_floats_caption\vbox
1842         {\strc_floats_caption_set_align
1843          \scratchdimen\dimexpr\captionhsize+\captionovershoot\relax
1844          \ifdim\scratchdimen<\hsize
1845            \hsize\scratchdimen
1846          \fi
1847          \strc_floats_make_complete_caption}%
1848     \else\ifx\p_strc_floats_caption_align\empty
1849       \setbox\b_strc_floats_caption\vbox
1850         {\strc_floats_caption_set_align
1851          \hsize\captionhsize
1852          \raggedcenter % overloads
1853          \strc_floats_make_complete_caption}%
1854     \else
1855       \setbox\b_strc_floats_caption\vbox
1856         {\strc_floats_caption_set_align
1857          \hsize\captionhsize
1858          \strc_floats_make_complete_caption}%
1859     \fi\fi
1860   \fi}
1861
1862\def\strc_floats_between_stack
1863  {\endgraf
1864   \nointerlineskip
1865   \floatcaptionparameter\c!inbetween
1866   \endgraf}
1867
1868\def\strc_floats_build_box_default % done
1869  {\strc_floats_align_content{\box\b_strc_floats_content}}
1870
1871\def\strc_floats_build_box_next_right#1%
1872  {\ifconditional\c_strc_floats_par_float \hpack \else \expandafter \strc_floats_align_content \fi % skip, no pack
1873     {\d_strc_float_temp_height\ht\b_strc_floats_content
1874      \box\b_strc_floats_content
1875      \doifnotinset\v!hang\floatcaptionlocation
1876        {\dotfskip{\floatcaptionparameter\c!distance}}%
1877      \vbox to\d_strc_float_temp_height{#1}}}
1878
1879\def\strc_floats_build_box_next_left#1%
1880  {\ifconditional\c_strc_floats_par_float \hpack \else \expandafter \strc_floats_align_content \fi % skip, no pack
1881     {\d_strc_float_temp_height\ht\b_strc_floats_content
1882      \vbox to\d_strc_float_temp_height{#1}%
1883      \doifnotinset\v!hang\floatcaptionlocation
1884        {\dotfskip{\floatcaptionparameter\c!distance}}%
1885      \box\b_strc_floats_content}}
1886
1887\def\strc_floats_build_box_next_outer
1888  {\doifelserightpagefloat\strc_floats_build_box_next_right\strc_floats_build_box_next_left}
1889
1890\def\strc_floats_build_box_next_inner
1891  {\doifelserightpagefloat\strc_floats_build_box_next_left\strc_floats_build_box_next_right}
1892
1893\def\strc_floats_build_box_next_right_hang#1%
1894  {\ifconditional\c_strc_floats_par_float \hpack \else \expandafter \strc_floats_align_content \fi
1895     {\d_strc_float_temp_height\ht\b_strc_floats_content
1896      \box\b_strc_floats_content
1897      \vbox to\d_strc_float_temp_height{#1}}}
1898
1899\def\strc_floats_build_box_next_left_hang#1%
1900  {\ifconditional\c_strc_floats_par_float \hpack \else \expandafter \strc_floats_align_content \fi
1901     {\d_strc_float_temp_height\ht\b_strc_floats_content
1902      \vbox to\d_strc_float_temp_height{#1}%
1903      \box\b_strc_floats_content}}
1904
1905% \def\strc_floats_build_box_next_right_margin_indeed#1#2%
1906%   {\ifconditional\c_strc_floats_par_float
1907%      \hpack\bgroup
1908%        \d_strc_float_temp_height\ht\b_strc_floats_content
1909%        \box\b_strc_floats_content
1910%        \hsmash{\hskip#1\vbox to\d_strc_float_temp_height{#2}}%
1911%      \egroup
1912%    \else
1913%      \begingroup
1914%      \d_strc_float_temp_height\ht\b_strc_floats_content
1915%      \everyrightofalignedline{\hsmash{\hskip#1\vbox to\d_strc_float_temp_height{#2}}}%
1916%      \strc_floats_align_content{\box\b_strc_floats_content}%
1917%      \endgroup
1918%     \fi}
1919%
1920% \def\strc_floats_build_box_next_left_margin_indeed#1#2%
1921%   {\ifconditional\c_strc_floats_par_float
1922%      \hpack\bgroup
1923%        \d_strc_float_temp_height\ht\b_strc_floats_content
1924%        \hsmash{\hskip-\dimexpr#1+\wd\b_strc_floats_caption\relax\vbox to\d_strc_float_temp_height{#2}}%
1925%        \box\b_strc_floats_content
1926%      \egroup
1927%    \else
1928%      \begingroup
1929%      \d_strc_float_temp_height\ht\b_strc_floats_content
1930%      \everyleftofalignedline{\hsmash{\hskip-\dimexpr#1+\wd\b_strc_floats_caption\relax\vbox to\d_strc_float_temp_height{#2}}}%
1931%      \strc_floats_align_content{\box\b_strc_floats_content}%
1932%      \endgroup
1933%    \fi}
1934
1935\def\strc_floats_build_box_next_right_margin_indeed#1#2%
1936  {\ifconditional\c_strc_floats_par_float
1937     \hpack\bgroup
1938       \d_strc_float_temp_height\ht\b_strc_floats_content
1939       \box\b_strc_floats_content
1940       \hsmash{\hskip#1\vbox to\d_strc_float_temp_height{#2}}%
1941     \egroup
1942   \else
1943     \begingroup
1944     \d_strc_float_temp_height\ht\b_strc_floats_content
1945     \setbox\scratchboxone\vbox{#2}%
1946     \ifdim\htdp\scratchboxone>\htdp\b_strc_floats_content
1947       \global\d_strc_floats_overflow\dimexpr\htdp\scratchboxone-\htdp\b_strc_floats_content\relax
1948     \fi
1949     \ht\scratchboxone\d_strc_float_temp_height
1950     \everyrightofalignedline{\hsmash{\hskip#1\box\scratchboxone}}%
1951     \strc_floats_align_content{\box\b_strc_floats_content}%
1952     \endgroup
1953    \fi}
1954
1955\def\strc_floats_build_box_next_left_margin_indeed#1#2%
1956  {\ifconditional\c_strc_floats_par_float
1957     \hpack\bgroup
1958       \d_strc_float_temp_height\ht\b_strc_floats_content
1959       \hsmash{\hskip-\dimexpr#1+\wd\b_strc_floats_caption\relax\vbox to\d_strc_float_temp_height{#2}}%
1960       \box\b_strc_floats_content
1961     \egroup
1962   \else
1963     \begingroup
1964     \d_strc_float_temp_height\ht\b_strc_floats_content
1965     \setbox\scratchboxone\vbox{#2}%
1966     \ifdim\htdp\scratchboxone>\htdp\b_strc_floats_content
1967       \global\d_strc_floats_overflow\dimexpr\htdp\scratchboxone-\htdp\b_strc_floats_content\relax
1968     \fi
1969     \ht\scratchboxone\d_strc_float_temp_height
1970     \everyleftofalignedline{\hsmash{\hskip-\dimexpr#1+\wd\scratchboxone\relax\box\scratchboxone}}%
1971     \strc_floats_align_content{\box\b_strc_floats_content}%
1972     \endgroup
1973   \fi}
1974
1975\def\strc_floats_build_box_next_right_margin
1976  {\strc_floats_build_box_next_right_margin_indeed\rightmargindistance}
1977
1978\def\strc_floats_build_box_next_left_margin
1979  {\strc_floats_build_box_next_left_margin_indeed \leftmargindistance}
1980
1981\def\strc_floats_build_box_next_outer_margin
1982  {\doifelserightpagefloat
1983     {\strc_floats_build_box_next_right_margin_indeed\rightmargindistance}
1984     {\strc_floats_build_box_next_left_margin_indeed \rightmargindistance}}
1985
1986\def\strc_floats_build_box_next_inner_margin
1987  {\doifelserightpagefloat
1988     {\strc_floats_build_box_next_left_margin_indeed \leftmargindistance}
1989     {\strc_floats_build_box_next_right_margin_indeed\leftmargindistance}}
1990
1991\def\strc_floats_build_box_next % beware, we first check on left/rightmargin because there can be left/right also
1992  {\let\next\strc_floats_build_box_next_left
1993   \processallactionsinset[\floatcaptionlocation]
1994     [ \v!outermargin=>\let\next\strc_floats_build_box_next_outer_margin,
1995       \v!innermargin=>\let\next\strc_floats_build_box_next_inner_margin,
1996        \v!leftmargin=>\let\next\strc_floats_build_box_next_left_margin,
1997       \v!rightmargin=>\let\next\strc_floats_build_box_next_right_margin,
1998       \v!lefthanging=>\let\next\strc_floats_build_box_next_left_hang,
1999      \v!righthanging=>\let\next\strc_floats_build_box_next_right_hang,
2000             \v!outer=>\let\next\strc_floats_build_box_next_outer,
2001             \v!inner=>\let\next\strc_floats_build_box_next_inner,
2002              \v!left=>\let\next\strc_floats_build_box_next_left,
2003             \v!right=>\let\next\strc_floats_build_box_next_right]%
2004   \next}
2005
2006\def\strc_floats_build_box_side
2007  {\ifconditional\c_strc_floats_par_float
2008     \let\next\strc_floats_build_box_high
2009   \else
2010     \let\next\strc_floats_build_box_middle
2011     \processallactionsinset[\floatcaptionlocation]
2012       [   \v!low=>\let\next\strc_floats_build_box_low,
2013        \v!middle=>\let\next\strc_floats_build_box_middle,
2014          \v!high=>\let\next\strc_floats_build_box_high]%
2015   \fi
2016   \next}
2017
2018\def\strc_floats_flush_right_caption_hang
2019  {\hsmash{\rlap{\dotfskip{\floatcaptionparameter\c!distance}\box\b_strc_floats_caption}}}
2020
2021\def\strc_floats_flush_left_caption_hang
2022  {\hsmash{\llap{\box\b_strc_floats_caption\dotfskip{\floatcaptionparameter\c!distance}}}}
2023
2024\def\strc_floats_flush_caption_hang
2025  {\doifelseinset\v!righthanging\floatcaptionlocation
2026     {\strc_floats_flush_right_caption_hang}
2027     {\doifelseinset\v!lefthanging\floatcaptionlocation
2028        {\strc_floats_flush_left_caption_hang}
2029        {\doifelseinset\v!hang\floatcaptionlocation
2030           {\doifelseinset\v!outer\floatcaptionlocation
2031              {\doifelserightpagefloat{\strc_floats_flush_right_caption_hang}{\strc_floats_flush_left_caption_hang}}
2032              {\doifelseinset\v!right\floatcaptiondirectives
2033                 {\strc_floats_flush_right_caption_hang}
2034                 {\strc_floats_flush_left_caption_hang}}}
2035        {\box\b_strc_floats_caption}}}}
2036
2037\def\strc_floats_build_box_high
2038  {\strc_floats_build_box_next{\strc_floats_between_stack\strc_floats_flush_caption_hang\vfill}}
2039
2040\def\strc_floats_build_box_low
2041  {\strc_floats_build_box_next{\vfill\strc_floats_flush_caption_hang\strc_floats_between_stack}}
2042
2043\def\strc_floats_build_box_middle
2044  {\strc_floats_build_box_next{\vfill\box\b_strc_floats_caption\vfill}}
2045
2046% \definefloat
2047%   [lefty][lefties][figure]
2048% \setupfloat
2049%   [lefty]
2050%   [default=left,
2051%    rightmargindistance=-2cm,
2052%    leftmargindistance=-2cm]
2053% \setupcaption
2054%   [lefty]
2055%   [location={bottom,overlay}]
2056%
2057% \starttext
2058%     \placelefty{}{} \input tufte \input tufte
2059%     \placelefty{}{} \input tufte \input tufte
2060% \stoptext
2061
2062\def\strc_floats_build_box_top_stack_normal_overlay
2063  {\vbox to \ht\b_strc_floats_content{\vss\strc_floats_build_box_top_stack_normal_content}}
2064
2065\def\strc_floats_build_box_top_stack_normal_content
2066  {\d_strc_float_temp_width\wd\b_strc_floats_content
2067   \ifconditional\c_strc_floats_par_float
2068     \hpack{\strc_floats_locate_side_float{\box\b_strc_floats_caption}}%
2069     \strc_floats_between_stack
2070     \hpack{\hbox{\box\b_strc_floats_content}}%
2071   \else
2072     \page_otr_command_set_float_hsize
2073     \hpack{\strc_floats_locate_text_float{\box\b_strc_floats_caption}}
2074     \strc_floats_between_stack
2075     \hpack{\strc_floats_align_content{\box\b_strc_floats_content}}%
2076   \fi}
2077
2078\def\strc_floats_build_box_bottom_stack_normal_overlay
2079  {\vbox to \ht\b_strc_floats_content{\strc_floats_build_box_bottom_stack_normal_content\vss}}
2080
2081\def\strc_floats_build_box_bottom_stack_normal_content
2082  {\d_strc_float_temp_width\wd\b_strc_floats_content
2083   \ifconditional\c_strc_floats_par_float
2084     \hpack{\hpack{\box\b_strc_floats_content}}%
2085     \strc_floats_between_stack
2086     \hpack{\strc_floats_locate_side_float{\box\b_strc_floats_caption}}%
2087   \else
2088     \page_otr_command_set_float_hsize
2089     \hpack{\strc_floats_align_content{\box\b_strc_floats_content}}%
2090     \strc_floats_between_stack
2091     \hpack{\strc_floats_locate_text_float{\box\b_strc_floats_caption}}%
2092   \fi}
2093
2094\def\strc_floats_build_box_top_stack_normal
2095  {\doifelseinset\v!overlay{\floatcaptionparameter\c!location}
2096      \strc_floats_build_box_top_stack_normal_overlay
2097      \strc_floats_build_box_top_stack_normal_content}
2098
2099\def\strc_floats_build_box_bottom_stack_normal
2100  {\doifinset\v!overlay{\floatcaptionparameter\c!location}
2101    \strc_floats_build_box_bottom_stack_normal_overlay
2102    \strc_floats_build_box_bottom_stack_normal_content}
2103
2104\def\strc_floats_build_box_top_stack_grid
2105  {\dp\b_strc_floats_caption\strutdepth
2106   \setbox\scratchbox\vbox
2107     {\d_strc_float_temp_width\wd\b_strc_floats_content
2108      \hsize\d_strc_float_temp_width
2109      \ifconditional\c_strc_floats_par_float
2110        \strc_floats_locate_side_float{\box\b_strc_floats_caption}%
2111        \vss\strc_floats_between_stack
2112        \hpack{\box\b_strc_floats_content}%
2113      \else
2114        \page_otr_command_set_float_hsize
2115        \strc_floats_locate_text_float{\box\b_strc_floats_caption}%
2116        \vss\strc_floats_between_stack
2117        \strc_floats_align_content{\box\b_strc_floats_content}%
2118      \fi}%
2119   \getnoflines{\dimexpr\htdp\scratchbox-10\scaledpoint\relax}% get rid of inaccuracy
2120   \vpack to \noflines\lineheight{\unvbox\scratchbox}}
2121
2122\def\strc_floats_build_box_bottom_stack_grid
2123  {\dp\b_strc_floats_caption\strutdepth
2124   \setbox\scratchbox\vbox
2125     {\d_strc_float_temp_width\wd\b_strc_floats_content
2126      \hsize\d_strc_float_temp_width
2127      \ifconditional\c_strc_floats_par_float
2128        \hpack{\box\b_strc_floats_content}%
2129        \vss\strc_floats_between_stack
2130        \strc_floats_locate_side_float{\box\b_strc_floats_caption}%
2131      \else
2132        \page_otr_command_set_float_hsize
2133        \strc_floats_align_content{\box\b_strc_floats_content}%
2134        \vss\strc_floats_between_stack
2135        \strc_floats_locate_text_float{\box\b_strc_floats_caption}%
2136      \fi}%
2137   \getnoflines{\dimexpr\htdp\scratchbox-10\scaledpoint\relax}% get rid of inaccuracy
2138   \vpack to \noflines\lineheight{\unvbox\scratchbox}}
2139
2140\def\strc_floats_build_box_top_stack_stretch
2141  {\dp\b_strc_floats_caption\strutdepth
2142   \setbox\scratchbox\vpack
2143     {\strc_floats_align_caption{\copy\b_strc_floats_caption}%
2144      \strc_floats_align_content{\copy\b_strc_floats_content}}%
2145   \getnoflines{\dimexpr\htdp\scratchbox-10\scaledpoint\relax}% get rid of inaccuracy
2146   \vbox to \noflines\lineheight % pack ?
2147     {\d_strc_float_temp_width\wd\b_strc_floats_content
2148      \hsize\d_strc_float_temp_width
2149      \ifconditional\c_strc_floats_par_float
2150        \strc_floats_locate_side_float{\box\b_strc_floats_caption}%
2151        \vss\strc_floats_between_stack\vss
2152        \hpack{\box\b_strc_floats_content}%
2153      \else
2154        \page_otr_command_set_float_hsize
2155        \strc_floats_locate_text_float{\box\b_strc_floats_caption}%
2156        \vss\strc_floats_between_stack\vss
2157        \strc_floats_align_content{\box\b_strc_floats_content}%
2158      \fi}}
2159
2160\def\strc_floats_build_box_bottom_stack_stretch
2161  {\dp\b_strc_floats_caption\strutdepth
2162   \setbox\scratchbox\vpack
2163     {\strc_floats_align_content{\copy\b_strc_floats_content}%
2164      \strc_floats_align_caption{\copy\b_strc_floats_caption}}%
2165   \getnoflines{\dimexpr\htdp\scratchbox-10\scaledpoint\relax}% get rid of inaccuracy
2166   \vbox to \noflines\lineheight
2167     {\d_strc_float_temp_width\wd\b_strc_floats_content
2168      \hsize\d_strc_float_temp_width
2169      \ifconditional\c_strc_floats_par_float
2170        \hpack{\box\b_strc_floats_content}%
2171        \vss\strc_floats_between_stack\vss
2172        \strc_floats_locate_side_float{\box\b_strc_floats_caption}%
2173      \else
2174        \page_otr_command_set_float_hsize
2175        \strc_floats_align_content{\box\b_strc_floats_content}%
2176        \vss\strc_floats_between_stack\vss
2177        \strc_floats_locate_text_float{\box\b_strc_floats_caption}%
2178      \fi}}
2179
2180\def\strc_floats_build_box_top
2181  {\let\next\strc_floats_build_box_top_stack_normal
2182   \processfirstactioninset[\floatcaptionparameter\c!location]
2183     [   \v!grid=>\let\next\strc_floats_build_box_top_stack_grid,
2184        \v!lines=>\let\next\strc_floats_build_box_top_stack_stretch]% was \v!grid but interfered
2185   \next}
2186
2187\def\strc_floats_build_box_bottom
2188  {\let\next\strc_floats_build_box_bottom_stack_normal
2189   \processfirstactioninset[\floatcaptionparameter\c!location]
2190     [   \v!grid=>\let\next\strc_floats_build_box_bottom_stack_grid,
2191        \v!lines=>\let\next\strc_floats_build_box_bottom_stack_stretch]% was \v!grid but interfered
2192   \next}
2193
2194\def\strc_floats_relocate_caption_right#1{\strc_floats_align_caption{\hbox to \d_strc_float_temp_width{\hss#1}}}
2195\def\strc_floats_relocate_caption_left #1{\strc_floats_align_caption{\hbox to \d_strc_float_temp_width{#1\hss}}}
2196
2197\unexpanded\def\installfloatboxbuilder#1#2{\setvalue{\??floatbuilder#1}{#2}}
2198
2199\def\strc_floats_build_box
2200  {\strc_floats_build_box_before
2201   \global\setbox\floatbox\vbox % pack ? probably not
2202     {\strc_floats_set_local_hsize
2203      \forgetall
2204      \ifconditional\c_floats_store_minimal_package
2205        \strc_floats_build_box_separate_make
2206      \else
2207      % \let\floatcaptionarrangement\s!default
2208        \let\floatcaptionarrangement\v!bottom % for Alan
2209        \processcommacommand[\floatcaptionparameter\c!location]\strc_floats_build_box_step
2210        \ifcsname\??floatbuilder\floatcaptionarrangement\endcsname
2211          \lastnamedcs
2212        \else
2213          \strc_floats_build_box_default
2214        \fi
2215      \fi}%
2216   \strc_floats_build_box_after}
2217
2218% \let\strc_floats_build_box_before\relax
2219% \let\strc_floats_build_box_after \relax
2220
2221\def\strc_floats_build_box_before
2222  {\let\currentfloatframed\currentfloat
2223   \floatwidth\wd
2224     \ifdim\wd\b_strc_floats_content>\wd\b_strc_floats_caption
2225       \b_strc_floats_content\else\b_strc_floats_caption
2226     \fi}
2227
2228\def\strc_floats_build_box_after
2229  {\doifelseframed\floatframedparameter\strc_floats_build_box_after_indeed\relax}
2230
2231\def\strc_floats_build_box_after_indeed
2232  {\global\setbox\floatbox\hpack
2233     {\edef\m_width{\floatframedparameter\c!width}%
2234      \ifx\m_width\v!fit
2235        \let\m_width\floatwidth
2236      \else\ifx\m_width\v!broad
2237        \let\m_width\v!fit
2238      \fi\fi
2239      \letfloatframedparameter\c!strut\v!no
2240      \letfloatframedparameter\c!width\m_width
2241      \inheritedfloatframedframed
2242        {\box\floatbox}}}
2243
2244% special purpose: used in floatcombinations
2245%
2246% todo : keep float content and caption separated in local
2247
2248\newbox\b_strc_floats_separate_content
2249\newbox\b_strc_floats_separate_caption
2250
2251\def\strc_floats_build_box_separate_set
2252  {\settrue\c_floats_adapt_to_caption_width
2253   \settrue\c_floats_store_minimal_package}
2254
2255% \def\strc_floats_build_box_separate_make
2256%   {\offinterlineskip
2257%    \vpack to \onepoint{\box\b_strc_floats_content}\break
2258%    \vpack to \onepoint{\box\b_strc_floats_caption}}
2259
2260%D Remark for \LMTX: we don't want to migrate inserts here so we unpack
2261%D (could be a flag). When migrated, the inserts end up in the vertical
2262%D list and we no longer have just a box (but inserts and lines again).
2263
2264% \def\strc_floats_build_box_separate_split#1%
2265%   {\setbox\scratchbox\vpack{#1}%
2266%    \setbox\scratchbox\vbox\bgroup
2267%      \unvpack\scratchbox
2268%      \setbox\scratchbox\lastbox % can have (unmigrated) inserts
2269%      \unvpack\scratchbox
2270%      \setbox\scratchbox\lastbox % can have (unmigrated) inserts
2271%      \unvpack\scratchbox
2272%      \setbox\scratchbox\lastbox % can have (unmigrated) inserts
2273%      \splittopskip\zeropoint
2274%      \global\setbox\b_strc_floats_separate_content\vsplit\scratchbox to \onepoint
2275%      \global\setbox\b_strc_floats_separate_caption\vsplit\scratchbox to \onepoint
2276%    \egroup
2277%    \global\setbox\b_strc_floats_separate_content\vpack
2278%      {\unvbox\b_strc_floats_separate_content
2279%       \setbox\scratchbox\lastbox
2280%       \unvbox\scratchbox}%
2281%    \global\setbox\b_strc_floats_separate_caption\tpack
2282%      {\unvbox\b_strc_floats_separate_caption
2283%       \setbox\scratchbox\lastbox
2284%       \unvbox\scratchbox}}
2285
2286\def\strc_floats_build_box_separate_make
2287  {\savebox\??localfloatstack{\number\numexpr\c_strc_localfloats_n+1\relax:a}{\box\b_strc_floats_content}%
2288   \savebox\??localfloatstack{\number\numexpr\c_strc_localfloats_n+1\relax:b}{\box\b_strc_floats_caption}}
2289
2290\unexpanded\def\strc_floats_build_box_separate_split#1%
2291  {\global\setbox\b_strc_floats_separate_content\vpack{\foundbox\??localfloatstack{\number#1:a}}%
2292   \global\setbox\b_strc_floats_separate_caption\tpack{\foundbox\??localfloatstack{\number#1:b}}}
2293
2294% \def\strc_floats_build_box_step#1%
2295%   {\doifdefined{\??floatbuilder#1}{\def\floatcaptionarrangement{#1}\quitcommalist}}
2296
2297\def\strc_floats_build_box_step#1%
2298  {\ifcsname\??floatbuilder#1\endcsname
2299     \def\floatcaptionarrangement{#1}% \let\floatcaptionarrangement\commalistelement
2300     \quitcommalist
2301   \fi}
2302
2303\def\strc_floats_locate_text_float
2304  {\let\next\strc_floats_align_caption
2305   \processallactionsinset[\floatcaptionparameter\c!location]
2306     [ \v!left=>\let\next\strc_floats_relocate_caption_left,
2307      \v!right=>\let\next\strc_floats_relocate_caption_right,
2308      \v!inner=>\doifelserightpagefloat{\let\next\strc_floats_relocate_caption_left }{\let\next\strc_floats_relocate_caption_right},
2309      \v!outer=>\doifelserightpagefloat{\let\next\strc_floats_relocate_caption_right}{\let\next\strc_floats_relocate_caption_left }]%
2310   \next}
2311
2312\installfloatboxbuilder \v!none         \strc_floats_build_box_default
2313\installfloatboxbuilder \s!default      \strc_floats_build_box_default
2314\installfloatboxbuilder \v!high         \strc_floats_build_box_high
2315\installfloatboxbuilder \v!low          \strc_floats_build_box_low
2316\installfloatboxbuilder \v!middle       \strc_floats_build_box_middle
2317
2318\installfloatboxbuilder \v!rightmargin  \strc_floats_build_box_side % added 2016-08-23
2319\installfloatboxbuilder \v!leftmargin   \strc_floats_build_box_side % added 2016-08-23
2320\installfloatboxbuilder \v!innermargin  \strc_floats_build_box_side % added 2016-08-23
2321\installfloatboxbuilder \v!outermargin  \strc_floats_build_box_side % added 2016-08-23
2322
2323\installfloatboxbuilder \v!left         \strc_floats_build_box_side
2324\installfloatboxbuilder \v!right        \strc_floats_build_box_side
2325\installfloatboxbuilder \v!inner        \strc_floats_build_box_side % added 2016-08-23
2326\installfloatboxbuilder \v!outer        \strc_floats_build_box_side % added 2016-08-23
2327
2328\installfloatboxbuilder \v!lefthanging  \strc_floats_build_box_side % added 2016-08-23
2329\installfloatboxbuilder \v!righthanging \strc_floats_build_box_side % added 2016-08-23
2330\installfloatboxbuilder \v!hang         \strc_floats_build_box_side % added 2016-08-23
2331
2332\installfloatboxbuilder \v!top          \strc_floats_build_box_top
2333\installfloatboxbuilder \v!bottom       \strc_floats_build_box_bottom
2334
2335% \setuplayout[grid=yes] \showgrid \setupcaptions[style=smallbodyfont,location=grid,inbetween=]
2336%
2337% \starttext
2338%     test \placefigure{}                 {\externalfigure[cow.pdf][frame=on,grid=yes]}   test \page
2339%     test \placefigure{\input zapf\relax}{\externalfigure[cow.pdf][frame=on,grid=yes]}   test \page
2340%     test \placefigure{}                 {\externalfigure[cow.pdf][frame=on,grid=depth]} test \page
2341%     test \placefigure{\input zapf\relax}{\externalfigure[cow.pdf][frame=on,grid=depth]} test \page
2342% \stoptext
2343
2344% This might move to page-flt:
2345
2346\newif\ifpostponecolumnfloats \postponecolumnfloatsfalse % don't change
2347
2348\setnewconstant\postcenterfloatmethod\plusone
2349
2350\def\postcenterfloatbox#1%
2351  {\scratchdimen
2352     \ifcase\postcenterfloatmethod
2353       #1% \wd\floatbox
2354     \or\ifinsidecolumns
2355       \ifpostponecolumnfloats\makeupwidth\else#1\fi
2356     \else\ifdim#1>\hsize
2357       \hsize
2358     \else
2359       \wd\floatbox
2360     \fi\fi\fi
2361   \global\setbox\floatbox\hbox to \scratchdimen
2362   % {\hfill\box\floatbox\hfill}} % geen \hss, gaat mis in kolommen !
2363   % {\hss  \box\floatbox\hss  }} % wel \hss, anders mis in colset
2364     {\ifconditional\c_page_floats_center_box_global
2365        \donetrue
2366      \else\ifconditional\c_page_floats_center_box_local
2367        \donetrue
2368      \else
2369        \donefalse
2370      \fi\fi
2371      \ifdim\scratchdimen>\effectivehsize
2372        \donefalse
2373      \fi
2374      \hss\ifdone\hskip\effectiveleftskip\fi
2375      \box\floatbox
2376      \ifdone\hskip\effectiverightskip\fi\hss}}
2377
2378\def\strc_floats_set_paragraph_variant
2379  {\bgroup
2380   \forgetall
2381   \postponenotes
2382   \dontcomplain
2383   \setbox\b_strc_floats_content\vbox{\borderedfloatbox}% \vpack >?
2384  %\page_backgrounds_add_local_to_box\b_strc_floats_content
2385   \ifnofloatcaption
2386     \global\setbox\floatbox\vpack{\box\b_strc_floats_content}%
2387   \else
2388     \strc_floats_check_caption_content
2389     \strc_floats_prepare_side_caption
2390     \setbox\b_strc_floats_caption\hbox{\floatcaptionparameter\c!command{\box\b_strc_floats_caption}}% \hpack ?
2391    %\moveboxontogrid\b_strc_floats_caption{\floatcaptionparameter\c!grid}\d_strc_floats_caption_height
2392    %\page_backgrounds_add_local_to_box\b_strc_floats_caption
2393     \strc_floats_build_side_box
2394   \fi
2395   \egroup}
2396
2397\def\strc_floats_prepare_side_caption
2398  {\dostarttagged\t!floatcaption\empty
2399   \edef\p_strc_floats_caption_width{\floatcaptionparameter\c!width}%
2400   \edef\p_strc_floats_caption_align{\floatcaptionparameter\c!align}%
2401   \ifx\p_strc_floats_caption_width\v!max
2402     \strc_floats_prepare_side_caption_max
2403   \else\ifx\p_strc_floats_caption_width\v!fit
2404     \strc_floats_prepare_side_caption_fit
2405   \else
2406     \strc_floats_prepare_side_caption_width
2407   \fi\fi
2408   \dostoptagged}
2409
2410% these could be \??floatpreparesidecaption
2411
2412% \setupfloat[figure][location=left]
2413% \setupcaption[figure][width=max]
2414%
2415% \placefigure{my figure caption my figure caption}{\framed[width=4cm,height=1cm]{}} \input tufte
2416% \placefigure{my figure caption}                  {\framed[width=4cm,height=1cm]{}} \input tufte
2417
2418\def\strc_floats_prepare_side_caption_max
2419  {\setbox\b_strc_floats_caption\vbox
2420     {\strc_floats_caption_set_align
2421      \hsize\wd\b_strc_floats_content
2422      \strc_floats_make_complete_caption}}
2423
2424\def\strc_floats_prepare_side_caption_fit % or center when smaller
2425  {\ifdim\wd\b_strc_floats_caption>\wd\b_strc_floats_content\relax
2426     \setbox\b_strc_floats_caption\vbox
2427       {\forgetall % needed?
2428        \strc_floats_caption_set_align
2429        \hsize\wd\b_strc_floats_content
2430        \strc_floats_make_complete_caption}%
2431   \else
2432     % maybe we should listen to the align option here (now side floats need the max option
2433     \setbox\b_strc_floats_caption\hpack to \wd\b_strc_floats_content
2434       {\hss\hbox{\strc_floats_make_complete_caption}\hss}%
2435   \fi}
2436
2437\def\strc_floats_prepare_side_caption_width
2438  {\setbox\b_strc_floats_caption\vbox
2439     {\strc_floats_caption_set_align
2440      \hsize\p_strc_floats_caption_width % \wd\b_strc_floats_content
2441      \strc_floats_make_complete_caption}}
2442
2443% % maybe (but then also prepare_page that way):
2444%
2445% \installcorenamespace{floatpreparesidecaption}
2446%
2447% \def\strc_floats_prepare_side_caption
2448%   {\dostarttagged\t!floatcaption\empty
2449%    \edef\p_strc_floats_caption_width{\floatcaptionparameter\c!width}%
2450%    \edef\p_strc_floats_caption_align{\floatcaptionparameter\c!align}%
2451%    \expandnamespacemacro\??floatpreparesidecaption\p_strc_floats_caption_width\s!unknown
2452%    \dostoptagged}
2453%
2454% \setvalue{\??floatpreparesidecaption\v!max}%
2455%   {\setbox\b_strc_floats_caption\vbox
2456%      {\strc_floats_caption_set_align
2457%       \hsize\wd\b_strc_floats_content
2458%       \strc_floats_make_complete_caption}}
2459%
2460% \setvalue{\??floatpreparesidecaption\v!fit}%
2461%   {\ifdim\wd\b_strc_floats_caption>\wd\b_strc_floats_content\relax
2462%      \setbox\b_strc_floats_caption\vbox
2463%        {\forgetall % needed?
2464%         \hsize\wd\b_strc_floats_content
2465%         \strc_floats_make_complete_caption}%
2466%    \else
2467%      \setbox\b_strc_floats_caption\hbox to \wd\b_strc_floats_content
2468%        {\hss\hbox{\strc_floats_make_complete_caption}\hss}%
2469%    \fi}
2470%
2471% \setvalue{\??floatpreparesidecaption\s!unknown}%
2472%   {\setbox\b_strc_floats_caption\vbox
2473%      {\strc_floats_caption_set_align
2474%       \hsize\p_strc_floats_caption_width % \wd\b_strc_floats_content
2475%       \strc_floats_make_complete_caption}}
2476
2477\def\strc_floats_locate_side_float#1%
2478  {\begingroup
2479   \alignstrutmode\zerocount
2480   \hsize\d_strc_float_temp_width \forgetall
2481   \alignedline{\floatparameter\c!location}\v!middle{#1}%
2482   \endgroup}
2483
2484\def\strc_floats_build_side_box
2485  {\let\strc_floats_align_content\relax
2486   \let\strc_floats_align_caption\relax
2487   \strc_floats_build_box}
2488
2489\def\strc_floats_set_box % todo : \global\setbox, currently messy
2490  {\ifvisible
2491     \par
2492     \edef\floatcaptiondirectives{\floatparameter\c!location,\floatcaptionparameter\c!location}%
2493     \ifconditional\c_strc_floats_par_float
2494       \strc_floats_set_paragraph_variant
2495     \else
2496       \strc_floats_set_page_variant
2497     \fi
2498     \strc_floats_set_local_dimensions
2499     \global\advance\totalnoffloats\plusone
2500     \ifconditional\c_floats_store_minimal_package \else
2501       \setbox\floatbox\hpack{\strc_float_save_data\box\floatbox}% still needed? we will do renumbering differently
2502     \fi
2503     \global\floatheight\htdp\floatbox
2504     \global\floatwidth\wd\floatbox
2505     \ifconditional\c_floats_store_minimal_package \else
2506       \doifnotinset\v!margin\floatlocation % gaat namelijk nog fout
2507         {\setbox\floatbox\vpack
2508            {\parindent\zeropoint
2509             \box\floatbox}}%
2510     \fi
2511     \wd\floatbox\floatwidth
2512     \ifdim\dimexpr\floatheight+\lineheight\relax<\textheight \else
2513       \global\floatheight\dimexpr\textheight-\lineheight\relax
2514       \ht\floatbox\floatheight
2515       \dp\floatbox\zeropoint
2516       \showmessage\m!floatblocks{10}{\the\totalnoffloats}%
2517     \fi
2518   \fi}
2519
2520% \def\dooutput{\sidefloatoutput} % redefinition of \dooutput
2521
2522\definefloat
2523  [\v!figure]
2524  [\v!figures]
2525
2526\definefloat
2527  [\v!table]
2528  [\v!tables]
2529
2530\setupfloat
2531  [\v!table]
2532  [\c!frame=\v!off]
2533
2534\definefloat
2535  [\v!intermezzo]
2536  [\v!intermezzi]
2537
2538\definefloat
2539  [\v!graphic]
2540  [\v!graphics]
2541
2542% float strategy, replaces some of the above macros
2543
2544\installcorenamespace{floatmethods}
2545
2546\let\floatmethod      \empty % set by lua
2547\let\floatlabel       \empty % set by lua
2548\let\floatcolumn      \empty % set by lua
2549\let\floatrow         \empty % set by lua
2550\let\forcedfloatmethod\empty % set by lua and floatcombinations
2551
2552\def\setfloatmethodvariables#1% \floatmethod \floatlabel \floatrow \floatcolumn
2553  {\clf_analysefloatmethod{#1}}
2554
2555\def\somesomewherefloat[#1]%
2556  {\page_floats_save_somewhere_float\s!somewhere{#1}}
2557
2558\def\strc_floats_get_box
2559  {\ifvisible
2560%      \let\floatlabel \empty
2561%      \let\floatcolumn\empty
2562%      \let\floatrow   \empty
2563%      \setfloatmethodvariables\floatlocation
2564     % todo: nog algemeen otr
2565%      \ifdefined\OTRSETsetpreferedcolumnslot
2566%        \OTRSETsetpreferedcolumnslot\floatcolumn\floatrow
2567%      \fi
2568     \ifcsname\??floatmethods\currentoutputroutine:\floatmethod\endcsname \else
2569        \let\floatmethod\v!here
2570     \fi
2571     \ifx\forcedfloatmethod\empty \else
2572       \let\floatmethod\forcedfloatmethod
2573     \fi
2574\let\askedfloatmethod\floatmethod
2575\ifexporting \ifx\askedfloatmethod\v!here \else
2576  \showmessage\m!floatblocks{15}{\askedfloatmethod,\v!here}%
2577  \let\floatlocation\v!here
2578\fi \fi
2579     % [] will go
2580     \edef\floatlocationmethod{\floatmethod,\floatlocation}%
2581     \csname\??floatmethods\currentoutputroutine:\floatmethod\endcsname
2582   \fi}
2583
2584\installcorenamespace{floatsettings}
2585
2586\unexpanded\def\installfloatmethod#1#2#3% routine keyword handler
2587  {\setvalue{\??floatmethods#1:#2}{#3}}
2588
2589\unexpanded\def\handlefloatmethod#1%
2590  {\csname\??floatmethods\currentoutputroutine:#1\endcsname}
2591
2592% \unexpanded\def\installfloatmethod#1#2#3% routine keyword handler
2593%   {\ifcsname\??floatsettings#1:#2\endcsname \else
2594%      \expandafter\newtoks\csname\??floatsettings#1:#2\endcsname
2595%    \fi
2596%    \setvalue{\??floatmethods#1:#2}{#3}}
2597%
2598% \unexpanded\def\startfloatmethodsettings#1#2 #3\stopfloatmethodsettings
2599%   {\csname\??floatsettings#1:#2\endcsname\expandafter{\the\csname\??floatsettings#1:#2\endcsname#3}}
2600%
2601% \let\stopfloatmethodsettings\relax
2602%
2603% \unexpanded\def\applyfloatmethodsettings#1#2{\the\??floatsettings#1:#2\endcsname}
2604
2605\definesystemconstant{tblr}
2606\definesystemconstant{lrtb}
2607\definesystemconstant{tbrl}
2608\definesystemconstant{rltb}
2609\definesystemconstant{btlr}
2610\definesystemconstant{lrbt}
2611\definesystemconstant{btrl}
2612\definesystemconstant{rlbt}
2613\definesystemconstant{fxtb}
2614\definesystemconstant{fxbt}
2615\definesystemconstant{fixd}
2616
2617% can move to page-one:
2618
2619\installfloatmethod \s!singlecolumn \v!here        \page_one_place_float_here
2620\installfloatmethod \s!singlecolumn \v!force       \page_one_place_float_force
2621\installfloatmethod \s!singlecolumn \v!left        \page_one_place_float_left
2622\installfloatmethod \s!singlecolumn \v!right       \page_one_place_float_right
2623\installfloatmethod \s!singlecolumn \v!text        \page_one_place_float_text
2624\installfloatmethod \s!singlecolumn \v!top         \page_one_place_float_top
2625\installfloatmethod \s!singlecolumn \v!bottom      \page_one_place_float_bottom
2626\installfloatmethod \s!singlecolumn \v!auto        \page_one_place_float_auto
2627\installfloatmethod \s!singlecolumn \v!margin      \page_one_place_float_margin
2628\installfloatmethod \s!singlecolumn \v!opposite    \page_one_place_float_face
2629\installfloatmethod \s!singlecolumn \v!page        \page_one_place_float_page
2630\installfloatmethod \s!singlecolumn \v!leftpage    \page_one_place_float_leftpage
2631\installfloatmethod \s!singlecolumn \v!rightpage   \page_one_place_float_rightpage
2632\installfloatmethod \s!singlecolumn \v!inmargin    \page_one_place_float_inmargin
2633\installfloatmethod \s!singlecolumn \v!inleft      \page_one_place_float_leftmargin
2634\installfloatmethod \s!singlecolumn \v!inright     \page_one_place_float_rightmargin
2635\installfloatmethod \s!singlecolumn \v!leftmargin  \page_one_place_float_leftmargin
2636\installfloatmethod \s!singlecolumn \v!rightmargin \page_one_place_float_rightmargin
2637\installfloatmethod \s!singlecolumn \v!leftedge    \page_one_place_float_leftedge
2638\installfloatmethod \s!singlecolumn \v!rightedge   \page_one_place_float_rightedge
2639\installfloatmethod \s!singlecolumn \v!somewhere   \page_one_place_float_somewhere
2640\installfloatmethod \s!singlecolumn \v!backspace   \page_one_place_float_backspace
2641\installfloatmethod \s!singlecolumn \v!cutspace    \page_one_place_float_cutspace
2642\installfloatmethod \s!singlecolumn \s!tblr        \page_one_place_float_top
2643\installfloatmethod \s!singlecolumn \s!lrtb        \page_one_place_float_top
2644\installfloatmethod \s!singlecolumn \s!tbrl        \page_one_place_float_top
2645\installfloatmethod \s!singlecolumn \s!fxtb        \page_one_place_float_top
2646\installfloatmethod \s!singlecolumn \s!rltb        \page_one_place_float_top
2647\installfloatmethod \s!singlecolumn \s!btlr        \page_one_place_float_bottom
2648\installfloatmethod \s!singlecolumn \s!lrbt        \page_one_place_float_bottom
2649\installfloatmethod \s!singlecolumn \s!btrl        \page_one_place_float_bottom
2650\installfloatmethod \s!singlecolumn \s!rlbt        \page_one_place_float_bottom
2651\installfloatmethod \s!singlecolumn \s!fxbt        \page_one_place_float_bottom
2652\installfloatmethod \s!singlecolumn \s!fixd        \page_one_place_float_force
2653
2654%D Local floats:
2655
2656\installcorenamespace{localfloats}
2657\installcorenamespace{localfloatstack}
2658
2659\installsetuponlycommandhandler \??localfloats {localfloats}
2660
2661\setuplocalfloats
2662  [%\c!before=\blank,
2663   %\c!after=\blank,
2664   \c!inbetween=\blank]
2665
2666\initializeboxstack\??localfloatstack
2667
2668\newcount\c_strc_localfloats_n  \let\noflocalfloats\c_strc_localfloats_n
2669
2670\unexpanded\def\resetlocalfloats
2671  {\global\c_strc_localfloats_n\zerocount
2672   \initializeboxstack\??localfloatstack}
2673
2674\unexpanded\def\somelocalfloat
2675  {\global\advance\c_strc_localfloats_n\plusone
2676   \savebox\??localfloatstack{\number\c_strc_localfloats_n}{\box\floatbox}}
2677
2678\unexpanded\def\getlocalfloats
2679  {\dorecurse\c_strc_localfloats_n
2680     {\ifnum\recurselevel=\plusone % 1\relax
2681        \directlocalfloatsparameter\c!before
2682      \else
2683        \directlocalfloatsparameter\c!inbetween
2684      \fi
2685      \dontleavehmode\hpack{\foundbox\??localfloatstack\recurselevel}% \restorebox...
2686      \ifnum\recurselevel=\c_strc_localfloats_n\relax
2687        \directlocalfloatsparameter\c!after
2688      \fi}}
2689
2690\unexpanded\def\flushlocalfloats
2691  {\getlocalfloats
2692   \resetlocalfloats}
2693
2694% \unexpanded\def\getlocalfloat#1%
2695%   {\normalexpanded{\foundbox{\??localfloatstack}{\number#1}}}% \vbox{\restorebox...}
2696
2697\unexpanded\def\getlocalfloat#1%
2698  {\foundbox\??localfloatstack{\number#1}} % \vbox{\restorebox...}
2699
2700\unexpanded\def\forcelocalfloats
2701  {\let\forcedfloatmethod\v!local}
2702
2703\installfloatmethod \s!singlecolumn \v!local \somelocalfloat
2704\installfloatmethod \s!multicolumn  \v!local \somelocalfloat
2705\installfloatmethod \s!mixedcolumn  \v!local \somelocalfloat
2706\installfloatmethod \s!columnset    \v!local \somelocalfloat
2707
2708\protect \endinput
2709