summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex3/xor/xo-place.dtx
blob: 0a2084595400563f4e813b277a6e1fe429579e29 (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
% \iffalse
%%
%% (C) Copyright 1999-2000 Frank Mittelbach, David Carlisle, Chris Rowley
%% All rights reserved.
%%
%% Not for general distribution. In its present form it is not allowed
%% to put this package onto CD or an archive without consulting the
%% the authors.
%% 
% \fi
%

%    \begin{macrocode}
\def\@tempa#1: #2.dtx,v #3 #4 #5 #6 #7${
  \ProvidesPackage{#2}[#4 #3 #5 #6]}
\@tempa$Id: xo-place.dtx,v 1.37 2000/08/11 07:14:28 latex3 Exp $
%    \end{macrocode}
%
%
%
% Ignore white space in this package.
%    \begin{macrocode}
\IgnoreWhiteSpace
%    \end{macrocode}
%
%
%
% \subsection{Selecting the next area to try}
%
%
% \begin{macro}{\std@try@this@area}
%    The |\std@try@this@area| command is called when we have
%    selected a float from the |\@activelist| and want to place it
%    in one of the open areas to see if it fits there. If we succeed
%    in finding a potential candidate place we will exit using
%    |\contruct@trial| which will run a trial cutting the galley to
%    see if each column gets the right kind of text and contains the
%    right kind of callouts.
%    The areas are tried in a defined order.
%
%    If we don't find any open areas we return putting the current
%    float onto the |\area@ddd| and then calling |\@trynextfloat|.
%
%    If we find an open area but for some reason the float is not
%    allowed to go there we close that area for floats of this type
%    and recurse (i.e. try to use the next open area for this type).
%
%    The reasons for failure to place the float into the first open
%    area are numerous. First there are restrictions on the number of
%    floats on a page (if we reach this all areas get closed) there
%    there are similar restrictions for each individual float area.
%
%    If those tests are passed we trial typeset the float with its
%    caption (or rather typeset and attach its caption) to determine
%    the size needed by the float. That will give us a dimension to
%    test against restrictions for the amount of space floats are
%    allowed to occupy etc.
%
%    \begin{macrocode}
\def\std@try@this@area{
%<*trace>
  \@tracepush{std@try@this@area}
%</trace>
%    \end{macrocode}
%    If all areas for the float type are closed we have to defer this float.
%    \begin{macrocode}
  \ifx\this@open@areas\@empty
%<*trace>
        \tr@ce{defer:~no~open~area~ available}
%</trace>
        \do@next\defer@and@try@next@float
  \else
%    \end{macrocode}
%    Otherwise the next area to try is the first of |\this@open@areas|:
%    \begin{macrocode}
    \setup@this@area{\expandafter\@carcube\this@open@areas\@nil}
%<*trace>
    \tr@ce{area~trial:~ \this@area}
%</trace>
%<*progress>
    \progress{~ area~trial:~ \this@area}
%</progress>
%    \end{macrocode}
%    Next test needs cleanup once the span has a decent data
%    structure.\footnote{FIX!!}
%    \begin{macrocode}
    \ifnum \this@area@span@number = \if!\this@span@number! 1\else  % big hack
                                    \this@span@number \fi
                                    \relax
%<*trace>
      \tr@ce{span~ count~ okay:~ \this@area \space =~ 
             \if!\this@span@number! 1\else  % big hack
                                    \this@span@number \fi}
%</trace>
%    \end{macrocode}
%
%    \begin{macrocode}
      \ifnum \pagesetup@max@float@num > \page@float@count
%    \end{macrocode}
%
%    \begin{macrocode}
        \ifnum\csname pagesetup@\this@area @float@num\endcsname =
              \csname \this@area @float@count \endcsname
%
%    \end{macrocode}
%    Current area doesn't accept any more floats, so try next one (if any)
%    \begin{macrocode}
%<*trace>
          \tr@ce{close~area:~\this@area\space float~num~reached ~
                 (\csname pagesetup@\this@area @float@num\endcsname)}
%</trace>
%<*progress>
          \progress@failed{\this@area\space float~num~reached ~
                 (\csname pagesetup@\this@area @float@num\endcsname)}
%</progress>
          \do@next\try@next@area
%    \end{macrocode}
%
%    \begin{macrocode}
        \else
          \xin@\this@area
               \this@page@closed
          \ifin@
%<*trace>
            \tr@ce{area~ closed~ for~ all~ types;~ member~ of~
                   (\this@page@closed)}
%</trace>
%<*progress>
            \progress@failed{area~ closed~ for~ all~ types}
%</progress>
            \do@next\try@next@area
          \else
%<*trace>
            \tr@ce{area~ not~ closed~ for~ all~ types:~ not~ member~ of~
                   (\this@page@closed)}
%</trace>
            \xin@\this@area
                 \this@closed@areas
            \ifin@
%<*trace>
              \tr@ce{area~ closed~ for~ class~ \this@class;~ member~ of~
                     (\this@closed@areas)}
%</trace>
%<*progress>
              \progress@failed
                    {area~ closed~ for~ class~ \this@class}
%</progress>
              \do@next\try@next@area
            \else
%<*trace>
              \tr@ce{area~ open~ for~ class~ \this@class;~ not~ member~ of~
                     (\this@closed@areas)}
%</trace>
              \xin@\this@area\this@fps
              \ifin@
%
                \append@caption@to@float
                \construct@and@test@col@hts
                \if@test
                  \do@next\try@next@area
                \else
                  \do@next\pretests@success@action
                \fi

              \else
%<*trace>
                \tr@ce{close~area:~\this@area\space float~not~allowed~
                       by~ user~ control~ (\this@fps)}
%</trace>
%<*progress>
                \progress@failed{\this@area\space float~not~allowed~
                       by~ user~ control~ (\this@fps)}
%</progress>
                \do@next\try@next@area
              \fi
            \fi
          \fi
        \fi
      \else
% defer
        \global\let\this@open@areas\@empty
%<*trace>
        \tr@ce{defer:~max~float~num~reached ~(\pagesetup@max@float@num)}
%</trace>
%<*progress>
        \progress@failed{max~float~num~reached ~(\pagesetup@max@float@num)}
%</progress>
        \do@next\defer@and@try@next@float
      \fi
    \else
%<*trace>
      \tr@ce{span~ count~ unsuitable:~ \this@area \space /=~ 
             \if!\this@span@number! 1\else  % big hack
                                    \this@span@number \fi}
%</trace>
%<*progress>
      \progress@failed{span~ count~ \this@area \space /=~ 
             \if!\this@span@number! 1\else  % big hack
                                    \this@span@number \fi}
%</progress>
      \do@next\try@next@area
    \fi
  \fi
%<*trace>
  \@tracepop{std@try@this@area}
%</trace>
  \do@continue
}
%    \end{macrocode}
% \end{macro}
%
%
%
%
% \begin{macro}{\do@next}
%    Emergency macro to reduce the number of input levels (as the code
%    got past the internal default of 300). This is because we have a
%    lot of recursion going on without being tail
%    recursion. Essentially this means some of the code needs slightly
%    different implementation.\footnote{fix}
%    \begin{macrocode}
\def\do@next{\let\do@continue}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\relaxed@try@this@area}
%    \begin{macrocode}
\def\relaxed@try@this@area{
%<*trace>
  \@tracepush{relaxed@try@this@area}
%</trace>
%    \end{macrocode}
%    If all areas for the float type are closed we have to defer this float.
%    \begin{macrocode}
  \ifx\this@open@areas\@empty
%<*trace>
        \tr@ce{defer:~no~open~area~ available}
%</trace>
        \do@next\defer@and@try@next@float
  \else
%    \end{macrocode}
%    Otherwise the next area to try is the first of |\this@open@areas|:
%    \begin{macrocode}
    \setup@this@area{\expandafter\@carcube\this@open@areas\@nil}
%<*trace>
    \tr@ce{area~trial:~ \this@area}
%</trace>
%<*progress>
    \progress{~ area~trial:~ \this@area}
%</progress>
%    \end{macrocode}
%    Next test needs cleanup once the span has a decent data
%    structure.\footnote{FIX!!}
%    \begin{macrocode}
    \ifnum \this@area@span@number = \if!\this@span@number! 1\else  % big hack
                                    \this@span@number \fi
                                    \relax
%<*trace>
      \tr@ce{span~ count~ okay:~ \this@area \space =~ 
             \if!\this@span@number! 1\else  % big hack
                                    \this@span@number \fi}
%</trace>
%    \end{macrocode}
%
%    \begin{macrocode}
      \xin@\this@area\this@page@closed
      \ifin@
%<*trace>
        \tr@ce{area~ closed~ for~ all~ types;~ member~ of~
               (\this@page@closed)}
%</trace>
%<*progress>
            \progress@failed{area~ closed~ for~ all~ types}
%</progress>
        \do@next\try@next@area
      \else
%<*trace>
        \tr@ce{area~ not~ closed~ for~ all~ types:~ not~ member~ of~
               (\this@page@closed)}
%</trace>
        \xin@\this@area
             \this@closed@areas
        \ifin@
%<*trace>
          \tr@ce{area~ closed~ for~ class~ \this@class;~ member~ of~
                 (\this@closed@areas)}
%</trace>
%<*progress>
          \progress@failed
                    {area~ closed~ for~ class~ \this@class}
%</progress>
          \do@next\try@next@area
        \else
%<*trace>
          \tr@ce{area~ open~ for~ class~ \this@class;~ not~ member~ of~
                 (\this@closed@areas)}
%</trace>
          \append@caption@to@float
          \construct@and@test@col@hts
          \if@test
            \do@next\try@next@area
          \else
            \do@next\pretests@success@action
          \fi
        \fi
      \fi
    \else
%<*trace>
      \tr@ce{span~ count~ unsuitable:~ \this@area \space /=~ 
             \if!\this@span@number! 1\else  % big hack
                                    \this@span@number \fi}
%</trace>
%<*progress>
      \progress@failed{span~ count~ \this@area \space /=~ 
             \if!\this@span@number! 1\else  % big hack
                                    \this@span@number \fi}
%</progress>
      \do@next\try@next@area
    \fi
  \fi
%<*trace>
  \@tracepop{relaxed@try@this@area}
%</trace>
  \do@continue
}
%    \end{macrocode}
% \end{macro}
%
%
%
%
% \begin{macro}{\construct@and@test@col@hts}
%    The |\construct@and@test@col@hts| loops over all columns
%    affected by the float area we want to place our float into
%    and reduces the column size as
%    needed. It sets the switch |@test| to true in case the float
%    doesn't fit into area for some reason. It is up to the calling
%    macro to take proper action in this case (including resetting
%    column heights to their former values).
%    \begin{macrocode}
\def\construct@and@test@col@hts {
%    \end{macrocode}
%    We use the information from the area not from the float (which
%    allows us to put small floats into larger areas.
%    \begin{macrocode}
  \update@this@area@columns
     {
      \expandafter
      \construct@and@test@col@ht
         \csname col@ht@ \the\count@ \endcsname
         {\the\count@}
%    \end{macrocode}
%    We need to break out of the updating loop if we found a column that
%    doesn't work, a) to save time and b) since the
%    |\construct@and@test@col@ht| resets the switch again to false
%    (in the current implementation).
%    \begin{macrocode}
      \if@test
         \count@\z@   % break out of loop
      \fi
     }
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\construct@and@test@col@ht}
%    The |\construct@and@test@col@ht| reduces the height of one column
%    by the size of the current float (plus some suitable extra space)
%    and tests if this reduction is possible/allowed. It sets the
%    switch |@test| to true if it encounters a problem.
%    \begin{macrocode}
\def\construct@and@test@col@ht#1#2{
%<*trace>
  \tr@ce{col height~before:~ \the#1 (\string#1)}
%</trace>
%    \end{macrocode}
%    In |\@tempdima| we calculate the amount of space we need if we
%    place the float. This is the size of the float, i.e., its height
%    and depth, plus either |\pagesetup@float@text@sep| if this is the
%    very first float in this column (on top or on bottom), or
%    |\pagesetup@float@area@sep| if it is the first float in the
%    current area, or |\pagesetup@float@float@sep| if we already have
%    floats in this area.
%    \begin{macrocode}
  \@tempdima          \ht\this@captioned@float
  \advance \@tempdima \dp\this@captioned@float
  \ifnum \csname col@ \this@area@type
                  @floats@#2@number\endcsname
          = \z@
%<*trace>
       \tr@ce{first~ float~ in~ any~ \this@area@type\space 
              in~ column~ #2:~
              adding~ \string\pagesetup@float@text@sep
              =\the\pagesetup@float@text@sep}
%</trace>
    \advance \@tempdima \pagesetup@float@text@sep
  \else
    \advance \@tempdima
      \expandafter
      \ifx \csname area@\this@area\endcsname\@empty 
         \pagesetup@float@area@sep
%<*trace>
         \tr@ce{first~ float~ in~ \this@area :~
                adding~ \string\pagesetup@float@area@sep
                =\the\pagesetup@float@area@sep}
%</trace>
      \else 
         \pagesetup@float@float@sep 
%<*trace>
         \tr@ce{additional~ float~ in~ \this@area :~
                adding~ \string\pagesetup@float@float@sep
                = \the\pagesetup@float@float@sep}
%</trace>
      \fi
  \fi
%    \end{macrocode}
%    Now we make the area size fully fall into the page grid (if there
%    is one). To do this we first substract any delta that has been
%    accumulated for the column (to get back to the real size) and
%    then run |\snap@to@grid| to get the next grid point.
%    \begin{macrocode}
  \advance \@tempdima 
          -\csname col@ \this@area@type @delta@ #2 \endcsname \relax
%    \end{macrocode}
%    The |\col@|\meta{area-type}|@delta@|\meta{col} are macros but
%    fortunately low-level \TeX{} supports register assignments of the
%    form |--3pt| so the above will work even if the macro contains a
%    negative value.
%    \begin{macrocode}
  \snap@to@grid  \@tempdima \pagesetup@grid@point@sep
%    \end{macrocode}
%
%    If the distance to the next grid point is larger than the
%    distance to the previous one, and if the space between floats and
%    text is allowed to shrink by the needed amount we will use the
%    previous grid point.
%    \begin{macrocode}
  \ifdim \returned@lower@delta@size < \returned@delta@size \relax
    \ifdim \returned@lower@delta@size < \pagesetup@float@text@shrink
%<*trace>
      \tr@ce{GRID:~ column~#2:~ choosing~ lower~ grid~ point}
%</trace>
%    \end{macrocode}
%    We do this by copying the |\returned@lower@...| to the macros
%    used below. Note that for the delta size we have to use the
%    negation since we want to backup by this amount and delta sizes
%    are always given in absolute values.
%    \begin{macrocode}
      \global\let \returned@size \returned@lower@size
      \xdef \returned@delta@size {-\returned@lower@delta@size }
    \fi
  \fi
%<*trace>
  \tr@ce{GRID:~ column~#2:~ \the\@tempdima\space ->~ \returned@size}
%</trace>
  \@tempdima \returned@size
%    \end{macrocode}
%    
%    After updating |\@tempdima| in this way we now have to check if
%    the space remaining for the text column is large enough.
%    \begin{macrocode}
  \@tempdimb#1
  \advance \@tempdimb -\@tempdima
  \@testfalse
  \ifdim \textminlines\baselineskip > \@tempdimb 
%    \end{macrocode}
%    If not we bail out
%    \begin{macrocode}
     \@testtrue
%<*trace>
     \tr@ce{close~area:~\this@area\space not~ enough~ text~ lines~
       left~
       (\textminlines x\the\baselineskip> \the\@tempdimb)}
%</trace>
%<*progress>
     \progress@failed{not~ enough~ text~ space~
       (\textminlines x\the\baselineskip\space
        >~ \the\@tempdimb)}
%</progress>
  \else
%    \end{macrocode}
%    Otherwise we have to update the column heights (and their saved
%    version in case we back out later) as well as storing the new
%    delta (which is still in |\returned@delta@size|).
%    \begin{macrocode}
%<*trace>
     \tr@ce{saved@col@ht@ #2~ <-~\the#1}
%</trace>
     \expandafter\xdef
        \csname saved@col@ht@ #2\endcsname{\the#1}
     \global#1\@tempdimb
     \global\expandafter\let
        \csname saved@col@ \this@area@type @delta@ #2 \expandafter \endcsname
        \csname col@ \this@area@type @delta@ #2 \endcsname
     \global\expandafter\let
        \csname col@ \this@area@type @delta@ #2 \endcsname
        \returned@delta@size
%<*trace>
     \tr@ce{GRID (delta):~ column~#2\this@area@type:~
        \csname saved@col@ \this@area@type @delta@ #2 
        \endcsname\space ->~ \returned@delta@size}
%</trace>
  \fi
%<*trace>
  \tr@ce{col height~after:~ \the#1}
%</trace>
}
%    \end{macrocode}
% \end{macro}
%
%    
% \begin{macro}{\textminlines}
%    Tmp definition; should be interfaced to pagesetup.
%    \begin{macrocode}
\def\textminlines{4}
%    \end{macrocode}
% \end{macro}
%
%    
%
% \subsection{Supporting grid based designs}
%
%
%
% \begin{macro}{\pagesetup@grid@point@sep}
%    |\pagesetup@grid@point@sep| is the distance between grid points
%    for page design or 0pt if we are not doing grid design.
%    \begin{macrocode}
\let\pagesetup@grid@point@sep\ERROR
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\snap@to@grid}
%    |\snap@to@grid| takes a dimension as first argument and a
%    ``grid-size'' as second argument and from those two values
%    calculates a new dimension which is a multiple of the grid-size
%    and equal or larger than the first argument.
%
%    It returns this calculated value globally in |\returned@size|. In
%    addition it will return in |\returned@delta@size| the delta
%    between the original and the new dimension.
%
%    It also returns a lower or equal grid point in
%    |\returned@lower@size| and the delta to it (absolute value) in
%    |\returned@lower@delta@size|. 
%
%    Thus the first argument lies on a grid point if and only if
%    |\returned@size| equals |\returned@lower@size|.
%
%    If we are not doing grid typesetting then |\snap@to@grid| is
%    actually a dummy which will return always the first argument in
%    |\returned@size| and |\returned@lower@size|, and |0pt| in the
%    deltas.
%
%    The actual definition is assigned within the page setup.
%    \begin{macrocode}
\let\snap@to@grid\ERROR
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\dummy@snap@to@grid}
%    In case we don't do grids we simply pretend that all sizes lie on
%    grid points.
%    \begin{macrocode}
\def \dummy@snap@to@grid #1#2{
   \begingroup
%    \end{macrocode}
%    Definitions below can be optimised for speed but the ones used
%    give better tracing.
%    \begin{macrocode}
     \@tempdima #1 \relax
     \xdef \returned@size { \the\@tempdima }
     \global\let \returned@lower@size \returned@size
     \gdef \returned@delta@size {0pt}
     \global\let \returned@lower@delta@size  \returned@delta@size
   \endgroup
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\std@snap@to@grid}
%    But if we do grid typesetting we have to do a bit more work
%    here.
%    \begin{macrocode}
\def \std@snap@to@grid #1#2{
%    \end{macrocode}
%    Everything is done in a group so that the register change do not
%    affect other parts of the code.
%    \begin{macrocode}
  \begingroup
%    \end{macrocode}
%    First we calculate in |\@tempdimc| the nearest grid point which
%    is smaller or equal to the given size in |#1| by using scaled
%    point arithmetic.
%    \begin{macrocode}
     \@tempdima #1\relax
     \@tempdimb #2\relax
     \@tempcnta \@tempdima      % orig size in sp
     \@tempcntb \@tempdimb      % grid size in sp
     \divide \@tempcnta \@tempcntb
     \@tempdimc \@tempcnta\@tempdimb
%    \end{macrocode}
%    If the calculated grid point is smaller than the original
%    dimension use the next larger one. But record the other in
%    |\returned@lower@size|.
%    \begin{macrocode}
     \ifdim \@tempdimc < \@tempdima
       \xdef \returned@lower@size { \the\@tempdimc }
       \advance\@tempdimc \@tempdimb 
     \fi
%    \end{macrocode}
%    The |\returned@size| will be whatever the result of the above is
%    and |\returned@delta@size| the difference to the given value in
%    |#1|. Note that |\returned@size| will always be larger or equal
%    to this value so the difference computed below will also be
%    non-negative!
%    \begin{macrocode}
     \xdef \returned@size { \the\@tempdimc }
     \advance \@tempdimc -\@tempdima
     \xdef \returned@delta@size { \the\@tempdimc }
%    \end{macrocode}
%    Now if this difference turns out to be zero then we actually
%    started with a dimension exactly on a grid point. In this case we
%    better define both |\returned@lower@size| and
%    |\returned@lower@delta@size| to equal their counterparts.
%    \begin{macrocode}
     \ifdim \@tempdimc = \z@
       \global \let \returned@lower@size \returned@size
       \global \let \returned@lower@delta@size \returned@delta@size
%    \end{macrocode}
%    Otherwise we only have to compute |\returned@lower@delta@size|
%    since in that case we already recorded |\returned@lower@size|
%    above (and we better had since by now we lost this information as
%    we reused |\@tempdimc|). Now the value for this macro should be
%    the difference between |\returned@delta@size| and our grid size
%    both of which are already stored in some temp registers,
%    thus\ldots
%    \begin{macrocode}
     \else
       \advance\@tempdimb-\@tempdimc
       \xdef \returned@lower@delta@size { \the\@tempdimb }
     \fi
  \endgroup
%<*trace>
  \tr@ce{GRID:~ \string\returned@lower@size=\returned@lower@size}
  \tr@ce{GRID:~ \string\returned@lower@delta@size=\returned@lower@delta@size}
  \tr@ce{GRID:~ \string\returned@size=\returned@size}
  \tr@ce{GRID:~ \string\returned@delta@size=\returned@delta@size}
%</trace>
}
%    \end{macrocode}
% \end{macro}
%
%
%
%
%
% \subsection{Deferring a float}
%
%
%
% \begin{macro}{\really@defer@and@try@next@float}
%    \begin{macrocode}
\def\really@defer@and@try@next@float{
%<*progress>
        \progress@failed{-->~ defer}
        \progress@nl{}
%</progress>
      \@cons\area@ddd\this@float@box
%<*trace>
      \tr@ce{this@page@closed~ <-~ "\this@page@closed"~ +~
             "\pagesetup@ddd@all@close"}
%</trace>
      \xdef\this@page@closed{\this@page@closed,
                 \pagesetup@ddd@all@close}

      \ifx\pagesetup@ddd@class@close\pagesetup@area@list
%<*trace>
        \tr@ce{this@closed@areas~ <-~ 
               "\pagesetup@ddd@class@close"~ (all~ closed)}
%</trace>
        \global\let\this@closed@areas\pagesetup@ddd@class@close
      \else
%<*trace>
        \tr@ce{this@closed@areas~ <-~ "\this@closed@areas"~ +~
               "\pagesetup@ddd@class@close"}
%</trace>
        \xdef\this@closed@areas{\this@closed@areas,
                   \pagesetup@ddd@class@close}
      \fi

      \global\expandafter\let\csname closed@\this@class
                                     @areas\endcsname % FMi tmp
                             \this@closed@areas
      \try@next@float
}
%    \end{macrocode}
% \end{macro}
% 
%    
%
% \begin{macro}{\defer@and@try@next@float}
%
%    This code either defers the current float and restarts by calling
%    |\try@next@float| or recurses after relaxing the placement
%    conditions (in case the current float should be flushed).
%
%    If the placement conditions are already relaxed we move the first
%    flush point that affects the current float one column forward and
%    then retry. This might result in succeding to place the float, if
%    not it will ultiamtely result in the flush point being moved from
%    the page at which point the float can be deferred.
%
%    \begin{macrocode}
\def\defer@and@try@next@float{
%<*trace>
  \@tracepush{defer@and@try@next@float}
%</trace>
%    \end{macrocode}
%    If there have been no flush points or if the flush points seen do
%    not affect the current float we can immediately defer it.
%    \begin{macrocode}
  \if@flushseen
    \xin@\this@class\flush@classes@list@max
    \ifin@
%<*trace>
      \tr@ce{flush:~ class~ \this@class\space in~
             \flush@classes@list@max}
%</trace>
%    \end{macrocode}
%    First test is just there to avoid doing any of the loops 
%    (might not be worth having)
%    \begin{macrocode}
      \ifnum \csname flush@min@col@1\endcsname > \curr@col@count
%<*trace>
        \tr@ce{flush:~ no~ flush~ points~ on~ page;~ defer}
%</trace>
        \do@next\really@defer@and@try@next@float
      \else
%    \end{macrocode}
%    
%    The code is often invoked before there is an attempt to split the
%    galley; this means we don't know which flush point affects the
%    current float and thus have to manually get at it.
%
%    So we loop through the |\flush@last@float@|\meta{num} values to
%    find the first one that a) affects the current float type and b)
%    holds a sequence number that is higher or equal to the sequence
%    number of the current float.
%    \begin{macrocode}
        \count@ \@ne
        \loop
%    \end{macrocode}
%    If |\count@| is greater than |\flush@seq@num| we have exhausted
%    all possible flush points without finding a candidate.
%    \begin{macrocode}
          \ifnum \flush@seq@num < \count@ 
            \in@false
          \else
%    \end{macrocode}
%    Otherwise, if |\this@sequence@number| is greater than
%    |\flush@last@float@|\meta{num} the current flush point is before
%    the call-out to the current float.
%    \begin{macrocode}
%<*trace>
            \tr@ce{flush:~  \this@sequence@number \space ???~
                   \csname flush@last@float@ \the\count@ \endcsname}
%</trace>
            \ifnum \this@sequence@number >
                   \csname flush@last@float@ \the\count@ \endcsname
                   \relax
%    \end{macrocode}
%    We set |\in@true| to get a repeat below with a new value of
%    |\count@|.
%    \begin{macrocode}
              \in@true
            \else
%    \end{macrocode}
%    Otherwise we have a flush point that is later in the galley in
%    comparison to the call-out of the current float thus potentially
%    affects it. Therefore we now have to check if the sequence class
%    of the current float is affected by the flush point found:
%    \begin{macrocode}
              \expandafter\xin@\expandafter\this@class
              \csname flush@classes@list@ \the\count@ \endcsname
%    \end{macrocode}
%    Now we could make good use of the |\unless| primitive of
%    e\TeX. But since we want to run with standard \TeX{} and don't
%    have |\xnotin@| available we invert the result.
%    \begin{macrocode}
              \ifin@ 
                \in@false 
              \else 
                \in@true
%<*trace>
                 \tr@ce{flush:~ class~ \this@class\space not~ in~ 
                   \csname flush@classes@list@ \the\count@ \endcsname
                   \space (ignored)
                   }
%</trace>
              \fi
            \fi
          \fi
        \ifin@
          \advance\count@\@ne
        \repeat
%<*trace>
        \tr@ce{flush:~ first~ float~ point~ after~ float~ =~
               \the\count@}
%</trace>
        \ifnum \flush@seq@num < \count@
%<*trace>
          \tr@ce{flush:~ this~ float~ past~all~flush~ points;~ defer}
%</trace>
          \do@next\really@defer@and@try@next@float
        \else
%    \end{macrocode}
%    Once a |flush@min@col| is larger than |\curr@col@count| it has
%    moved to the next page. In particular this is true for the
%    artificial value |\maxdimen| to which it is sometimes set to
%    denote this fact. If so we can defer our float.
%    \begin{macrocode}
          \ifnum \csname flush@min@col@\the\count@\endcsname 
               > \curr@col@count
%<*trace>
            \tr@ce{flush:~ float~ past~ all~ flush~ points~
                   on~ current~ page;~ defer}
%</trace>
            \do@next\really@defer@and@try@next@float
          \else
%    \end{macrocode}
%    If we have already relaxed the conditions and we are still in
%    conflict with a flush point on the current page we nearly ran out
%    of options. In this case we are forced to move the flush point,
%    but rather than moving it to the next page and defering the float
%    we can move it one column further (which might make it fall off
%    the page though) and then retry to place the float since we have
%    now more space available.
%    \begin{macrocode}
            \ifx\try@this@area\relaxed@try@this@area
%<*trace>
              \tr@ce{flush:~ defer~ forced;~ move~ 
                     flush~ point~ columns}
%</trace>
%<*progress>
              \progress@nl{}
              \progress@nl{Flushing~ impossible~ -->~ breaking~
                           before~ flush~ point~ and~ retry}
%</progress>
%    \end{macrocode}
%    We should only increment the |flush@min@col@| value of the first
%    flush point that affects our float (this will automatically move
%    later flush points if necessary). Incrementing the later ones is
%    incorrect as they might not need moving!
%    \begin{macrocode}
              \expandafter \gincrement@num
                 \csname flush@min@col@ \the\count@ \endcsname
%<*trace>
              \tr@ce{flush@min@col@\the\count@ \space <-~ 
                     \csname flush@min@col@ \the\count@ \endcsname
                     }
%</trace>
%<*progress>
              \progress@nl{}
              \progress@nl{Defer~ impossible~ -->~ moving~
                           flush~ point~ to~ column~
                           \csname flush@min@col@ \the\count@\endcsname
                           \space
                           and~ retry}
%</progress>
%    \end{macrocode}
%    Not clear that it is really necessary to check all areas again,
%    but it is late (after midnight) and it is definitely not
%    wrong.\footnote{Check!}
%    \begin{macrocode}
              \relax@float@placement@conditions  % needed to reset open areas
              \do@next\try@this@area

            \else
%    \end{macrocode}
%
%    \begin{macrocode}
              \relax@float@placement@conditions
              \do@next\try@this@area
            \fi
          \fi
        \fi
      \fi
    \else
%<*trace>
      \tr@ce{flush:~ class~ \this@class\space not~ in~
             \flush@classes@list@max;~ defer}
%</trace>
      \do@next\really@defer@and@try@next@float
    \fi

  \else
%<*trace>
    \tr@ce{flush:~ no~ flush~ point~ seen; defer}
%</trace>
    \do@next\really@defer@and@try@next@float
  \fi

%<*trace>
  \@tracepop{defer@and@try@next@float}
%</trace>
  \do@continue
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\relax@float@placement@conditions}
%    \begin{macrocode}
\def \relax@float@placement@conditions {
%<*progress>
    \progress@failed{-->~ retry~ with~ relaxed~ conditions}
    \progress@nl{}
%</progress>
%<*trace>
    \tr@ce{flush:~relax~placement~conditions}
%</trace>
    \global\let\try@this@area\relaxed@try@this@area
% next line perhaps external?
    \global\let\this@open@areas\saved@this@open@areas

    \global\let\check@some@constraints\relaxed@check@some@constraints
    \global\let\check@callout@constraints\relaxed@check@callout@constraints
    \global\let\calculate@target@fl@column\relaxed@calculate@target@fl@column
}
%    \end{macrocode}
% \end{macro}
%    
% \begin{macro}{\tighten@float@placement@conditions}
%    \begin{macrocode}
\def\tighten@float@placement@conditions {
%<*trace>
    \tr@ce{flush:~tighten~placement~conditions}
%</trace>
    \global\let\try@this@area\std@try@this@area

    \global\let\check@some@constraints\std@check@some@constraints
    \global\let\check@callout@constraints\std@check@callout@constraints
    \global\let\calculate@target@fl@column\std@calculate@target@fl@column
}
%    \end{macrocode}
% \end{macro}
%
%
%    
% \begin{macro}{\partly@tighten@float@placement@conditions}
%    This is used when we have placed the last float that is affected
%    by a certain flush point. We don't want to tighten up completely
%    since this would essentially mean that we can't place any further
%    floats since callout relationships etc might be violated for
%    them. Good question is whether or not the last restriction should
%    be used again since this too might prevent any further placements.
%    \begin{macrocode}
\def\partly@tighten@float@placement@conditions {
%<*trace>
    \tr@ce{flush:~partly~tighten~placement~conditions}
%</trace>
    \global\let\try@this@area\std@try@this@area

%    \global\let\check@some@constraints\std@check@some@constraints
%    \global\let\check@callout@constraints\std@check@callout@constraints
    \global\let\calculate@target@fl@column\std@calculate@target@fl@column
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Checking float placement during trial}
%
% The interface to checking float placement in relation to its callout
% is the following piece of code in |\grab@column@or|:
%\begin{verbatim}
%   \let\@elt\check@callout@constraints
%   \float@classes@list
%\end{verbatim}
% This loops through all float types and executes
% |\check@callout@constraints| with the float type as an argument. The output
% routine |\grab@column@or| itself is called for each column of a trial
% configuration, thus the above loop is called for each column
% individually (|\curr@col@count| can be used to determine the current
% column number).
%
% By giving |\check@callout@constraints| an appropriate definition a
% pagesetup template can implement different relationships between
% callout and float.
%
% Possible tests (getting stronger):
% \begin{itemize}
%
% \item
%   Don't check, i.e., add the float when you find it and it fits
%   according to other criteria (like number of floats in the area,
%   etc.). This is implemented in |\check@callout@none|.
%
%
% \item
%  Check if callouts for all floats on the page (not column) are
%  either on the same page or on an earlier page; i.e., callout can be
%  late as long as the float is visible from the callout.
%
%   Fail if for last column and all float types:
%     last callout number for float type is smaller than maximum last float
%     of type put into any column.\footnote{This description is
%     probably wrong}
%
%   This is implemented in |\check@callout@page|.
%
% \item
%  Check if callouts for all floats in the column are either on the
%  same column or on an earlier column.
%
%  Fail if for any column and any float type:
%  last callout number for float type is smaller last float sequence
%  number for type recorded for this column.
%
%  This case consists in fact of two subcases depending on how we
%  interpret to which column a spanning float belongs. If we claim
%  that a spanning float is placed into its starting column, then we
%  fail if its call-out is in a later column even though this column
%  might still be spanned by the float area.
%
%  This is implemented in |\check@callout@column|.
%
% \item
%  Check if callouts for all floats in the column are on an earlier
%   column or if on the same column the float was added to the bottom
%   (or marginal) area; i.e. strict float/callout order
%
%   Fail if for each type and for any column:
%     `top' callout number  less than `top' float number  
%      (at top of text column)
%\begin{verbatim}    
%      [Corectness proof: 
%       TRUE  => first callout's float comes before bottom
%                  and so comes too early 
%             => FAIL
%       FALSE => first callout's float comes in bottom and all other
%                  callouts come later and so are in bottom or beyond 
%             => OK
%       ]
%\end{verbatim}
%   The proof above is in fact only valid if you look at the whole
%   document and not only at a single page since a float in the bottom
%   area of the last column with its callout on the next page will
%   only be detected when testing the next page. Therefore one needs
%   an additional check of type |\check@callout@column|.
%
%   This is implemented in |\check@callout@after|.
%
%
% \end{itemize}
%
%
% \begin{macro}{\check@callout@none}
%    This test is an easy one: just do nothing, i.e., gobble the argument.
%    \begin{macrocode}
\let\check@callout@none\@gobble
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\check@callout@page}
%    We are are only interested in the callout/float relation per page
%    we only have to do a check when producing the last column, i.e.,
%    when |\curr@col@count| is |\col@count|.
%    \begin{macrocode}
\def\check@callout@page#1{
%<*trace>
  \@tracepush{check@callout@page}
%</trace>
  \ifnum\curr@col@count=\col@count
%    \end{macrocode}
%    We store in |\fl@max| the highest sequence number for floats of
%    the current type up to the end of the page. For this we have to
%    find the maximum of |\fl@0@|\meta{type} (highest float number on
%    previous pages) and those for the columns, e.g.,  
%    |\fl@|\meta{colnum}|@|\meta{type}; this is done by the following
%    code:
%    \begin{macrocode}
    \global\expandafter\let\expandafter\fl@max
                       \csname fl@0@#1\endcsname
    \forall@columns {
      \ifnum\csname fl@\the\curr@col@count @#1\endcsname>\fl@max\relax
         \xdef\fl@max{\csname fl@\the\curr@col@count @#1\endcsname}
      \fi
    }
%    \end{macrocode}
%    We then store the number of the last callout in |\count@|; the
%    |0| will take care of the potential problem that there was never any
%    callout so far. And we better have a |\relax| afterwards since
%    otherwise we will expand the |\ifnum| before we have finished
%    assigning the |\count@|.
%    \begin{macrocode}
    \count@0\LastMark{#1}\relax
%<*trace>
    \tr@ce{Last~callout~ (#1)~ =~ \the\count@}
%</trace>
%    \end{macrocode}
%    Now we have to compare those two numbers to find out if that
%    trial has failed:
%    \begin{macrocode}
    \ifnum\count@<\fl@max\relax
      \@failtrue
%<*progress>
    \progress@failed{last~callout~
       \the\count@\space~<~\fl@max
       \space last~float~put~on~page~or~ earlier}
%</progress>
%<*trace>
    \tr@ce{Failed:~(#1)~ last~callout~
       \the\count@\space~<~\fl@max
       \space last~float~put~on~page~or~ earlier}
    \else
    \tr@ce{OK:~(#1)~ last~callout~
       \the\count@\space~>=~\fl@max
       \space last~float~put~on~page~or~ earlier}
%</trace>
    \fi
  \fi
%<*trace>
  \@tracepop{check@callout@page}
%</trace>
}
%    \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\fl@max}
%    The macro |\fl@max| is used within |\check@callout@page| to hold
%    the highest sequence number of any allocated float on the current
%    page for the type under testing.  It will be recalculated on
%    each pass.\footnote{One could generate this value while running through
%    the trials --- this would perhaps be a bit more time efficient.}
%    \begin{macrocode}
\let\fl@max\ERROR
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\check@callout@column}
%    Checking each column separately means we have to compare for each
%    type the last callout on this or previous columns (i.e., as
%    returned by |\LastMark|) with the highest sequence number for
%    floats of this type in the current column (as stored in
%    |fl@|\meta{col}|@|\meta{type}). So we first store the callout
%    info in |\count@|.
%    \begin{macrocode}
\def\check@callout@column#1{
%<*trace>
  \@tracepush{check@callout@column}
%</trace>
  \count@0\LastMark{#1}\relax
%    \end{macrocode}
%    Then we do the test. If there are no floats of the current type
%    in the current column |\fl@|\meta{col}|@|\meta{type} will be zero
%    and thus the following test will come out true. This is the
%    correct behaviour as any callouts that might be present will be
%    correctly evaluated in tests on neighboring columns with floats. 
%    \begin{macrocode}
  \ifnum\count@<\csname fl@\the\curr@col@count @#1\endcsname\relax
%<*progress>
  \progress@failed{last~ callout~
         \the\count@\space <~
         \csname fl@\the\curr@col@count @#1\endcsname
         \space last~ float~ placed~ in~ column~ \the\curr@col@count}
%</progress>
%<*trace>
  \tr@ce{Failed:~(#1)~ last~ callout~
         \the\count@\space <~
         \csname fl@\the\curr@col@count @#1\endcsname
         \space last~float~placed}
%</trace>
%    \end{macrocode}
%    If the test fails we abort this trial by setting the switch
%    |@fail| to true. We also set
%    |\curr@col@count| to |\col@count| which will save us any further
%    iteration (in case this wasn't the last column). Finally we
%    locally set |\@elt| to |\@gobble| which will essentially about
%    the current loop through the |\float@classes@list|.
%    \begin{macrocode}
    \@failtrue
    \global\curr@col@count\col@count
    \let\@elt\@gobble
%    \end{macrocode}
%    Otherwise the constraints for callout of current float type are
%    met so we report this fact if we do tracing.
%    \begin{macrocode}
%<*trace>
  \else
  \tr@ce{OK:~(#1)~ last~ callout~
         \the\count@\space >=~
         \csname fl@\the\curr@col@count @#1\endcsname
         \space last~float~placed}
%</trace>
  \fi
%<*trace>
  \@tracepop{check@callout@column}
%</trace>
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\check@callout@after}
%
%    \begin{macrocode}
\def\check@callout@after#1{
%<*trace>
  \@tracepush{check@callout@after}
%</trace>
%    \end{macrocode}
%
%    We first check if all floats are either on the same column than
%    their callout or on an later column by calling
%    |\check@callout@column|. If this returns |@fail| we immediately
%    abort any further processing.
%    \begin{macrocode}
  \check@callout@column{#1}
  \if@fail\else
%    \end{macrocode}
%
%    If the above check found no violation we have to check for top
%    area floats that might preceed their callouts.
%
%    For this we look at the value of the
%    |\tfl@|\meta{col}|@|\meta{float-type} macro which holds the
%    highest float sequence number for floats of this type allocated
%    in that column.
%    \begin{macrocode}
     \global\expandafter\let\expandafter
            \returned@sequence@number
            \csname tfl@\the\curr@col@count @#1\endcsname
%    \end{macrocode}
%    
%    If there was no float in the top area we get |0| back and in
%    that case we are done since all our constraints are met.
%    \begin{macrocode}
     \ifnum \returned@sequence@number = \z@
%<*trace>
     \tr@ce{OK:~(#1)~ top~ areas~ have~ no~ floats}
%</trace>
    \else
%    \end{macrocode}
%
%    Otherwise we have to look at the top callout number and compare
%    it to the last float number of the top area.
%    \begin{macrocode}
      \count@ 0\PreviousMark{#1}\relax
%    \end{macrocode}
%    If that callout number is less than the last float number we
%    failed since this means that there is a float in the top area
%    which callout has not yet been seem. So we abort the
%    trial. Otherwise our constraints are met.
%    \begin{macrocode}
      \ifnum \count@ < \returned@sequence@number \relax
%    \end{macrocode}
%    But before aborting we give some information on why we
%    failed. This has to come first since we change |\curr@col@count|
%    below.
%    \begin{macrocode}
%<*progress>
        \progress@failed{top~ callout~
              \the\count@\space <~ \returned@sequence@number
              \space last~ float~ put~ in~ top~ 
              of~ column~ \the\curr@col@count}
%</progress>
        \@failtrue
        \global\curr@col@count\col@count
        \let\@elt\@gobble
%<*trace>
        \tr@ce{Failed:~(#1)~ top~ callout~
              \the\count@\space <~ \returned@sequence@number
              \space last~float~put~in~top}
      \else
        \tr@ce{OK:~(#1)~ top~ callout~
               \the\count@\space >=~ \returned@sequence@number
              \space last~float~put~in~top}
%</trace>
      \fi
    \fi
  \fi
%<*trace>
  \@tracepop{check@callout@after}
%</trace>
}
%    \end{macrocode}
% \end{macro}
%
%
%
%
% \subsection{Checking bottom float footnote constraints}
%
% In |\grab@column@or|, the output routine that grabs a single column
% during a trial, we have the command |\check@some@constraints| which
% allows to check some constraints and if they aren't met is supposed
% to set the switch |@fail|.
%
% This can, for example be used to implement a constraint that bottom
% floats are only allowed if there are no footnotes in the current
% column.\footnote{At the moment this is restricted to single column
%    floats. Spanning floats are always allowed.}
%
% \begin{macro}{\check@float@footnote@forbidden}
%    The command |\check@float@footnote@forbidden| is the
%    implementation for |\check@some@constraints| that prevents bottom
%    floats if the current column contains footnotes.
%    \begin{macrocode}
\def\check@float@footnote@forbidden{
%<*trace>
  \@tracepush{check@float@footnote@forbidden}
%</trace>
  \ifvoid\footins
  \else
%    \end{macrocode}
%    If the current column contains footnotes and we have bottom
%    floats we fail. First we check if there is a bottom area for this
%    column defined if not we pretend there is an empty one.
%    \begin{macrocode}
    \expandafter
    \ifx \csname area@b\the\curr@col@count1\endcsname
         \relax
         \global\expandafter\let
            \csname area@b\the\curr@col@count1\endcsname
            \@empty
    \fi
%    \end{macrocode}
%    Then we check if the bottom area is empty and fail otherwise
%    \begin{macrocode}
    \expandafter
    \ifx \csname area@b\the\curr@col@count1\endcsname
         \@empty
%<*trace>
      \tr@ce{OK:~ no~ old~ bottom~ floats}
%</trace>
    \else
%<*progress>
      \progress@failed{old~bottom~floats:~ \expandafter\meaning
          \csname area@b\the\curr@col@count1\endcsname}
%</progress>
%<*trace>
      \tr@ce{Failed:~ old~bottom~floats:~ \expandafter\meaning
          \csname area@b1\the\curr@col@count\endcsname}
%</trace>
      \@failtrue
    \fi
%    \end{macrocode}
%    Finally we test if the float we are try to place is going onto a
%    bottom area.
%
%    However we only do this if the float doesn't span.\footnote{Extend?}
%    \begin{macrocode}
    \ifnum \this@area@span@number = \@ne
%<*trace>
      \tr@ce{this@area,column:~ \this@area,~\the\curr@col@count}
%</trace>
      \if b \this@area@type
         \ifnum \this@area@col@number = \curr@col@count
           \@failtrue
         \fi
      \fi
    \fi
    \if@fail
%<*progress>
      \progress@failed{column~ \the\curr@col@count\space
                       contains~ footnotes~ and~ bottom~ floats}
%</progress>
%<*trace>
      \tr@ce{Failed:~ column~ \the\curr@col@count\space
                      contains~ footnotes~ and~ bottom~ floats}
%</trace>
      \global\curr@col@count\col@count
    \fi
  \fi
%<*trace>
  \@tracepop{check@float@footnote@forbidden}
%</trace>
}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\check@float@footnote@none}
%
%    This is the implementation for |\check@some@constraints| if we
%    don't care about mixing footnotes and bottom floats. The reason
%    |\@empty| rather than |\relax| is used is that otherwise the
%    |\ifx| test in the template would fail.
%    \begin{macrocode}
\let\check@float@footnote@none\@empty
%    \end{macrocode}
% \end{macro}
%
%
%
%
%
%
% \endinput
\endinput
%
% $Log: xo-place.dtx,v $
% Revision 1.37  2000/08/11 07:14:28  latex3
% added header
%
% Revision 1.36  2000/08/11 06:49:47  latex3
% untabify
%
% Revision 1.35  2000/08/11 06:45:03  latex3
% only partially tighten float constraints after passing a flush point
%
% Revision 1.34  2000/07/23 21:03:19  latex3
% removed obsolete commentary
%
% Revision 1.33  2000/07/21 13:53:17  latex3
% more renaming for float sequence class concept
%
% Revision 1.32  2000/07/18 21:06:36  latex3
% introduced float sequence classes
%
% Revision 1.31  2000/07/12 17:24:53  latex3
% more support for grids
%
% Revision 1.30  2000/07/10 21:00:57  latex3
% support for grid typesetting
%
% Revision 1.29  2000/07/04 19:42:05  latex3
% fix tracing for GRID stuff
%
% Revision 1.28  2000/07/01 15:57:25  latex3
% use \update@this@area@columns
% integrate code to support grid design (first draft)
%
% Revision 1.27  2000/06/29 17:18:14  latex3
% introduced \setup@this@area
%
% Revision 1.26  2000/06/26 15:03:40  latex3
% making prototype for \pagesetup@float@area@sep
%
% Revision 1.25  2000/06/22 20:08:09  latex3
% renamed some macros to get them more uniform
%
% Revision 1.24  2000/06/22 11:01:24  latex3
% When substracting heights from columns do this for the columns spanned
% by the area. Don't use the span number from the float (in the future
% this might be smaller than the span number of the area)
%
% Revision 1.23  2000/06/19 21:38:04  latex3
% fixed flush point handling when deferring
%
% Revision 1.22  2000/06/18 19:03:53  latex3
% added "Checking bottom float footnote constraints" from xo-page
%
% Revision 1.21  2000/06/16 11:20:15  latex3
% rename \construct@and@test@col@height to \construct@and@test@col@ht
% rename \construct@and@test@col@heights to \construct@and@test@col@hts
% rename \cl@height1 to \@col@ht@1 (etc)
%
% Revision 1.20  2000/06/16 11:06:37  latex3
% support float-callout-span-constraint
%
% Revision 1.19  2000/06/16 07:49:49  latex3
% improve progress info
%
% Revision 1.18  2000/06/15 17:49:02  latex3
% moved macros from xo-page into here since they deal with placement
%
% Revision 1.17  2000/06/15 15:23:32  latex3
% implemented new semantics for area names
%
% Revision 1.16  2000/06/13 20:48:18  latex3
% docu update
%
% Revision 1.15  2000/06/06 12:50:40  latex3
% before attempting fuzzy flushpoints
%
% Revision 1.14  2000/05/03 18:57:56  latex3
% provide \construct@and@test@col@heights subroutine
%
% fix problem that deferred floats would not stop other floats going
% into earlier areas
%
% Revision 1.13  2000/03/31 17:08:50  latex3
% avoid using up too much input stack by using tail recursion in
% strategic places (tmp fix)
%
% Revision 1.12  2000/03/26 21:04:03  latex3
% some renaming of macros
%
% Revision 1.11  2000/03/24 15:34:27  latex3
% version that starts supporting spans (still a hack yet)
%
% Revision 1.10  2000/03/22 15:52:37  latex3
% some normalisations of names
% first go at spans (tmp version)
%
% Revision 1.9  2000/03/17 20:23:11  latex3
% more fixes to flushing (looks good now)
%
% Revision 1.8  2000/03/16 10:28:29  latex3
% partial and full flush working for the first time
%
% Revision 1.7  2000/03/05 19:31:56  latex3
% some renaming
% extend to multiple columns (6 max right now)
% fix defer logic: when flushseen don't defer immediately
%
% Revision 1.6  2000/02/27 15:12:45  david
% *** empty log message ***
%
% Revision 1.5  2000/02/27 11:27:45  david
% first attempt at flush floats
%
% Revision 1.4  2000/02/26 18:24:21  david
% renaming, and using \initialise@areas
%
% Revision 1.3  2000/02/16  13:40:09  latex3
% added 3col support
%
% Revision 1.2  2000/02/16  10:10:43  latex3
% added documentation
% added test for float area size after adding float
%
% Revision 1.1  2000/02/13  22:27:39  latex3
% Initial revision
%