summaryrefslogtreecommitdiff
path: root/tex/context/base/core-mul.tex
blob: ec5578012f2274f6fe6e19a3321f96ebf95766f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
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
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
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
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
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
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
%D \module
%D   [       file=core-mul,
%D        version=1998.03.15,
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=Multi Column Output,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{Context Core Macros / Multi Column Output}

\unprotect

% check \count<insert> multiplications  

% some day try this in balancing routine 
%
% \ifdim\pagetotal>\pagegoal
%   \eject
% \else
%   \goodbreak
% \fi
 
%D The following macro's implement a multi||column output
%D routine. The original implementation was based on Donald
%D Knuth's implementation, which was adapted by Craig Platt to
%D support balancing of the last page. I gradually adapted
%D Platt's version to our needs but under certain
%D circumstances things still went wrong. I considered all
%D calls to Platt's \type{\balancingerror} as undesirable.

\startmessages  dutch  library: columns
  title: kolommen
      1: maximaal -- kolommen
      2: gebruik eventueel \string\filbreak
      3: probleempje, probeer [balanceren=nee]
      4: plaatsblok boven nog niet mogelijk
      5: plaatsblok onder nog niet mogelijk
      6: -- plaatsblok(en) opgeschort
      7: balanceren afgebroken na 100 stappen
      8: gebalanceerd in -- stap(pen)
      9: uitlijnen controleren!
     10: (minder dan) 1 regel over
     11: plaatsblok te breed voor kolom
     12: plaatsblok verplaatst naar volgende kolom / --
     13: breed figuur geplaatst boven kolommen
\stopmessages

\startmessages  english  library: columns
  title: columns
      1: only -- columns possible
      2: use \string\filbreak\space as alternative
      3: problems, disable balancing
      4: top float not yet supported
      5: bottom float not yet supported
      6: -- float(s) postponed
      7: balancing aborted after 100 steps
      8: balanced in -- step(s)
      9: check raggedness
     10: (less than) 1 line left
     11: float to wide for column
     12: float moved to next column / --
     13: wide float moved to top of columns
\stopmessages

\startmessages  german  library: columns
  title: Spalten
      1: nur -- Spalten moeglich
      2: benutzte \string\filbreak\space als Alternative
      3: Problem, verwende [ausgleich=nein]
      4: Gleitobjekt oben ncoh nicht unterstuetzt
      5: Gleitobjekt unten ncoh nicht unterstuetzt
      6: -- Gleitobjekt(e) verschoben
      7: ausgleich nach 100 Schritten abgebrocheb
      8: ausgeglichen nach  -- Schritt(en)
      9: Ausrichtung ueberpruefen
     10: (weniger als) 1 Zeile uebrig
     11: Gleitobjekt zu breit fuer Spalte
     12: Gleitobjekt in naechste Zeile verschoben / --
     13: breites Gleitobjekt an den Anfang der Spalten verschoben
\stopmessages

\startmessages  czech  library: columns
  title: sloupce
      1: je mozno pouze -- sloupcu
      2: pouzijte \string\filbreak\space jako alternativu
      3: problem, vypina se vyvazovani
      4: horni plovouci objekt jeste neni podporovan
      5: spodni plovouci objekt jeste neni podporovan
      6: -- plovouci objekt(y) odlozeny
      7: vyvazovani ukonceno po 100 krocich
      8: vyvazeno v -- krocich
      9: kontrola nerovnost
     10: zbyl (mene nez) 1 radek
     11: plovouci objekt je pro sloupec prilis siroky
     12: plovouci objekt je presunut do nasledujiciho sloupce / -- 
     13: siroky plovouci objekt je presunut nad sloupce
\stopmessages

\startmessages  italian  library: columns
  title: colonne
      1: solo -- colonne possibili
      2: in alternativa, usare \string\filbreak
      3: problemi, disabilitare il bilanciamento
      4: float in cima non ancora supportato
      5: float in fondo non ancora supportato
      6: -- float(s) posticipate
      7: bilanciamento annullato dopo 100 passi
      8: bilanciamento in -- passo/i
      9: controllare seghettamento
     10: (meno di) una riga rimasta
     11: oggetto mobile troppo ampio per la colonna
     12: oggetto mobile spostata alla colonna successiva / --
     13: oggetto mobile ampio spostato sopra le colonne
\stopmessages

\startmessages  norwegian  library: columns
  title: kolonner
      1: maksimalt -- kolonner
      2: bruk \string\filbreak\space som et alternativ
      3: problemer, slår av balansering
      4: flytblokker øverst er ikke støttet enda
      5: flytblokker nedert er ikke støttet enda
      6: -- flytblokk forskjøvet
      7: balansering avbrutt etter 100 iterasjoner
      8: balansert etter -- iterasjoner
      9: kontroller tekstlayout!
     10: (mindre enn) 1 linje igjen
     11: flytblokk for bredt for kolonna
     12: flytblokk forskjøvet til neste kolonne / --
     13: bred flytblokk forksjøvet til toppen av kolonnene
\stopmessages

%D This completely new implementation can handle enough
%D situations for everyday documents, but is still far from
%D perfect. While at the moment the routine doesn't support
%D all kind of floats, it does support:
%D
%D \startopsomming[opelkaar]
%D \som  an unlimitted number of columns
%D \som  ragged or not ragged bottoms
%D \som  optional balancing without \type{\balancingerrors}
%D \som  different \type{\baselineskips}, \type{\spacing},
%D       \type{\topskip} and \type{\maxdepth}
%D \som  left- and right indentation, e.g. within lists
%D \som  moving columns floats to the next column or page
%D \som  handling of floats that are to wide for a columns
%D \stopopsomming
%D
%D One could wonder why single and multi||columns modes are
%D still separated. One reason for this is that \TeX\ is not
%D suited well for handling multi||columns. As a result, the
%D single columns routines are more robust. Handling one
%D column as a special case of multi||columns is posible but at
%D the cost of worse float handling, worse page breaking,
%D worse etc. Complicated multi||column page handling should
%D be done in \kap{DTP}||systems anyway.
%D
%D There are three commands provided for entering and leaving
%D multi||column mode and for going to the next column:
%D
%D \interface \type{\beginmulticolumns} \\ \\
%D \interface \type{\endmulticolumns}   \\ \\
%D \interface \type{\ejectcolumn}       \\ \\
%D
%D This routines are sort of stand||alone. They communicate
%D with the rest of \CONTEXT\ by means of some interface
%D macro's, which we only mention.
%D
%D \interface \type{\nofcolumns} \\
%D   the number of columns \\
%D \interface \type{\minbalancetoplines} \\
%D   the minimum number op balanced top lines \\ 
%D \interface \type{\betweencolumns} \\
%D   the stuff between columns \\
%D \interface \type{\finaloutput{action}{box}} \\
%D   some kind of \type{\pagebody} and \type{\shipout} \\
%D
%D \interface \type{\ifbalancecolumns} \\
%D   balancing the colums or not \\
%D \interface \type{\ifstretchcolumns} \\
%D   ragging the bottom or not \\
%D
%D \interface \type{\ifheightencolumns} \\
%D     fix the heigh tor not \\
%D \interface \type{\fixedcolumnheight} \\
%D     the optional fixed height \\
%D
%D \interface \type{\ifinheritcolumns} \\
%D     handle ragging or not \\
%D \interface \type{\ifr@ggedbottom} \\
%D     use ragged bottoms \\
%D \interface \type{\ifb@selinebottom} \\
%D     put the bottom line on the baseline \\
%D \interface \type{\ifnormalbottom} \\
%D     put the bottom line at the baseline \\
%D
%D \interface \type{\ifreversecolumns} \\
%D     reverse the order in wich columns are flushed \\
%D
%D \interface \type{\usercolumnwidth} \\
%D     the calculated width of a column \\
%D \interface \type{\columntextwidth} \\
%D     the maximum width of a column \\
%D \interface \type{\columntextheight} \\
%D     the minimum width of a column \\
%D
%D \interface \type{\spacingfactor} \\
%D     the spacing factor \\
%D \interface \type{\bodyfontsize} \\
%D     the (local) bodyfontsize \\
%D \interface \type{\openlineheight} \\
%D     the lineheight (including \type{\spacing}) \\
%D
%D \interface \type{\Everybodyfont} \\
%D     communication channel to font switching routines \\
%D
%D \interface \type{\global\settopskip} \\
%D   set \type{\topskip} \\
%D \interface \type{\setcolumnwarnings} \\
%D   set \type{\badness} and \type{\fuzz} \\
%D \interface \type{\setcolumninserts} \\
%D   set \type{\insert}'s \\
%D \interface \type{\setvsize} \\
%D   set \type{\vsize} and \type{\pagegoal} \\
%D \interface \type{\sethsize} \\
%D   set \type{\hsize} \\
%D
%D \interface \type{\flushcolumnfloats} \\
%D   push saved column floats (next page) \\
%D \interface \type{\flushcolumnfloat} \\
%D   push saved column floats (next column) \\
%D \interface \type{\setcolumnfloats} \\
%D   initialize column floats \\
%D
%D \interface \type{\finishcolumnbox} \\
%D   do something special (a hook) \\
%D \interface \type{\postprocesscolumnpagebox} \\
%D   do something with each columnbox (also a hook) \\
%D \interface \type{\postprocesscolumnbox} \\
%D   do something with each columnbox (also a hook) \\
%D \interface \type{\postprocesscolumnline} \\
%D   do something with each columnline (also a hook) \\
%D \interface \type{\currentcolumn} \\
%D   the current column \\
%D
%D These interface macro's are called upon or initialized
%D by the multi||column macro's.

%D A lot of footnote stuff added!

\def\finalcolumntextwidth   {\zetbreedte}
\def\finalcolumntextheight  {\teksthoogte}
\def\columntextwidth        {\zetbreedte}
\def\columntextheight       {\teksthoogte}
\def\usercolumnwidth        {\tekstbreedte}
\def\columntextoffset       {\!!zeropoint}

\def\fixedcolumnheight      {\teksthoogte}
\def\betweencolumns         {\hskip\bodyfontsize}

\def\setcolumnwarnings      {\dontcomplaincolumnboxes}
\def\setcolumninserts       {\dontpermitcolumninserts}

\let\setcolumnfloats        \relax % in CONTEXT used for floats
\let\flushcolumnfloats      \relax % in CONTEXT used for floats
\let\flushcolumnfloat       \relax % in CONTEXT used for floats
\let\finishcolumnbox        \relax % in CONTEXT used for backgrounds

% %D In fact, the column height and width are set by means of
% %D two macro's. One can change their meaning if needed:
%
% \def\setcolumntextheight%
%   {\def\columntextheight{\teksthoogte}}
%
% \def\setcolumntextwidth%
%   {\def\columntextwidth{\zetbreedte}}

%D Both macros are redefined in \CONTEXT\ when backgrounds
%D are applied to columns. The final values are used when
%D flushing the columns.

\newcount\nofcolumns       \nofcolumns=2

\def\maxnofcolumns        {16}
\def\allocatednofcolumns  {0}
\def\minbalancetoplines   {1}

\newif\ifbalancecolumns    \balancecolumnsfalse
\newif\ifstretchcolumns    \stretchcolumnsfalse
\newif\ifinheritcolumns    \inheritcolumnsfalse
\newif\ifheightencolumns   \heightencolumnsfalse

\newbox\partialpage
\newbox\restofpage

\newbox\savedfloatlist

\newdimen\intercolumnwidth
\newdimen\localcolumnwidth
\newdimen\partialpageheight
\newdimen\savedpagetotal

\newtoks\singlecolumnout

%D The next dimension reports the final column height 

\newdimen\finalcolumnheights 
\newcount\finalcolumnlines

%D It's more convenient to use \type {\columnwidth} instead 
%D of messing around with boxes each time.

\newdimen\columnwidth
\newdimen\gutterwidth

\def\determinecolumnwidth% 
  {\bgroup
   \setbox\scratchbox=\hbox
     {\setcolumnhsize
      \global\columnwidth=\usercolumnwidth
      \global\gutterwidth=\intercolumnwidth}%
   \egroup}

%D During initialization the temporary boxes are allocated.
%D This enables us to use as much columns as we want, without
%D exhausting the pool of boxes too fast. We could have packed
%D them in one box, but we've got enough boxes.
%D
%D Two sets of boxes are declared, the txtboxes are used for
%D the text, the topboxes are for moved column floats.

\def\@@txtcol{@@txtcol}
\def\@@topcol{@@topcol}

\def\initializemulticolumns#1%
  {\ifnum#1>\maxnofcolumns\relax
     \showmessage{\m!columns}{1}{\maxnofcolumns}%
     \nofcolumns=\maxnofcolumns
   \else
     \nofcolumns=#1\relax
   \fi
   \ifnum\nofcolumns>\allocatednofcolumns\relax
     \dorecurse
       {#1}
       {\ifnum\recurselevel>\allocatednofcolumns\relax
          \newbox\next
          \global\letvalue{\@@txtcol\recurselevel}=\next
          \newbox\next
          \global\letvalue{\@@topcol\recurselevel}=\next
        \fi}%
     \xdef\allocatednofcolumns{\the\nofcolumns}%
   \fi
   \edef\firstcolumnbox{\getvalue{\@@txtcol1}}%
   \edef\firsttopcolumnbox{\getvalue{\@@topcol1}}%
   \edef\lastcolumnbox{\getvalue{\@@txtcol\the\nofcolumns}}%
   \edef\lasttopcolumnbox{\getvalue{\@@topcol\the\nofcolumns}}}

%D Without going in details we present two macro's which
%D handle the columns. The action which is transfered by the
%D the first and only parameter can do something with
%D \type{\currentcolumnbox}. In case of the mid columns,
%D \type{\firstcolumnbox} and \type{\lastcolumnbox} are handled
%D outside these macro's.

%\def\dohandlemidcolumns#1%
%  {\dorecurse
%     {\nofcolumns}
%     {\ifnum\recurselevel>1
%        \ifnum\recurselevel<\nofcolumns\relax
%           \edef\currentcolumnbox{\getvalue{\@@txtcol\recurselevel}}%
%           \edef\currenttopcolumnbox{\getvalue{\@@topcol\recurselevel}}%
%           \let\currentcolumn=\recurselevel
%           #1\relax
%        \fi
%      \fi}}
%
%\def\dohandleallcolumns#1%
%  {\dorecurse
%     {\nofcolumns}
%     {\edef\currentcolumnbox{\getvalue{\@@txtcol\recurselevel}}%
%      \edef\currenttopcolumnbox{\getvalue{\@@topcol\recurselevel}}%
%      \let\currentcolumn=\recurselevel
%      #1\relax}}

\def\dohandlecolumn#1%
  {\edef\currentcolumnbox   {\getvalue{\@@txtcol\recurselevel}}%
   \edef\currenttopcolumnbox{\getvalue{\@@topcol\recurselevel}}%
   \let\currentcolumn=\recurselevel
   #1\relax}

\def\dohandleallcolumns#1%
  {\dorecurse{\nofcolumns}{\dohandlecolumn{#1}}}

\def\dohandlerevcolumns#1%
  {\dostepwiserecurse{\nofcolumns}{1}{-1}{\dohandlecolumn{#1}}}

\def\dohandlemidcolumns#1%
  {\dohandleallcolumns
     {\ifnum\recurselevel>1\relax\ifnum\recurselevel<\nofcolumns\relax
        \dohandlecolumn{#1}%
      \fi\fi}}

%D Going to a new columns is done by means of a
%D \type{\ejectcolumn}. The following definition does not
%D always work.

\def\ejectcolumn%
  {\goodbreak
   \showmessage{\m!columns}{2}{}}

%D The next macro should never be called so let's deal with it.
%D There were several solutions to these kind of errors. First
%D we check for a good breakpoint before firing up the
%D multi||column routine (\type{\break} or \type{\allowbreak}).
%D We do the same at the end of the routine
%D (\type{\allowbreak}). These allowances are definitely
%D needed!
%D
%D Some on first sight redundant calls to for instance
%D \type{\setvsize} in the flushing, splitting and balancing
%D macro's can definitely not be omitted! Some are just there
%D to handle situations that only few times arise. One of
%D those can be that the output routine is invoked before
%D everything is taken care of. This happens when we
%D flush (part of) the current page with an \type{\unvbox}
%D with a \type{\pagetotal}~$\approx$ \type{\pagegoal}. One
%D simply cannot balance columns that are just balanced.
%D
%D I hope one never sees the following message. Because it
%D took me a lot of time to develop the multi||columns
%D routines, every (although seldom) warning gives me the
%D creeps!

\def\balancingerror%
  {\showmessage{\m!columns}{3}{}%
   \finaloutput\unvbox\normalpagebox}

%D Here we present the two \type{\dont...} macro's, which are
%D of course \CONTEXT||specific ones.

\def\dontcomplaincolumnboxes%
  {\mindermeldingen}

\def\dontpermitcolumninserts%
  {\def\dotopfloat%
     {\showmessage{\m!columns}{4}{}%
      \doexecfloat}%
   \def\dobotfloat%
     {\showmessage{\m!columns}{5}{}%
      \doexecfloat}}

\def\getinsertionheights\to#1\\% \relax'm
  {#1=\!!zeropoint
   \def\doaddinsertionheight##1%
     {\ifvoid##1\else
        \advance#1 by 1\skip##1     
        \advance#1 by \ht##1        
       \fi}%
   \doaddinsertionheight\topins
   \doaddinsertionheight\botins
   \ifcleverfootnotes
     \doaddinsertionheight\savedfootins
   \else
     \doaddinsertionheight\footins
   \fi}

%D The local column width is available in the dimension
%D register \type{\localcolumnwidth}, which is calculated as:

\def\setcolumnhsize% beware, this one is available for use in macros 
  {\setbox0=\hbox
     {\parindent\!!zeropoint\betweencolumns}%
   \intercolumnwidth=\wd0
   \localcolumnwidth=\columntextwidth
   \advance\localcolumnwidth by -\leftskip
   \advance\localcolumnwidth by -\rightskip
   \advance\localcolumnwidth by -\nofcolumns\intercolumnwidth
   \advance\localcolumnwidth by \intercolumnwidth
   \divide\localcolumnwidth  by \nofcolumns
   \dimen0=\columntextoffset
   \multiply\dimen0 by 2
   \advance\localcolumnwidth by -\dimen0
   \usercolumnwidth=\localcolumnwidth
   \hsize=\localcolumnwidth} % we don't do it \global

%D One should be aware that when font related dimensions are
%D used in typesetting the in||between material, these
%D dimensions are influenced by bodyfont switches inside
%D multi||column mode.

\def\setcolumnvsize%
  {%\global\vsize=\columntextheight
   \global\vsize=-\columntextoffset
   \global\multiply\vsize by 2
   \global\advance\vsize by \columntextheight
   \ifdim\partialpageheight>\!!zeropoint
     \global\advance\vsize by -\partialpageheight
   \fi
   \getinsertionheights\to\dimen0\\% 
   \global\advance\vsize by -\dimen0
   \ifgridsnapping % evt altijd, nog testen
     \getnoflines\vsize
     \vsize=\noflines\openlineheight
     \advance\vsize by .5\openlineheight % collect enough data
   \fi
   \global\vsize=\nofcolumns\vsize
   \global\pagegoal=\vsize} % let's do it only here

%D It really starts here. After some checks and initializations
%D we change the output routine to continous multi||column
%D mode. This mode handles columns that fill the current and
%D next full pages. The method used is (more or less)
%D multiplying \type{\vsize} and dividing \type{\hsize} by
%D \type{\nofcolumns}. More on this can be found in the
%D \TeX book. We save the top of the current page in box
%D \type{\partialpage}.
%D
%D We manipulate \type{\topskip} a bit, just to be shure that
%D is has no flexibility. This has te be done every time a
%D font switch takles place, because \type{\topskip} can depend
%D on this.
%D
%D Watch the trick with the \type{\vbox}. This way we get the
%D right interlining and white space.

\def\beginmulticolumns%
  {\par
   \flushfootnotes
   \xdef\precolumndepth{\the\prevdepth}%
   \begingroup
   \dontshowcomposition
  %\setcolumntextwidth\relax
  %\setcolumntextheight\relax
   \widowpenalty=0 % is gewoon beter
   \clubpenalty=0  % zeker bij grids
   \ifsomefloatwaiting
     \showmessage{\m!columns}{6}{\the\savednoffloats}%
     \global\setbox\savedfloatlist=\box\floatlist
     \xdef\restoresavedfloats%
       {\global\savednoffloats=\the\savednoffloats
        \global\setbox\floatlist=\box\savedfloatlist
        \global\noexpand\somefloatwaitingtrue}%
     \global\savednoffloats=0
     \global\somefloatwaitingfalse
   \else
     \global\let\restoresavedfloats=\relax
   \fi
   \dimen0=\pagetotal
   \advance\dimen0 by \parskip
   \advance\dimen0 by \openlineheight
   \ifdim\dimen0<\pagegoal
     \allowbreak
   \else
     \break % Sometimes fails
   \fi
   \appendtoks\topskip=1\topskip\to\everybodyfont
   \the\everybodyfont
   \initializemulticolumns\nofcolumns
   \setcolumninserts
   \hangafter=0
   \hangindent=\!!zeropoint
   \everypar{}%
   \ifdim\pagetotal=\!!zeropoint \else
     \vbox{\forgetall\strut}%
     \vskip-\openlineheight
   \fi
   \global\savedpagetotal=\pagetotal
   \global\singlecolumnout=\output
   \global\output={\global\setbox\partialpage=\vbox{\unvbox\normalpagebox}}%
   \eject % no \holdinginserts=1, can make footnote disappear ! 
   \global\partialpageheight=\ht\partialpage
   \global\output={\continuousmulticolumnsout}%
   \setcolumnfloats
   \dohandleallcolumns
     {\global\setbox\currenttopcolumnbox=\box\voidb@x}%
   \checkbegincolumnfootnotes
   \let\sethsize=\setcolumnhsize
   \let\setvsize=\setcolumnvsize
   \sethsize
   \setvsize
   \showcomposition}

%D When we leave the multi||column mode, we have to process the
%D not yet shipped out part of the columns. When we don't
%D balance, we simply force a continuous output, but a balanced
%D output is more tricky.

%D First we try to fill up the page and when all or something
%D is left we try to balance things. This is another useful
%D adaption of the ancesters of these macro's. It takes some
%D reasoning to find out what happens and maybe I'm making
%D some mistake, but it works.
%D
%D Voiding box \type{\partialpage} is sometimes necessary,
%D e.g. when there is no text given between \type{\begin..}
%D and \type{\end..}. The \type{\par} is needed!

\def\endmulticolumns%
  {%\par
   \vskip\lineheight\vskip-\lineheight % take footnotes into account
   \dontshowcomposition
   \doflushcolumnfloat % added recently
  %\doflushcolumnfloats % no, since it results in wrong top floats
   \flushfootnotes      % before start of columns 
   \par
   \ifbalancecolumns
     \global\output={\continuousmulticolumnsout}%
     \goodbreak
     \global\output={\balancedmulticolumnsout}%
   \else
     \goodbreak
   \fi
   \eject                 % the prevdepth is important, try e.g. toclist in
   \prevdepth\!!zeropoint % columns before some noncolumned text text
   \global\output=\singlecolumnout
   \ifvoid\partialpage\else
     \unvbox\partialpage
   \fi
   \global\partialpageheight=\!!zeropoint
   \endgroup % here
   \nofcolumns=1
   \setvsize % the outer one!
   \checkendcolumnfootnotes
   \dosomebreak\allowbreak
   \restoresavedfloats}

%D NEW: still to be documented!

\newinsert\savedfootins

\def\checkbegincolumnfootnotes%
  {\ifcleverfootnotes
     \doflushfootnotes
     \ifdim\ht\footins>\!!zeropoint % hm, actually unknown 
       \global\setbox\savedfootins=\box\footins
     \else
       \global\setbox\savedfootins=\box\voidb@x
     \fi
   \else
     \global\setbox\savedfootins=\box\voidb@x
   \fi
   \global\skip\savedfootins=\skip\footins
   \global\count\savedfootins=\count\footins
   \setupfootnotes}

\def\checkendcolumnfootnotes%
  {\ifcleverfootnotes\ifvoid\savedfootins\else
     \global\setbox\footins=\box\savedfootins
   \fi\fi
   \global\skip\footins=\skip\savedfootins
   \global\count\footins=\count\savedfootins}

%D Because some initializations happen three times, we
%D defined a macro for them. The \type{\everypar{}} is
%D needed because we don't want anything to interfere.

\def\setmulticolumnsout%
  {\everypar{}%
   \setcolumnwarnings
   \settopskip
   \setmaxdepth
   \topskip=1\topskip
   \splittopskip=\topskip
   \splitmaxdepth=\maxdepth
   \boxmaxdepth=\maxdepth % dangerous
   \emergencystretch=\!!zeropoint\relax} % sometimes needed !

%D Flushing the page comes to pasting the columns together and
%D appending the result to box \type{\partialpage}, if not
%D void. I've seen a lot of implementations in which some skip
%D was put between normal text and multi||column text. When we
%D don't want this, the baselines can be messed up. I hope the
%D seemingly complicated calculation of a correction
%D \type{\kern} is adequate to overcome this. Although not
%D watertight, spacing is taken into account and even multiple
%D mode changes on one page go well. But cross your fingers and
%D don't blame me.
%D
%D One of the complications of flushing out the boxes is that
%D \type{\partialpage} needs to be \type{\unvbox}'ed, otherwise
%D there is too less flexibility in the page when using
%D \type{\r@ggedbottom}. It took a lot of time before these
%D kind of problems were overcome. Using \type{\unvbox} at the
%D wrong moment can generate \type{\balancingerror}'s.
%D
%D One can use the macros \type {\maxcolumnheight} and \type
%D {\maxcolumndepth} when generating material between columns
%D as well as postprocessing column lines.

\let\maxcolumnheight=\!!zeropoint
\let\maxcolumndepth =\!!zeropoint

\newbox\columnpagebox

\def\setmaxcolumndimensions%
  {\let\maxcolumnheight=\!!zeropoint
   \let\maxcolumndepth =\!!zeropoint
   \dohandleallcolumns
     {\ifdim\ht\currentcolumnbox>\maxcolumnheight
        \edef\maxcolumnheight{\the\ht\currentcolumnbox}%
      \fi
      \ifdim\dp\currentcolumnbox>\maxcolumndepth
        \edef\maxcolumndepth{\the\dp\currentcolumnbox}%
      \fi}}

% \def\flushcolumnedpage%
%   {\bgroup
%    \forgetall
%    \setmulticolumnsout
%    \showcomposition
%    \setmaxcolumndimensions
%    \postprocesscolumns
%    \dohandleallcolumns % \hbox i.v.m. \showcomposition
%      {\global\setbox\currentcolumnbox=\hbox to \localcolumnwidth
%         {\box\currentcolumnbox
%          \global\wd\currentcolumnbox=\localcolumnwidth
%          \ifheightencolumns
%            \global\ht\currentcolumnbox=\fixedcolumnheight
%          \fi}}%
%    \setmaxcolumndimensions
%    \overlaycolumnfootnotes
%    \setbox0=\vbox
%      {\hbox to \finalcolumntextwidth
%         {\ifreversecolumns
%            \@EA\dohandlerevcolumns
%          \else
%            \@EA\dohandleallcolumns
%          \fi
%            {\finishcolumnbox{\hbox
%               {\ifx\finishcolumnbox\relax\else\strut\fi
%                \box\currentcolumnbox}}%
%             \hfil}%
%          \unskip}}%
%    \scratchdimen=\!!zeropoint
%    \dohandleallcolumns
%      {\ifdim-\ht\currenttopcolumnbox<\scratchdimen
%         \scratchdimen=-\ht\currenttopcolumnbox
%       \fi
%       \global\setbox\currenttopcolumnbox=\box\voidb@x}%
%    \advance\scratchdimen by \ht0
%    \setbox2=\hbox to \columntextwidth
%      {\vrule\!!width\!!zeropoint\!!height\scratchdimen\!!depth\dp0
%       \dostepwiserecurse{2}{\nofcolumns}{1}{\hfil\betweencolumns}\hfil}%
%    \setbox0=\hbox
%      {\box0\hskip-\columntextwidth\color[black]{\box2}}%
%    \ifvoid\partialpage \else
%      \ifgridsnapping % do you believe this junk?
%        \scratchdimen=\savedpagetotal
%        \advance\scratchdimen by -\ht\partialpage
%        \advance\scratchdimen by -\dp\partialpage
%        \advance\scratchdimen by -\topskip
%        \box\partialpage
%        \kern\scratchdimen
%      \else
%        \unvbox\partialpage
%      \fi
%    \fi
%    \global\partialpageheight=\!!zeropoint
%    \setvsize
%    \dosomebreak\nobreak
%    \ifgridsnapping \else
%      \dimen0=\topskip
%      \advance\dimen0 by -\openstrutheight
%      \nointerlineskip
%      \vskip-\dimen0
%    \fi
%    \prevdepth\openstrutdepth
%    \nointerlineskip
%    \dp0=\!!zeropoint
%    \global\finalcolumnheights=\ht0
%    \getnoflines\finalcolumnheights
%    \global\finalcolumnlines=\noflines
%    \box0
%    \egroup}

\def\flushcolumnedpage%
  {\bgroup
   \forgetall
   \setmulticolumnsout
   \showcomposition
   \setmaxcolumndimensions
   \postprocesscolumns
   \dohandleallcolumns % \hbox i.v.m. \showcomposition
     {\global\setbox\currentcolumnbox=\hbox to \localcolumnwidth
        {\box\currentcolumnbox
         \global\wd\currentcolumnbox=\localcolumnwidth
         \ifheightencolumns
           \global\ht\currentcolumnbox=\fixedcolumnheight
         \fi}}%
   \setmaxcolumndimensions
   \overlaycolumnfootnotes
   \setbox\columnpagebox=\vbox
     {\hbox to \finalcolumntextwidth
        {\ifreversecolumns
           \@EA\dohandlerevcolumns
         \else
           \@EA\dohandleallcolumns
         \fi
           {\finishcolumnbox{\hbox
              {\ifx\finishcolumnbox\relax\else\strut\fi
               \box\currentcolumnbox}}%
            \hfil}%
         \unskip}}%
   \scratchdimen=\!!zeropoint
   \dohandleallcolumns
     {\ifdim-\ht\currenttopcolumnbox<\scratchdimen
        \scratchdimen=-\ht\currenttopcolumnbox
      \fi
      \global\setbox\currenttopcolumnbox=\box\voidb@x}%
   \advance\scratchdimen by \ht\columnpagebox
   \setbox\scratchbox=\hbox to \columntextwidth
     {\vrule
        \!!width\!!zeropoint
        \!!height\scratchdimen
        \!!depth\dp\columnpagebox
      \dostepwiserecurse{2}{\nofcolumns}{1}{\hfil\betweencolumns}\hfil}%
   \setbox\columnpagebox=\hbox
     {\box\columnpagebox
      \hskip-\columntextwidth
      \color[black]{\box\scratchbox}}%
   \postprocesscolumnpagebox % new, acts upon \box\columnpagebox
   \ifvoid\partialpage \else
     \ifgridsnapping % do you believe this junk?
       \scratchdimen=\savedpagetotal
       \advance\scratchdimen by -\ht\partialpage
       \advance\scratchdimen by -\dp\partialpage
       \advance\scratchdimen by -\topskip
       \box\partialpage
       \kern\scratchdimen
     \else
       \unvbox\partialpage
     \fi
   \fi
   \global\partialpageheight=\!!zeropoint
   \setvsize
   \dosomebreak\nobreak
   \ifgridsnapping \else
     \scratchdimen=\topskip
     \advance\scratchdimen by -\openstrutheight
     \nointerlineskip
     \vskip-\scratchdimen
   \fi
   \prevdepth\openstrutdepth
   \nointerlineskip
   \dp\columnpagebox=\!!zeropoint
   \global\finalcolumnheights=\ht\columnpagebox
   \getnoflines\finalcolumnheights
   \global\finalcolumnlines=\noflines
   \box\columnpagebox
   \egroup}

%D In case one didn't notice, finaly \type{\finishcolumnbox} is
%D applied to all boxes. One can use these hooks for special
%D purposes.
%D
%D Once upon a time I wanted to manipulate the individual lines
%D in a column. This feature is demonstrated in the two examples
%D below.
%D
%D \startbuffer
%D \def\postprocesscolumnline#1% or \postprocesscolumnbox
%D   {\ruledhbox{\box#1}\hss}
%D
%D \startkolommen[n=4]
%D \dorecurse{25}{line: \recurselevel\par}
%D \stopkolommen
%D \stopbuffer
%D
%D \typebuffer
%D
%D Here we show the natural width of the lines:
%D
%D {\haalbuffer}
%D
%D The next example does a bit more advanced manipulation:
%D
%D \startbuffer
%D \def\postprocesscolumnline#1%
%D   {\ifodd\currentcolumn
%D      \hfill\unhbox#1\relax
%D    \else
%D      \relax\unhbox#1\hfill
%D    \fi}
%D
%D \startkolommen[n=4]
%D \dorecurse{25}{line \recurselevel\par}
%D \stopkolommen
%D \stopbuffer
%D
%D \typebuffer
%D
%D Here we also see an application of \type{\currentcolumn}:
%D
%D {\haalbuffer}
%D
%D This feature is implemented using the reshape macros
%D presented in \type{supp-box}.

\def\postprocesscolumns%
  {\ifx\postprocesscolumnline\undefined \else
     \dohandleallcolumns
       {\global\setbox\currentcolumnbox=\vtop
          {\beginofshapebox
           \unvbox\currentcolumnbox
           \unskip\unskip
           \endofshapebox
           \reshapebox
             {\dimen0=\ht\shapebox
              \dimen2=\dp\shapebox
              \setbox\shapebox=\hbox to \hsize
                {\postprocesscolumnline\shapebox}%
              \ht\shapebox=\dimen0
              \dp\shapebox=\dimen2
              \box\shapebox}%
           \flushshapebox
           \everypar{}\parskip\!!zeropoint % = \forgetall
           \strut\endgraf
           \vskip-\lineheight
           \vfil}}%
   \fi
   \ifx\postprocesscolumnbox\undefined \else
     \dohandleallcolumns
       {\global\setbox\currentcolumnbox=\hbox
          {\postprocesscolumnbox\currentcolumnbox}}
   \fi}

%D We default to doing nothing!

\let\postprocesscolumnline   =\undefined
\let\postprocesscolumnbox    =\undefined
\let\postprocesscolumnpagebox=\relax

%D \macros
%D   {reversecolumnstrue} 
%D
%D We can force the macro that takes care of combining 
%D the columns, to flush them in the revere order. Of 
%D course, by default we don't reverse. 

\newif\ifreversecolumns 
 
%D Here comes the simple splitting routine. It's a bit
%D longer than expected because of ragging bottoms or not.
%D This part can be a bit shorter but I suppose that I will
%D forget what happens. The splitting takes some already
%D present material (think of floats) into account!
%D
%D First we present some auxiliary routines. Any material,
%D like for instance floats, that is already present in the
%D boxes is preserved.

% \def\splitcolumn#1from \box#2to \dimen#3 top \box#4%
%   {\bgroup
%    \ifdim\ht#4>\!!zeropoint
%      \dimen0=\dimen#3\relax
%      \dimen2=\dimen#3\relax
%      \advance\dimen0 by -\ht#4
%      \setbox0=\vsplit#2 to \dimen0
%      \global\setbox#1=\vbox to \dimen2{\unvcopy#4\unvbox0}%
%    \else
%      \global\setbox#1=\vsplit#2 to \dimen#3
%    \fi
%    \egroup}

% \def\splitcolumn#1from \box#2to \dimen#3 top \box#4%
%   {\bgroup
%    \ifdim\ht#4>\!!zeropoint
%      \dimen0=\dimen#3\relax
%      \dimen2=\dimen2
%      \advance\dimen0 by -\ht#4%
%      \columnfootnotecorrection{#1}{\dimen0}%
%      \setbox0=\vsplit#2 to \dimen0
%      \global\setbox#1=\vbox to \dimen2
%        {\ifgridsnapping
%           \dimen0=-\openstrutheight\advance\dimen0 by \topskip
%           \vskip\dimen0\copy#4\vskip-\dimen0
%         \else
%           \unvcopy#4%
%         \fi
%         \unvbox0
%         \fakecolumnfootnotes{#1}}%
%    \else
%      \ifcleverfootnotes
%        \columnfootnotecorrection{#1}{\dimen#3}%
%        \setbox0=\vsplit#2 to \dimen#3%
%        \global\setbox#1=\vbox to \dimen#3%
%          {\unvbox0
%           \fakecolumnfootnotes{#1}}%
%     \else
%        \global\setbox#1=\vsplit#2 to \dimen#3%
%      \fi
%    \fi
%    \egroup}

\def\splitcolumn#1from \box#2to \dimen#3 top \box#4%
  {\bgroup
   \ifdim\ht#4>\!!zeropoint
     \dimen0=\dimen#3\relax
     \dimen2=\dimen0
     \advance\dimen0 by -\ht#4%
     \columnfootnotecorrection{#1}{\dimen0}%
     \setbox0=\vsplit#2 to \dimen0
     \global\setbox#1=\vbox to \dimen2
       {\ifgridsnapping
          \dimen0=-\openstrutheight\advance\dimen0 by \topskip
          \vskip\dimen0\copy#4\vskip-\dimen0
        \else
          \unvcopy#4%
        \fi
        \fuzzysnappedbox\unvbox0
        \fakecolumnfootnotes{#1}}%
   \else
     \ifcleverfootnotes
       \columnfootnotecorrection{#1}{\dimen#3}%
       \setbox0=\vsplit#2 to \dimen#3%
       \global\setbox#1=\vbox to \dimen#3%
         {\fuzzysnappedbox\unvbox0
          \fakecolumnfootnotes{#1}}%
     \else
       \global\setbox#1=\vsplit#2 to \dimen#3%
       \global\setbox#1=\vbox
         {\fuzzysnappedbox\unvbox{#1}}% % or \box ?
     \fi
   \fi
   \egroup}

\def\splitcurrentcolumn from \box#1to \dimen#2%
  {\splitcolumn\currentcolumnbox from \box#1 to \dimen#2 top \box\currenttopcolumnbox}

\def\splitfirstcolumn from \box#1to \dimen#2%
  {\splitcolumn\firstcolumnbox from \box#1 to \dimen#2 top \box\firsttopcolumnbox}

\def\splitlastcolumn from \box#1to \dimen#2%
  {\global\setbox\lastcolumnbox=\vbox
     {\unvcopy\lasttopcolumnbox
      \fuzzysnappedbox\unvbox{#1}%
      \fakecolumnfootnotes\lastcolumnbox}}

%D NEW: still to be documented.

\def\fakecolumnfootnotes#1%
  {\relax
   \ifcleverfootnotes
     \ifnum#1=\lastcolumnbox
       \ifdim\ht\footins>\!!zeropoint
         \vskip1\skip\footins % remove stretch and shrink 
         \kern\ht\footins % a \vskip would be is discarded! 
       \fi
     \fi
   \fi}

\def\columnfootnotecorrection#1#2%
  {\relax
   \ifcleverfootnotes
     \ifnum#1=\lastcolumnbox\relax
       \ifdim\ht\footins>\!!zeropoint
         \advance#2 by -\ht\footins
         \advance#2 by -\skip\footins
       \fi
     \fi
   \fi}

\def\overlaycolumnfootnotes%   VERVANGEN !!!
  {\relax
   \ifcleverfootnotes\ifdim\ht\footins>\!!zeropoint
     \bgroup
     \scratchdimen=\ht\firstcolumnbox
     \advance\scratchdimen by -\openstrutdepth % \dp\strutbox
     \getnoflines\scratchdimen
     \advance\noflines by -2
     \scratchdimen=\noflines\lineheight
     \advance\scratchdimen by \topskip
     \setbox0=\hbox
       {\lower\scratchdimen\vbox{\placefootnoteinserts}}%
     \ht0=\openstrutheight % \ht\strutbox
     \dp0=\openstrutdepth  % \dp\strutbox
     \scratchdimen=\ht\lastcolumnbox
     \global\setbox\lastcolumnbox=\vbox to \scratchdimen
       {\box\lastcolumnbox
        \vskip-\scratchdimen
        \color[black]{\box0}}%
     \egroup
   \fi\fi}

%D Here comes the routine that splits the long box in columns.
%D The macro \type{\flushcolumnfloats} can be used to flush
%D either floats that were present before the multi||column
%D mode was entered, or floats that migrate to next columns.
%D Flushing floats is a delicate process.

\def\continuousmulticolumnsout% 
  {\bgroup
   \forgetall
   \setmulticolumnsout
   \dontshowcomposition
   \dimen0=\columntextheight
   \getinsertionheights\to\dimen2\\% toegevoegd ivm voetnoten
   \advance\dimen2 by \partialpageheight
   \dimen0=\columntextheight
   \advance\dimen0 by -\partialpageheight
   \getinsertionheights\to\dimen2\\%
   \advance\dimen0 by -\dimen2
   \ifgridsnapping % evt altijd, nog testen
     \getnoflines{\dimen0}
     \dimen0=\noflines\openlineheight
   \fi
   \dohandleallcolumns
     {\splitcurrentcolumn from \box\normalpagebox to \dimen0}
   \setbox\restofpage=\vbox{\unvbox\normalpagebox}%
   \ifinheritcolumns
     \ifr@ggedbottom % vreemd 
%\ifbottomnotes % can better be a state 
       \dohandleallcolumns
         {\global\setbox\currentcolumnbox=\vbox to \ht\firstcolumnbox
            {\dimen0=\dp\currentcolumnbox
             \unvbox\currentcolumnbox
             \vskip-\dimen0
             \vskip\openstrutdepth % \dp\strutbox
             \prevdepth\openstrutdepth % \dp\strutbox
             \vfill}}%
%\else
%  \dimen0=\ht\firstcolumnbox
%\fi
\ifbottomnotes \else
  \dimen0=\ht\firstcolumnbox
\fi
     \fi
     \ifn@rmalbottom
       \advance\dimen0 by \maxdepth
       \dohandleallcolumns
         {\global\setbox\currentcolumnbox=\vbox to \dimen0
            {\unvbox\currentcolumnbox}}%
     \fi
     \ifb@selinebottom
       % the columns are on top of the baseline
     \fi
   \else
     \dohandleallcolumns
       {\global\setbox\currentcolumnbox=\vbox to \dimen0
          {\ifstretchcolumns
             \unvbox\currentcolumnbox
           \else
             \unvbox\currentcolumnbox % wel of niet \unvbox ?
             \vfill
           \fi}}%
     \dohandleallcolumns
       {\global\ht\currentcolumnbox=\dimen0}%
   \fi
   \setbox\partialpage=\vbox{\flushcolumnedpage}%
   \finaloutput\box\partialpage
   \sethsize
   \setvsize
   \flushcolumnfloats
   \unvbox\restofpage
   % \penalty\outputpenalty % gaat gruwelijk mis in opsommingen
   \egroup}

%D And this is the balancing stuff. Again, part of the routine
%D is dedicated to handling ragged bottoms, but here we also
%D see some handling concerning the stretching of columns.
%D We set \type{\widowpenalty} at~0, which enables us to
%D balance columns with few lines. The use of \type{\box2} and
%D \type{\box4} garantees a more robust check when skips are
%D used.

\def\balancedmulticolumnsout% 
  {\bgroup
   \setmulticolumnsout
   \dontshowcomposition
   \widowpenalty=0
   \setbox0=\vbox{\unvbox\normalpagebox}%
\ifdim\ht0>\openlineheight % at least one line 
  \ifnum\minbalancetoplines<2 % balance anyway 
    \donetrue 
  \else % check criterium to available lines  
    \getnoflines{\ht0}%
    \divide\noflines by \nofcolumns \relax
    \ifnum\noflines<\minbalancetoplines \relax
      \dimen0=\ht0 
      \advance\dimen0 by \ht\firsttopcolumnbox
      \advance\dimen0 by \openlineheight \relax % let's play safe
      \ifdim\dimen0>\columntextheight % column exceeding text height 
        \donetrue
      \else % it seems to fit 
        \donefalse 
      \fi
    \else % balance indeed
      \donetrue
    \fi
  \fi
\else % balancing does not make sense 
  \donefalse
\fi
\ifdone % start balancing 
  %\ifdim\ht0>\openlineheight
     \dimen0=\ht0
     \advance\dimen0 by \topskip
     \advance\dimen0 by -\baselineskip
     \dohandleallcolumns
       {\advance\dimen0 by \ht\currenttopcolumnbox}%
     \divide\dimen0 by \nofcolumns
     \vbadness=\!!tenthousand\relax
     \count255=0
     \bgroup
     \ifgridsnapping
       \dimen2=\lineheight
     \else
       \dimen2=\!!onepoint % RUBISH
       \dimen2=\spacingfactor\dimen2
     \fi
     \loop
       \advance\count255 by 1
       \global\setbox\restofpage=\copy0\relax
       \splitfirstcolumn from \box\restofpage to \dimen0
       \dohandlemidcolumns
         {\splitcurrentcolumn from \box\restofpage to \dimen0}%
       \splitlastcolumn from \box\restofpage to \dimen0
       \setbox2=\vbox{\unvcopy\firstcolumnbox}%
       \dimen4=\!!zeropoint
       \dohandleallcolumns
         {\setbox4=\vbox 
            {\unvcopy\currentcolumnbox
            %rather new, test this on pdftex-z.tex
             \unpenalty\unskip\unpenalty\unskip}% maybe better in main splitter
            %\writestatus{balance}{\the\currentcolumnbox: \the\ht4}%
             \dimen6=\ht4
             \ifdim\dimen6>\dimen4 \dimen4=\dimen6 \fi}%
\advance\dimen4 by -.0005pt % get rid of accurracy problem, pretty new  
       \ifnum\count255>100\relax
         \donefalse
       \else\ifdim\dimen4>\ht2
         \donetrue
       \else
         \donefalse
       \fi\fi
       \ifdone
         \advance\dimen0 by \dimen2\relax
     \repeat
     \dohandleallcolumns
       {\global\setbox\currentcolumnbox=\vbox{\unvcopy\currentcolumnbox}}% NIEUW
     \ifnum\count255>100\relax
       \showmessage{\m!columns}{7}{}%
     \else
       \showmessage{\m!columns}{8}{\the\count255\space}%
     \fi
     \egroup
     \ifinheritcolumns
       \dimen0=\ht\firstcolumnbox
       \dimen2=\ht\firstcolumnbox
       \advance\dimen2 by -\openlineheight
       \dohandleallcolumns
         {\dimen4=\ht\currentcolumnbox
          \dimen6=10\openlineheight
          \global\setbox\currentcolumnbox=\vbox to \dimen0
            {\unvbox\currentcolumnbox
             \ifdim\dimen4>\dimen6
               \ifdim\dimen4<\dimen0
                 \ifdim\dimen4>\dimen2
                   \vskip\!!zeropoint  % !!
                 \else
                   \vskip\openlineheight
                   \vfill
                 \fi
               \else
                 \vskip\!!zeropoint
               \fi
             \else
               \vskip\openlineheight
               \vfill
             \fi}}%
     \else
       \bgroup
       \ifstretchcolumns
         \dimen0=\ht\firstcolumnbox
         \dimen2=\bottomtolerance\ht\firstcolumnbox
         \setbox0=\vbox{\unvcopy\lastcolumnbox}%
         \advance\dimen0 by -\ht0\relax
         \advance\dimen0 by -\dp0\relax
         \ifdim\dimen0>\openlineheight\relax
           \ifdim\dimen0>\dimen2\relax
             % \stretchcolumnsfalse % beter goed slecht dan slecht goed
             \showmessage{\m!columns}{9}{}%
           \fi
         \fi
       \fi
       \dohandleallcolumns
         {\global\setbox\currentcolumnbox=\vbox to \ht\firstcolumnbox
            {\ifstretchcolumns
               \unvbox\currentcolumnbox
             \else
               \box\currentcolumnbox
               \vfill
             \fi}}%
       \egroup
     \fi
   \else
     \showmessage{\m!columns}{10}{}%
     \global\setbox\firstcolumnbox=\vbox{\unvbox0}%
   \fi
   \global\output={\balancingerror}%
   \b@selinebottomtrue % forces depth in separation rule
   \flushcolumnedpage
   \allowbreak
   \egroup}

%D The multicolumn mechanism is incorporated in a \CONTEXT\
%D interface, which acts like:
%D
%D \starttypen
%D \startcolumns[n=4,balance=no,stretch=no,line=on]
%D   some text
%D \stopcolumns
%D \stoptypen
%D
%D The setup is optional. The default behaviour of columns
%D can be set up with:
%D
%D \starttypen
%D \setupcolumns
%D   [n=2,
%D    balance=yes,
%D    stretch=text,
%D    line=off]
%D \stoptypen
%D
%D In this case, stretching is according to the way it's
%D done outside columns (\type{\inheritcolumnstrue}). Also
%D we can setup the \type{tolerance} within a column, the
%D \type{distance} between columns and the fixed
%D \type{height} of a column.

%D Multi||column output: the float routines
%D
%D Here come the routines that handle the placement of column
%D floats. Floats that are to big migrate to the next
%D column. Floats that are too wide, migrate to the top of the
%D next page, where they span as much columns as needed.
%D Floats that are left over from outside the multi||column
%D mode are flushed first. In macro \type{\finaloutput} the
%D topfloats that are left from previous text should be set.
%D
%D When there are some floats in the queue, we inhibit the
%D flushing of floats on top of columns. The number of
%D waiting floats is preswent in \type{\savednoftopfloats} and
%D is saved. As long as there are floats waiting, the topfloats
%D are places as if we are outside multi||column mode. This is
%D neccessary for e.g. multicolumn lists.
%D
%D When all those floats are flushed, we switch to the local
%D flushing routine.

\def\setcolumnfloats%
  {\xdef\globalsavednoffloats{\the\savednoffloats}%
   \ifnum\globalsavednoffloats>0
     \setglobalcolumnfloats
   \else
     \setlocalcolumnfloats
   \fi}

\def\setglobalcolumnfloats%
  {\everypar={}%
   \let\flushcolumnfloat=\relax
   \let\doroomfloat=\relax
   \let\flushcolumnfloats=\noflushcolumnfloats}

\def\setlocalcolumnfloats%
  {\everypar=
     {\flushfootnotes\flushcolumnfloat\flushmargincontents\checkindentation}%
   \let\flushcolumnfloat=\doflushcolumnfloat
   \let\doroomfloat=\docolumnroomfloat
   \let\flushcolumnfloats=\doflushcolumnfloats
\let\doflushfloats\doflushcolumnfloats % new
   \let\dosetbothinserts=\relax
   \let\dotopinsertions=\relax}

\def\noflushcolumnfloats%
  {\bgroup
   \xdef\localsavednoffloats{\the\savednoffloats}%
   \global\savednoffloats=\globalsavednoffloats
   \dotopinsertions
   \xdef\globalsavenoffloats{\the\savednoffloats}%
   \ifnum\globalsavednoffloats=0
     \setlocalcolumnfloats
   \fi
   \global\savednoffloats=\localsavednoffloats
   \egroup}

%D We need to calculate the amount of free space in a columns.
%D When there is not enough room, we migrate the float to the
%D next column. These macro's are alternatives (and
%D look||alikes) of \type{\doroomfloat}. When a float is to
%D wide, for one column, it is moved to the top of the next
%D page. Of course such moved floats have to be taken into
%D account when we calculate the available space. It's a pitty
%D that such things are no integral part of \TEX.

% \def\getcolumnstatus\column#1\total#2\goal#3\\%
%   {\ifdim\pagegoal<\maxdimen
%      \dimen0=\pagegoal
%      \divide\dimen0 by \nofcolumns
%      \dimen2=\!!zeropoint
%      \count255=0\relax
%      \dimen8=\columntextheight
%      \advance\dimen8 by -\partialpageheight
%      %\advance\dimen8 by -\maxdepth % recently deleted
%      \def\dogetcolumnstatus%
%        {\advance\count255 by 1\relax
%         \advance\dimen2 by \ht\currenttopcolumnbox
%         \advance\dimen2 by \dp\currenttopcolumnbox
%         \dimen4=\dimen2\relax
%         \advance\dimen4 by \pagetotal
%         \dimen6=\count255\dimen8
%         \ifdim\dimen4>\dimen6
%         \else
%           \let\dogetcolumnstatus=\relax
%         \fi}%
%      \dohandleallcolumns{\dogetcolumnstatus}%
%      \ifdim\dimen4=\dimen6
%        \dimen4=\!!zeropoint
%        \advance\count255 by 1
%      \fi
%      #1=\count255
%      #2=\dimen4
%      #3=\dimen6
%    \else
%      #1=1
%      #2=\!!zeropoint
%      #3=\teksthoogte
%      \advance#3 by -\partialpageheight
%    \fi}

\def\getcolumnstatus\column#1\total#2\goal#3\\%
  {\ifdim\pagegoal<\maxdimen
     \dimen0=\pagetotal
   \else
     \dimen0=\!!zeropoint
   \fi
   \dimen2=\!!zeropoint
   \count255=0
   \dimen8=\columntextheight
   \advance\dimen8 by -\partialpageheight
   \def\dogetcolumnstatus%
     {\advance\count255 by 1
      \advance\dimen2 by \ht\currenttopcolumnbox
      \advance\dimen2 by \dp\currenttopcolumnbox
      \dimen4=\dimen2
      \advance\dimen4 by \dimen0
      \dimen6=\count255\dimen8
      \ifdim\dimen4>\dimen6
      \else
        \let\dogetcolumnstatus=\relax
      \fi}%
   \dohandleallcolumns{\dogetcolumnstatus}%
   \ifnum\count255=0 \count255=1 \fi
   #1=\count255
   #2=\dimen4
   #3=\dimen6 }

\def\getinsertionheight%
  {\ifdim\pagegoal<\maxdimen
     \bgroup
     \dimen0=\columntextheight
     \advance\dimen0 by -\pagegoal
     \xdef\insertionheight{\the\dimen0}%
     \egroup
   \else
     \global\let\insertionheight=\!!zeropoint
   \fi}

\def\docolumnroomfloat%
  {\ifpostponecolumnfloats 
     \global\roomforfloatfalse
   \else\ifnofloatpermitted
     \global\roomforfloatfalse
   \else
     \bgroup
     \getcolumnstatus\column\count255\total\dimen0\goal\dimen2\\%
     \advance\dimen0 by 2\openlineheight % nog nodig ?
    %\ifnum\count255=\nofcolumns
    %  \getinsertionheight
    % %\message{\insertionheight}\wait
    %  \advance\dimen0 by \insertionheight
    %\fi
     \setbox\scratchbox=\vbox % tricky met objecten ?
       {\blanko[\@@bkvoorwit]
        \snaptogrid\vbox{\copy\floatbox}}%
     \advance\dimen0 by \ht\scratchbox
     \advance\dimen0 by .5\lineheight % needed because goal a bit higher
    %\message{column: \the\count255; total: \the\dimen0; goal: \the\dimen2}\wait
     \ifdim\dimen0>\dimen2
       \global\roomforfloatfalse
     \else
       \global\roomforfloattrue
     \fi
     \ifdim\wd\floatbox>\hsize
       \showmessage{\m!columns}{11}{}%
       \global\roomforfloatfalse
     \fi
     \egroup
   \fi\fi}

%D Flushing one float is done as soon as possible, i.e.
%D \type{\everypar}. This means that (at the moment)
%D sidefloats are not supported (overulled)!

\newif\ifflushingcolumnfloats \flushingcolumnfloatstrue

\def\doflushcolumnfloat%
  {\ifpostponecolumnfloats\else\ifflushingcolumnfloats\ifprocessingverbatim\else\ifsomefloatwaiting
     \bgroup
     \forgetall
     \let\doflushcolumnfloat=\relax
     \getcolumnstatus\column\count255\total\dimen0\goal\dimen2\\%
     \ifdim\dimen0>\!!zeropoint
       \dogetfloat
       \ifdim\wd\floatbox>\hsize
         \doresavefloat
       \else
        %\setbox2=\vbox
        %  {\blanko[\@@bkvoorwit]
        %   \snaptogrid\vbox{\copy\floatbox}%
        %   \blanko[\@@bknawit]
         \setbox2=\vbox
           {\blanko[\@@bkvoorwit]
            \snaptogrid\vbox{\copy\floatbox}}%
         \advance\dimen0 by \ht2 
         \ifdim\dimen0>\dimen2
           \ifnum\count255<\nofcolumns
             \advance\count255 by 1
             \edef\currenttopcolumnbox{\getvalue{\@@topcol\the\count255}}%
             \ifdim\ht\currenttopcolumnbox=\!!zeropoint
               \global\setbox\currenttopcolumnbox=\vbox
                 {\snaptogrid\vbox{\copy\floatbox}
                  \witruimte % nodig ?
                  \blanko[\@@bknawit]}%
               \dimen4=\ht\currenttopcolumnbox
               \advance\dimen4 by \dp\currenttopcolumnbox
               \global\advance\vsize by -\dimen4
               \advance\dimen4 by -\pagegoal
               \global\pagegoal=-\dimen4
               \showmessage{\m!columns}{12}{a}%
             \else
               \showmessage{\m!columns}{12}{b}%
               \doresavefloat
             \fi
           \else
             \showmessage{\m!columns}{12}{c}%
             \doresavefloat
           \fi
         \else
           \ifhmode{\setbox0=\lastbox}\fi% waar is die er in geslopen
           \par
           \ifdim\prevdepth<\!!zeropoint\relax % anders bovenaan kolom witruimte
           \else
             \nobreak
             \blanko[\@@bkvoorwit]
             \nobreak
           \fi
           \flushfloatbox
           \blanko[\@@bknawit]
         \fi
       \fi
     \fi
     \egroup
   \fi\fi\fi\fi}

%D This one looks complicated. Upto \type{\nofcolumns} floats
%D are placed, taking the width of a float into account. This
%D routine can be improved on different ways:
%D
%D \startopsomming[intro,opelkaar]
%D \som taking into account some imaginary baseline, just to
%D      get the captions in line
%D \som multipass flushing until as many floats are displaced
%D      as possible
%D \stopopsomming
%D
%D When handling lots of (small) floats spacing can get worse
%D because of lining out the columns.

\def\doflushcolumnfloats%
  {\ifpostponecolumnfloats\else
     \bgroup
     \forgetall
     \ifsomefloatwaiting
       \dimen8=\!!zeropoint
       \dimen4=\!!zeropoint
       \count0=0            % count0 can be used local
       \count2=\nofcolumns  % count2 can be used local
       \dohandleallcolumns
         {\ifnum\count0>0\relax % the wide one's reserved space
            \global\setbox\currenttopcolumnbox=\vbox
              {\snaptogrid\vbox
                 {\copy\currenttopcolumnbox
                  \hbox{\vphantom{\copy\floatbox}}}
                  \witruimte % nodig ?
                  \blanko[\@@bknawit]}%
          \else
            \dogetfloat
\ifdim\wd\floatbox>\finalcolumntextwidth % better somewhere else too 
  \global\setbox\floatbox=\hbox to \finalcolumntextwidth{\hss\box\floatbox\hss}%
\fi % otherwise the graphic may disappear
            \ifdim\wd\floatbox>\hsize
              \dimen0=\wd\floatbox
              \advance\dimen0 by \intercolumnwidth
              \dimen2=\hsize
              \advance\dimen2 by \intercolumnwidth
              \advance\dimen0 by .5pt % hm, why 1  
              \advance\dimen2 by .5pt % hm, why 2
              \divide\dimen0 by \dimen2
              \count0=\dimen0
              \advance\count0 by 1
              \ifnum\count0>\count2
                \doresavefloat
                \count0=0
              \else
                \dimen0=\count0\hsize
                \advance\dimen0 by \count0\intercolumnwidth
                \advance\dimen0 by -\intercolumnwidth
                \global\setbox\floatbox=\hbox to \dimen0
                 %{\hss\hbox{\copy\floatbox}\hss}%
                  {\processaction[\@@bkplaats] % how easy to forget 
                     [  \v!links=>\copy\floatbox\hss,
                       \v!rechts=>\hss\copy\floatbox,
                      \s!default=>\hss\copy\floatbox\hss,
                      \s!unknown=>\hss\copy\floatbox\hss]}%
              \fi
              \showmessage{\m!columns}{13}{}%
            \else
            %  \showmessage{\m!columns}{13}{}%
            \fi
            \ifdim\ht\floatbox>\!!zeropoint\relax
              \global\setbox\currenttopcolumnbox=\vbox
                {\snaptogrid\vbox
                   {\copy\currenttopcolumnbox
                    \copy\floatbox}
                 \witruimte % nodig ?
                 \blanko[\@@bknawit]}%
            \fi
            \dimen6=\ht\currenttopcolumnbox
            \advance\dimen6 by \dp\currenttopcolumnbox
          \fi
          \ifdim\dimen4<\ht\currenttopcolumnbox
            \dimen4=\ht\currenttopcolumnbox
          \fi
          \advance\dimen8 by \dimen6
          \advance\count2 by -1
          \advance\count0 by -1 }%
       \setvsize
       \global\advance\vsize by -\dimen8
       \global\pagegoal=\vsize
     \else
       %\doflushfloats % does not snap!
     \fi
     \egroup
   \fi}

%D This were the multi||column routines. They can and need to
%D be improved but at the moment their behaviour is acceptable.
%D
%D One inprovement can be to normalize the height of floats
%D to $n\times$\type{\lineheight} with a macro like:
%D
%D \starttypen
%D \normalizevbox{...}
%D \stoptypen

\protect \endinput

% border case, should fit on one page 
%
% \startkolommen 
% 
% 1 \input tufte  \par \plaatsfiguur{}{\omlijnd[breedte=\hsize,hoogte=3cm]{1}}
% 2 \input tufte  \par \plaatsfiguur{}{\omlijnd[breedte=\hsize,hoogte=3cm]{2}}
% 3 \input tufte  \par \plaatsfiguur{}{\omlijnd[breedte=\hsize,hoogte=3cm]{3}}
% 
% \stopkolommen