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