page-one.mkxl /size: 29 Kb    last modification: 2025-02-21 11:03
1%D \module
2%D   [       file=page-one,
3%D        version=2000.10.20,
4%D          title=\CONTEXT\ Page Macros,
5%D       subtitle=Default Routine,
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\writestatus{loading}{ConTeXt Page Macros / Default Routine}
15
16%D This is just the good old \CONTEXT\ output routine, which has been there right
17%D from the start.
18
19% todo: flush page figures without header and footer
20
21\unprotect
22
23% OTRONE: basic single column
24
25\newconstant \c_page_one_float_method
26
27\protected\def\page_one_command_next_page
28  {\page_otr_eject_page}
29
30\protected\def\page_one_command_next_page_and_inserts
31  {\page_otr_eject_page_and_flush_inserts}
32
33\protected\def\page_one_command_set_hsize
34  {\global\hsize\textwidth
35   \columnwidth\textwidth} % bonus so that it's not zero
36
37\protected\def\page_one_command_set_float_hsize
38  {\global\hsize\textwidth}
39
40%D It's complicated:
41
42\newconditional\c_page_one_set_vsize_tmp
43
44\installtextracker{otr.insertheights}
45  {\c_page_one_set_vsize_tmp\conditionaltrue}
46  {\c_page_one_set_vsize_tmp\conditionalfalse}
47
48\def\page_one_command_set_vsize_tmp
49  {\settotalinsertionheight
50   \writestatus
51     {set vsize one}
52     {insert heights=\the\insertheights,
53      total insertion height=\the\totalinsertionheight,
54      delta=\todimension{\insertheights-\totalinsertionheight}}%
55   \page_one_command_set_vsize_new}
56
57\def\page_one_command_set_vsize_old
58  {\settotalinsertionheight
59   \pagegoal{\vsize-\totalinsertionheight}}
60
61\def\page_one_command_set_vsize_new
62  {\pagegoal{%
63      \vsize
64     -\d_page_floats_inserted_top
65     -\d_page_floats_inserted_bottom
66     -\insertheights
67   }}
68
69\protected\def\page_one_command_set_vsize
70  {\ifgridsnapping
71     \ifcase\layoutlines
72       \getrawnoflines\textheight
73     \else
74       \noflines\layoutlines
75     \fi
76     \global\vsize\noflines\openlineheight
77   \else
78     \global\vsize\textheight
79   \fi
80   %
81   \ifzeropt\textadaptive\else
82     \global\d_page_adapts_delta\textadaptive
83     \global\pageextragoal-\textadaptive
84   \fi
85   %
86   \global\advanceby\vsize\d_page_adapts_delta
87   % alternatively we could set it in builders.buildpage_filter
88 % \ifdim\pagegoal<\maxdimen .. \fi
89 % \writestatus{!!!!!!!!}{\the\vsize-> v:\the\pagevsize,g:\the\pagegoal,t:\the\pagetotal,i:\the\insertheights}%
90   \ifconditional\c_page_one_set_vsize_tmp
91     \page_one_command_set_vsize_tmp
92   \orelse\ifzeropt\insertheights
93     \page_one_command_set_vsize_old
94   \else
95     \page_one_command_set_vsize_new
96   \fi}
97
98% 1 = partial page, 2 = whole page, 3 = partial page
99
100% We really need a setting! Todo, what key to use?
101
102\pushoverloadmode
103    \setnewconstant\kindofpagetextareas\plustwo                     % \plusone can become default some day
104    \overloaded\mutable\let\kindofpagetextareas\kindofpagetextareas % for now mutable, can become a key/value
105\popoverloadmode
106
107\def\page_one_registered_text_area_a % two arguments: (un)vbox n
108  {\ifconditional\c_page_areas_enabled
109     \expandafter\page_one_registered_text_area_a_indeed
110   \else
111     \expandafter\firstofoneargument
112   \fi}
113
114\def\page_one_registered_text_area_b % one arguments: content
115  {\ifconditional\c_page_areas_enabled
116     \expandafter\page_one_registered_text_area_b_indeed
117   \else
118     \expandafter\firstofoneargument
119   \fi}
120
121\def\page_one_registered_text_area_a_indeed % two arguments: (un)vbox n
122  {\ifcase\kindofpagetextareas
123     \expandafter\firstofoneargument
124   \or % partial page (experimental)
125     \expandafter\page_areas_register_direct
126   \or % whole page   (default)
127     \expandafter\firstofoneargument
128   \else
129     \expandafter\firstofoneargument
130   \fi}
131
132\def\page_one_registered_text_area_b_indeed % one arguments: content
133  {\ifcase\kindofpagetextareas
134     % \expandafter\firstofoneargument
135   \or % partial page (experimental)
136     % \expandafter\firstofoneargument
137   \or % whole page   (default)
138     \expandafter\page_areas_register_boxed
139   \else
140     % \expandafter\firstofoneargument
141   \fi}
142
143\newdimension\d_page_one_natural_depth
144\newbox      \b_page_one_bottom_notes
145\newbox      \b_page_one_contents
146
147\let\page_one_command_package_show_state\relax
148
149% \fakepagenotes ... needs checking
150%
151% we can also have bottom notes on top of bottom insertions
152
153%D \starttyping
154%D \setuplayout[height=middle] \showframe
155%D
156%D % \markpages[stretch][lines=2] % current page
157%D
158%D \starttext
159%D     \brokenpenalty 10000 \clubpenalty 20000 \widowpenalty 20000
160%D     \dorecurse{10}{\samplefile{tufte}\par} \page
161%D     \startmarkpages[stretch][lines=2]
162%D         \dorecurse{10}{\samplefile{tufte}\par} \page
163%D     \stopmarkpages
164%D     \dorecurse{10}{\samplefile{tufte}\par} \page
165%D \stoptext
166%D \stoptyping
167
168%D This will be replaced by vz
169
170\newinteger\c_page_one_stretch % we use marked pages which actually slow down a little
171
172\def\page_one_check_stretch_contents
173  {\ifdim{\textheight-\ht\b_page_one_contents}<\c_page_one_stretch\lineheight
174     \setbox\b_page_one_contents\vpack\bgroup
175       % no need to speed up low level
176       \scale[\c!height=\textheight,\c!width=\textwidth]{\box\b_page_one_contents}%
177     \egroup
178   \fi}
179
180\def\page_one_check_stretch_lines
181  {\edef\m_lines{\markedpageparameter\v!stretch\v!lines}%
182   \ifempty\m_lines\else\c_page_one_stretch\m_lines\fi}
183
184\let\page_one_hook_for_checks\gobbleoneargument
185
186\protected\def\page_one_command_package_contents#1#2% \box<n> \unvbox<n> % this one will be redone (checked)
187  {\bgroup
188   \strc_notes_check_if_bottom_present
189   \d_page_one_natural_depth\dp#2\relax
190   % we need to set the height as otherwise the shrink will not kick in so the following
191   % no longer applies:
192   %
193   % \setbox\b_page_one_contents\vbox \ifconditional\c_notes_bottom_present to \textheight \fi
194   %
195   \page_layouts_check_stretch#2%
196   %
197%    \ifconditional\c_notes_bottom_present\else
198%       \doifmarkedpage\v!stretch\page_one_check_stretch_lines
199%    \fi
200   \setbox\b_page_one_contents\vbox \ifcase\c_page_one_stretch to \textheight\fi % probably no pack
201     {\page_otr_command_flush_top_insertions
202      % this is messy ... we will provide a more tight area (no big deal as we can
203      % do that at the lua end)
204    % \parfillskip\zeroskip
205      \page_one_registered_text_area_a#1#2% \unvbox <box>
206      %
207      \ifgridsnapping
208        \unskip % new per 2019-06-18, otherwise weird bottom floats
209        \vkern{\openstrutdepth-\d_page_one_natural_depth}%
210        \prevdepth\openstrutdepth
211        \page_otr_command_flush_bottom_insertions
212        \vfil
213      \orelse\ifcase\bottomraggednessmode
214        % ragged (default)
215        \unskip % new per 2019-06-18, otherwise weird bottom floats
216        \vkern{\openstrutdepth-\d_page_one_natural_depth}%
217        \prevdepth\openstrutdepth
218        % these have whitespace before but we can have some more options
219        % like a \vfill or so
220        \page_otr_command_flush_bottom_insertions
221        \vfil
222      \or
223        % align (normal)
224        \page_otr_command_flush_bottom_insertions
225      \or
226        % baseline
227        \unskip % new per 2019-06-18, otherwise weird bottom floats
228        \vkern{\maxdepth-\d_page_one_natural_depth}%
229      % \srule depth {\maxdepth-\d_page_one_natural_depth}%
230        \page_otr_command_flush_bottom_insertions
231      \or
232        % depth
233        \vkern-\d_page_one_natural_depth
234        \unskip % new per 2019-06-18, otherwise weird bottom floats
235        \page_otr_command_flush_bottom_insertions
236      \fi
237      \fakepagenotes}%
238   \page_one_hook_for_checks\b_page_one_contents % todo
239   \page_one_command_package_show_state
240   \ifconditional\c_notes_bottom_present
241     \ifgridsnapping
242       \ifcase\layoutlines
243         \getrawnoflines\textheight
244       \else
245         \noflines\layoutlines
246       \fi
247       \scratchoffset{\numexpr\noflines-\plusone\relax\lineheight+\topskip}%
248     \else
249       \scratchoffset\ht\b_page_one_contents
250     \fi
251     \setbox\b_page_one_bottom_notes\hpack
252       {\lower\scratchoffset\vbox{\placebottomnotes\par\kern\zeropoint}}% kerns makes notes sit on bottom % pack ?
253     \smashbox\b_page_one_bottom_notes
254     \ht\b_page_one_contents\zeropoint
255     \page_one_registered_text_area_b
256       {\vpack to \textheight
257          {\box\b_page_one_contents
258           \box\b_page_one_bottom_notes}}%
259   \else
260     \ifcase\c_page_scale_lines
261       % nothing to do: vz not enabled
262     \orelse\ifdim\d_page_box_stretch_delta>\zeropoint
263       \page_scale_text_box_register_box\b_page_one_contents
264       \page_scale_text_box\b_page_one_contents
265     \else
266       \page_scale_text_box_register_page
267       \page_scale_text_box\b_page_one_contents
268     \fi
269%      \ifcase\c_page_one_stretch\else
270%         \page_one_check_stretch_contents
271%      \fi
272     \ht\b_page_one_contents\textheight
273     \page_one_registered_text_area_b
274       {\box\b_page_one_contents}%
275   \fi
276   \egroup}
277
278\protected\def\page_one_command_side_float_output
279  {\page_otr_construct_and_shipout\unvbox\normalpagebox\plusone} % three arguments, we need to be in the output group
280
281\protected\def\page_one_command_routine
282  {\page_sides_output_routine}
283
284%D Insertions
285
286\newconditional\c_page_one_top_of_insert
287\newconditional\c_page_one_correct_top_insert  \c_page_one_correct_top_insert\conditionaltrue % false moves up (tight)
288\newgluespec   \s_page_one_between_top_insert
289
290\def\page_one_prepare_top_float
291  {\ifzeropt\d_page_floats_inserted_top
292     \c_page_one_top_of_insert\conditionaltrue
293   \else
294     \c_page_one_top_of_insert\conditionalfalse
295   \fi
296   \s_page_one_between_top_insert\ifdim\d_strc_floats_top>\d_strc_floats_bottom\d_strc_floats_top\else\d_strc_floats_bottom\fi\relax
297   \global\advanceby\d_page_floats_inserted_top{\ht\floatbox+\dp\floatbox+\s_page_one_between_top_insert}}
298
299\def\page_one_insert_top_float % maybe remember last beforeskip
300  {\floatingpenalty\zerocount
301   \insert\namedinsertionnumber\s!topfloat\bgroup
302     \forgetall
303     \ifconditional\c_page_one_top_of_insert
304       \ifconditional\c_page_one_correct_top_insert
305         \topskipcorrection % [xx] new: see icare topbleed
306         \kern-\lineskip
307         \par
308         \prevdepth\maxdimen
309       \fi
310     \fi
311\page_inserts_detach\floatbox % experiment
312     \page_otr_command_flush_float_box
313\page_inserts_attach          % experiment
314     \vskip\s_page_one_between_top_insert
315   \egroup}
316
317\mutable\let\totaltopinserted\!!zeropoint
318\mutable\let\totalbotinserted\!!zeropoint
319
320\protected\def\page_one_command_set_top_insertions
321  {\bgroup
322   % a bit strange place but okay
323   \page_one_command_set_always_insertions_top
324   \page_one_command_set_always_insertions_bottom
325   %
326   \ifconditional\c_page_floats_some_waiting
327     \noffloatinserts\zerocount
328     \let\totaltopinserted\!!zeropoint
329     \page_one_command_set_top_insertions_indeed
330     \ifnum\rootfloatparameter\c!nbottom=\zerocount % \ifnum\c_page_floats_n_of_bottom=\zerocount
331       \ifnum\rootfloatparameter\c!nlines>\zerocount
332         \ifdim\totaltopinserted>\zeropoint\relax
333           \ifdim{\lineheight*(\rootfloatparameter\c!nlines)+\totaltopinserted}>\textheight
334             \showmessage\m!floatblocks8{\rootfloatparameter\c!nlines}%
335             \page_otr_fill_and_eject_page % was tripple: vfilll
336           \fi
337         \fi
338       \fi
339     \fi
340   \fi
341   \egroup}
342
343\def\page_one_command_set_top_insertions_indeed
344  {\ifnum\noffloatinserts<\c_page_floats_n_of_top
345     \page_floats_get
346     \page_one_prepare_top_float
347     \ifdim\d_page_floats_inserted_top<\textheight\relax
348       \xdef\totaltopinserted{\the\d_page_floats_inserted_top}%
349       \page_one_insert_top_float
350       \ifconditional\c_page_floats_some_waiting
351         \advanceby\noffloatinserts \plusone
352       \else
353         \noffloatinserts\c_page_floats_n_of_top\relax
354       \fi
355       \page_floats_report_flushed
356     \else
357       \page_floats_resave\s!text
358       \noffloatinserts\c_page_floats_n_of_top\relax
359     \fi
360   \else
361     \ifconditional\c_page_floats_some_waiting
362       \showmessage\m!floatblocks6{\the\c_page_floats_n_of_top}%
363     \fi
364     \let\page_one_command_set_top_insertions_indeed\relax
365   \fi
366   \page_one_command_set_top_insertions_indeed}
367
368\protected\def\page_one_command_set_bottom_insertions
369  {\bgroup
370   \ifconditional\c_page_floats_some_waiting
371     \noffloatinserts\zerocount
372     \page_one_command_set_bottom_insertions_indeed
373   \fi
374   \egroup}
375
376\def\page_one_command_set_bottom_insertions_indeed
377  {\ifnum\noffloatinserts<\c_page_floats_n_of_bottom\relax
378     \page_floats_get
379     \global\advanceby\d_page_floats_inserted_bottom{\ht\floatbox+\dp\floatbox+\d_strc_floats_top}%
380     \ifdim\d_page_floats_inserted_bottom<\pagegoal\relax
381       \floatingpenalty\zerocount
382       \insert\namedinsertionnumber\s!bottomfloat\bgroup
383         \forgetall
384         \blank[\rootfloatparameter\c!spacebefore]%
385         \page_otr_command_flush_float_box
386       \egroup
387       \ifconditional\c_page_floats_some_waiting
388         \advanceby\noffloatinserts \plusone
389       \else
390         \noffloatinserts\c_page_floats_n_of_bottom
391       \fi
392       \page_floats_report_flushed
393     \else
394       \page_floats_resave\s!text
395       \noffloatinserts\c_page_floats_n_of_bottom\relax
396     \fi
397     \global\c_page_floats_not_permitted\conditionaltrue % vgl topfloats s!
398   \else
399     \ifconditional\c_page_floats_some_waiting
400       \showmessage\m!floatblocks7{\the\c_page_floats_n_of_bottom}%
401     \fi
402     \let\page_one_command_set_bottom_insertions_indeed\relax
403   \fi
404   \page_one_command_set_bottom_insertions_indeed}
405
406% \protected\def\page_one_command_flush_top_insertions
407%   {\ifzeropt\insertheight\namedinsertionnumber\s!topfloat\else
408%      \page_one_command_flush_top_insertions_indeed % less tracing
409%    \fi
410%    \global\d_page_floats_inserted_top\zeropoint}
411
412\protected\def\page_one_command_flush_top_insertions
413  {\ifzeropt\insertheight\namedinsertionnumber\s!topfloat\else
414     \page_one_command_flush_top_insertions_indeed % less tracing
415     \ifcase\bottomraggednessmode\or\else
416       % will be an option because of stretch size effect when we limit
417       \ifzerodim\d_page_box_stretch_delta
418         \vskip\zeropoint\s!plus\openstrutdepth\s!minus\openstrutdepth\relax
419       \fi
420     \fi
421   \fi
422   \global\d_page_floats_inserted_top\zeropoint}
423
424\def\page_one_command_flush_top_insertions_indeed
425  {\ifgridsnapping
426     \insertbox\namedinsertionnumber\s!topfloat
427     \vkern-\topskip
428     \vkern\strutheight % [xx] new: see icare topbleed
429   \else
430     \ifcase\c_page_floats_insertions_topskip_mode
431       % 0: default, do nothing
432     \or
433       % 1: no topskip (crossed fingers)
434       \vskip-\topskip % skip !
435       \vkern\strutheight
436     \fi
437     \insertunbox\namedinsertionnumber\s!topfloat
438   \fi}
439
440\protected\def\page_one_command_flush_bottom_insertions
441  {\ifzeropt\insertheight\namedinsertionnumber\s!bottomfloat\else
442     \page_one_command_flush_bottom_insertions_indeed
443   \fi
444   \global\d_page_floats_inserted_bottom\zeropoint
445   \global\c_page_floats_not_permitted\conditionalfalse}
446
447\def\page_one_command_flush_bottom_insertions_indeed
448  {\ifgridsnapping
449   % \rootfloatparameter\c!bottombefore
450     \snaptogrid\hbox{\insertbox\namedinsertionnumber\s!bottomfloat}%
451   % \rootfloatparameter\c!bottomafter
452   \else
453     \rootfloatparameter\c!bottombefore
454     \insertunbox\namedinsertionnumber\s!bottomfloat
455     \rootfloatparameter\c!bottomafter
456   \fi}
457
458\protected\def\page_one_command_flush_floats
459  {\global\c_page_floats_flushing\conditionaltrue
460   \ifconditional\c_page_floats_some_waiting
461     \par
462     % if kept, then option and definitely off in gridmode ! ! ! !
463     % \ifvmode \prevdepth\maxdimen \fi % prevents whitespace; problematic in icare tests
464     \page_one_command_flush_floats_indeed
465   \fi
466   \global\savednoffloats\zerocount
467   \global\c_page_floats_some_waiting\conditionalfalse
468   \global\c_page_floats_flushing\conditionalfalse}
469
470\protected\def\page_one_command_flush_float_box
471  {\ifconditional\c_page_floats_center_box \ifdim\wd\floatbox<\hsize
472     \global\setbox\floatbox\hpack to \hsize{\hss\box\floatbox\hss}%
473   \fi \fi
474   \snaptogrid\hpack{\box\floatbox}} % was copy
475
476\def\page_one_command_floats_get_compressed
477  {\c_page_floats_center_box\conditionalfalse % not needed as we do call directly
478   %% no longer (interferes with footnotes):
479   %%
480   %% \page_one_command_set_vsize % test 2011.06.24.001
481   %%
482   \global\setbox\floatbox\hbox to \hsize
483     {\hfil
484      \dorecurse\nofcollectedfloats
485        {\ifcase\columndirection % nog document wide
486           \page_floats_flush\s!text\plusone
487         \else
488           \page_floats_flush\s!text{\tointeger{\nofcollectedfloats-\recurselevel+1}}%
489         \fi
490         \hpack to \ifdim\naturalfloatwd>\makeupwidth\makeupwidth\else\naturalfloatwd\fi
491           {\hss\box\floatbox\hss}%
492         \ifnum\recurselevel<\nofcollectedfloats
493           \hfil
494         \fi}%
495      \hfil}}
496
497\def\page_one_command_flush_floats_indeed
498  {\ifconditional\c_page_floats_some_waiting
499     \ifconditional\c_page_floats_pack_flushed
500       \page_floats_collect\s!text\hsize\d_page_floats_compress_distance
501       \ifcase\nofcollectedfloats
502         \page_floats_get
503       \or
504         \page_floats_get
505       \else
506         \page_one_command_floats_get_compressed
507       \fi
508     \else
509       \page_floats_get
510     \fi
511     % there is a chance that due to rounding errors, the float
512     % fits on a page where it was first rejected, in which case
513     % the prevdepth is -maxdimen and we cannot obey the grid
514     \doplacefloatbox
515     \expandafter\page_one_command_flush_floats_indeed
516   \fi}
517
518\protected\def\page_one_command_flush_margin_blocks
519  {\ifconditional\c_page_margin_blocks_present % \ifvoid\b_page_margin_blocks \else
520     \ifzeropt\pagetotal
521        \null % \fixedspace
522     \fi
523     \page_otr_command_next_page % \page
524     \ifvoid\b_page_margin_blocks
525       \global\c_page_margin_blocks_present\conditionalfalse
526     \else
527       \doubleexpandafter\page_one_command_flush_margin_blocks
528     \fi
529   \fi}
530
531\protected\def\page_one_command_check_if_float_fits
532  {\ifconditional\c_page_floats_not_permitted
533     \global\c_page_floats_room\conditionalfalse
534   \else
535     % new per 31/5/2004, should be an option, only one column mode
536     \begingroup
537     \scratchdimen{\pagetotal+\lineheight}%
538     \ifdim\scratchdimen>\pagegoal
539       \goodbreak % hack ?
540     \fi
541     % should be an option
542     \endgroup
543     \scratchdimenone{%
544        \pagetotal
545       +\floatheight
546       +\d_strc_floats_top
547       +\d_strc_floats_overflow
548       -\pageshrink
549     }%
550     \scratchdimentwo\pagegoal
551     \relax % needed
552     \ifcase\c_page_one_float_method
553       % method 0 : raw
554     \or
555       % method 1 : safe
556       % too fuzzy as it can change and for a high page it's a lot : \scratchdimentwo .99\pagegoal
557       \advanceby\scratchdimentwo -\strutdp
558     \or
559       % method 2 : tight
560       \advanceby\scratchdimenone -\onepoint
561     \fi
562     \relax % really needed ! ! ! !
563     \ifdim\scratchdimenone>\scratchdimentwo
564       \global\c_page_floats_room\conditionalfalse
565     \else
566       \global\c_page_floats_room\conditionaltrue
567     \fi
568   \fi}
569
570\protected\def\page_one_command_flush_saved_floats
571  {\global\d_page_floats_inserted_top\zeropoint
572   \global\d_page_floats_inserted_bottom\zeropoint
573   \ifconditional\c_page_floats_flushing \else
574     \page_one_command_set_top_insertions
575     \page_one_command_set_bottom_insertions
576     \ifconditional\c_page_floats_some_waiting
577       \ifcstok{\rootfloatparameter\c!cache}\v!no
578         \page_one_command_flush_floats % could be _otr_
579       \fi
580     \orelse\ifconditional\c_page_margin_blocks_present
581       \page_one_command_flush_floats
582     \fi
583   \fi}
584
585% \def\page_one_place_float_here_indeed
586%   {\ifgridsnapping
587%      % otherwise real bad outcome
588%    \else
589%      \baselinecorrection % this has to be done better (and definitely not in column mode)
590%    \fi
591%    \doplacefloatbox
592%    \page_floats_report_total
593%    \dohandlenextfloatindent}
594
595% \def\page_one_place_float_here_indeed
596%   {\ifgridsnapping
597%      % otherwise real bad outcome
598%    \else
599%     % this was not really applied (delayed)
600%     % \baselinecorrection % this has to be done better (and definitely not in column mode)
601%     % so we now use this:
602%       \checkprevdepth
603%    \fi
604%    \doplacefloatbox
605%    \page_floats_report_total
606%    \dohandlenextfloatindent}
607
608\def\page_one_place_float_here_indeed
609  {\ifgridsnapping
610     % otherwise real bad outcome
611   \else
612    \forcestrutdepth
613   \fi
614   \doplacefloatbox
615   \page_floats_report_total
616   \dohandlenextfloatindent}
617
618\def\page_one_place_float_force
619  {\showmessage\m!floatblocks9\empty
620   \page_one_place_float_here_indeed}
621
622\def\page_one_place_float_side_indeed#1%
623  {\setbox\floatbox\vpack{\box\floatbox}% ? can go
624   \wd\floatbox\floatwidth
625   #1{\box\floatbox}%
626   \ifinset\v!tall\floatlocationmethod
627     \page_sides_flush_floats_after_par
628   \fi}
629
630\def\page_one_place_float_left
631  {\page_one_place_float_side_indeed
632   \page_sides_process_float_left
633   \presetindentation}
634
635\def\page_one_place_float_right
636  {\page_one_place_float_side_indeed
637   \page_sides_process_float_right}
638
639\def\page_one_place_float_margin
640  {\page_margin_blocks_process_float
641   \nonoindentation} % new, due to popular request
642
643\def\page_one_place_float_leftmargin
644  {\page_one_place_float_side_indeed
645   \page_sides_process_float_leftmargin
646   \nonoindentation} % new, due to popular request
647
648\def\page_one_place_float_rightmargin
649  {\page_one_place_float_side_indeed
650   \page_sides_process_float_rightmargin
651   \nonoindentation} % new, due to popular request
652
653\def\page_one_place_float_leftedge
654  {\page_one_place_float_side_indeed
655   \page_sides_process_float_leftedge}
656
657\def\page_one_place_float_rightedge
658  {\page_one_place_float_side_indeed
659   \page_sides_process_float_rightedge}
660
661\def\page_one_place_float_inmargin
662  {\page_one_place_float_side_indeed
663   \page_sides_process_float_cutspace}
664
665\def\page_one_place_float_backspace
666  {\page_one_place_float_side_indeed
667   \page_sides_process_float_backspace}
668
669\def\page_one_place_float_cutspace
670  {\page_one_place_float_side_indeed
671   \page_sides_process_float_cutspace}
672
673\def\page_one_place_float_page       {\page_floats_save_page_float     \s!page     \floatlocationmethod}
674\def\page_one_place_float_leftpage   {\page_floats_save_page_float     \s!leftpage \floatlocationmethod}
675\def\page_one_place_float_rightpage  {\page_floats_save_page_float     \s!rightpage\floatlocationmethod}
676\def\page_one_place_float_somewhere  {\page_floats_save_somewhere_float\s!somewhere\floatlocationmethod}
677
678\def\page_one_place_float_here
679  {\page_one_place_float_otherwise_here}
680
681\def\page_one_place_float_auto
682  {\page_one_place_float_otherwise
683   \nonoindentation} % new, due to popular request
684
685\def\page_one_place_float_top
686  {\page_one_place_float_otherwise
687   \nonoindentation}
688
689\def\page_one_place_float_bottom
690  {\page_one_place_float_otherwise
691   \nonoindentation} % new, due to popular request
692
693\def\page_one_place_float_otherwise
694  {\ifinset\v!here\floatlocationmethod
695     \page_one_place_float_otherwise_here
696   \else
697     \page_one_place_float_otherwise_else
698   \fi}
699
700\def\page_one_place_float_otherwise_here
701  {\ifinset\v!always\floatlocationmethod
702     \page[\v!preference]%
703     \page_otr_command_check_if_float_fits
704     \ifconditional\c_page_floats_room
705       \page_one_place_float_here_indeed
706     \else
707       \showmessage\m!floatblocks9\empty
708       \page_floats_resave\s!text
709     \fi
710   \orelse\ifconditional\c_page_floats_some_waiting
711     \page_floats_save\s!text
712     \nonoindentation
713   \else
714     \page[\v!preference]%
715     \page_otr_command_check_if_float_fits
716     \ifconditional\c_page_floats_room
717       \page_one_place_float_here_indeed
718     \else
719       \page_floats_save\s!text
720       \nonoindentation
721     \fi
722   \fi}
723
724% Some new always top/bottom trickery.
725%
726% Musical timestamp: 2023/3/2, listening to / watching Camille Bigeault on YT
727% (ANATMAN, Room 8, and others), a bit late discovery, creative drumming! Gavin
728% Harrison level creativity.
729
730\def\page_one_place_float_otherwise_else
731   {\ifinset\v!always\floatlocationmethod
732      \page_otr_command_check_if_float_fits
733      \ifconditional\c_page_floats_room
734        \page_one_place_float_auto_top_bottom
735      \else
736        \showmessage\m!floatblocks9\empty
737        \ifinset\v!top\floatlocationmethod
738          \page_floats_save\s!top
739        \orelse\ifinset\v!bottom\floatlocationmethod
740          \page_floats_save\s!bottom
741        \else
742          \page_floats_resave\s!text
743        \fi
744      \fi
745    \else
746      \page_otr_command_check_if_float_fits
747      \ifconditional\c_page_floats_room
748        \page_one_place_float_auto_top_bottom
749      \else
750        \page_floats_save\s!text
751        \nonoindentation
752      \fi
753    \fi}
754
755\protected\def\page_one_command_set_always_insertions_bottom_indeed
756  {\page_floats_flush\s!bottom\plusone
757   \floatingpenalty\zerocount
758   \insert\namedinsertionnumber\s!bottomfloat\bgroup
759     \forgetall
760     \blank[\rootfloatparameter\c!spacebefore]%
761     \page_otr_command_flush_float_box
762   \egroup}
763
764\protected\def\page_one_command_set_always_insertions_bottom % will become an otr command
765  {\ifzero\nofstackedfloatsincategory\s!bottom\else
766     \page_one_command_set_always_insertions_bottom_indeed
767     \expandafter\page_one_command_set_always_insertions_bottom
768   \fi}
769
770\protected\def\page_one_command_set_always_insertions_top_indeed
771  {\page_floats_flush\s!top\plusone
772   \floatingpenalty\zerocount
773   \insert\namedinsertionnumber\s!bottomfloat\bgroup
774     \forgetall
775     \blank[\rootfloatparameter\c!spacebefore]%
776     \page_otr_command_flush_float_box
777   \egroup}
778
779\protected\def\page_one_command_set_always_insertions_top % will become an otr command
780  {\ifzero\nofstackedfloatsincategory\s!top\else
781     \page_one_command_set_always_insertions_top_indeed
782     \expandafter\page_one_command_set_always_insertions_top
783   \fi}
784
785\mutable\def\floatautofactor{.5}
786
787\def\page_one_place_float_auto_top_bottom
788  {\ifx\floatmethod\v!auto
789     \ifdim\pagetotal<\floatautofactor\pagegoal % when empty page, maxdimen
790       \page_one_place_float_top_indeed
791     \else
792       \page_one_place_float_bottom_indeed
793     \fi
794   \else
795     \ifx\floatmethod\v!top
796       \page_one_place_float_top_indeed
797     \orelse\ifx\floatmethod\v!bottom
798       \page_one_place_float_bottom_indeed
799     \else
800       \page_one_place_float_here_indeed
801     \fi
802   \fi}
803
804\def\page_one_place_float_top_indeed % maybe remember last beforeskip
805  {\page_one_prepare_top_float
806   \page_one_insert_top_float
807   \page_floats_report_total}
808
809\def\page_one_place_float_bottom_indeed
810  {\global\advanceby\d_page_floats_inserted_bottom{\ht\floatbox+\dp\floatbox+\d_strc_floats_top}%
811   \floatingpenalty\zerocount
812   \insert\namedinsertionnumber\s!bottomfloat\bgroup
813     \forgetall
814     \blank[\rootfloatparameter\c!spacebefore]%
815     \page_otr_command_flush_float_box
816   \egroup
817   \page_floats_report_total}
818
819\def\page_one_place_float_face % links, rechts, midden, hoog, midden, laag
820  {%\checkwaitingfloats{#1}%
821   \startopposite
822   \page_otr_command_flush_float_box
823   \stopopposite
824  }%\page_floats_report_total}
825
826\protected\def\page_one_command_flush_side_floats
827  {\page_sides_flush_floats}
828
829\protected\def\page_one_command_synchronize_side_floats
830  {\page_sides_synchronize_floats}
831
832\protected\def\page_one_command_test_page
833  {\testpage}
834
835\protected\def\page_one_command_flush_all_floats
836  {\ifconditional\c_page_floats_some_waiting
837     \begingroup
838     \c_page_floats_n_of_top\plusthousand
839     \c_page_floats_n_of_bottom\zerocount
840     % this is needed in case a float that has been stored
841     % ends up at the current page; this border case occurs when
842     % the calculated room is 'eps' smaller that the room available
843     % when just flushing; so now we have (maybe optional):
844     \pagebaselinecorrection % hm, needs checking, not needed when no floats
845     % alas, this is tricky but needed (first surfaced in prikkels)
846     \page_otr_command_flush_floats
847     \endgroup
848   \fi}
849
850\defineoutputroutine
851  [\s!singlecolumn]
852  [\s!page_otr_command_routine                =\page_one_command_routine,
853   \s!page_otr_command_package_contents       =\page_one_command_package_contents,
854   \s!page_otr_command_set_vsize              =\page_one_command_set_vsize,
855   \s!page_otr_command_set_hsize              =\page_one_command_set_hsize,
856 % \s!page_otr_command_synchronize_hsize      =\page_one_command_synchronize_hsize,
857   \s!page_otr_command_next_page              =\page_one_command_next_page,
858   \s!page_otr_command_next_page_and_inserts  =\page_one_command_next_page_and_inserts,
859   \s!page_otr_command_set_top_insertions     =\page_one_command_set_top_insertions,
860   \s!page_otr_command_set_bottom_insertions  =\page_one_command_set_bottom_insertions,
861   \s!page_otr_command_flush_top_insertions   =\page_one_command_flush_top_insertions,
862   \s!page_otr_command_flush_bottom_insertions=\page_one_command_flush_bottom_insertions,
863   \s!page_otr_command_check_if_float_fits    =\page_one_command_check_if_float_fits,
864 % \s!page_otr_command_set_float_hsize        =\page_one_command_set_float_hsize,
865   \s!page_otr_command_flush_float_box        =\page_one_command_flush_float_box,
866   \s!page_otr_command_side_float_output      =\page_one_command_side_float_output,
867   \s!page_otr_command_synchronize_side_floats=\page_one_command_synchronize_side_floats,
868   \s!page_otr_command_flush_floats           =\page_one_command_flush_floats,
869   \s!page_otr_command_flush_side_floats      =\page_one_command_flush_side_floats,
870   \s!page_otr_command_flush_saved_floats     =\page_one_command_flush_saved_floats,
871   \s!page_otr_command_flush_all_floats       =\page_one_command_flush_all_floats,
872   \s!page_otr_command_flush_margin_blocks    =\page_one_command_flush_margin_blocks,
873   \s!page_otr_command_test_column            =\page_one_command_test_page,
874]
875
876% \setupoutputroutine
877%   [\s!singlecolumn]
878
879\protect \endinput
880