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
|
%D \module
%D [ file=page-lay,
%D version=2000.10.20, % copied from main-001
%D title=\CONTEXT\ Page Macros,
%D subtitle=Layout Specification,
%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 Page Macros / Layout Specification}
%D This module is now etex dependent.
% to be translated into english
% hoofdhoogte wordt bij status=hoog niet aangepast op outer
% level, wel binnen bepaalde berekeningen
%D Before you start wondering why some of the page related
%D modules skip upward or left in order to place elements, you
%D must realize that the reference point is the top left
%D corner of the main typesetting area. One reason for this
%D choice is that it suited some viewers that displayed page
%D areas. Another reason is that margins, edges and top and
%D bottom areas are kind of virtual, while the header, text
%D and footer areas normally determine the text flow.
\unprotect
%D First we get rid of the funny \TEX\ offset defaults of one
%D inch by setting them to zero.
\voffset = 0pt % setting this to -1in let's go metapost crazy
\hoffset = 0pt % setting this to -1in let's go metapost crazy
%D The dimensions related to layout areas are represented by
%D real dimensions.
\newdimen\paperheight \paperheight = 297mm
\newdimen\paperwidth \paperwidth = 210mm
\newdimen\printpaperheight \printpaperheight = \paperheight
\newdimen\printpaperwidth \printpaperwidth = \paperwidth
\newdimen\makeupheight % calculated
\newdimen\makeupwidth % calculated
\newdimen\textheight % calculated
\newdimen\textwidth % calculated
\newdimen\topspace \topspace = 2cm
\newdimen\backspace \backspace = \topspace
\newdimen\cutspace \cutspace = 0pt
\newdimen\bottomspace \bottomspace = 0pt
\newdimen\headerheight \headerheight = 2cm
\newdimen\footerheight \footerheight = \headerheight
\newdimen\topoffset \topoffset = 0pt
\newdimen\backoffset \backoffset = \topoffset
\newdimen\leftmarginwidth \leftmarginwidth = 3cm
\newdimen\rightmarginwidth \rightmarginwidth = \leftmarginwidth
\newdimen\leftedgewidth \leftedgewidth = 3cm
\newdimen\rightedgewidth \rightedgewidth = \leftedgewidth
\newdimen\topheight \topheight = 0cm
\newdimen\bottomheight \bottomheight = \topheight
\newcount\layoutlines \layoutlines = 0
\newcount\layoutcolumns \layoutcolumns = 0
\newdimen\layoutcolumndistance \layoutcolumndistance = 0pt
\newdimen\layoutcolumnwidth \layoutcolumnwidth = 0pt
%D We can save some tokens and fuzzy parameters by using a
%D symbolic name for the current set of layout parameters.
\let\currentlayout\empty
\def\layoutparameter#1%
{\csname\??ly\ifcsname
\??ly\currentlayout#1\endcsname\currentlayout
\fi#1\endcsname}
\def\namedlayoutparameter#1#2%
{\csname\??ly\ifcsname\??ly #1#2\endcsname#1\else
\ifcsname\??ly\currentlayout#2\endcsname\currentlayout
\fi\fi#2\endcsname}
%D Beause normal \TEX\ has at most 256 dimensions (of which a
%D substantial part is already in use), we provide a way to
%D generate a format with macro based alternatives. For a long
%D time, this used to be the default case. Beware: only fixed
%D dimensions can be used in calculations! By the way, the
%D gain in speed can hardly be called impressive and is roughly
%D 1 second on a 35 second run of 850 empty pages with a
%D couple of backgrounds only (which is far less than one
%D percent on a normal document).
%D The next series of dimensions are complemented by left
%D and rights ones.
\newdimen \margindistance
\newdimen \edgedistance
\newdimen \marginwidth
\newdimen \edgewidth
%D Because a distance does not really makes sense when there
%D is no area, we use a zero distance in case there is no
%D area.
\def\layoutdistance#1#2%
{\ifdim\zeropoint<#1\layoutparameter#2\else\zeropoint\fi}
%D The horizontal distances are:
\newdimen \leftedgedistance
\newdimen \rightedgedistance
\newdimen \leftmargindistance
\newdimen \rightmargindistance
%D The vertical distances are:
\newdimen \topdistance
\newdimen \headerdistance
\newdimen \footerdistance
\newdimen \bottomdistance
%D We need to calculate the extra distances:
\def\setlayoutdimensions
{\global\marginwidth \layoutparameter\c!margin
\global\edgewidth \layoutparameter\c!edge
\global\margindistance \layoutparameter\c!margindistance
\global\edgedistance \layoutparameter\c!edgedistance
\global\leftedgedistance \layoutdistance \leftedgewidth \c!leftedgedistance
\global\rightedgedistance \layoutdistance \rightedgewidth \c!rightedgedistance
\global\leftmargindistance \layoutdistance \leftmarginwidth \c!leftmargindistance
\global\rightmargindistance\layoutdistance \rightmarginwidth \c!rightmargindistance
\global\topdistance \layoutdistance \topheight \c!topdistance
\global\headerdistance \layoutdistance \headerheight \c!headerdistance
\global\footerdistance \layoutdistance \footerheight \c!footerdistance
\global\bottomdistance \layoutdistance \bottomheight \c!bottomdistance}
\def\setlayoutdistances % local in \setreducedvsize
{\headerdistance\layoutdistance\headerheight\c!headerdistance
\footerdistance\layoutdistance\footerheight\c!footerdistance}
% these are wrong in the running text, assumes some swapping, needs a cleanup
\def\outermarginwidth {\rightorleftpageaction\rightmarginwidth \leftmarginwidth }
\def\innermarginwidth {\rightorleftpageaction\leftmarginwidth \rightmarginwidth}
\def\outermargindistance{\rightorleftpageaction\rightmargindistance\leftmargindistance }
\def\innermargindistance{\rightorleftpageaction\leftmargindistance \rightmargindistance}
\def\outeredgewidth {\rightorleftpageaction\rightedgewidth \leftedgewidth }
\def\inneredgewidth {\rightorleftpageaction\leftedgewidth \rightedgewidth}
\def\outeredgedistance {\rightorleftpageaction\rightedgedistance\leftedgedistance }
\def\inneredgedistance {\rightorleftpageaction\leftedgedistance \rightedgedistance}
\def\outerspacewidth {\rightorleftpageaction\cutspace\backspace}
\def\innerspacewidth {\rightorleftpageaction\backspace\cutspace}
\newtoks\extralayoutcalculations \def\calculatelayoutextras{\the\extralayoutcalculations}
% \appendtoks
% non etex calculations used to go here
% \to \extralayoutcalculations
\newtoks\everyswapmargins % watch the order !
\appendtoks
\swapdimens\leftmargindistance\rightmargindistance
\swapdimens\leftedgedistance \rightedgedistance
\swapdimens\leftmarginwidth \rightmarginwidth
\swapdimens\leftedgewidth \rightedgewidth
\to \everyswapmargins
\appendtoks
\swapmacros\leftmargintotal \rightmargintotal
\swapmacros\leftedgetotal \rightedgetotal
\swapmacros\leftsidetotal \rightsidetotal
\swapmacros\leftcombitotal \rightcombitotal
\swapmacros\innermargintotal\outermargintotal
\swapmacros\inneredgetotal \outeredgetotal
\swapmacros\innercombitotal \outercombitotal
\swapmacros\innersidetotal \outersidetotal
\to \everyswapmargins
%D \macros
%D {definepapersize}
%D
%D Before we start calculating layout dimensions, we will
%D first take care of paper sizes. The first argument can be
%D either an assignment (for defaults) or an identifier, in
%D which case the second argument is an assignment.
%D
%D \showsetup{definepapersize}
\def\definepapersize
{\dodoubleempty\dodefinepapersize}
\def\definepapersize
{\dotripleempty\dodefinepapersize}
\def\dodefinepapersize[#1][#2][#3]%
{\ifsecondargument
\doifsomething{#1} % to be sure
{\doifassignmentelse{#2}
{\getparameters
[\??pp#1] % geen \c!scale, scheelt hash ruimte
[\c!width=\@@ppwidth,\c!height=\@@ppheight,\c!offset=\@@ppoffset,#2]}
{\setvalue{\??pp:1:#1}{#2}%
\setvalue{\??pp:2:#1}{#3}}}%
\else
\getparameters[\??pp][#1]%
\setuppapersize % hm. this will freeze !
\fi}
%D For the moment we need to fake this macro.
\ifx\setuppapersize\undefined
\let\setuppapersize\relax
\fi
%D We set the defaults to the dimensions of an A4 sheet of
%D paper.
\definepapersize
[\c!width=210mm,\c!height=297mm,\c!offset=\zeropoint]
%D Yet undocumented, let's see if it gets noticed.
%D
%D \starttyping
%D \definepapersize[main] [A4] [A4]
%D \definepapersize[extra][A4,landscape][A4,landscape]
%D
%D \starttext
%D \setuppapersize[main]
%D Page 1. \page
%D Page 2. \page
%D \setuppapersize[extra]
%D Page 2 \page
%D \setuppapersize[main]
%D Page 3. \page
%D Page 4. \page
%D \adaptpapersize[extra]
%D Page 5. \page
%D Page 6. \page
%D \stoptext
%D \stoptyping
%D \macros
%D {setuppaper,setuppapersize}
%D
%D When setting up the papersize on which to typeset and
%D print, we can also determine some more characteristics.
%D
%D \showsetup{setuppapersize}
%D
%D We keep track of these features with the following
%D variables.
\chardef\papermirror =0 \chardef\printmirror =0
\chardef\paperorientation=0 \chardef\printorientation=0 % beware: later no chardef
\chardef\paperreverse =0 \chardef\printreverse =0
\chardef\paperlandscape =0 \chardef\printlandscape =0
\let\papersize\empty \let\printpapersize\empty
\def\paperscale{1} \newif\ifnegateprintbox
\def\setuppaper[#1]%
{\getparameters[\??pp][\c!paper=,\c!page=,#1]%
\edef\@@ppxy{\the\numexpr\@@ppnx*\@@ppny\relax}%
\doifelsenothing\@@pppage
{\doifelsenothing\@@pppaper
{} % {\setuppapersize} % added, removed, no need for, too tricky, mag-01 (fixed by freezing pp's)
{\dodosetuppapersize[\papersize][\@@pppaper]}}
{\doifelsenothing\@@pppaper
{\dodosetuppapersize[\@@pppage][\printpapersize]}
{\dodosetuppapersize[\@@pppage][\@@pppaper]}}}
\def\setuppapersize
{\dodoubleempty\dosetuppapersize}
\def\dosetuppapersize[#1][#2]%
{\doifassignmentelse{#1}
{\setuppaper[#1]}
{\doifelsenothing{#2}
{\expanded{\dodosetuppapersize
[\executeifdefined{\??pp:1:#1}{#1}]%
[\executeifdefined{\??pp:2:#1}{}]}}
{\doifassignmentelse{#2}
{\getparameters[\??pp\executeifdefined{\??pp:1:#1}{#1}][#2]}
{\expanded{\dodosetuppapersize
[\executeifdefined{\??pp:1:#1}{#1}]%
[\executeifdefined{\??pp:1:#2}{#2}]}}}}}
\let\reinstatepapersize\relax
\def\adaptpapersize
{\global\let\reinstatepapersize\restorepapersize
\setuppapersize}
\appendtoks
\reinstatepapersize
\global\let\reinstatepapersize\relax
\to \everyaftershipout
\def\dodosetuppapersize[#1][#2]%
{\ifsecondargument
\expanded{\dododosetuppapersize[#1][#2]}%
\calculatehsizes
\calculatevsizes
\recalculatebackgrounds
\recalculatelayout
\else\iffirstargument
\setuppapersize[#1][#2]%
\else\ifx\papersize\undefined\else
\restorepapersize
\fi\fi\fi}
% dimen freeze is a bit tricky, but catches local redundant calls
% with values where e.g width is defined in terms of \paperwidth
\def\dododosetuppapersize[#1][#2]%
{\xdef\restorepapersize{\noexpand\setuppapersize[#1][#2]}%
\dosetuppaperorientation{#1}\paperlandscape\paperorientation\paperreverse\papermirror
\dosetuppaperorientation{#2}\printlandscape\printorientation\printreverse\printmirror
\def\docommand##1%
{\doifsomething{##1}{\doifdefined{\??pp##1\c!width}
{\global\paperwidth \getvalue{\??pp##1\c!width}%
\global\paperheight\getvalue{\??pp##1\c!height}%
\ifinpagebody
\setevalue{\??pp##1\c!height}{\the\paperheight}%
\setevalue{\??pp##1\c!width }{\the\paperwidth }%
\fi
\calculatepaperoffsets{##1}%
\xdef\papersize{##1}}}}%
\processcommacommand[#1]\docommand
\doifdefinedelse{\??pp#1\c!scale}
{\edef\paperscale{\getvalue{\??pp#1\c!scale}}}
{\edef\paperscale{1}}%
\def\docommand##1%
{\doifsomething{##1}{\doifdefined{\??pp##1\c!width}
{\global\printpaperwidth \getvalue{\??pp##1\c!width}%
\global\printpaperheight\getvalue{\??pp##1\c!height}%
\ifinpagebody
\setevalue{\??pp##1\c!height}{\the\printpaperheight}%
\setevalue{\??pp##1\c!width }{\the\printpaperwidth}%
\fi
\xdef\printpapersize{##1}}}}%
\processcommacommand[#2]\docommand
\global\setdimentoatleast\paperwidth \onepoint
\global\setdimentoatleast\paperheight \onepoint
\global\setdimentoatleast\printpaperwidth \onepoint
\global\setdimentoatleast\printpaperheight\onepoint
\ifcase\paperlandscape\else
\doglobal\swapdimens\paperwidth\paperheight
\fi
\ifcase\printlandscape\else
\doglobal\swapdimens\printpaperwidth\printpaperheight
\fi
% this check can be confusing, so we've added the possibility
% to bypass this test: \setuppapersize[option=fit]
\doif\@@ppoption\v!max % \v!fit is
{\bgroup
% we need to pre-swap else we get the wrong paper size
\ifcase\paperorientation\else
\doifinset\paperorientation{90,270}{\swapdimens\paperwidth\paperheight}%
\fi
\ifcase\printorientation\else
\doifinset\printorientation{90,270}{\swapdimens\printpaperwidth\printpaperheight}%
\fi
\ifdim\paperheight>\printpaperheight
\global\printpaperheight\paperheight
\writestatus\m!systems{print height forced to paper height}%
\fi
\ifdim\paperwidth>\printpaperwidth
\global\printpaperwidth\paperwidth
\writestatus\m!systems{print width forced to paper width}%
\fi
\egroup}}
\def\dosetuppaperorientation#1#2#3#4#5%
{\global\chardef#2\zerocount
\global\chardef#5\zerocount
\globallet#3\!!zerocount
\globallet#4\!!zerocount
\global\negateprintboxfalse
\processallactionsinset
[#1]
[ \v!landscape=>\global\chardef#2\plusone,
\v!mirrored=>\global\chardef#5\plusone,
\v!rotated=>\gdef#3{90}\gdef#4{270},
\v!negative=>\global\negateprintboxtrue,
90=>\gdef#3{90}\gdef#4{270},
180=>\gdef#3{180}\gdef#4{0},
270=>\gdef#3{270}\gdef#4{90}]}
\ifx\calculatepaperoffsets\undefined
\def\calculatepaperoffsets#1%
{\scratchdimen\getvalue{\??pp#1\c!offset}%
\global\advance\paperwidth -2\scratchdimen
\global\advance\paperheight-2\scratchdimen}
\fi
\let\restorepapersize\relax
% \def\docheckforems#1%
% {\beforesplitstring#1\at em\to\asciia
% \doifnot\asciia{#1}
% {\aftersplitstring\asciia\at=\to\asciia
% \doifsomething\asciia{\showmessage\m!systems{10}{#1}}}}
%
% \def\checkforems[#1]%
% {\processcommalist[#1]\docheckforems}
\ifx\setups\undefined \def\setups[#1]{\setdefaultpenalties} \fi
% \newtoks \everybeforelayout \relax
% \newtoks \everyafterlayout \relax
\def\recalculatelayout
{\doifsomething{\layoutparameter\c!page\layoutparameter\c!paper}
{\expanded{\dododosetuppapersize[\layoutparameter\c!page][\layoutparameter\c!paper]}}%
\dorecalculatelayout}
\ifdefined\docheckgridsnapping \else \let\docheckgridsnapping\relax \fi
\def\dorecalculatelayout
{%\the\everybeforelayout
\setups[\layoutparameter\c!preset]%
\global\leftmarginwidth \layoutparameter\c!leftmargin
\global\rightmarginwidth\layoutparameter\c!rightmargin
\global\leftedgewidth \layoutparameter\c!leftedge
\global\rightedgewidth \layoutparameter\c!rightedge
\global\headerheight \layoutparameter\c!header
\global\footerheight \layoutparameter\c!footer
\global\bottomheight \layoutparameter\c!bottom
\global\topheight \layoutparameter\c!top
\global\backspace \layoutparameter\c!backspace
\global\topspace \layoutparameter\c!topspace
\setlayoutdimensions % the rest of the `dimensions'
\docheckgridsnapping
\doprocesslocalsetups{\layoutparameter\c!setups}% depends on gridsnapping !
\simplesetupwhitespace
\simplesetupblank
\setupinterlinespace[\v!reset]% \synchronizegloballinespecs
\global\cutspace\layoutparameter\c!cutspace
\relax
\doifelse{\layoutparameter\c!width}\v!middle
{\ifdim\cutspace=\zeropoint
\global\cutspace\backspace
\fi
\global\makeupwidth\dimexpr\paperwidth-\backspace-\cutspace\relax}
{\doifelse{\layoutparameter\c!width}\v!fit
{\ifdim\cutspace=\zeropoint
\global\cutspace\backspace
\fi
\global\makeupwidth\dimexpr\paperwidth-\cutspace\relax
\scratchdimen\dimexpr\backspace
-\leftedgewidth -\leftedgedistance
-\leftmarginwidth-\leftmargindistance\relax
\ifdim\scratchdimen<\zeropoint
\scratchdimen\zeropoint
\fi
\global\advance\makeupwidth\dimexpr
-\rightmargindistance-\rightmarginwidth
-\rightedgedistance -\rightedgewidth
-\scratchdimen\relax}
{\global\makeupwidth\layoutparameter\c!width\relax
\ifdim\cutspace=\zeropoint
\global\cutspace\dimexpr\paperwidth-\makeupwidth-\backspace\relax
% \else
% A kind of inconsistent specification, but used
% in for instance s-pre-19.tex; the cutspace is
% used only for determining some kind of right
% margin; don't use this in doublesided mode
\fi}}%
\scratchdimen\layoutparameter\c!bottomspace\relax
%\ifdim\scratchdimen=\zeropoint
% \scratchdimen\topspace
%\fi
\global\bottomspace\layoutparameter\c!bottomspace\relax
\global\layoutlines0\number\layoutparameter\c!lines\relax % may be empty
\ifcase\layoutlines
\doifelse{\layoutparameter\c!height}\v!middle
{\ifdim\bottomspace=\zeropoint
\global\bottomspace\topspace
\fi
\global\makeupheight\dimexpr\paperheight-\topspace-\bottomspace\relax}
{\doifelse{\layoutparameter\c!height}\v!fit
{\ifdim\bottomspace=\zeropoint
\global\bottomspace\topspace
\fi
\global\makeupheight\dimexpr\paperheight-\bottomspace\relax
\scratchdimen\dimexpr\topspace-\topheight-\topdistance\relax
\ifdim\scratchdimen<\zeropoint
\scratchdimen\zeropoint
\fi
\global\advance\makeupheight\dimexpr-\bottomdistance-\bottomheight-\scratchdimen\relax}
{\global\makeupheight\layoutparameter\c!height\relax
\ifdim\bottomspace=\zeropoint
\global\bottomspace\dimexpr\paperheight-\makeupheight-\topspace\relax
\else
% inconsistent specification
\fi}}%
\else
% beware, when the bodyfont changes (switched) this will change as well; implementing
% a global lineheight is tricky: should we take the bodyfont interlinespace or the one set
% independent of the bodyfont (before or after a layout spec); way too fuzzy, so we
% stick to the current method (after a night of experimenting ...2003/10/13)
\global\makeupheight\dimexpr
\layoutparameter\c!lines\lineheight-\strutheight+\topskip+
\headerdistance+\headerheight+\footerdistance+\footerheight\relax
\fi
\backoffset\layoutparameter\c!horoffset
\topoffset \layoutparameter\c!veroffset
\global\setdimentoatleast\makeupwidth\onepoint
\global\setdimentoatleast\makeupheight \onepoint
% \checkcurrentlayout % here ?
% \the\everyafterlayout
\calculatelayoutextras
\calculatehsizes
\calculatevsizes
\calculatepseudocolumns
\recalculatebackgrounds}
\def\calculatepseudocolumns
{\global\layoutcolumns\layoutparameter\c!columns
\global\layoutcolumndistance\layoutparameter\c!columndistance
\global\layoutcolumnwidth\dimexpr\makeupwidth-\layoutcolumns\layoutcolumndistance+\layoutcolumndistance\relax
\global\divide\layoutcolumnwidth\layoutcolumns
\dorecurse\layoutcolumns
{\setxvalue{\??ly:c:\recurselevel}%
{\the\numexpr\recurselevel-\plusone\relax\dimexpr\layoutcolumnwidth+\layoutcolumndistance\relax}}}
%\dorecurse\layoutcolumns
% {\setxvalue{\??ly:c:\recurselevel}{\the\dimexpr
% (\numexpr(\recurselevel-1)\dimexpr(\layoutcolumnwidth+\layoutcolumndistance))}}
\def\layoutcolumnoffset#1%
{\executeifdefined{\??ly:c:#1}\zeropoint}
\def\checklayout
{\ifdim\makeupheight=\layoutlines\lineheight \else \recalculatelayout \fi}
\appendtoks \checklayout \to \everystarttext
% document:
%
% \setuplayout[odd][state=stop] \setuplayout[even][state=stop] \setuplayout[page]
%
% \startstandardmakeup[page=blank] ... \stopstandardmakeup
\def\changetolayout#1%
{%\writestatus\m!layouts{changing to layout #1}%
\xdef\currentlayout{#1}\recalculatelayout}
\def\checkcurrentoddlayout
{\ifcsname\??ly\v!odd\c!state\endcsname
\doifvalue{\??ly\v!odd\c!state}\v!start{\changetolayout\v!odd}%
\fi}
\def\checkcurrentevenlayout
{\ifcsname\??ly\v!even\c!state\endcsname
\doifvalue{\??ly\v!even\c!state}\v!start{\changetolayout\v!even}%
\fi}
\ifx\lastpage\undefined \def\lastpage{1} \fi
\def\reverserealfolio
{\ifnum\lastpage>\plusone
\ifnum\lastpage=\realfolio
\v!last
\else\ifnum\plusone=\realfolio
\v!first
\else
\the\numexpr\realfolio-\lastpage\relax
\fi\fi
\else
\!!zerocount
\fi}
\def\checkcurrentlayout % public and used in naw, so keep this name
{\ifcsname\??ly\realfolio\c!state\endcsname
\doifvalue{\??ly\realfolio\c!state}\v!start{\changetolayout\realfolio}%
\else\ifcsname\??ly\reverserealfolio\c!state\endcsname
\doifvalue{\??ly\reverserealfolio\c!state}\v!start{\changetolayout\reverserealfolio}%
\else\ifcsname\??ly\v!current\c!state\endcsname
\changetolayout\v!current % no start test ?
\else
\doifoddpageelse\checkcurrentoddlayout\checkcurrentevenlayout
\fi\fi\fi}
% testcase
%
% \setuppagenumbering[alternative=doublesided]
%
% \setuplayout [width=11cm]
% \definelayout [odd] [backspace=1cm]
% \definelayout [even] [backspace=4cm]
% \definelayout [5] [backspace=5cm]
% \definelayout [6] [backspace=5cm]
% \definelayout [-2] [backspace=0cm,cutspace=0cm]
% \definelayout [last] [backspace=0cm,cutspace=0cm]
%
% \checkcurrentlayout \showframe
%
% \starttext
% \dorecurse{20} {\input knuth \endgraf \input tufte \endgraf}
% \stoptext
%appendtoks \checkcurrentlayout \to \everyaftershipout % no
\appendtoks \checkcurrentlayout \to \everystarttext
\appendtoks
\dochecknextlayout
\to \everyaftershipout
% \def\dochecknextlayout
% {\ifx\currentlayout\v!current
% % prevent redundant calculations
% \else
% \globallet\currentlayout\empty
% \global\letbeundefined{\??ly\v!current\c!state}%
% \checkcurrentlayout
% \fi}
%
% this breaks after a standardmakeup
\def\dochecknextlayout{\checkcurrentlayout}
\newif\ifdoublesidedprint
\def\presetcenterpagebox % in \setuplayout !!!!!!!!!!!!!!!!
{\doublesidedprintfalse
\normalexpanded{\noexpand\processallactionsinset[\@@lylocation]}
[ \v!middle=>{\setuppapersize[\c!left=\hss,\c!right=\hss,\c!top=\vss,\c!bottom=\vss]},
\v!left=>{\setuppapersize[\c!left=,\c!right=\hss]},
\v!right=>{\setuppapersize[\c!left=\hss,\c!right=]},
\v!bottom=>{\setuppapersize[\c!top=\vss,\c!bottom=]},
\v!top=>{\setuppapersize[\c!top=,\c!bottom=\vss]},%
\v!doublesided=>\doublesidedprinttrue,
\v!singlesided=>\doublesidedprintfalse]}
\def\definelayout
{\dodoubleargument\dodefinelayout}
\def\dodefinelayout[#1][#2]%
{\getparameters[\??ly#1][\c!state=\v!start,#2]}
% \def\dodosetuplayout[#1][#2]%
% {\ConvertToConstant\doifnot{#2}\v!reset % #2 ?
% {\getparameters[\??ly#1][#2]%
% \checkforems[#2]}}
\def\dodosetuplayout[#1][#2]%
{\doifnot{#2}\v!reset{\getparameters[\??ly#1][#2]}}
% global needed for non-doublesided standardmakeup
\def\dosetuplayout[#1][#2]%
{\globallet\currentlayout\empty % new, global
\ifsecondargument
\dodosetuplayout[#1][#2]%
\else\iffirstargument
\doifassignmentelse{#1}
{\dodosetuplayout[][#1]}
{\doifnot{#1}\v!reset{\xdef\currentlayout{#1}}}% new, global
\fi\fi
\recalculatelayout
\checkcurrentlayout % here ?
\presetcenterpagebox}
\def\setuplayout
{\dodoubleempty\dosetuplayout}
\let\@@zaheight\!!zeropoint
\def\dopushpagedimensions
{\xdef\oldtextheight {\the\textheight }%
\xdef\oldfooterheight{\the\footerheight}%
\global\let\@@zaheight\@@zaheight}
\def\dopoppagedimensions
{\global\textheight \oldtextheight
\global\footerheight\oldfooterheight
\recalculatelayout
\global\let\pushpagedimensions\dopushpagedimensions
\global\let\poppagedimensions\relax}
\let\poppagedimensions \relax
\let\pushpagedimensions\dopushpagedimensions
% Elke \csname ... \endcsname wordt ook aangemaakt, dus ook
% in een test met \doifdefined. Bij veel bladzijden kan dit
% te veel macro's kosten. Vandaar de set \adaptedpages. Het
% kost tijd, maar scheelt macro's.
\let\adaptedpages\empty
\def\adaptpagedimensions
{\ifx\adaptedpages\empty\else
\adaptpagedimensionsindeed
\fi}
\def\adaptpagedimensionsindeed
{\rawdoifinsetelse\realfolio\adaptedpages
{\removefromcommalist\realfolio\adaptedpages
\getvalue{\??za\realfolio}%
\letbeundefined{\??za\realfolio}}}
\def\checkpagedimensions
{\poppagedimensions
\adaptpagedimensions}
\def\reportpagedimensions
{\ifx\poppagedimensions\relax \else
\space\the\dimexpr\@@zaheight\relax\space-\space
\fi
\realfolio}
\def\dodoadaptlayout[#1]%
{\getparameters[\??za][\c!height=,\c!lines=0,#1]%
\pushpagedimensions
\ifcase\@@zalines\relax
\showmessage\m!layouts1{\@@zaheight,\realfolio}%
\else
\showmessage\m!layouts1{\@@zalines\space\v!lines,\realfolio}%
\def\@@zaheight{\@@zalines\openlineheight}%
\fi
\doifelse\@@zaheight\v!max
{\balancedimensions\textheight\footerheight\footerheight}
{\balancedimensions\textheight\footerheight\@@zaheight}%
\ifdim\footerheight<\zeropoint
\global\advance\textheight \footerheight
\global\footerheight\zeropoint
\global\xdef\@@zaheight{\layoutparameter\c!footer\space(\v!max)}%
\fi
\setvsize
\global\pagegoal\vsize % nog corrigeren voor insertions ?
\recalculatebackgrounds
\global\let\pushpagedimensions\relax
\global\let\poppagedimensions\dopoppagedimensions}
\def\doadaptlayout[#1][#2]%
{\doifelsenothing{#2}
{\dodoadaptlayout[#1]}
{\def\docommand##1%
{\addtocommalist{##1}\adaptedpages
\setgvalue{\??za##1}{\dodoadaptlayout[#2]}}%
\processcommalist[#1]\docommand
\adaptpagedimensions}}
\def\adaptlayout
{\dodoubleempty\doadaptlayout}
% describe interface
%D Centering the paper area on the print area is determined
%D by the \type {top}, \type {bottom}, \type {left} and \type
%D {right} parameters.
\def\centerpagebox#1%
{\printpaperwidth \paperscale\printpaperwidth
\printpaperheight\paperscale\printpaperheight
\setbox#1\vbox to \printpaperheight
{\@@pptop
\hbox to \printpaperwidth
{\ifdoublesidedprint
\doifbothsides
{\@@ppleft \box#1\@@ppright}
{\@@ppleft \box#1\@@ppright}
{\@@ppright\box#1\@@ppleft }%
\else
\@@ppleft \box#1\@@ppright
\fi}%
\par
\@@ppbottom}}
\def\offsetprintbox#1%
{\ifdim\topoffset=\zeropoint % \relax
\ifdim\backoffset=\zeropoint
\donefalse
\else
\donetrue
\fi
\else
\donetrue
\fi
\ifdone
\edef\next{\wd#1\the\wd#1\ht#1\the\ht#1\dp#1\the\dp#1}%
\setbox#1\vbox
{\offinterlineskip
\vskip\topoffset
\hskip\doifbothsides\backoffset\backoffset{-\backoffset}%
\box#1}%
\next
\fi}
\def\replicatepagebox#1%
{\ifnum\@@lynx>\plusone
\donetrue
\else\ifnum\@@lyny>\plusone
\donetrue
\else
\donefalse
\fi\fi
\ifdone
\setbox#1\vbox
{\offinterlineskip
\dorecurse\@@lyny
{\hbox{\dorecurse\@@lynx{\copy#1\hskip\@@lydx}\unskip}%
\vskip\@@lydy}
\unskip}%
\fi}
\def\orientpagebodybox#1#2#3%
{\ifnum#2#3>\zerocount
\setbox#1\vbox
{\edef\somerotation{\ifdoublesided\ifodd\realpageno#2\else#3\fi\else#2\fi}%
\dorotatebox\somerotation\hbox{\box#1}}%
\fi}
\def\orientpaperbox#1%
{\orientpagebodybox{#1}\paperorientation\paperreverse}
\def\orientprintbox#1%
{\orientpagebodybox{#1}\printorientation\printreverse}
\def\mirrorpagebodybox#1#2%
{\ifcase#2\or
\setbox#1\vbox{\domirrorbox\vbox{\box#1}}%
\fi}
\def\mirrorpaperbox#1%
{\mirrorpagebodybox{#1}\papermirror}
\def\mirrorprintbox#1%
{\mirrorpagebodybox{#1}\printmirror}
\def\scalepagebox#1%
{\ifdim\@@lyscale\points=\onepoint \else
\setbox#1\vbox{\scale[\c!sx=\@@lyscale,\c!sy=\@@lyscale]{\box#1}}%
\paperwidth \@@lyscale\paperwidth
\paperheight\@@lyscale\paperheight
\fi}
\def\negateprintbox#1%
{\ifnegateprintbox
\negatecolorbox{#1}%
\fi}
\def\pagecutmarksymbol {\the\realpageno}
\def\pagecutmarklength {.5cm}
\let\pagecutmarktoptext \empty
\let\pagecutmarkbottomtext \empty
\def\extrapagecutmarkbottomtext
{\rlap{\jobname}\hfill\currentdate\space-\space\currenttime\hfill\llap{\realfolio}}
\def\makepagecutbox % #1
{\let\cutmarksymbol \pagecutmarksymbol
\let\cutmarklength \pagecutmarklength
\let\cutmarktoptext \pagecutmarktoptext
\let\cutmarkbottomtext\pagecutmarkbottomtext
\makecutbox}
\setvalue{\??ly:n:\c!marking:\v!on}%
{\makepagecutbox}
\setvalue{\??ly:n:\c!marking:\v!page}% only at outer when nx/ny > 0
{\makepagecutbox}
\setvalue{\??ly:n:\c!marking:\v!empty}%
{\let\pagecutmarksymbol\empty
\let\pagecutmarktoptext\empty
\let\pagecutmarkbottomtext\empty
\makepagecutbox}
\setvalue{\??ly:n:\c!marking:\v!text}%
{\let\pagecutmarksymbol\empty
\let\pagecutmarkbottomtext\extrapagecutmarkbottomtext
\makepagecutbox}
\setvalue{\??ly:c:\c!marking:\v!color}%
{\doaddpagecolormarks\colormarkbox}
\setvalue{\??ly:c:\c!marking:\v!screen}%
{\doaddpagecolormarks\rastermarkbox}
\letvalue{\??ly:c:\c!marking:\v!unknown}\gobbleoneargument
\letvalue{\??ly:n:\c!marking:\v!unknown}\gobbleoneargument
% \def\addpagecutmarks {\executeifdefined{\??ly:n:\c!marking:\@@lymarking}\gobbleoneargument}
% \def\addpagecolormarks{\executeifdefined{\??ly:c:\c!marking:\@@lymarking}\gobbleoneargument}
\def\addpagecutmarks {\expandcheckedcsname{\??ly:n:\c!marking:}\@@lymarking\s!unknown}
\def\addpagecolormarks{\expandcheckedcsname{\??ly:c:\c!marking:}\@@lymarking\s!unknown}
\def\doaddpagecolormarks#1#2%
{\makepagecutbox{#2}%
\ifnum\horizontalcutmarks>\plustwo \chardef\colormarkoffset\plusfour \fi
\ifnum\verticalcutmarks >\plustwo \chardef\colormarkoffset\plusfour \fi
#1{#2}}
% NOG EENS NAGAAN WANNEER NU GLOBAL EN WANNEER NIET
\ifx\doifelselayoutsomeline\undefined % defined in page-txt
\let\doifelselayoutsomeline\secondofthreearguments
\fi
\def\compensatevsizeheader {\advance\textheight-\dimexpr\headerheight+\headerdistance\relax}
\def\compensatevsizefooter {\advance\textheight-\dimexpr\footerheight+\footerdistance\relax}
\def\globalcompensatevsizeheader{\global\advance\textheight-\dimexpr\headerheight+\headerdistance\relax}
\def\globalcompensatevsizefooter{\global\advance\textheight-\dimexpr\footerheight+\footerdistance\relax}
\def\compensatevsizeheaderzero{\headerheight\zeropoint\setlayoutdistances}
\def\compensatevsizefooterzero{\footerheight\zeropoint\setlayoutdistances}
\def\calculatevsizes
{\textheight\makeupheight
\doifelselayoutsomeline\v!header\compensatevsizeheader\donothing
\doifelselayoutsomeline\v!footer\compensatevsizefooter\donothing
\setvsizemodes
\resetglobal
\setvsize}
\def\calculateglobalvsizes
{\global\textheight\makeupheight
\doifelselayoutsomeline\v!header\globalcompensatevsizeheader\donothing
\doifelselayoutsomeline\v!footer\globalcompensatevsizefooter\donothing
\setvsizemodes
\setvsize}
\def\setvsizemodes
{\ifzeropt\headerheight
\resetsystemmode\v!header
\else
\setsystemmode\v!header
\fi
\ifzeropt\footerheight
\resetsystemmode\v!footer
\else
\setsystemmode\v!footer
\fi}
\def\calculatereducedvsizes
{\textheight\makeupheight
\doifelselayoutsomeline\v!header\compensatevsizeheader\compensatevsizeheaderzero
\doifelselayoutsomeline\v!footer\compensatevsizefooter\compensatevsizefooterzero}
\newdimen\innermakeupwidth % special purpose
\newdimen\innermakeupmargin % special purpose
\chardef\innermakeupcompensation\plusone
\def\compensatedinnermakeupmargin
{\dimexpr\ifnum\innermakeupcompensation=\plusone+\innermakeupmargin\else\zeropoint\fi\relax}
\def\freezetextwidth % \makeupwidth may be set to \textwidth
{\textwidth\makeupwidth % which is a tricky but valid value
\doifsomething{\layoutparameter\c!textwidth}
{\textwidth\layoutparameter\c!textwidth}% % local
\global\innermakeupwidth\textwidth
\doifelsenothing{\layoutparameter\c!textmargin}
{\global\innermakeupmargin\zeropoint}
{\global\innermakeupmargin\layoutparameter\c!textmargin}%
\global\advance\innermakeupwidth-\dimexpr\innermakeupmargin+\innermakeupmargin\relax
\advance\textwidth-\dimexpr\innermakeupmargin+\innermakeupmargin\relax} % local
\def\calculatehsizes
{\freezetextwidth
\sethsize}
% De onderstaande macro voert commando's uit, afhankelijk van
% het karakter van het paginanummer.
%
% \doifoddpageelse{then-commando}{else-commando}
%D When we start at an even page, we need to swap the layout
%D differently. We cannot adapt the real page number, since
%D it is used in cross referencing. The next switch is set
%D when we start at an even page.
\newif\ifshiftedrealpageno
% We could use nested if here plus some \@EAEAEA's but but the
% next variant has less expansion which is nicer in tracing.
\def\doifoddpageelse {\ifshiftedrealpageno\expandafter\doifoddpageelseyes \else\expandafter\doifoddpageelsenop \fi}
\def\doifoddpageelseyes{\ifodd \realpageno\expandafter\secondoftwoarguments\else\expandafter\firstoftwoarguments \fi}
\def\doifoddpageelsenop{\ifodd \realpageno\expandafter\firstoftwoarguments \else\expandafter\secondoftwoarguments\fi}
\let\doifonevenpaginaelse\doifoddpageelse
\def\redoifoddpageelse#1{\doifoddpageelse}
\def\doifbothsidesoverruled
{\ifdoublesided
\expandafter\redoifoddpageelse
\else
\expandafter\firstofthreearguments
\fi}
\def\doifbothsides% #1 #2 #3
{\ifdoublesided
\expandafter\doifbothsidesindeed
\else
\expandafter\firstofthreearguments
\fi}
\def\doifbothsidesindeed
{\ifsinglesided
\expandafter\firstofthreearguments
\else
\expandafter\redoifoddpageelse
\fi}
\newdimen\texthoffset
\def\settexthoffset
{\texthoffset\doifbothsides\backspace\backspace{\dimexpr\paperwidth-\backspace-\makeupwidth\relax}}
% The next hack is too tricky as we may shipout more pages:
%
% \def\freezepagestatechecks
% {\the\everyfreezepagestatechecks}
%
% \newtoks \everyfreezepagestatechecks
%
% \appendtoks
% \doifbothsides
% {\let\doifbothsides\firstofthreearguments}%
% {\let\doifbothsides\secondofthreearguments}%
% {\let\doifbothsides\thirdofthreearguments}%
% \rightorleftpageaction
% {\let\rightorleftpageaction\firstoftwoarguments}%
% {\let\rightorleftpageaction\secondoftwoarguments}%
% \doifmarginswapelse
% {\let\doifmarginswapelse\firstoftwoarguments}%
% {\let\doifmarginswapelse\secondoftwoarguments}%
% \to \everyfreezepagestatechecks
%
% \prependtoks
% \freezepagestatechecks
% \to \everybeforeshipout
\def\goleftonpage
{\hskip-\dimexpr\leftmargindistance+\leftmarginwidth+\leftedgedistance+\leftedgewidth\relax}
\def\doifmarginswapelse#1#2%
{\doifbothsides{#1}{#1}{#2}}
\def\swapmargins
{\doifmarginswapelse\relax\doswapmargins}
\def\doswapmargins
{\let\swapmargins \relax % to prevent local swapping
\let\doswapmargins\relax % to prevent local swapping
\the\everyswapmargins}
\def\rightorleftpageaction
{\ifdoublesided
\expandafter\rightorleftpageactionindeed
\else
\expandafter\firstoftwoarguments
\fi}
\def\rightorleftpageactionindeed
{\ifsinglesided
\expandafter\firstoftwoarguments
\else
\expandafter\doifoddpageelse
\fi}
\def\outermarginwidth {\rightorleftpageaction\rightmarginwidth \leftmarginwidth }
\def\innermarginwidth {\rightorleftpageaction\leftmarginwidth \rightmarginwidth}
\def\outermargindistance{\rightorleftpageaction\rightmargindistance\leftmargindistance }
\def\innermargindistance{\rightorleftpageaction\leftmargindistance \rightmargindistance}
\def\outeredgewidth {\rightorleftpageaction\rightedgewidth \leftedgewidth }
\def\inneredgewidth {\rightorleftpageaction\leftedgewidth \rightedgewidth}
\def\outeredgedistance {\rightorleftpageaction\rightedgedistance\leftedgedistance }
\def\inneredgedistance {\rightorleftpageaction\leftedgedistance \rightedgedistance}
\def\outerspacewidth {\rightorleftpageaction\cutspace \backspace}
\def\innerspacewidth {\rightorleftpageaction\backspace\cutspace }
\def\leftmargintotal {\dimexpr\leftmarginwidth +\leftmargindistance \relax}
\def\rightmargintotal {\dimexpr\rightmarginwidth+\rightmargindistance\relax}
\def\leftedgetotal {\dimexpr\leftedgewidth +\leftedgedistance \relax}
\def\rightedgetotal {\dimexpr\rightedgewidth +\rightedgedistance \relax}
\def\leftsidetotal {\dimexpr\leftmarginwidth +\leftedgetotal \relax}
\def\rightsidetotal {\dimexpr\rightmarginwidth+\rightedgetotal\relax}
\def\leftcombitotal {\dimexpr\leftmargintotal +\leftedgetotal \relax}
\def\rightcombitotal {\dimexpr\rightmargintotal+\rightedgetotal\relax}
\def\innermargintotal {\dimexpr\innermarginwidth+\innermargindistance\relax}
\def\outermargintotal {\dimexpr\outermarginwidth+\outermargindistance\relax}
\def\inneredgetotal {\dimexpr\inneredgewidth +\inneredgedistance \relax}
\def\outeredgetotal {\dimexpr\outeredgewidth +\outeredgedistance \relax}
\def\innercombitotal {\dimexpr\innermargintotal+\inneredgetotal\relax}
\def\outercombitotal {\dimexpr\outermargintotal+\outeredgetotal\relax}
\def\innersidetotal {\dimexpr\innermarginwidth+\inneredgetotal\relax}
\def\outersidetotal {\dimexpr\outermarginwidth+\outeredgetotal\relax}
%D \macros
%D {startlocallayout}
%D
%D These macros should be used with care. They permit local
%D layouts (as used in fitting pages, see \type {page-app.tex}).
%D This is kind of obsolete now that we have \type
%D {\definelayout}, so this hack will disappear in future
%D versions.
\def\startlocallayout
{\globalpushmacro\restorepapersize
\globalpushmacro\currentlayout}
\def\stoplocallayout
{\globalpopmacro\currentlayout
\globalpopmacro\restorepapersize
\restorepapersize
\setuplayout}
%D \macros
%D {showprint, showframe, showlayout, showsetups}
%D
%D We predefine a couple of tracing macros.
%D
%D \showsetup{showprint}
%D \showsetup{showframe}
%D \showsetup{showlayout}
%D \showsetup{showsetups}
%D %showsetup{showmargins}
\fetchruntimecommand \showprint {page-run.mkii}
\fetchruntimecommand \showframe {page-run.mkii}
\fetchruntimecommand \showlayout {page-run.mkii}
\fetchruntimecommand \showsetups {page-run.mkii}
\fetchruntimecommand \showmargins {page-run.mkii}
%D The default dimensions are quite old and will not change.
%D The funny fractions were introduced when we went from fixed
%D dimensions to relative ones. Since \CONTEXT\ is a dutch
%D package, the dimensions are based on the metric system. The
%D asymmetrical layout is kind of handy for short
%D quick||and||dirty stapled documents.
%D
%D Although valid, it is not a real good idea to use
%D dimensions based on the \type {em} unit. First of all,
%D since there are no fonts loaded yet, this dimension makes
%D no sense, and second, you would loose track of values,
%D since they could change while going to a new page,
%D depending on the current font setting.
\setuplayout
[ \c!topspace=.08417508418\paperheight, % 2.5cm
\c!top=\zeropoint,
\c!topdistance=\zeropoint,
\c!header=.06734006734\paperheight, % 2.0cm
\c!headerdistance=\zeropoint,
\c!height=.84175084175\paperheight, % 25.0cm
\c!footerdistance=\layoutparameter\c!headerdistance,
\c!footer=.06734006734\paperheight, % 2.0cm
\c!bottomdistance=\layoutparameter\c!topdistance,
\c!bottom=\zeropoint,
\c!backspace=.11904761905\paperwidth, % 2.5cm
\c!edge=\zeropoint,
\c!edgedistance=\layoutparameter\c!margindistance,
\c!margin=.12649983170\paperwidth, % snijwit-2*afstand
\c!margindistance=.02008341748\paperwidth, % 12.0pt
\c!leftedge=\layoutparameter\c!edge,
\c!leftedgedistance=\layoutparameter\c!edgedistance,
\c!leftmargin=\layoutparameter\c!margin,
\c!leftmargindistance=\layoutparameter\c!margindistance,
\c!width=.71428571429\paperwidth, % 15.0cm
\c!rightmargindistance=\layoutparameter\c!margindistance,
\c!rightmargin=\layoutparameter\c!margin,
\c!rightedgedistance=\layoutparameter\c!edgedistance,
\c!rightedge=\layoutparameter\c!edge,
\c!veroffset=\zeropoint,
\c!bottomspace=\zeropoint,
\c!horoffset=\zeropoint,
\c!cutspace=\zeropoint,
\c!textwidth=, % dangerous option -> centered / local
\c!textmargin=, % dangerous option -> both sides
\c!textdistance=\zeropoint, % shift down on grid
\c!style=,
\c!color=,
\c!marking=\v!off,
\c!location=, % \v!singlesided, but empty is signal
\c!scale=1,
\c!nx=1,
\c!ny=1,
\c!dx=\zeropoint,
\c!dy=\zeropoint,
\c!grid=\v!no,
\c!preset=,
\c!setups=\systemsetupsprefix\s!default,
\c!clipoffset=\zeropoint,
\c!lines=0,
\c!paper=, % for foxet
\c!page=, % for foxet
\c!columns=1,
\c!columndistance=\zeropoint]
%D First we define a whole range of (DIN) papersizes,
%D of which the A-series makes most sense. We enable checking.
%D We also set some of the parameters that will be used when
%D positioning the typeset paper onto the print paper.
\setuppaper % (size) % only used in XY imposition
[\c!width=\zeropoint,
\c!height=\zeropoint,
\c!topspace=\zeropoint,
\c!backspace=\zeropoint,
\c!dx=\zeropoint,
\c!dy=\zeropoint,
\c!nx=1,
\c!ny=1,
\c!method=\v!normal]
\setuppapersize
[\c!option=\v!max,
\c!top=,
\c!bottom=\vss,
\c!left=,
\c!right=\hss]
\definepapersize [A0] [\c!width=841mm,\c!height=1189mm]
\definepapersize [A1] [\c!width=594mm,\c!height=841mm]
\definepapersize [A2] [\c!width=420mm,\c!height=594mm]
\definepapersize [A3] [\c!width=297mm,\c!height=420mm]
\definepapersize [A4] [\c!width=210mm,\c!height=297mm]
\definepapersize [A5] [\c!width=148mm,\c!height=210mm]
\definepapersize [A6] [\c!width=105mm,\c!height=148mm]
\definepapersize [A7] [\c!width=74mm,\c!height=105mm]
\definepapersize [A8] [\c!width=52mm,\c!height=74mm]
\definepapersize [A9] [\c!width=37mm,\c!height=52mm]
\definepapersize [A10] [\c!width=26mm,\c!height=37mm]
\definepapersize [B0] [\c!width=1000mm,\c!height=1414mm]
\definepapersize [B1] [\c!width=707mm,\c!height=1000mm]
\definepapersize [B2] [\c!width=500mm,\c!height=707mm]
\definepapersize [B3] [\c!width=353mm,\c!height=500mm] % [\c!width=354mm,\c!height=500mm]
\definepapersize [B4] [\c!width=250mm,\c!height=353mm] % [\c!width=250mm,\c!height=354mm]
\definepapersize [B5] [\c!width=176mm,\c!height=250mm] % [\c!width=177mm,\c!height=250mm]
\definepapersize [B6] [\c!width=125mm,\c!height=176mm] % [\c!width=125mm,\c!height=177mm]
\definepapersize [B7] [\c!width=88mm,\c!height=125mm]
\definepapersize [B8] [\c!width=62mm,\c!height=88mm] % [\c!width=63mm,\c!height=88mm]
\definepapersize [B9] [\c!width=44mm,\c!height=62mm] % [\c!width=44mm,\c!height=63mm]
\definepapersize [B10] [\c!width=31mm,\c!height=44mm]
\definepapersize [C0] [\c!width=917mm,\c!height=1297mm]
\definepapersize [C1] [\c!width=648mm,\c!height=917mm] % [\c!width=649mm,\c!height=917mm]
\definepapersize [C2] [\c!width=458mm,\c!height=648mm] % [\c!width=459mm,\c!height=649mm]
\definepapersize [C3] [\c!width=324mm,\c!height=458mm] % [\c!width=324mm,\c!height=459mm]
\definepapersize [C4] [\c!width=229mm,\c!height=324mm]
\definepapersize [C5] [\c!width=162mm,\c!height=229mm]
\definepapersize [C6] [\c!width=114mm,\c!height=162mm] % [\c!width=115mm,\c!height=162mm]
\definepapersize [C7] [\c!width=81mm,\c!height=114mm] % [\c!width=81mm,\c!height=115mm]
\definepapersize [C8] [\c!width=57mm,\c!height=81mm]
\definepapersize [C9] [\c!width=40mm,\c!height=57mm]
\definepapersize [C10] [\c!width=28mm,\c!height=40mm]
%D Per August 2004 the rounding of some (seldom used) sizes
%D were corrected top the latest DIN specifications. Peter
%D Rolf came up with these and a few more missing sizes.
%D Watch out: spaces and slashes!
\definepapersize [4 A0] [\c!width=1682mm,\c!height=2378mm]
\definepapersize [2 A0] [\c!width=1189mm,\c!height=1682mm]
\definepapersize [C6/C5] [\c!width=114mm,\c!height=229mm]
%D Because there are no standardized screen sizes, we define
%D a bunch of sizes with $4:3$ ratios. The \type {S6} size is
%D nearly as wide as a sheet of \type {A4} paper.
\definepapersize [S3] [\c!width=300pt,\c!height=225pt]
\definepapersize [S4] [\c!width=400pt,\c!height=300pt]
\definepapersize [S5] [\c!width=500pt,\c!height=375pt]
\definepapersize [S6] [\c!width=600pt,\c!height=450pt]
\definepapersize [S8] [\c!width=800pt,\c!height=600pt]
\definepapersize [SW] [\c!width=800pt,\c!height=450pt]
\definepapersize [SM] [\c!width=720pt,\c!height=450pt]
%D These are handy too:
\definepapersize [S33] [\c!width=300pt,\c!height=300pt]
\definepapersize [S44] [\c!width=400pt,\c!height=400pt]
\definepapersize [S55] [\c!width=500pt,\c!height=500pt]
\definepapersize [S66] [\c!width=600pt,\c!height=600pt]
%D One may wonder if \TEX\ should be used for typesetting
%D \CDROM\ covers, but it does not hurt to have the paper size
%D ready.
\definepapersize [CD] [\c!width=120mm,\c!height=120mm]
%D The next series is for our English speaking friends who
%D decided to stick to non metric values. Thanks to Nelson
%D Beebe for completing the inch based list.
\definepapersize [letter] [\c!width=8.5in,\c!height=11in]
\definepapersize [ledger] [\c!width=11in,\c!height=17in]
\definepapersize [tabloid] [\c!width=17in,\c!height=11in]
\definepapersize [legal] [\c!width=8.5in,\c!height=14in]
\definepapersize [folio] [\c!width=8.5in,\c!height=13in]
\definepapersize [executive] [\c!width=7.25in,\c!height=10.5in]
\definepapersize [A] [\c!width=8.5in,\c!height=11in] % 1 sheet
\definepapersize [B] [\c!width=11in,\c!height=17in] % 2 sheets
\definepapersize [C] [\c!width=17in,\c!height=22in] % 4 sheets
%D The next set is for Tobias Burnus, who gave me the sizes.
\definepapersize [envelope 9] [\c!width=8.88in,\c!height=3.88in]
\definepapersize [envelope 10] [\c!width=9.5in,\c!height=4.13in]
\definepapersize [envelope 11] [\c!width=10.38in,\c!height=4.5in]
\definepapersize [envelope 12] [\c!width=11.0in,\c!height=4.75in]
\definepapersize [envelope 14] [\c!width=11.5in,\c!height=5.0in]
\definepapersize [monarch] [\c!width=7.5in,\c!height=3.88in]
\definepapersize [check] [\c!width=8.58in,\c!height=3.88in]
\definepapersize [DL] [\c!width=110mm,\c!height=220mm] % [\c!width=220mm,\c!height=110mm]
\definepapersize [E4] [\c!width=280mm,\c!height=400mm]
%D The next three sets are supplied by Taco:
\definepapersize [RA0] [\c!width=860mm,\c!height=1220mm]
\definepapersize [RA1] [\c!width=610mm,\c!height=860mm]
\definepapersize [RA2] [\c!width=430mm,\c!height=610mm]
\definepapersize [RA3] [\c!width=305mm,\c!height=430mm]
\definepapersize [RA4] [\c!width=215mm,\c!height=305mm]
%D ISO SRA (supplementary raw A) sizes:
\definepapersize [SRA0] [\c!width=900mm,\c!height=1280mm]
\definepapersize [SRA1] [\c!width=640mm,\c!height=900mm]
\definepapersize [SRA2] [\c!width=450mm,\c!height=640mm]
\definepapersize [SRA3] [\c!width=320mm,\c!height=450mm]
\definepapersize [SRA4] [\c!width=225mm,\c!height=320mm]
%D Swedish thesis formats:
\definepapersize [G5] [\c!width=169mm,\c!height=239mm]
\definepapersize [E5] [\c!width=155mm,\c!height=220mm]
%D Industry invention:
\definepapersize [A3plus] [\c!width=329mm,\c!height=483mm]
%D We can now default to a reasonable size. We match the print
%D paper size with the typeset paper size. This setting should
%D come after the first layout specification (already done).
\setuppapersize
[A4][A4]
%D A few goodies:
\definepapersize
[oversized]
[ \c!width=\dimexpr\paperwidth +1.5cm\relax,
\c!height=\dimexpr\paperheight+1.5cm\relax]
\definepapersize
[doublesized]
[ \c!width=\dimexpr \paperwidth \relax,
\c!height=\dimexpr2\paperheight\relax]
\definepapersize
[doubleoversized]
[ \c!width=\dimexpr \paperheight+1.5cm\relax,
\c!height=\dimexpr2\paperwidth +1.5cm\relax]
%D For orthogonality:
\definepapersize
[undersized]
[ \c!width=\dimexpr\paperwidth -1.5cm\relax,
\c!height=\dimexpr\paperheight-1.5cm\relax]
\definelayout
[\v!page]
[\c!backspace=\zeropoint,
\c!cutspace=\zeropoint,
\c!topspace=\zeropoint,
\c!bottomspace=\zeropoint,
\c!margin=\zeropoint,
\c!edge=\zeropoint,
\c!header=\zeropoint,
\c!footer=\zeropoint,
\c!top=\zeropoint,
\c!bottom=\zeropoint,
\c!leftmargin=\zeropoint,
\c!rightmargin=\zeropoint,
\c!leftedge=\zeropoint,
\c!rightedge=\zeropoint,
\c!textdistance=\zeropoint,
\c!width=\v!middle,
\c!height=\v!middle,
\c!lines=0,
\c!grid=\v!no]
\definelayout
[\v!middle]
[\c!width=\v!middle,
\c!height=\v!middle]
\protect \endinput
|