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
|
%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}
% 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\kopoffset \kopoffset = 0pt
\newdimen\rugoffset \rugoffset = \kopoffset
\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%
% {\ifundefined{\??ly\currentlayout#1}%
% \getvalue{\??ly#1}%
% \else
% \getvalue{\??ly\currentlayout#1}%
% \fi}
%
% faster
\def\layoutparameter#1%
{\csname\??ly
\ifundefined{\??ly\currentlayout#1}\else\currentlayout\fi
#1\endcsname}
\def\namedlayoutparameter#1#2%
{\ifundefined{\??ly#1#2}%
\layoutparameter{#2}%
\else
\getvalue{\??ly#1#2}%
\fi}
%D Look how ugly a speed up looks:
\beginTEX
\def\layoutparameter#1%
{\csname\??ly\@EA\ifx\csname
\??ly\currentlayout#1\endcsname\relax\else\currentlayout
\fi#1\endcsname}
\def\namedlayoutparameter#1#2%
{\csname\??ly
\@EA\ifx\csname\??ly#1#2\endcsname\relax
\@EA\ifx\csname\??ly\currentlayout#2\endcsname\relax
\else\currentlayout\fi
\else#1\fi
\fi#2\endcsname}
\endTEX
%D Its \ETEX\ counterpart is:
\beginETEX \ifcsname
\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}
\endETEX
%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}
\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
\scratchdimen\leftmarginwidth \advance\scratchdimen\leftmargindistance \xdef\leftmargintotal {\the\scratchdimen}%
\scratchdimen\rightmarginwidth \advance\scratchdimen\rightmargindistance \xdef\rightmargintotal{\the\scratchdimen}%
\scratchdimen\leftedgewidth \advance\scratchdimen\leftedgedistance \xdef\leftedgetotal {\the\scratchdimen}%
\scratchdimen\rightedgewidth \advance\scratchdimen\rightedgedistance \xdef\rightedgetotal {\the\scratchdimen}%
\scratchdimen\leftmarginwidth \advance\scratchdimen\leftedgetotal \xdef\leftsidetotal {\the\scratchdimen}%
\scratchdimen\rightmarginwidth \advance\scratchdimen\rightedgetotal \xdef\rightsidetotal {\the\scratchdimen}%
\scratchdimen\leftmargintotal \advance\scratchdimen\leftedgetotal \xdef\leftcombitotal {\the\scratchdimen}%
\scratchdimen\rightmargintotal \advance\scratchdimen\rightedgetotal \xdef\rightcombitotal {\the\scratchdimen}%
%
\scratchdimen\innermarginwidth \advance\scratchdimen\innermargindistance \xdef\innermargintotal{\the\scratchdimen}%
\scratchdimen\outermarginwidth \advance\scratchdimen\outermargindistance \xdef\outermargintotal{\the\scratchdimen}%
\scratchdimen\inneredgewidth \advance\scratchdimen\inneredgedistance \xdef\inneredgetotal {\the\scratchdimen}%
\scratchdimen\outeredgewidth \advance\scratchdimen\outeredgedistance \xdef\outeredgetotal {\the\scratchdimen}%
\scratchdimen\innermargintotal \advance\scratchdimen\inneredgetotal \xdef\innercombitotal {\the\scratchdimen}%
\scratchdimen\outermargintotal \advance\scratchdimen\outeredgetotal \xdef\outercombitotal {\the\scratchdimen}%
\scratchdimen\innermarginwidth \advance\scratchdimen\inneredgetotal \xdef\innersidetotal {\the\scratchdimen}%
\scratchdimen\outermarginwidth \advance\scratchdimen\outeredgetotal \xdef\outersidetotal {\the\scratchdimen}%
\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\dodefinepapersize[#1][#2]%
{\ifsecondargument
\doifsomething{#1} % to be sure
{\getparameters
[\??pp#1] % geen \c!scale, scheelt hash ruimte
[\c!width=\@@ppwidth,\c!height=\@@ppheight,\c!offset=\@@ppoffset,#2]}%
\else
\getparameters[\??pp][#1]%
\setuppapersize
\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 \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
\chardef\paperreverse =0 \chardef\printreverse =0
\chardef\paperlandscape =0 \chardef\printlandscape =0
\let\papersize\empty \let\printpapersize\empty
\def\paperscale{1} \newif\ifnegateprintbox
% \def\dosetuppapersize[#1][#2]%
% {\doifassignmentelse{#1}
% {\getparameters[\??pp][#1]}
% {\doifassignmentelse{#2}
% {\getparameters[\??pp#1][#2]}
% {\dodosetuppapersize[#1][#2]}}}
%
% The next version is more extensive; here we can
% associate paper and page with key/value like settinsg,
% which is handy in 'example' when we use setups
\def\setuppaper[#1]%
{\getparameters[\??pp][\c!paper=,\c!page=,#1]%
\scratchcounter\@@ppnx
\multiply\scratchcounter\@@ppny
\edef\@@ppxy{\the\scratchcounter}%
\doifelsenothing\@@pppage
{\doifsomething\@@pppaper
{\dodosetuppapersize[\papersize][\@@pppaper]}}
{\doifelsenothing\@@pppaper
{\dodosetuppapersize[\@@pppage][\printpapersize]}
{\dodosetuppapersize[\@@pppage][\@@pppaper]}}}
\def\setuppapersize
{\dodoubleempty\dosetuppapersize}
\def\dosetuppapersize[#1][#2]%
{\doifassignmentelse{#1}
{\setuppaper[#1]}
{\doifassignmentelse{#2}
{\getparameters[\??pp#1][#2]}
{\dodosetuppapersize[#1][#2]}}}
\def\dodosetuppapersize[#1][#2]%
{\ifsecondargument
\expanded{\dododosetuppapersize[#1][#2]}%
\calculatehsizes
\calculatevsizes
\recalculatelogos
\recalculatebackgrounds
\recalculatelayout
\else\iffirstargument
\setuppapersize[#1][#2]%
\else\ifx\papersize\undefined\else
\restorepapersize
\fi\fi\fi}
\def\dododosetuppapersize[#1][#2]%
{\xdef\restorepapersize
{\noexpand\setuppapersize[#1][#2]}%
\dosetuppaperorientation{#1}\paperlandscape\paperorientation\paperreverse\papermirror
\dosetuppaperorientation{#2}\printlandscape\printorientation\printreverse\printmirror
\def\docommando##1%
{\doifsomething{##1}{\doifdefined{\??pp##1\c!width}
{\global\paperwidth\getvalue{\??pp##1\c!width}%
\global\paperheight\getvalue{\??pp##1\c!height}%
\calculatepaperoffsets{##1}%
\xdef\papersize{##1}}}}%
\processcommacommand[#1]\docommando
\doifdefinedelse{\??pp#1\c!scale}
{\edef\paperscale{\getvalue{\??pp#1\c!scale}}}
{\edef\paperscale{1}}%
\def\docommando##1%
{\doifsomething{##1}{\doifdefined{\??pp##1\c!width}
{\global\printpaperwidth\getvalue{\??pp##1\c!width}%
\global\printpaperheight\getvalue{\??pp##1\c!height}%
\xdef\printpapersize{##1}}}}%
\processcommacommand[#2]\docommando
\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
\doifinset\paperorientation{90,270}{\swapdimens\paperwidth\paperheight}%
\doifinset\printorientation{90,270}{\swapdimens\printpaperwidth\printpaperheight}%
\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\checkforems[#1]%
{\def\docommando##1%
{\beforesplitstring##1\at em\to\asciia
\doifnot\asciia{##1}
{\aftersplitstring\asciia\at=\to\asciia
\doifsomething\asciia
{\showmessage\m!systems{10}{##1}}}}%
\processcommalist[#1]\docommando}
\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}
\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'
\doifelse\@@lygrid\v!yes\gridsnappingtrue\gridsnappingfalse
\ifgridsnapping
\setsystemmode\v!grid
\else
\resetsystemmode\v!grid
\fi
\setups[\layoutparameter\c!setups]% depends on gridsnapping !
\simplesetupwhitespace
\simplesetupblank
\global\cutspace\layoutparameter\c!cutspace
\relax
\doifelse{\layoutparameter\c!width}\v!middle
{\ifdim\cutspace=\zeropoint
\global\cutspace\backspace
\fi
\global\makeupwidth\paperwidth
\global\advance\makeupwidth -\backspace
\global\advance\makeupwidth -\cutspace}
{\doifelse{\layoutparameter\c!width}\v!fit
{\ifdim\cutspace=\zeropoint
\global\cutspace\backspace
\fi
\global\makeupwidth\paperwidth
\global\advance\makeupwidth -\cutspace
\scratchdimen\backspace
\advance\scratchdimen -\leftedgewidth
\advance\scratchdimen -\leftedgedistance
\advance\scratchdimen -\leftmarginwidth
\advance\scratchdimen -\leftmargindistance\relax
\ifdim\scratchdimen<\zeropoint
\scratchdimen\zeropoint
\fi
\global\advance\makeupwidth -\rightmargindistance
\global\advance\makeupwidth -\rightmarginwidth
\global\advance\makeupwidth -\rightedgedistance
\global\advance\makeupwidth -\rightedgewidth
\global\advance\makeupwidth -\scratchdimen}
{\global\makeupwidth\layoutparameter\c!width\relax
\ifdim\cutspace=\zeropoint
\global\cutspace\paperwidth
\global\advance\cutspace-\makeupwidth
\global\advance\cutspace-\backspace
% \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\paperheight
\global\advance\makeupheight -\topspace
\global\advance\makeupheight -\bottomspace}
{\doifelse{\layoutparameter\c!height}\v!fit
{\ifdim\bottomspace=\zeropoint
\global\bottomspace\topspace
\fi
\global\makeupheight\paperheight
\global\advance\makeupheight -\bottomspace
\scratchdimen\topspace
\advance\scratchdimen -\topheight
\advance\scratchdimen -\topdistance\relax
\ifdim\scratchdimen<\zeropoint
\scratchdimen\zeropoint
\fi
\global\advance\makeupheight -\bottomdistance
\global\advance\makeupheight -\bottomheight
\global\advance\makeupheight -\scratchdimen}
{\global\makeupheight\layoutparameter\c!height\relax
\ifdim\bottomspace=\zeropoint
\global\bottomspace\paperheight
\global\advance\bottomspace-\makeupheight
\global\advance\bottomspace-\topspace
\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\layoutparameter\c!lines\lineheight
% new, cleaner
\global\advance\makeupheight-\strutheight
\global\advance\makeupheight \topskip
% new, was a bug
\global\advance\makeupheight \headerdistance
\global\advance\makeupheight \footerdistance
% so far
\global\advance\makeupheight \headerheight
\global\advance\makeupheight \footerheight
\fi
\rugoffset\layoutparameter\c!horoffset
\kopoffset\layoutparameter\c!veroffset
\global\setdimentoatleast\makeupwidth\onepoint
\global\setdimentoatleast\makeupheight \onepoint
% \checkcurrentlayout % here ?
% \the\everyafterlayout
\calculatelayoutextras
\calculatehsizes
\calculatevsizes
\calculatepseudocolumns
\checkgridsnapping
\recalculatelogos
\recalculatebackgrounds}
\def\calculatepseudocolumns
{\global\layoutcolumns\layoutparameter\c!columns
\global\layoutcolumndistance\layoutparameter\c!columndistance
\global\layoutcolumnwidth-\layoutcolumns\layoutcolumndistance
\global\advance\layoutcolumnwidth\layoutcolumndistance
\global\advance\layoutcolumnwidth\makeupwidth
\global\divide\layoutcolumnwidth\layoutcolumns
\dorecurse\layoutcolumns
{\scratchdimen\layoutcolumnwidth
\advance\scratchdimen\layoutcolumndistance
\scratchcounter\recurselevel
\advance\scratchcounter\minusone
\scratchdimen\scratchcounter\scratchdimen
\setxvalue{\??ly:c:\recurselevel}{\the\scratchdimen}}}
%\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\checkcurrentlayout % public and used in naw, so keep this name
{\ifundefined{\??ly\realfolio\c!state}%
\doifoddpageelse\checkcurrentoddlayout\checkcurrentevenlayout
\else
\doifvalue{\??ly\realfolio\c!state}\v!start
{\xdef\currentlayout{\realfolio}\recalculatelayout}% new, global
\fi}
\def\checkcurrentoddlayout
{\ifundefined{\??ly\v!odd\c!state}\else
\doifvalue{\??ly\v!odd\c!state}\v!start
{\globallet\currentlayout\v!odd\recalculatelayout}% new, global
\fi}
\def\checkcurrentevenlayout
{\ifundefined{\??ly\v!even\c!state}\else
\doifvalue{\??ly\v!even\c!state}\v!start
{\globallet\currentlayout\v!even\recalculatelayout}% new, global
\fi}
\appendtoks \checkcurrentlayout \to \everyaftershipout
\newif\ifdoublesidedprint
\def\presetcenterpagebox % in \setuplayout !!!!!!!!!!!!!!!!
{\doublesidedprintfalse
\ExpandFirstAfter\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\dosetuplayout[#1][#2]%
% {\let\currentlayout\empty
% \ifsecondargument
% \dodosetuplayout[#1][#2]%
% \else\iffirstargument
% \doifassignmentelse{#1}
% {\dodosetuplayout[][#1]}
% {\doifnot{#1}\v!reset{\def\currentlayout{#1}}}%
% \fi\fi
% \recalculatelayout
% \checkcurrentlayout % here ?
% \presetcenterpagebox}
% 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
\rawdoifinsetelse\realfolio\adaptedpages
{\getvalue{\??za\realfolio}%
\letbeundefined{\??za\realfolio}}
\donothing
\fi}
\def\checkpagedimensions
{\poppagedimensions
\adaptpagedimensions}
\def\reportpagedimensions
{\ifx\poppagedimensions\relax \else
\space\@@zaheight\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 ?
\recalculatelogos
\recalculatebackgrounds
\global\let\pushpagedimensions\relax
\global\let\poppagedimensions\dopoppagedimensions}
\def\doadaptlayout[#1][#2]%
{\doifelsenothing{#2}
{\dodoadaptlayout[#1]}
{\def\docommando##1%
{\addtocommalist{##1}\adaptedpages
\setgvalue{\??za##1}{\dodoadaptlayout[#2]}}%
\processcommalist[#1]\docommando
\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
\orsideone \@@ppleft \box#1\@@ppright
\orsidetwo \@@ppright\box#1\@@ppleft
\od \else \@@ppleft \box#1\@@ppright
\fi}%
\par
\@@ppbottom}}
\def\offsetprintbox#1%
{\ifdim\kopoffset=\zeropoint % \relax
\ifdim\rugoffset=\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
{%\forgetall
\offinterlineskip
\vskip\kopoffset
\doifbothsides
\hskip\rugoffset
\orsideone
\hskip\rugoffset
\orsidetwo
\hskip-\rugoffset
\od
\box#1}%
\next
\fi}
% \def\replicatebox#1#2#3%
% {\setbox#1=\vbox
% {%\forgetall
% \offinterlineskip
% \dorecurse{#3}
% {\hbox{\dorecurse{#2}{\copy#1\hskip\@@lydx}\unskip}%
% \vskip\@@lydy}
% \unskip}}
%
% \def\replicatepagebox#1%
% {\ifnum\@@lynx>0 \ifnum\@@lyny>0
% \replicatebox{#1}{\@@lynx}{\@@lyny}%
% \fi\fi}
\def\replicatepagebox#1%
{\ifnum\@@lynx>\plusone
\donetrue
\else\ifnum\@@lyny>\plusone
\donetrue
\else
\donefalse
\fi\fi
\ifdone
\setbox#1\vbox
{%\forgetall
\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{\ifdubbelzijdig\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}
\def\addpagecutmarks % #1
{\doifelse\@@lymarking\v!on
\makepagecutbox
{\doifelse\@@lymarking\v!empty
{\let\pagecutmarksymbol\empty
\let\pagecutmarktoptext\empty
\let\pagecutmarkbottomtext\empty
\makepagecutbox}
{\doifelse\@@lymarking\v!text
{\let\pagecutmarksymbol\empty
\let\pagecutmarkbottomtext\extrapagecutmarkbottomtext
\makepagecutbox}
\gobbleoneargument}}}
\def\addpagecolormarks % #1
{\doifelse\@@lymarking\v!color
{\doaddpagecolormarks\colormarkbox}
{\doifelse\@@lymarking\v!screen
{\doaddpagecolormarks\rastermarkbox}
\gobbleoneargument}}
\def\doaddpagecolormarks#1#2%
{\makepagecutbox{#2}%
\ifnum\horizontalcutmarks>2 \chardef\colormarkoffset4 \fi
\ifnum\verticalcutmarks >2 \chardef\colormarkoffset4 \fi
#1{#2}}
\newif\ifdubbelzijdig \dubbelzijdigfalse
\newif\ifenkelzijdig \enkelzijdigtrue
\def\doifsometextlineelse#1%
{\edef\!!stringa{\csname\??tk#1\c!state\endcsname}%
\ifx\!!stringa\v!none
\@EA\secondoftwoarguments
\else\ifx\!!stringa\v!high
\@EAEAEA\secondoftwoarguments
\else
\@EAEAEA\firstoftwoarguments
\fi\fi}
% NOG EENS NAGAAN WANNEER NU GLOBAL EN WANNEER NIET
\def\calculatevsizes % global needed in \recalculatelayoutregel
{\redoglobal\textheight\makeupheight
\doifsometextlineelse \v!header
{\redoglobal\advance\textheight -\headerheight
\redoglobal\advance\textheight -\headerdistance}%
\donothing
\doifsometextlineelse \v!footer
{\redoglobal\advance\textheight -\footerheight
\redoglobal\advance\textheight -\footerdistance}%
\donothing
\ifzeropt\headerheight
\resetsystemmode\v!header
\else
\setsystemmode\v!header
\fi
\ifzeropt\footerheight
\resetsystemmode\v!footer
\else
\setsystemmode\v!footer
\fi
\resetglobal
\setvsize}
\def\calculatereducedvsizes
{\textheight\makeupheight
\doifsometextlineelse \v!header
{\advance\textheight -\headerheight
\advance\textheight -\headerdistance}%
{\headerheight\zeropoint
\setlayoutdistances}%
\doifsometextlineelse \v!footer
{\advance\textheight -\footerheight
\advance\textheight -\footerdistance}%
{\footerheight\zeropoint
\setlayoutdistances}}
\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
\doifsomething{\layoutparameter\c!textmargin}%
{\advance\textwidth-\layoutparameter\c!textmargin % local
\advance\textwidth-\layoutparameter\c!textmargin}} % 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
% \def\doifoddpageelse#1#2%
% {\ifshiftedrealpageno
% \ifodd\realpageno#2\else#1\fi
% \else
% \ifodd\realpageno#1\else#2\fi
% \fi}
\def\doifoddpageelse
{\ifshiftedrealpageno
\ifodd\realpageno
\@EAEAEA\secondoftwoarguments
\else
\@EAEAEA\firstoftwoarguments
\fi
\else
\ifodd\realpageno
\@EAEAEA\firstoftwoarguments
\else
\@EAEAEA\secondoftwoarguments
\fi
\fi}
\let\doifonevenpaginaelse\doifoddpageelse
% what are those \relax'es doing there?
\def\doifbothsidesoverruled#1\orsideone#2\orsidetwo#3\od
{\ifdubbelzijdig
\doifoddpageelse{#2}{#3}\relax
\else
#1\relax
\fi}
\def\doifbothsides#1\orsideone#2\orsidetwo#3\od
{\ifdubbelzijdig
\ifenkelzijdig
#1\relax
\else
\doifoddpageelse{#2}{#3}\relax
\fi
\else
#1\relax
\fi}
\newdimen\texthoffset
\def\settexthoffset
{\doifbothsides
\texthoffset\backspace
\orsideone
\texthoffset\backspace
\orsidetwo
\texthoffset\paperwidth
\advance\texthoffset-\backspace
\advance\texthoffset-\makeupwidth
\od}
\def\goleftonpage
{\hskip-\leftmargindistance
\hskip-\leftmarginwidth
\hskip-\leftedgedistance
\hskip-\leftedgewidth}
\def\doifmarginswapelse#1#2%
{\doifbothsides#1\orsideone#1\orsidetwo#2\od}
\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
{\ifdubbelzijdig
\ifenkelzijdig
\@EAEAEA\firstoftwoarguments
\else
\@EAEAEA\doifoddpageelse
\fi
\else
\@EA\firstoftwoarguments
\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}
\beginETEX \dimexpr
\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}
\endETEX
%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}
\fetchruntimecommand \showframe {page-run}
\fetchruntimecommand \showlayout {page-run}
\fetchruntimecommand \showsetups {page-run}
\fetchruntimecommand \showmargins {page-run}
%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]
\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 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:
\beginETEX \dimexpr
\definepapersize
[oversized]
[\c!width=\dimexpr(\paperwidth+1.5cm),
\c!height=\dimexpr(\paperheight+1.5cm)]
\definepapersize
[doublesized]
[\c!width=\dimexpr(\paperwidth),
\c!height=\dimexpr(2\paperheight)]
\definepapersize
[doubleoversized]
[\c!width=\dimexpr(\paperheight+1.5cm),
\c!height=\dimexpr(2\paperwidth+1.5cm)]
%D For orthogonality:
\definepapersize
[undersized]
[\c!width=\dimexpr(\paperwidth-1.5cm),
\c!height=\dimexpr(\paperheight-1.5cm)]
\endETEX
\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
|