1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21\writestatus{loading}{ConTeXt Page Macros Simple Multi Column}
22
23
24
25
26
27
28\unprotect
29
30\definesystemvariable {ks}
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62\installcorenamespace {columns}
63
64\installframedcommandhandler \??columns {columns} \??columns
65
66
67
68
69 \unexpanded\def\ejectcolumn
70 {\goodbreak
71 \showmessage\m!columns2\empty}
72
73
74
75
76\unexpanded\def\page_mul_place_float_top
77 {\showmessage\m!columns4\empty\page_one_place_float_here}
78
79\unexpanded\def\page_mul_place_float_bottom
80 {\showmessage\m!columns5\empty\page_one_place_float_here}
81
82\unexpanded\def\page_mul_place_float_here
83 {\page_one_place_float_here}
84
85\unexpanded\def\page_mul_place_float_force
86 {\page_one_place_float_force}
87
88\unexpanded\def\page_mul_command_side_float_output
89 {\page_otr_construct_and_shipout\unvbox\normalpagebox\zerocount}
90
91\unexpanded\def\page_mul_command_flush_side_floats
92 {\page_sides_forget_floats}
93
94\unexpanded\def\page_mul_command_synchronize_side_floats
95 {\page_sides_forget_floats}
96
97\unexpanded\def\page_mul_command_next_page
98 {\page_otr_eject_page}
99
100\unexpanded\def\page_mul_command_next_page_and_inserts
101 {\page_otr_eject_page_and_flush_inserts}
102
103\let\page_mul_initialize_floats\relax
104\let\page_mul_flush_floats \relax
105\let\page_mul_flush_float \relax
106
107
108
109\let\finishcolumnbox\relax
110
111
112
113\ifdefined\nofcolumns \else \newcount\nofcolumn \fi
114\ifdefined\mofcolumns \else \newcount\mofcolumn \fi
115
116\appendtoks
117 \nofcolumns\columnsparameter\c!n\relax
118\to \everysetupcolumns
119
120
121
122\installcorenamespace{columnseparators}
123
124\setvalue{\??columnseparators\v!on }{\let\page_mul_between_columns\page_mul_between_columns_rule}
125\setvalue{\??columnseparators\v!off }{\let\page_mul_between_columns\page_mul_between_columns_space}
126\setvalue{\??columnseparators }{\let\page_mul_between_columns\page_mul_between_columns_space}
127\setvalue{\??columnseparators\s!unknown}{\let\page_mul_between_columns\p_page_mul_rule}
128
129\def\page_mul_between_columns_rule
130 {\bgroup
131 \starttextproperties
132 \scratchdistance\dimexpr\columnsparameter\c!distance2\relax
133 \hskip\scratchdistance\relax
134 \vrule
135 \s!width\linewidth
136 \ifnum\bottomraggednessmode=\plustwo
137 \s!depth\strutdepth
138 \fi
139 \hskip\scratchdistance\relax
140 \stoptextproperties
141 \egroup}
142
143\def\page_mul_between_columns_space
144 {\hskip\columnsparameter\c!distance\relax}
145
146\let\page_mul_between_columns\page_mul_between_columns_space
147
148
149
150\newdimen \d_page_mul_available_width
151\newdimen \d_page_mul_distance
152\newdimen \d_page_mul_leftskip
153\newdimen \d_page_mul_rightskip
154\newdimen \d_page_mul_offset
155\newdimen \d_page_mul_forced_height
156\newdimen \d_page_mul_used_width
157\newdimen \d_page_mul_temp
158
159\newcount \c_page_mul_balance_minimum
160\newcount \c_page_mul_n_of_lines
161
162\newbox \b_page_mul_preceding
163\newdimen \d_page_mul_preceding_height
164\newdimen \d_page_mul_preceding_depth
165\newconditional\c_page_mul_preceding_present
166
167\newbox \b_page_mul_preceding_rest_of_page
168
169\newconditional\c_page_mul_reverse
170\newconditional\c_page_mul_trace
171
172
173
174 \newdimen\finalcolumnheights
175 \newcount\finalcolumnlines
176
177 \newdimen\savedpagetotal
178
179 \newif\ifstretchcolumns \stretchcolumnsfalse
180 \newif\ifheightencolumns \heightencolumnsfalse
181 \newif\ifinheritcolumns \inheritcolumnsfalse
182 \newif\ifbalancecolumns
183
184
185
186\unexpanded\def\page_mul_command_set_hsize
187 {\setbox\scratchbox\hbox{\page_mul_between_columns}
188 \d_page_mul_distance\wd\scratchbox
189 \d_page_mul_available_width\dimexpr
190 \makeupwidth
191 \d_page_mul_leftskip
192 \d_page_mul_rightskip
193 \nofcolumns\d_page_mul_distance
194 \d_page_mul_distance
195 \relax
196 \d_page_mul_used_width\dimexpr
197 \d_page_mul_available_width\nofcolumns
198 \d_page_mul_offset*\plustwo
199 \relax
200 \textwidth\d_page_mul_used_width
201 \hsize\d_page_mul_used_width}
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272\setnewconstant\multicolumnlinemethod\zerocount
273
274\def\multicolumnovershootratio{.5}
275
276\unexpanded\def\page_mul_set_n_of_lines
277 {\settotalinsertionheight
278 \d_page_mul_temp\dimexpr
279 \d_page_mul_offset*\plustwo
280 \textheight
281 \ifdim\d_page_mul_preceding_height>\zeropoint \d_page_mul_preceding_height \fi
282 \totalinsertionheight
283 \relax
284 \ifcase\multicolumnlinemethod
285 \getnoflines \d_page_mul_temp \or
286 \getrawnoflines\d_page_mul_temp \else
287 \getrawnoflines\d_page_mul_temp
288 \fi
289
290 \ifnum\layoutlines>\zerocount \ifnum\noflines>\layoutlines
291 \noflines\layoutlines
292 \fi \fi
293 \c_page_mul_n_of_lines\noflines}
294
295\unexpanded\def\page_mul_command_set_vsize
296 {\page_one_command_set_vsize
297 \page_mul_set_n_of_lines
298 \d_page_mul_temp\nofcolumns\dimexpr
299 \c_page_mul_n_of_lines\openlineheight
300 \multicolumnovershootratio\openlineheight
301 \relax
302 \global\vsize\d_page_mul_temp
303 \pagegoal \d_page_mul_temp}
304
305
306
307
308
309
310
311
312
313
314
315
316\newconstant\c_page_mul_routine
317
318\setnewconstant\c_page_mul_routine_regular \zerocount
319\setnewconstant\c_page_mul_routine_intercept \plusone
320\setnewconstant\c_page_mul_routine_continue \plustwo
321\setnewconstant\c_page_mul_routine_balance \plusthree
322\setnewconstant\c_page_mul_routine_error \plusfour
323
324\unexpanded\def\page_mul_command_routine
325 {\ifcase\c_page_mul_routine
326 \page_one_command_routine
327 \or
328 \page_mul_routine_intercept
329 \or
330 \page_mul_routine_continue
331 \or
332 \page_mul_routine_balance
333 \or
334 \page_mul_routine_error
335 \fi}
336
337\def\page_mul_routine_intercept
338 {\global\setbox\b_page_mul_preceding\vbox
339 {\page_otr_command_flush_top_insertions
340 \unvbox\normalpagebox}}
341
342\def\page_mul_routine_error
343 {\showmessage\m!columns3\empty
344 \page_otr_construct_and_shipout\unvbox\normalpagebox\zerocount}
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363\unexpanded\def\page_mul_initialize_variables
364 {\reseteverypar
365 \dontcomplain
366 \settopskip
367 \setmaxdepth
368 \topskip 1\topskip
369 \splittopskip \topskip
370 \splitmaxdepth \maxdepth
371 \boxmaxdepth \maxdepth
372 \emergencystretch\zeropoint
373 \relax}
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392\newdimen\maxcolumnheight
393\newdimen\maxcolumndepth
394
395\newbox\columnpagebox
396
397\def\page_mul_calculate_column_result_dimensions
398 {\maxcolumnheight\zeropoint
399 \maxcolumndepth \zeropoint
400 \dohandleallcolumnscs\page_mul_calculate_column_result_dimensions_step}
401
402\def\page_mul_calculate_column_result_dimensions_step
403 {\ifdim\ht\currentcolumnbox>\maxcolumnheight
404 \maxcolumnheight\ht\currentcolumnbox
405 \fi
406 \ifdim\dp\currentcolumnbox>\maxcolumndepth
407 \maxcolumndepth\dp\currentcolumnbox
408 \fi}
409
410\setnewconstant\multicolumntopflushmethod\plusone
411\setnewconstant\multicolumntopalignmethod\plustwo
412
413\def\page_mul_flush_preceding_normal
414 {\unvbox\b_page_mul_preceding}
415
416\def\page_mul_flush_preceding_ongrid
417 {\scratchdimen\dimexpr
418 \savedpagetotal
419 \d_page_mul_preceding_height
420 \d_page_mul_preceding_depth
421 \topskip
422 \relax
423 \box\b_page_mul_preceding
424 \kern\scratchdimen}
425
426\def\page_mul_flush_packaged_columns_continued
427 {\bgroup
428 \page_mul_flush_packaged_columns_indeed
429 \box\columnpagebox
430 \egroup}
431
432\def\page_mul_flush_packaged_columns_balanced
433 {\bgroup
434 \page_mul_flush_packaged_columns_indeed
435
436 \setbox\columnpagebox\vbox
437 {\offinterlineskip
438 \scratchdimen\htdp\columnpagebox
439 \box\columnpagebox
440 \vskip\scratchdimen}
441 \ht\columnpagebox\dimexpr
442 \noflines\openlineheight
443 \openstrutdepth
444 \ifgridsnapping
445
446 \else
447 \openlineheight
448 \topskip
449 \fi
450 \relax
451 \dp\columnpagebox\openstrutdepth
452
453 \box\columnpagebox
454 \egroup}
455
456\def\page_mul_synchronize_marks
457 {\dohandleallcolumns{\page_marks_synchronize_column\plusone\nofcolumns\mofcolumns\currentcolumnbox}}
458
459\def\page_mul_flush_packaged_columns_indeed
460 {\ifvoid\b_page_mul_preceding
461 \setfalse\c_page_mul_preceding_present
462 \else
463 \settrue\c_page_mul_preceding_present
464 \page_apply_postprocessors_box\b_page_mul_preceding
465 \fi
466 \forgetall
467 \page_mul_initialize_variables
468 \page_mul_calculate_column_result_dimensions
469 \page_mul_postprocess_linenumbers
470 \page_mul_synchronize_marks
471 \page_mul_postprocess_lines
472 \page_mul_postprocess_columns
473 \dohandleallcolumns
474 {\global\setbox\currentcolumnbox\hpack to \d_page_mul_used_width
475 {\box\currentcolumnbox}
476 \wd\currentcolumnbox\d_page_mul_used_width
477 \ifheightencolumns
478 \ht\currentcolumnbox\d_page_mul_forced_height
479 \fi}
480 \page_mul_calculate_column_result_dimensions
481 \overlaycolumnfootnotes
482 \setbox\columnpagebox\vpack
483 {\ifconditional\c_page_mul_reverse\reversehpack\else\naturalhpack\fi to \makeupwidth
484 {\hskip\ifconditional\c_page_mul_reverse\d_page_mul_rightskip\else\d_page_mul_leftskip\fi\relax
485 \dohandleallcolumns
486 {\finishcolumnbox
487 {\setbox\scratchbox\hpack
488 {\ifx\finishcolumnbox\relax\else\strut\fi
489 \box\currentcolumnbox}
490 \anch_mark_column_box\scratchbox\currentcolumn
491 \box\scratchbox}
492 \hfil}
493 \unskip
494 \hskip\ifconditional\c_page_mul_reverse\d_page_mul_leftskip\else\d_page_mul_rightskip\fi}}
495 \scratchdimen\zeropoint
496 \dohandleallcolumns
497 {\ifdim\ht\currenttopcolumnbox<\scratchdimen
498 \scratchdimen\ht\currenttopcolumnbox
499 \fi
500 \global\setbox\currenttopcolumnbox\emptybox}
501 \advance\scratchdimen \ht\columnpagebox
502 \setbox\scratchbox\hbox to \makeupwidth
503 {\vrule
504 \s!width \zeropoint
505 \s!height\scratchdimen
506 \s!depth \dp\columnpagebox
507 \dostepwiserecurse\plustwo\nofcolumns\plusone{\hfil\page_mul_between_columns}\hfil}
508 \setbox\columnpagebox\hpack
509 {\box\columnpagebox
510 \hskip\makeupwidth
511 \box\scratchbox}
512 \page_mul_postprocess_page
513 \ifconditional\c_page_mul_preceding_present
514 \settrue\c_page_mul_preceding_present
515
516 \ifcase\multicolumntopalignmethod
517 \page_mul_flush_preceding_normal
518 \or
519 \page_mul_flush_preceding_ongrid
520 \else\ifgridsnapping
521 \page_mul_flush_preceding_ongrid
522 \else
523 \page_mul_flush_preceding_normal
524 \fi \fi
525 \fi
526 \global\d_page_mul_preceding_height\zeropoint
527 \page_otr_command_set_vsize
528 \dosomebreak\nobreak
529 \ifgridsnapping \else
530 \ifcase\multicolumntopflushmethod
531
532
533 \or
534
535 \ifconditional\c_page_mul_preceding_present
536
537
538
539
540 \nointerlineskip
541 \vskip\dimexpr\openstrutheight\topskip\relax
542 \fi
543 \or
544
545
546
547
548 \nointerlineskip
549 \vskip\dimexpr\openstrutheight\topskip\relax
550 \or
551
552
553
554
555
556
557
558 \nointerlineskip
559 \vskip\dimexpr\openstrutheight\topskip\lineheight\relax
560 \vbox{\strut}
561 \fi
562 \fi
563 \prevdepth\openstrutdepth
564 \nointerlineskip
565 \dp\columnpagebox\zeropoint
566 \global\finalcolumnheights\ht\columnpagebox
567 \getnoflines\finalcolumnheights
568 \global\finalcolumnlines\noflines}
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616\ifdefined\postprocesscolumnline \else\let\postprocesscolumnline \relax\fi
617\ifdefined\postprocesscolumnbox \else\let\postprocesscolumnbox \relax\fi
618\ifdefined\postprocesscolumnpagebox \else\let\postprocesscolumnpagebox \relax\fi
619
620
621\def\page_mul_postprocess_lines {\ifx\postprocesscolumnline \relax\else\page_mul_postprocess_lines_indeed \fi}
622\def\page_mul_postprocess_columns {\ifx\postprocesscolumnbox \relax\else\page_mul_postprocess_columns_indeed \fi}
623\def\page_mul_postprocess_page {\ifx\postprocesscolumnpagebox \relax\else\page_mul_postprocess_page_indeed \fi}
624
625
626
627
628\def\page_mul_postprocess_linenumbers
629 {\dohandleallcolumns{\page_apply_postprocessors_column\currentcolumnbox}}
630
631\def\page_mul_postprocess_lines_indeed
632 {\dohandleallcolumnscs\page_mul_postprocess_lines_step}
633
634\def\page_mul_postprocess_lines_step
635 {\global\setbox\currentcolumnbox\vtop
636 {\beginofshapebox
637 \unvbox\currentcolumnbox
638 \unskip\unskip
639 \endofshapebox
640 \reshapebox
641 {\scratchheight\ht\shapebox
642 \scratchdepth \dp\shapebox
643 \setbox\shapebox\hbox to \hsize
644 {\postprocesscolumnline\shapebox}
645 \ht\shapebox\scratchheight
646 \dp\shapebox\scratchdepth
647 \box\shapebox}
648 \flushshapebox
649 \reseteverypar
650 \parskip\zeropoint
651 \verticalstrut
652 \vskip\struttotal
653 \vfil}}
654
655\def\page_mul_postprocess_columns_indeed
656 {\dohandleallcolumnscs\page_mul_postprocess_columns_step}
657
658\def\page_mul_postprocess_columns_step
659 {\global\setbox\currentcolumnbox\hbox
660 {\postprocesscolumnbox\currentcolumnbox}}
661
662\def\page_mul_postprocess_page_indeed
663 {\postprocesscolumnpagebox\columnpagebox}
664
665
666
667
668
669
670
671
672
673\newdimen\d_page_mul_split_height_used
674\newdimen\d_page_mul_split_height_max
675
676\def\page_mul_split_column#1#2#3#4
677 {\bgroup
678 \ifdim\ht#4>\zeropoint
679 \d_page_mul_split_height_used#3\relax
680 \d_page_mul_split_height_max\d_page_mul_split_height_used
681 \advance\d_page_mul_split_height_used \ht#4
682 \columnfootnotecorrection{#1}\d_page_mul_split_height_used
683 \setbox\scratchbox\vsplit#2 to \d_page_mul_split_height_used
684 \global\setbox#1\vbox to \d_page_mul_split_height_max
685 {\ifgridsnapping
686 \scratchdimen\dimexpr\topskip\openstrutheight\relax
687 \vskip\scratchdimen
688 \copy#4
689 \vskip\scratchdimen
690 \else
691 \unvcopy#4
692 \fi
693 \unvbox\scratchbox
694 \fakecolumnfootnotes{#1}}
695 \else\ifcase\c_strc_notes_page_location
696 \global\setbox#1\vsplit#2 to #3
697 \global\setbox#1\vbox
698 {\unvbox{#1}}
699 \else
700 \columnfootnotecorrection{#1}{#3}
701 \setbox\scratchbox\vsplit#2 to #3
702 \global\setbox#1\vbox to #3
703 {\unvbox\scratchbox
704 \fakecolumnfootnotes{#1}}
705 \fi \fi
706 \egroup}
707
708\def\page_mul_split_current_column#1#2
709 {\page_mul_split_column\currentcolumnbox{#1}{#2}\currenttopcolumnbox}
710
711\def\page_mul_split_first_column#1#2
712 {\page_mul_split_column\firstcolumnbox{#1}{#2}\firsttopcolumnbox}
713
714\def\page_mul_split_last_column#1#2
715 {\global\setbox\lastcolumnbox\vbox
716 {\unvcopy\lasttopcolumnbox
717 \unvbox{#1}
718 \fakecolumnfootnotes\lastcolumnbox}}
719
720
721
722 \def\fakecolumnfootnotes#1
723 {\relax
724 \ifcase\c_strc_notes_page_location\else
725 \ifnum#1=\lastcolumnbox
726 \fakenotes
727 \fi
728 \fi}
729
730 \def\columnfootnotecorrection#1#2
731 {\relax
732 \ifcase\c_strc_notes_page_location
733
734 \or
735 \ifnum#1=\firstcolumnbox\relax
736 \calculatetotalclevernoteheight
737 \advance#2 \totalnoteheight
738 \fi
739 \else
740 \ifnum#1=\lastcolumnbox\relax
741 \calculatetotalclevernoteheight
742 \advance#2 \totalnoteheight
743 \fi
744 \fi}
745
746 \def\overlaycolumnfootnotes
747 {\relax
748 \ifcase\c_strc_notes_page_location
749
750 \or
751 \checknotepresence \ifnotespresent \page_mul_notes_flush_first_column \fi
752 \or
753 \checknotepresence \ifnotespresent \page_mul_notes_flush_last_column \fi
754 \fi}
755
756 \newbox\b_page_mul_notes
757
758 \def\page_mul_notes_flush_first_column
759 {\begingroup
760 \setbox\b_page_mul_notes\vbox{\placenoteinserts}
761 \ifzeropt\ht\b_page_mul_notes
762
763 \else
764 \page_mul_set_n_of_lines
765 \advance\c_page_mul_n_of_lines \minustwo
766 \scratchdimen\dimexpr\c_page_mul_n_of_lines\lineheight\topskip\relax
767 \setbox\b_page_mul_notes\hpack{\lower\scratchdimen\box\b_page_mul_notes}
768 \ht\b_page_mul_notes\openstrutheight
769 \dp\b_page_mul_notes\openstrutdepth
770 \wd\b_page_mul_notes\zeropoint
771 \scratchdimen\ht\firstcolumnbox
772 \global\setbox\firstcolumnbox\vbox to \scratchdimen
773 {\box\firstcolumnbox
774 \vskip\scratchdimen
775 \box\b_page_mul_notes}
776 \fi
777 \endgroup}
778
779 \def\page_mul_notes_flush_last_column
780 {\begingroup
781 \setbox\b_page_mul_notes\vbox{\placenoteinserts}
782 \ifzeropt\ht\b_page_mul_notes
783
784 \else
785
786 \scratchdimen\dimexpr\ht\firstcolumnbox\openstrutdepth\relax
787 \getnoflines\scratchdimen
788 \advance\noflines \minustwo
789 \scratchdimen\dimexpr\noflines\lineheight\topskip\relax
790 \setbox\b_page_mul_notes\hpack{\lower\scratchdimen\box\b_page_mul_notes}
791 \ht\b_page_mul_notes\openstrutheight
792 \dp\b_page_mul_notes\openstrutdepth
793 \wd\b_page_mul_notes\zeropoint
794 \scratchdimen\ht\lastcolumnbox
795 \global\setbox\lastcolumnbox\vbox to \scratchdimen
796 {\box\lastcolumnbox
797 \vskip\scratchdimen
798 \box\b_page_mul_notes}
799 \fi
800 \endgroup}
801
802
803
804
805
806
807\def\page_mul_routine_continue
808 {\bgroup
809 \forgetall
810 \page_mul_initialize_variables
811
812
813
814
815
816
817
818
819 \page_mul_set_n_of_lines
820 \d_page_mul_balance_target\c_page_mul_n_of_lines\openlineheight
821 \ifconditional\c_page_mul_trace
822 \writestatus\m!columns{continue: lines=\the\c_page_mul_n_of_lines, target=\the\d_page_mul_balance_target, textheight=\the\textheight}
823 \fi
824 \dohandleallcolumns
825 {\page_mul_split_current_column\normalpagebox\d_page_mul_balance_target}
826 \setbox\b_page_mul_preceding_rest_of_page\vbox{\unvbox\normalpagebox}
827 \ifinheritcolumns
828 \ifcase\bottomraggednessmode
829
830 \dohandleallcolumns
831 {\global\setbox\currentcolumnbox\vbox to \ht\firstcolumnbox
832 {\scratchdepth\dp\currentcolumnbox
833 \unvbox\currentcolumnbox
834 \vskip\dimexpr\openstrutdepth\scratchdepth\relax
835 \prevdepth\openstrutdepth
836 \vfill}}
837 \strc_notes_check_if_bottom_present
838
839
840
841 \or
842
843 \advance\d_page_mul_balance_target\maxdepth
844 \dohandleallcolumns
845 {\global\setbox\currentcolumnbox\vbox to \d_page_mul_balance_target
846 {\unvbox\currentcolumnbox}}
847 \or
848
849
850 \fi
851 \else
852 \dohandleallcolumns
853 {\global\setbox\currentcolumnbox\vbox to \d_page_mul_balance_target
854 {\ifstretchcolumns
855 \unvbox\currentcolumnbox
856 \else
857 \unvbox\currentcolumnbox
858 \vfill
859 \fi}}
860 \dohandleallcolumns
861 {\ht\currentcolumnbox\d_page_mul_balance_target}
862 \fi
863 \setbox\b_page_mul_preceding\vbox{\page_mul_flush_packaged_columns_continued}
864 \page_otr_construct_and_shipout\box\b_page_mul_preceding\zerocount
865 \page_otr_command_set_hsize
866 \page_otr_command_set_vsize
867 \page_mul_flush_floats
868 \unvbox\b_page_mul_preceding_rest_of_page
869
870 \egroup}
871
872
873
874
875
876
877
878\newbox \b_page_mul_balance_content
879\newbox \b_page_mul_balance_first_column
880\newbox \b_page_mul_balance_column
881\newconstant \c_page_mul_balance_tries_max
882\newcount \c_page_mul_balance_tries
883\newdimen \d_page_mul_balance_target
884\newdimen \d_page_mul_balance_target_less
885\newdimen \d_page_mul_balance_natural_height
886\newdimen \d_page_mul_balance_regular_height
887\newdimen \d_page_mul_balance_step
888\newdimen \d_page_mul_balance_fuzzyness
889\newdimen \d_page_mul_balance_threshold
890\newconditional\c_page_mul_balance_possible
891
892\c_page_mul_balance_tries_max 250
893
894\def\page_mul_routine_balance
895 {\bgroup
896
897 \page_mul_initialize_variables
898 \widowpenalty\zerocount
899 \setbox\b_page_mul_balance_content\vbox{\unvbox\normalpagebox}
900 \ifdim\ht\b_page_mul_balance_content>\openlineheight
901 \ifnum\c_page_mul_balance_minimum<\plustwo
902 \settrue\c_page_mul_balance_possible
903 \else
904 \getnoflines{\ht\b_page_mul_balance_content}
905 \divide\noflines \nofcolumns \relax
906 \ifnum\noflines<\c_page_mul_balance_minimum \relax
907 \ifdim\dimexpr\ht\b_page_mul_balance_content\ht\firsttopcolumnbox\openlineheight\relax>\makeupheight
908 \settrue\c_page_mul_balance_possible
909 \else
910 \setfalse\c_page_mul_balance_possible
911 \fi
912 \else
913 \settrue\c_page_mul_balance_possible
914 \fi
915 \fi
916 \else
917 \setfalse\c_page_mul_balance_possible
918 \fi
919 \ifconditional\c_page_mul_balance_possible
920 \page_mul_balance_try_one
921 \ifinheritcolumns
922 \page_mul_balance_try_two
923 \else
924 \page_mul_balance_try_three
925 \fi
926 \else
927
928 \showmessage\m!columns{10}\empty
929 \global\setbox\firstcolumnbox\vbox{\unvbox\b_page_mul_balance_content}
930 \fi
931 \c_page_mul_routine\c_page_mul_routine_error
932 \baselinebottom
933 \page_mul_flush_packaged_columns_balanced
934 \page_mul_eject_page
935 \egroup}
936
937\def\page_mul_eject_page
938 {
939
940
941 \allowbreak
942 }
943
944\def\page_mul_balance_try_one
945 {\d_page_mul_balance_target\dimexpr\ht\b_page_mul_balance_content\topskip\baselineskip\relax
946 \dohandleallcolumns
947 {\advance\d_page_mul_balance_target \ht\currenttopcolumnbox}
948 \divide\d_page_mul_balance_target \nofcolumns
949 \vbadness\plustenthousand
950 \c_page_mul_balance_tries\zerocount
951 \bgroup
952 \ifgridsnapping
953 \d_page_mul_balance_step\lineheight
954 \else
955 \d_page_mul_balance_step\spacingfactor\onepoint
956 \fi
957 \doloop\page_mul_balance_try_one_attempt
958 \page_mul_balance_try_one_attempt_final
959 \ifnum\c_page_mul_balance_tries>\c_page_mul_balance_tries_max\relax
960 \showmessage\m!columns7\empty
961 \else
962 \showmessage\m!columns8{\the\c_page_mul_balance_tries}
963 \fi
964 \egroup}
965
966\def\page_mul_balance_try_one_attempt
967 {\advance\c_page_mul_balance_tries \plusone
968 \global\setbox\b_page_mul_preceding_rest_of_page\copy\b_page_mul_balance_content\relax
969 \page_mul_split_first_column\b_page_mul_preceding_rest_of_page\d_page_mul_balance_target
970 \dohandlemidcolumns
971 {\page_mul_split_current_column\b_page_mul_preceding_rest_of_page\d_page_mul_balance_target}
972 \page_mul_split_last_column\b_page_mul_preceding_rest_of_page\d_page_mul_balance_target
973 \setbox\b_page_mul_balance_first_column\vbox{\unvcopy\firstcolumnbox}
974 \d_page_mul_balance_natural_height\zeropoint
975 \dohandleallcolumns\page_mul_balance_try_one_attempt_step
976 \advance\d_page_mul_balance_natural_height .0005pt
977 \ifnum\c_page_mul_balance_tries>\c_page_mul_balance_tries_max\relax
978 \exitloop
979 \else\ifdim\d_page_mul_balance_natural_height>\ht\b_page_mul_balance_first_column
980 \advance\d_page_mul_balance_target \d_page_mul_balance_step\relax
981 \else
982 \exitloop
983 \fi\fi}
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011\def\page_mul_balance_try_one_attempt_final
1012 {\global\setbox\b_page_mul_preceding_rest_of_page\box\b_page_mul_balance_content
1013 \page_mul_split_first_column\b_page_mul_preceding_rest_of_page\d_page_mul_balance_target
1014 \dohandlemidcolumns
1015 {\page_mul_split_current_column\b_page_mul_preceding_rest_of_page\d_page_mul_balance_target}
1016 \page_mul_split_last_column\b_page_mul_preceding_rest_of_page\d_page_mul_balance_target
1017 \dohandleallcolumns
1018 {\global\setbox\currentcolumnbox\vbox{\unvbox\currentcolumnbox}}}
1019
1020\def\page_mul_balance_try_one_attempt_step
1021 {\setbox\b_page_mul_balance_column\vbox
1022 {\unvbox\currentcolumnbox
1023 \unpenalty
1024 \unskip
1025 \unpenalty
1026 \unskip}
1027 \ifdim\ht\b_page_mul_balance_column>\d_page_mul_balance_natural_height
1028 \d_page_mul_balance_natural_height\ht\b_page_mul_balance_column
1029 \fi}
1030
1031
1032
1033
1034
1035\def\page_mul_balance_try_two
1036 {\d_page_mul_balance_target\zeropoint
1037 \dohandleallcolumns
1038 {\ifdim\ht\currentcolumnbox>\d_page_mul_balance_target
1039 \d_page_mul_balance_target\ht\currentcolumnbox
1040 \fi}
1041 \d_page_mul_balance_target_less\dimexpr\d_page_mul_balance_target\openlineheight\relax
1042 \dohandleallcolumnscs\page_mul_balance_try_two_step}
1043
1044\def\page_mul_balance_try_two_step
1045 {\d_page_mul_balance_regular_height\ht\currentcolumnbox
1046 \d_page_mul_balance_threshold\plusten\openlineheight
1047 \global\setbox\currentcolumnbox\vbox to \d_page_mul_balance_target
1048 {\unvbox\currentcolumnbox
1049 \ifdim\d_page_mul_balance_regular_height>\d_page_mul_balance_threshold
1050 \ifdim\d_page_mul_balance_regular_height<\d_page_mul_balance_target
1051 \ifdim\d_page_mul_balance_regular_height>\d_page_mul_balance_target_less
1052 \vskip\zeropoint
1053 \else
1054 \vskip\openlineheight
1055 \vfill
1056 \fi
1057 \else
1058 \vskip\zeropoint
1059 \fi
1060 \else
1061 \vskip\openlineheight
1062 \vfill
1063 \fi}}
1064
1065\def\page_mul_balance_try_three
1066 {\bgroup
1067 \ifstretchcolumns
1068 \d_page_mul_balance_target\ht\firstcolumnbox
1069 \d_page_mul_balance_fuzzyness\bottomtolerance\ht\firstcolumnbox
1070 \setbox\b_page_mul_balance_content\vbox{\unvcopy\lastcolumnbox}
1071 \advance\d_page_mul_balance_target\htdp\b_page_mul_balance_content\relax
1072 \ifdim\d_page_mul_balance_target>\openlineheight\relax
1073 \ifdim\d_page_mul_balance_target>\d_page_mul_balance_fuzzyness\relax
1074
1075 \showmessage\m!columns9\empty
1076 \fi
1077 \fi
1078 \fi
1079 \dohandleallcolumnscs\page_mul_balance_try_three_step
1080 \egroup}
1081
1082\def\page_mul_balance_try_three_step
1083 {\global\setbox\currentcolumnbox\vbox to \ht\firstcolumnbox
1084 {\ifstretchcolumns
1085 \unvbox\currentcolumnbox
1086 \else
1087 \box\currentcolumnbox
1088 \vfill
1089 \fi}}
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155 \def\page_mul_initialize_floats
1156 {\setlocalcolumnfloats}
1157
1158 \newconditional\onlylocalcolumnfloats
1159 \newtoks \everylocalcolumnfloatspar
1160
1161 \unexpanded\def\page_mul_command_flush_floats
1162 {\ifconditional\onlylocalcolumnfloats
1163 \doflushcolumnfloats
1164 \else
1165 \page_one_command_flush_floats
1166 \fi}
1167
1168 \unexpanded\def\page_mul_command_check_if_float_fits
1169 {\ifconditional\onlylocalcolumnfloats
1170 \docolumnroomfloat
1171 \fi}
1172
1173 \unexpanded\def\page_mul_command_flush_saved_floats
1174 {\ifconditional\onlylocalcolumnfloats\relax
1175 \else
1176 \page_one_command_flush_saved_floats
1177 \fi}
1178
1179 \unexpanded\def\page_mul_command_flush_top_insertions
1180 {\ifconditional\onlylocalcolumnfloats\relax
1181 \else
1182 \page_one_command_flush_top_insertions
1183 \fi}
1184
1185 \appendtoks
1186 \flushnotes
1187 \page_mul_flush_float
1188
1189 \checkindentation
1190 \to \everylocalcolumnfloatspar
1191
1192 \def\setlocalcolumnfloats
1193 {\settrue\onlylocalcolumnfloats
1194 \everypar\everylocalcolumnfloatspar
1195 \let\page_mul_flush_float \doflushcolumnfloat
1196 \let\page_mul_flush_floats\doflushcolumnfloats}
1197
1198 \def\setglobalcolumnfloats
1199 {\setfalse\onlylocalcolumnfloats
1200 \reseteverypar
1201 \let\page_mul_flush_float \relax
1202 \let\page_mul_flush_floats\noflushcolumnfloats}
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216 \def\noflushcolumnfloats{\doflushcolumnfloats}
1217
1218
1219
1220
1221
1222
1223
1224
1225 \def\getcolumnstatus#1#2#3
1226 {\dimen0=\ifdim\pagegoal<\maxdimen \pagetotal \else \zeropoint \fi
1227 \dimen2=\zeropoint
1228 \count255=\zerocount
1229 \dimen8=\makeupheight
1230 \advance\dimen8 \d_page_mul_preceding_height
1231 \def\dogetcolumnstatus
1232 {\advance\count255 \plusone
1233 \advance\dimen2 \ht\currenttopcolumnbox
1234 \advance\dimen2 \dp\currenttopcolumnbox
1235 \dimen4\dimen2
1236 \advance\dimen4 \dimen0
1237 \dimen6=\count255\dimen8
1238 \ifdim\dimen4>\dimen6
1239 \else
1240 \let\dogetcolumnstatus\relax
1241 \fi}
1242 \dohandleallcolumns{\dogetcolumnstatus}
1243 \ifnum\count255=0 \count255=1 \fi
1244 #1=\count255
1245 #2=\dimen4
1246 #3=\dimen6 }
1247
1248 \def\getinsertionheight
1249 {\ifdim\pagegoal<\maxdimen
1250 \bgroup
1251 \dimen0=\makeupheight
1252 \advance\dimen0 \pagegoal
1253 \xdef\insertionheight{\the\dimen0}
1254 \egroup
1255 \else
1256 \glet\insertionheight\zeropoint
1257 \fi}
1258
1259 \def\docolumnroomfloat
1260 {\ifpostponecolumnfloats
1261 \global\setfalse\c_page_floats_room
1262 \else\ifconditional\c_page_floats_not_permitted
1263 \global\setfalse\c_page_floats_room
1264 \else
1265 \bgroup
1266 \getcolumnstatus{\count255}{\dimen0}{\dimen2}
1267 \page_floats_get_info\s!text
1268 \setbox\scratchbox\vbox
1269 {\blank[\rootfloatparameter\c!spacebefore]
1270 \snaptogrid\vbox{\vskip\floatheight}}
1271 \advance\dimen0\dimexpr\ht\scratchbox2\openlineheight.5\lineheight\relax\relax
1272 \ifdim\dimen0>\dimen2
1273 \global\setfalse\c_page_floats_room
1274 \else
1275 \global\settrue\c_page_floats_room
1276 \fi
1277 \ifdim\floatwidth>\hsize
1278 \showmessage\m!columns{11}\empty
1279 \global\setfalse\c_page_floats_room
1280 \fi
1281 \egroup
1282 \fi\fi}
1283
1284
1285
1286
1287 \newif\ifflushingcolumnfloats \flushingcolumnfloatstrue
1288
1289 \def\doflushcolumnfloat
1290 {\ifpostponecolumnfloats\else\ifflushingcolumnfloats\ifconditional\c_page_floats_some_waiting
1291 \doflushcolumnfloatindeed
1292 \fi\fi\fi}
1293
1294 \def\doflushcolumnfloatindeed
1295 {\bgroup
1296 \forgetall
1297 \let\doflushcolumnfloat\relax
1298 \getcolumnstatus{\mofcolumns}{\dimen0}{\dimen2}
1299 \ifdim\dimen0>\zeropoint
1300 \page_floats_get_info\s!text
1301 \ifdim\floatwidth>\hsize
1302
1303 \else
1304 \setbox2\vbox
1305 {\blank[\rootfloatparameter\c!spacebefore]
1306 \snaptogrid\vbox{\vskip\floatheight}}
1307 \advance\dimen0 \ht2
1308 \ifdim\dimen0>\dimen2
1309 \ifnum\mofcolumns<\nofcolumns
1310 \advance\mofcolumns \plusone
1311 \ifdim\ht\currenttopcolumnbox=\zeropoint
1312 \page_floats_flush\s!text\plusone
1313 \global\setbox\currenttopcolumnbox\vbox
1314 {\snaptogrid\vbox{\box\floatbox}
1315 \whitespace
1316 \blank[\rootfloatparameter\c!spaceafter]}
1317 \dimen4=\htdp\currenttopcolumnbox
1318 \global\advance\vsize \dimen4
1319 \advance\dimen4 \pagegoal
1320 \pagegoal\dimen4
1321 \showmessage\m!columns{12}a
1322 \else
1323 \showmessage\m!columns{12}b
1324 \fi
1325 \else
1326 \showmessage\m!columns{12}c
1327 \fi
1328 \else
1329 \ifhmode{\setbox0\lastbox}\fi
1330 \par
1331 \ifdim\prevdepth<\zeropoint \else
1332 \nobreak
1333 \blank[\rootfloatparameter\c!spacebefore]
1334 \nobreak
1335 \fi
1336 \page_floats_flush\s!text\plusone
1337 \page_otr_command_flush_float_box
1338 \blank[\rootfloatparameter\c!spaceafter]
1339 \fi
1340 \fi
1341 \fi
1342 \egroup}
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357 \def\doflushcolumnfloats
1358 {\ifpostponecolumnfloats\else
1359 \bgroup
1360 \forgetall
1361 \ifconditional\c_page_floats_some_waiting
1362 \dimen8\zeropoint
1363 \dimen4\zeropoint
1364 \count0\zerocount
1365 \count2\nofcolumns
1366 \dohandleallcolumns
1367 {\ifnum\count0>\zerocount
1368 \global\setbox\currenttopcolumnbox\vbox
1369 {\snaptogrid\vbox
1370 {\copy\currenttopcolumnbox
1371 \hpack{\vphantom{\vskip\floatheight}}}
1372 \whitespace
1373 \blank[\rootfloatparameter\c!spaceafter]}
1374 \else
1375 \page_floats_get_info\s!text
1376 \ifdim\floatwidth>\hsize
1377 \dimen0\dimexpr\floatwidth\d_page_mul_distance.5pt\relax
1378 \dimen2\dimexpr\hsize \d_page_mul_distance.5pt\relax
1379 \divide\dimen0 \dimen2
1380 \count0\dimen0
1381 \advance\count0 \plusone
1382 \ifnum\count0>\count2
1383 \count0\zerocount
1384 \else
1385 \dimen0\dimexpr\count0\hsize\count0\d_page_mul_distance\d_page_mul_distance\relax
1386 \page_floats_flush\s!text\plusone
1387 \ifdim\floatwidth>\makeupwidth
1388 \global\setbox\floatbox\hbox to \makeupwidth{\hss\box\floatbox\hss}
1389 \fi
1390 \global\setbox\floatbox\hbox to \dimen0
1391 {\processaction[\rootfloatparameter\c!location]
1392 [ \v!left=>\box\floatbox\hss,
1393 \v!right=>\hss\box\floatbox,
1394 \s!default=>\hss\box\floatbox\hss,
1395 \s!unknown=>\hss\box\floatbox\hss]}
1396 \fi
1397 \showmessage\m!columns{13}\empty
1398 \else
1399 \page_floats_flush\s!text\plusone
1400 \ifdim\floatwidth>\makeupwidth
1401 \global\setbox\floatbox\hbox to \makeupwidth{\hss\box\floatbox\hss}
1402 \fi
1403
1404 \fi
1405 \ifdim\ht\floatbox>\zeropoint\relax
1406 \global\setbox\currenttopcolumnbox\vbox
1407 {\snaptogrid\vbox
1408 {\box\currenttopcolumnbox
1409 \box\floatbox}
1410 \whitespace
1411 \blank[\rootfloatparameter\c!spaceafter]}
1412 \fi
1413 \dimen6\htdp\currenttopcolumnbox
1414 \fi
1415 \ifdim\dimen4<\ht\currenttopcolumnbox
1416 \dimen4\ht\currenttopcolumnbox
1417 \fi
1418 \advance\dimen8 \dimen6
1419 \advance\count2 \minusone
1420 \advance\count0 \minusone }
1421 \page_otr_command_set_vsize
1422 \global\advance\vsize \dimen8
1423 \pagegoal\vsize
1424 \else
1425
1426 \fi
1427 \egroup
1428 \fi}
1429
1430
1431
1432
1433 \def\insertcolumnfloats
1434 {\doloop
1435 {\ifconditional\c_page_floats_some_waiting
1436 \bgroup
1437 \forgetall
1438
1439 \page_floats_get
1440 \blank[\rootfloatparameter\c!spacebefore]
1441 \snaptogrid\vbox{\copy\floatbox}
1442 \blank[\rootfloatparameter\c!spaceafter]
1443 \egroup
1444 \else
1445 \exitloop
1446 \fi}}
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466\def\backgroundfinishcolumnbox
1467 {\inheritedcolumnsframed}
1468
1469
1470
1471
1472
1473
1474
1475\unexpanded\def\page_columns_align_option_yes {\stretchcolumnstrue \inheritcolumnsfalse}
1476\unexpanded\def\page_columns_align_option_no {\stretchcolumnsfalse\inheritcolumnsfalse}
1477\unexpanded\def\page_columns_align_option_text{\stretchcolumnsfalse\inheritcolumnstrue }
1478
1479\newtoks\t_page_mul_initialize
1480
1481\unexpanded\def\startcolumns
1482 {\dosingleempty\page_mul_start}
1483
1484\def\page_mul_start[#1]
1485 {\bgroup
1486 \ifinsidecolumns
1487 \page_mul_start_nop
1488 \else
1489 \iffirstargument
1490 \setupcolumns[#1]
1491 \fi
1492 \nofcolumns\columnsparameter\c!n\relax
1493 \ifnum\nofcolumns>\plusone
1494 \page_mul_start_yes
1495 \else
1496 \page_mul_start_nop
1497 \fi
1498 \fi}
1499
1500\unexpanded\def\page_mul_start_nop
1501 {\let\stopcolumns\page_mul_stop_nop}
1502
1503\unexpanded\def\page_mul_stop_nop
1504 {\egroup}
1505
1506\unexpanded\def\page_mul_start_yes
1507 {\whitespace
1508 \begingroup
1509 \let\stopcolumns\page_mul_stop_indeed
1510 \global\insidecolumnstrue
1511 \the\t_page_mul_initialize
1512
1513 \flushnotes
1514 \begingroup
1515
1516 \d_page_mul_leftskip\leftskip
1517 \d_page_mul_rightskip\rightskip
1518 \leftskip\zeropoint
1519 \rightskip\zeropoint
1520
1521 \widowpenalty\zerocount
1522 \clubpenalty \zerocount
1523
1524 \page_floats_column_push_saved
1525
1526 \ifdim\dimexpr\pagetotal\parskip\openlineheight\relax<\pagegoal
1527 \allowbreak
1528 \else
1529 \break
1530 \fi
1531 \appendtoks
1532 \topskip1\topskip
1533 \to \everybodyfont
1534 \the\everybodyfont
1535 \saveinterlinespace
1536
1537 \initializecolumns\nofcolumns
1538
1539 \hangafter\zerocount
1540 \hangindent\zeropoint
1541 \reseteverypar
1542 \ifdim\pagetotal=\zeropoint \else
1543 \verticalstrut
1544 \vskip\struttotal
1545 \fi
1546 \global\savedpagetotal\pagetotal
1547 \setupoutputroutine[\s!multicolumn]
1548 \c_page_mul_routine\c_page_mul_routine_intercept
1549 \page_otr_trigger_output_routine
1550 \global\d_page_mul_preceding_height\ht\b_page_mul_preceding
1551 \c_page_mul_routine\c_page_mul_routine_continue
1552 \page_mul_initialize_floats
1553 \dohandleallcolumns{\global\setbox\currenttopcolumnbox\emptybox}
1554 \checkbegincolumnfootnotes
1555 \page_otr_command_set_hsize
1556 \page_otr_command_set_vsize}
1557
1558\setnewconstant\multicolumnendsyncmethod\plusone
1559
1560\unexpanded\def\page_mul_stop_indeed
1561 {\relax
1562 \ifnum\multicolumnendsyncmethod=\plustwo
1563 \synchronizeoutput
1564 \else
1565
1566 \vskip \lineheight
1567 \vskip\lineheight
1568 \fi
1569 \doflushcolumnfloat
1570
1571 \flushnotes
1572 \par
1573 \ifbalancecolumns
1574 \ifnum\multicolumnendsyncmethod=\plusone
1575 \c_page_mul_routine\c_page_mul_routine_continue
1576 \goodbreak
1577 \fi
1578 \c_page_mul_routine\c_page_mul_routine_balance
1579 \else
1580 \goodbreak
1581 \fi
1582
1583 \page_otr_trigger_output_routine
1584 \prevdepth\zeropoint
1585
1586 \c_page_mul_routine\c_page_mul_routine_regular
1587
1588 \ifvoid\b_page_mul_preceding\else
1589 \unvbox\b_page_mul_preceding
1590 \fi
1591 \global\d_page_mul_preceding_height\zeropoint
1592 \endgroup
1593 \nofcolumns\plusone
1594 \page_otr_command_set_vsize
1595 \checkendcolumnfootnotes
1596 \dosomebreak\allowbreak
1597 \page_floats_column_pop_saved
1598
1599 \global\insidecolumnsfalse
1600 \endgroup
1601 \egroup}
1602
1603\appendtoks
1604 \edef\p_option{\columnsparameter\c!option}
1605 \ifx\p_option\v!background
1606 \let\finishcolumnbox\backgroundfinishcolumnbox
1607 \doifelseinset{\columnsparameter\c!offset}{\v!none,\v!overlay}
1608 {\d_page_mul_offset\zeropoint}
1609 {\d_page_mul_offset\dimexpr\columnsparameter\c!offset\columnsparameter\c!rulethickness\relax}
1610 \else
1611 \d_page_mul_offset\zeropoint
1612 \fi
1613 \edef\p_command{\columnsparameter\c!command}
1614 \ifx\p_command\empty \else
1615 \let\postprocesscolumnline\p_command
1616 \fi
1617 \edef\p_height{\columnsparameter\c!height}
1618 \ifx\p_height\empty
1619 \d_page_mul_forced_height\textheight
1620 \heightencolumnsfalse
1621 \else
1622 \d_page_mul_forced_height\p_height\relax
1623 \heightencolumnstrue
1624 \fi
1625 \edef\p_direction{\columnsparameter\c!direction}
1626 \ifx\p_direction\v!right
1627 \setfalse\c_page_mul_reverse
1628 \else
1629 \settrue\c_page_mul_reverse
1630 \fi
1631 \edef\p_balance{\columnsparameter\c!balance}
1632 \ifx\p_balance\v!yes
1633 \balancecolumnstrue
1634 \else
1635 \balancecolumnsfalse
1636 \fi
1637
1638
1639
1640
1641
1642 \stretchcolumnsfalse
1643 \inheritcolumnstrue
1644 \edef\p_align{\columnsparameter\c!align}
1645 \ifx\p_align\empty \else
1646 \setupalign[\p_align]
1647 \fi
1648 \edef\p_tolerance{\columnsparameter\c!tolerance}
1649 \ifx\p_tolerance\empty \else
1650 \setuptolerance[\p_tolerance]
1651 \fi
1652 \edef\p_blank{\columnsparameter\c!blank}
1653 \ifx\p_blank\empty \else
1654 \setupblank[\p_blank]
1655 \fi
1656 \ifdim\s_spac_whitespace_parskip>\zeropoint\relax
1657 \setupwhitespace[\p_blank]
1658 \fi
1659 \c_page_mul_balance_minimum\columnsparameter\c!ntop\relax
1660 \edef\p_page_mul_rule{\columnsparameter\c!rule}
1661 \expandnamespacemacro\??columnseparators\p_page_mul_rule\s!unknown
1662\to \t_page_mul_initialize
1663
1664
1665
1666\installcolumnbreakmethod \s!multicolumn \v!preference
1667 {\goodbreak}
1668
1669
1670
1671
1672
1673
1674\installcolumnbreakmethod \s!multicolumn \v!yes
1675 {\vskip .5\pagegoal
1676 \penalty200
1677 \vskip.5\pagegoal}
1678
1679
1680
1681\setupcolumns
1682 [\c!n=2,
1683 \c!ntop=1,
1684 \c!command=,
1685 \c!direction=\v!right,
1686 \c!rule=\v!off,
1687 \c!tolerance=\v!tolerant,
1688 \c!distance=1.5\bodyfontsize,
1689 \c!height=,
1690 \c!balance=\v!yes,
1691 \c!align=\v!text,
1692 \c!blank={\v!line,\v!fixed},
1693 \c!option=,
1694 \c!rulethickness=\linewidth,
1695 \c!offset=.5\bodyfontsize]
1696
1697
1698
1699
1700 \unexpanded\def\setupcolumnspan[#1]
1701 {\getparameters[\??ks][#1]}
1702
1703 \presetlocalframed
1704 [\??ks]
1705
1706 \setupcolumnspan
1707 [\c!n=2,
1708 \c!offset=\v!overlay,
1709 \c!frame=\v!off]
1710
1711 \newbox\b_page_columns_span \let\page_mul_postprocess_spanbox\gobbleoneargument
1712
1713 \unexpanded\def\startcolumnspan
1714 {\dosingleempty\dostartcolumnspan}
1715
1716 \unexpanded\def\stopcolumnspan
1717 {\egroup}
1718
1719 \def\dostartcolumnspan[#1]
1720 {\bgroup
1721 \setupcolumnspan[#1]
1722 \forgetall
1723 \ifinsidecolumns
1724 \advance\hsize \d_page_mul_distance
1725 \hsize\@@ksn\hsize
1726 \advance\hsize \d_page_mul_distance
1727 \fi
1728 \dowithnextboxcs\dofinishcolumnsetspan\vbox\bgroup
1729
1730 \EveryPar{\begstrut\EveryPar{}}}
1731
1732 \def\dofinishcolumnsetspan
1733 {\setbox\b_page_columns_span\flushnextbox
1734 \ifinsidecolumns\wd\b_page_columns_span\hsize\fi
1735 \page_mul_postprocess_spanbox\b_page_columns_span
1736 \scratchdimen\ht\b_page_columns_span
1737 \setbox\b_page_columns_span\hbox
1738 {\localframed[\??ks][\c!offset=\v!overlay]{\box\b_page_columns_span}}
1739 \ht\b_page_columns_span\scratchdimen
1740 \dp\b_page_columns_span\strutdp
1741 \wd\b_page_columns_span\hsize
1742 \ifinsidecolumns
1743 \ifnum\@@ksn>1
1744 \page_otr_command_set_vsize
1745 \dohandleallcolumns
1746 {\ifnum\currentcolumn>\@@ksn\else
1747 \global\setbox\currenttopcolumnbox=\vbox
1748 {\ifnum\currentcolumn=1
1749 \snaptogrid\vbox{\copy\b_page_columns_span}
1750 \else
1751 \snaptogrid\vbox{\vphantom{\copy\b_page_columns_span}}
1752 \fi}
1753 \wd\currenttopcolumnbox\hsize
1754 \global\advance\vsize \ht\currenttopcolumnbox
1755 \fi}
1756 \pagegoal\vsize
1757 \else
1758 \snaptogrid\vbox{\box\b_page_columns_span}
1759 \fi
1760 \else
1761 \snaptogrid\vbox{\box\b_page_columns_span}
1762 \fi
1763 \endgraf
1764 \ifvmode\prevdepth\strutdp\fi
1765 \egroup}
1766
1767
1768
1769\unexpanded\def\startsimplecolumns
1770 {\dosingleempty\page_mul_simple_start}
1771
1772\def\page_mul_simple_start[#1]
1773 {\bgroup
1774 \setsimplecolumnshsize[#1]
1775 \nopenalties
1776 \setbox\scratchbox\vbox\bgroup
1777 \forgetall}
1778
1779\unexpanded\def\stopsimplecolumns
1780 {\removebottomthings
1781 \egroup
1782 \rigidcolumnbalance\scratchbox
1783 \egroup}
1784
1785\unexpanded\def\setsimplecolumnshsize[#1]
1786 {\getdummyparameters
1787 [\c!width=\hsize,
1788 \c!distance=1.5\bodyfontsize,
1789 \c!n=2,
1790 \c!lines=0,
1791 #1]
1792 \edef\rigidcolumnlines
1793 {\directdummyparameter\c!lines}
1794 \setrigidcolumnhsize
1795 {\directdummyparameter\c!width}
1796 {\directdummyparameter\c!distance}
1797 {\directdummyparameter\c!n}}
1798
1799
1800
1801\unexpanded\def\page_mul_command_test_column
1802 {\dodoubleempty\page_mul_command_test_column_indeed}
1803
1804\unexpanded\def\page_mul_command_test_column_indeed[#1][#2]
1805 {\page_otr_command_flush_top_insertions\endgraf
1806 \ifdim\pagegoal<\maxdimen
1807 \ifdim\pagetotal<\pagegoal
1808 \d_page_tests_test\dimexpr
1809 \pagegoal
1810 \pagetotal
1811 \ifdim\lastskip<\parskip\parskip\fi
1812 \ifsecondargument#2\fi
1813 \relax
1814 \getrawnoflines\d_page_tests_test
1815 \ifnum#1>\noflines
1816 \column
1817 \fi
1818 \else
1819 \penalty\plustenthousand
1820 \fi
1821 \fi}
1822
1823
1824
1825\let\page_mul_command_package_contents\page_one_command_package_contents
1826\let\page_mul_command_flush_float_box \page_one_command_flush_float_box
1827\let\page_mul_command_flush_all_floats\page_one_command_flush_all_floats
1828
1829\defineoutputroutine
1830 [\s!multicolumn]
1831 [\s!page_otr_command_routine =\page_mul_command_routine,
1832 \s!page_otr_command_package_contents =\page_mul_command_package_contents,
1833 \s!page_otr_command_set_vsize =\page_mul_command_set_vsize,
1834 \s!page_otr_command_set_hsize =\page_mul_command_set_hsize,
1835
1836 \s!page_otr_command_next_page =\page_mul_command_next_page,
1837 \s!page_otr_command_next_page_and_inserts =\page_mul_command_next_page_and_inserts,
1838
1839
1840 \s!page_otr_command_flush_top_insertions =\page_mul_command_flush_top_insertions,
1841
1842 \s!page_otr_command_check_if_float_fits =\page_mul_command_check_if_float_fits,
1843
1844 \s!page_otr_command_flush_float_box =\page_mul_command_flush_float_box,
1845 \s!page_otr_command_side_float_output =\page_mul_command_side_float_output,
1846 \s!page_otr_command_synchronize_side_floats=\page_mul_command_synchronize_side_floats,
1847 \s!page_otr_command_flush_floats =\page_mul_command_flush_floats,
1848 \s!page_otr_command_flush_side_floats =\page_mul_command_flush_side_floats,
1849 \s!page_otr_command_flush_saved_floats =\page_mul_command_flush_saved_floats,
1850 \s!page_otr_command_flush_all_floats =\page_mul_command_flush_all_floats,
1851
1852 \s!page_otr_command_test_column =\page_mul_command_test_column
1853 ]
1854
1855\installfloatmethod \s!multicolumn \v!here \page_mul_place_float_here
1856\installfloatmethod \s!multicolumn \v!force \page_mul_place_float_force
1857\installfloatmethod \s!multicolumn \v!top \page_mul_place_float_top
1858\installfloatmethod \s!multicolumn \v!bottom \page_mul_place_float_bottom
1859
1860\appendtoks
1861 \flushingcolumnfloatsfalse
1862\to \everybeforesectionheadhandle
1863
1864\appendtoks
1865 \flushingcolumnfloatstrue
1866\to \everyaftersectionheadhandle
1867
1868\protect \endinput
1869 |