page-lay.mkxl /size: 60 Kb    last modification: 2021-10-28 13:51
1%D \module
2%D   [       file=page-lay,
3%D        version=2000.10.20, % copied from main-001
4%D          title=\CONTEXT\ Page Macros,
5%D       subtitle=Layout Specification,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Page Macros / Layout Specification}
15
16%D Before you start wondering why some of the page related modules skip upward or
17%D left in order to place elements, you must realize that the reference point is the
18%D top left corner of the main typesetting area. One reason for this choice is that
19%D it suited some viewers that displayed page areas. Another reason is that margins,
20%D edges and top and bottom areas are kind of virtual, while the header, text and
21%D footer areas normally determine the text flow.
22
23\unprotect
24
25%D The dimensions related to layout areas are represented by real dimensions.
26
27\newdimen\paperheight          \paperheight          = 297mm
28\newdimen\paperwidth           \paperwidth           = 210mm
29\newdimen\paperoffset          \paperoffset          = \zeropoint
30\newdimen\paperbleed           \paperbleed           = \zeropoint
31\newdimen\spinewidth           \spinewidth           = \zeropoint
32
33\newdimen\printpaperheight     \printpaperheight     = \paperheight
34\newdimen\printpaperwidth      \printpaperwidth      = \paperwidth
35
36\newdimen\makeupheight                               % calculated
37\newdimen\makeupwidth                                % calculated
38
39\newdimen\textheight                                 % calculated
40\newdimen\textwidth                                  % calculated
41
42\newdimen\topspace             \topspace             = 2cm
43\newdimen\backspace            \backspace            = \topspace
44\newdimen\cutspace             \cutspace             = \zeropoint
45\newdimen\bottomspace          \bottomspace          = \zeropoint
46
47\newdimen\headerheight         \headerheight         = 2cm
48\newdimen\footerheight         \footerheight         = \headerheight
49
50\newdimen\topoffset            \topoffset            = \zeropoint
51\newdimen\backoffset           \backoffset           = \topoffset
52
53\newdimen\leftmarginwidth      \leftmarginwidth      = 3cm
54\newdimen\rightmarginwidth     \rightmarginwidth     = \leftmarginwidth
55
56\newdimen\leftedgewidth        \leftedgewidth        = 3cm
57\newdimen\rightedgewidth       \rightedgewidth       = \leftedgewidth
58
59\newdimen\topheight            \topheight            = \zeropoint
60\newdimen\bottomheight         \bottomheight         = \topheight
61
62\newcount\layoutlines          \layoutlines          = \zerocount
63\newcount\layoutcolumns        \layoutcolumns        = \zerocount
64\newdimen\layoutcolumndistance \layoutcolumndistance = \zeropoint
65\newdimen\layoutcolumnwidth    \layoutcolumnwidth    = \zeropoint
66
67\newdimen\totaltextwidth
68
69%D The next series of dimensions are complemented by left and rights ones.
70
71\newdimen\margindistance
72\newdimen\edgedistance
73\newdimen\marginwidth
74\newdimen\edgewidth
75
76%D Because a distance does not really makes sense when there is no area, we use a
77%D zero distance in case there is no area.
78
79%D The horizontal distances are:
80
81\newdimen\leftedgedistance
82\newdimen\rightedgedistance
83\newdimen\leftmargindistance
84\newdimen\rightmargindistance
85
86%D The vertical distances are:
87
88\newdimen\topdistance
89\newdimen\headerdistance
90\newdimen\textdistance
91\newdimen\footerdistance
92\newdimen\bottomdistance
93
94\newdimen\textovershoot % available in pagebuilder
95
96%D We need to calculate the extra distances:
97
98\newdimen\naturalmarginwidth
99\newdimen\naturaledgewidth
100\newdimen\naturalmargindistance
101\newdimen\naturaledgedistance
102\newdimen\naturalleftedgedistance
103\newdimen\naturalrightedgedistance
104\newdimen\naturalleftmargindistance
105\newdimen\naturalrightmargindistance
106\newdimen\naturaltopdistance
107\newdimen\naturalheaderdistance
108\newdimen\naturaltextdistance
109\newdimen\naturalfooterdistance
110\newdimen\naturalbottomdistance
111
112%D Now we've come to the setup and definition commands.
113
114\installcorenamespace{layout}
115\installcorenamespace{layoutlocation}
116\installcorenamespace{layoutalternative}
117\installcorenamespace{layoutcolumn}
118\installcorenamespace{layoutmethod}
119
120\installswitchcommandhandler \??layout {layout} \??layout
121
122\appendtoks
123    \doifnothing{\directlayoutparameter\c!state}{\letlayoutparameter\c!state\v!start}%
124\to \everydefinelayout
125
126\newconditional \layouthaschanged \settrue\layouthaschanged % used in mp
127
128\appendtoks
129    \ifcase\layoutsetupmode
130        % can't happen
131    \or % \setuplayout[name][key=value]
132      \ifx\previouslayout\currentlayout
133        \letlayoutparameter\c!state\v!normal % global ? still needed ?
134        \let\currentlayout\currentlayout
135        \page_layouts_synchronize
136        \page_layouts_check_next
137      \fi
138    \or % \setuplayout[key=value]
139      % we can inherit so we always synchronize
140      \letlayoutparameter\c!state\v!normal % global ? still needed ?
141      \let\currentlayout\previouslayout
142      \page_layouts_synchronize
143      \page_layouts_check_next
144    \or % \setuplayout[name]
145      \ifx\currentlayout\v!reset
146        \let\currentlayout\empty
147      \fi
148      \letlayoutparameter\c!state\v!normal % global ? still needed ?
149      \glet\currentlayout\currentlayout % global
150      \page_layouts_synchronize
151      \page_layouts_check_next
152    \or % \setuplayout (reverts to main layout)
153      \letlayoutparameter\c!state\v!normal % global ? still needed ?
154      \glet\currentlayout\empty % global
155      \page_layouts_synchronize
156      \page_layouts_check_next
157    \fi
158    \global\settrue\layouthaschanged
159\to \everysetuplayout
160
161\appendtoks
162    \global\setfalse\layouthaschanged
163\to \everyaftershipout
164
165\permanent\def\doifelselayoutdefined#1%
166  {\ifcsname\namedlayouthash{#1}\c!state\endcsname % maybe a helper
167      \expandafter\firstoftwoarguments
168   \else
169      \expandafter\secondoftwoarguments
170   \fi}
171
172\aliased\let\doiflayoutdefinedelse\doifelselayoutdefined
173
174\permanent\def\layoutdistance#1#2{\ifdim\zeropoint<#1#2\else\zeropoint\fi}
175
176% \newconditional\reverselayout
177
178\def\page_layouts_set_dimensions
179  {\global\naturalmarginwidth        \layoutparameter\c!margin
180   \global\naturaledgewidth          \layoutparameter\c!edge
181   \global\naturalmargindistance     \layoutparameter\c!margindistance
182   \global\naturaledgedistance       \layoutparameter\c!edgedistance
183   \global\naturalleftedgedistance   \layoutparameter\c!leftedgedistance
184   \global\naturalrightedgedistance  \layoutparameter\c!rightedgedistance
185   \global\naturalleftmargindistance \layoutparameter\c!leftmargindistance
186   \global\naturalrightmargindistance\layoutparameter\c!rightmargindistance
187   \global\naturaltopdistance        \layoutparameter\c!topdistance
188   \global\naturalheaderdistance     \layoutparameter\c!headerdistance
189   \global\naturaltextdistance       \layoutparameter\c!textdistance
190   \global\naturalfooterdistance     \layoutparameter\c!footerdistance
191   \global\naturalbottomdistance     \layoutparameter\c!bottomdistance
192   %
193   \global\marginwidth               \naturalmarginwidth
194   \global\edgewidth                 \naturaledgewidth
195   \global\margindistance            \naturalmargindistance
196   \global\edgedistance              \naturaledgedistance
197   %
198   \global\leftedgedistance          \layoutdistance\leftedgewidth   \naturalleftedgedistance
199   \global\rightedgedistance         \layoutdistance\rightedgewidth  \naturalrightedgedistance
200   \global\leftmargindistance        \layoutdistance\leftmarginwidth \naturalleftmargindistance
201   \global\rightmargindistance       \layoutdistance\rightmarginwidth\naturalrightmargindistance
202   \global\topdistance               \layoutdistance\topheight       \naturaltopdistance
203   \global\headerdistance            \layoutdistance\headerheight    \naturalheaderdistance
204   \global\textdistance                                              \naturaltextdistance
205   \global\footerdistance            \layoutdistance\footerheight    \naturalfooterdistance
206   \global\bottomdistance            \layoutdistance\bottomheight    \naturalbottomdistance}
207
208\def\page_layouts_set_distances % local in \setreducedvsize
209  {\headerdistance\layoutdistance\headerheight\naturalheaderdistance
210   \footerdistance\layoutdistance\footerheight\naturalfooterdistance}
211
212% these are wrong in the running text, assumes some swapping, needs a cleanup
213
214\newtoks\extralayoutcalculations
215
216\def\page_layouts_calculate_extras
217  {\the\extralayoutcalculations}
218
219\newtoks\everyswapmargins % watch the order !
220
221\appendtoks
222    \enforced\swapcsvalues\leftmargindistance\rightmargindistance
223    \enforced\swapcsvalues\leftedgedistance  \rightedgedistance
224    \enforced\swapcsvalues\leftmarginwidth   \rightmarginwidth
225    \enforced\swapcsvalues\leftedgewidth     \rightedgewidth
226    %
227    \enforced\swapcsvalues\leftmargintotal   \rightmargintotal
228    \enforced\swapcsvalues\leftedgetotal     \rightedgetotal
229    \enforced\swapcsvalues\leftsidetotal     \rightsidetotal
230    \enforced\swapcsvalues\leftcombitotal    \rightcombitotal
231    \enforced\swapcsvalues\innermargintotal  \outermargintotal
232    \enforced\swapcsvalues\inneredgetotal    \outeredgetotal
233    \enforced\swapcsvalues\innercombitotal   \outercombitotal
234    \enforced\swapcsvalues\innersidetotal    \outersidetotal
235\to \everyswapmargins
236
237%D The papersize macros have a long history and we don't want to change the commands
238%D so they keep looking a bit complex.
239
240%D \macros
241%D   {definepapersize}
242%D
243%D Before we start calculating layout dimensions, we will first take care of paper
244%D sizes. The first argument can be either an assignment (for defaults) or an
245%D identifier, in which case the second argument is an assignment.
246%D
247%D \showsetup{definepapersize}
248%D
249%D Yet undocumented, let's see if it gets noticed.
250%D
251%D \starttyping
252%D \definepapersize[main] [A4]          [A4]
253%D \definepapersize[extra][A4,landscape][A4,landscape]
254%D
255%D \starttext
256%D     \setuppapersize[main]
257%D     Page 1. \page
258%D     Page 2. \page
259%D     \setuppapersize[extra]
260%D     Page 2 \page
261%D     \setuppapersize[main]
262%D     Page 3. \page
263%D     Page 4. \page
264%D     \adaptpapersize[extra]
265%D     Page 5. \page
266%D     Page 6. \page
267%D \stoptext
268%D \stoptyping
269%D
270%D \macros
271%D   {setuppaper,setuppapersize}
272%D
273%D When setting up the papersize on which to typeset and print, we can also
274%D determine some more characteristics.
275%D
276%D \showsetup{setuppapersize}
277%D
278%D We keep track of these features with the following
279%D variables.
280
281\installcorenamespace{layouttarget}
282\installcorenamespace{layoutpaper}
283\installcorenamespace{layoutprint}
284\installcorenamespace{layoutcurrent}
285
286\installcommandhandler \??layouttarget {layouttarget} \??layouttarget % so this is a sort of mix, not really a user command / maybe switch handler
287
288\newconditional\c_page_target_paper_mirror
289\newconstant   \c_page_target_paper_orientation
290\newconstant   \c_page_target_paper_reverse
291\newconditional\c_page_target_paper_landscape
292\newconditional\c_page_target_paper_negate
293
294\newconditional\c_page_target_print_mirror
295\newconstant   \c_page_target_print_orientation
296\newconstant   \c_page_target_print_reverse
297\newconditional\c_page_target_print_landscape
298\newconditional\c_page_target_print_negate
299\newconditional\c_page_target_print_doublesided
300
301\let\v_page_target_left_fill  \relax
302\let\v_page_target_right_fill \relax
303\let\v_page_target_top_fill   \relax
304\let\v_page_target_bottom_fill\relax
305
306\let\papersize     \empty
307\let\printpapersize\empty
308
309\def\v_page_target_top      {\namedlayouttargetparameter\papersize\c!top   }
310\def\v_page_target_bottom   {\namedlayouttargetparameter\papersize\c!bottom}
311\def\v_page_target_left     {\namedlayouttargetparameter\papersize\c!left  }
312\def\v_page_target_right    {\namedlayouttargetparameter\papersize\c!right }
313\def\v_page_target_method   {\rootlayouttargetparameter           \c!method}
314\def\v_page_target_scale    {\rootlayouttargetparameter           \c!scale }
315\def\v_page_target_nx       {\numexpr\rootlayouttargetparameter   \c!nx       \relax}
316\def\v_page_target_ny       {\numexpr\rootlayouttargetparameter   \c!ny       \relax}
317\def\v_page_target_dx       {\dimexpr\rootlayouttargetparameter   \c!dx       \relax}
318\def\v_page_target_dy       {\dimexpr\rootlayouttargetparameter   \c!dy       \relax}
319\def\v_page_target_width    {\dimexpr\rootlayouttargetparameter   \c!width    \relax}
320\def\v_page_target_height   {\dimexpr\rootlayouttargetparameter   \c!height   \relax}
321\def\v_page_target_topspace {\dimexpr\rootlayouttargetparameter   \c!topspace \relax}
322\def\v_page_target_backspace{\dimexpr\rootlayouttargetparameter   \c!backspace\relax}
323\def\v_page_target_offset   {\dimexpr\rootlayouttargetparameter   \c!offset   \relax}
324
325\def\v_page_target_xy       {\numexpr\v_page_target_nx*\v_page_target_ny\relax}
326
327%D Normally we will not use this command directly but for now it works out okay. In
328%D the future we might use more of the related commands.
329
330\setuplayouttarget
331  [% these are rather special
332   \c!nx=1,
333   \c!ny=1,
334   \c!dx=\zeropoint,
335   \c!dy=\zeropoint,
336   \c!topspace=\zeropoint,
337   \c!backspace=\zeropoint,
338   \c!width=\zeropoint,
339   \c!height=\zeropoint,
340   %
341   \c!method=\v!normal,
342   \c!option=\v!max,
343   \c!alternative=\v!normal,
344   %
345   \c!scale=1,
346   \c!offset=\zeropoint,
347   %
348   \c!top=,
349   \c!bottom=,
350   \c!left=,
351   \c!right=,
352   %
353   \c!location=]
354
355% \definepapersize[name][A4][A3]
356% \definepapersize[name][settings]
357
358\permanent\tolerant\protected\def\definepapersize[#1]#*[#2]#*[#3]%
359  {\edef\currentlayouttarget{#1}%
360   \ifempty\currentlayouttarget
361     % invalid target
362   \orelse\ifhastok={#2}%
363     \definelayouttarget[#1][#2]%
364   \else
365     \edefcsname\??layoutpaper#1\endcsname{#2}%
366     \ifparameter#3\or
367       \edefcsname\??layoutprint#1\endcsname{#3}%
368     \else
369       \edefcsname\??layoutprint#1\endcsname{#2}%
370     \fi
371   \fi}
372
373\appendtoks
374    \letcsname\??layoutcurrent\currentlayouttarget\endcsname\relax
375\to \everydefinelayouttarget
376
377%def\page_paper_the_paper_size#1{\ifcsname\??layoutpaper#1\endcsname\csname\??layoutpaper#1\endcsname\else#1\fi}
378%def\page_paper_the_print_size#1{\ifcsname\??layoutprint#1\endcsname\csname\??layoutprint#1\endcsname\else#1\fi}
379
380\def\page_paper_the_paper_size#1{\ifcsname\??layoutpaper#1\endcsname\lastnamedcs\else#1\fi}
381\def\page_paper_the_print_size#1{\ifcsname\??layoutprint#1\endcsname\lastnamedcs\else#1\fi}
382
383% \setuppaper    [page=A4,paper=A3] % the k/v variant, changes the current page mapping
384% \setuppapersize[A4][a=b,c=d]      % the k/v variant, changes nothing, just settings
385% \setuppapersize[A4][A3]           % changes the current page mapping
386
387\let\page_paper_reinstate\relax
388\let\page_paper_restore  \relax
389
390\permanent\tolerant\protected\def\setuppapersize[#1]#*[#2]%
391  {\ifarguments
392     \page_paper_restore
393   \orelse\ifhastok={#1}%
394     \page_paper_setup_size_settings[#1]%
395   \orelse\ifhastok={#2}%
396     \page_paper_setup_size_settings_by_name[#1][#2]%
397   \else
398     \page_paper_setup_size_change_size[#1][#2]%
399   \fi}
400
401\protected\def\page_paper_setup_size_settings[#1]% sometimes used to set paper/print size
402  {\let\currentlayouttarget\empty
403   \edef\m_layouttarget_paper_saved{\page_paper_the_paper_size{\layouttargetparameter\c!page }}%
404   \edef\m_layouttarget_print_saved{\page_paper_the_print_size{\layouttargetparameter\c!paper}}%
405   \setupcurrentlayouttarget[#1]%
406   \edef\m_layouttarget_paper{\page_paper_the_paper_size{\layouttargetparameter\c!page }}%
407   \edef\m_layouttarget_print{\page_paper_the_print_size{\layouttargetparameter\c!paper}}%
408   \ifx\m_layouttarget_paper_saved\m_layouttarget_paper
409     \ifx\m_layouttarget_print_saved\m_layouttarget_print
410       % we didn't change the size, maybe only sx or sy or so
411     \else
412       \page_paper_setup_size_settings_recalibrate
413     \fi
414   \else
415     \page_paper_setup_size_settings_recalibrate
416   \fi}
417
418\def\page_paper_setup_size_settings_recalibrate
419  {\ifempty\m_layouttarget_paper
420     % forget about it
421   \else
422     \ifempty\m_layouttarget_print
423        \let\m_layouttarget_print\m_layouttarget_paper
424     \fi
425     \page_paper_set_current[\m_layouttarget_paper][\m_layouttarget_print]%
426   \fi
427   \letlayouttargetparameter\c!page \papersize
428   \letlayouttargetparameter\c!paper\printpapersize}
429
430\protected\def\page_paper_setup_size_settings_by_name[#1][#2]%
431  {\def\currentlayouttarget{\page_paper_the_paper_size{#1}}%
432   \setuplayouttarget[#2]}
433
434\protected\def\page_paper_setup_size_change_size[#1][#2]%
435  {\doifelsenothing{#2}
436     {\page_paper_set_current[#1][#1]}
437     {\page_paper_set_current[#1][#2]}}
438
439\permanent\let\setuppaper\page_paper_setup_size_settings
440
441\permanent\protected\def\adaptpapersize
442  {\glet\page_paper_reinstate\page_paper_restore
443   \setuppapersize}
444
445\appendtoks
446    \page_paper_reinstate
447    \glet\page_paper_reinstate\relax
448\to \everyaftershipout
449
450\protected\def\page_paper_set_restore#1#2%
451  {\xdef\page_paper_restore{\page_paper_set_current_indeed[#1][#2]}}
452
453\protected\def\page_paper_set_current[#1][#2]%
454  {\normalexpanded{\page_paper_set_current_indeed
455     [\page_paper_the_paper_size{#1}]%
456     [\page_paper_the_print_size{#2}]}}
457
458\protected\def\page_paper_reset_paper
459  {\global\setfalse\c_page_target_paper_landscape
460   \global\setfalse\c_page_target_paper_mirror
461   \global\setfalse\c_page_target_paper_negate
462   \global\c_page_target_paper_orientation\uprotationangle
463   \global\c_page_target_paper_reverse    \uprotationangle}
464
465\protected\def\page_paper_reset_print
466  {\global\setfalse\c_page_target_print_landscape
467   \global\setfalse\c_page_target_print_mirror
468   \global\setfalse\c_page_target_print_negate
469   \global\c_page_target_print_orientation\uprotationangle
470   \global\c_page_target_print_reverse    \uprotationangle}
471
472\letcsname\??layoutpaper\v!reset\endcsname\page_paper_reset_paper
473\letcsname\??layoutprint\v!reset\endcsname\page_paper_reset_print
474
475\defcsname\??layoutpaper\v!landscape\endcsname
476  {\global\settrue\c_page_target_paper_landscape}
477
478\defcsname\??layoutpaper\v!mirrored\endcsname
479  {\global\settrue\c_page_target_paper_mirror}
480
481\defcsname\??layoutpaper\v!negative\endcsname
482  {\global\settrue\c_page_target_paper_negate}
483
484\defcsname\??layoutpaper\v!rotated\endcsname
485  {\global\c_page_target_paper_orientation\rightrotationangle
486   \global\c_page_target_paper_reverse    \leftrotationangle}
487
488\defcsname\??layoutpaper\number\rightrotationangle\endcsname
489  {\global\c_page_target_paper_orientation\rightrotationangle
490   \global\c_page_target_paper_reverse    \leftrotationangle}
491
492\defcsname\??layoutpaper\number\downrotationangle\endcsname
493  {\global\c_page_target_paper_orientation\downrotationangle
494   \global\c_page_target_paper_reverse    \zerocount}
495
496\defcsname\??layoutpaper\number\leftrotationangle\endcsname
497  {\global\c_page_target_paper_orientation\leftrotationangle
498   \global\c_page_target_paper_reverse    \rightrotationangle}
499
500\defcsname\??layoutprint\v!landscape\endcsname
501  {\global\settrue\c_page_target_print_landscape}
502
503\defcsname\??layoutprint\v!mirrored\endcsname
504  {\global\settrue\c_page_target_print_mirror}
505
506\defcsname\??layoutprint\v!negative\endcsname
507  {\global\settrue\c_page_target_print_negate}
508
509\defcsname\??layoutprint\v!rotated\endcsname
510  {\global\c_page_target_print_orientation\rightrotationangle
511   \global\c_page_target_print_reverse    \leftrotationangle}
512
513\defcsname\??layoutprint\number\rightrotationangle\endcsname
514  {\global\c_page_target_print_orientation\rightrotationangle
515   \global\c_page_target_print_reverse    \leftrotationangle}
516
517\defcsname\??layoutprint\number\downrotationangle \endcsname
518  {\global\c_page_target_print_orientation\downrotationangle
519   \global\c_page_target_print_reverse    \zerocount}
520
521\defcsname\??layoutprint\number\leftrotationangle \endcsname
522  {\global\c_page_target_print_orientation\leftrotationangle
523   \global\c_page_target_print_reverse    \rightrotationangle}
524
525\def\page_paper_handle_page_option #1{\begincsname\??layoutpaper#1\endcsname}
526\def\page_paper_handle_print_option#1{\begincsname\??layoutprint#1\endcsname}
527
528\protected\def\page_paper_identify_target#1%
529  {\ifcsname\??layoutcurrent#1\endcsname
530     \edef\currentlayouttarget{#1}%
531   \fi}
532
533\newdimen\d_page_minimum_paper_size \d_page_minimum_paper_size\luaexpr{math.pi}\onebasepoint
534
535\protected\def\page_paper_set_current_indeed[#1][#2]%
536  {\edef\m_page_asked_paper{#1}% can be the restores
537   \edef\m_page_asked_print{#2}%
538   %
539   \page_paper_set_restore\m_page_asked_paper\m_page_asked_print
540   %
541   % locate page target
542   \let\currentlayouttarget\empty
543   \page_paper_reset_paper
544   \processcommacommand[\m_page_asked_paper]\page_paper_identify_target
545   \ifempty\currentlayouttarget
546     \let\currentlayouttarget\currentpage
547   \fi
548   \glet\papersize\currentlayouttarget
549   \page_paper_reset_paper
550   \processcommacommand[\m_page_asked_paper]\page_paper_handle_page_option
551   \global\paperwidth \layouttargetparameter\c!width \relax
552   \global\paperheight\layouttargetparameter\c!height\relax
553   \ifdim\paperwidth<\d_page_minimum_paper_size
554     \global\paperwidth\d_page_minimum_paper_size
555   \fi
556   \ifdim\paperheight<\d_page_minimum_paper_size
557     \global\paperheight\d_page_minimum_paper_size
558   \fi
559   \ifconditional\c_page_target_paper_landscape
560     \enforced\global\swapcsvalues\paperwidth\paperheight
561   \fi
562   \ifinpagebody % local freeze
563     \normalexpanded{\setlayouttargetparameter\c!height{\the\paperheight}}%
564     \normalexpanded{\setlayouttargetparameter\c!width {\the\paperwidth }}%
565   \fi
566   %
567   \page_paper_set_offsets
568   %  locate paper target
569   \page_paper_reset_print
570   \processcommacommand[\m_page_asked_print]\page_paper_identify_target
571   \glet\printpapersize\currentlayouttarget
572   \page_paper_reset_print
573   \processcommacommand[\m_page_asked_print]\page_paper_handle_print_option
574   \global\printpaperwidth \layouttargetparameter\c!width \relax
575   \global\printpaperheight\layouttargetparameter\c!height\relax
576   \ifdim\printpaperwidth<\onepoint
577     \global\printpaperwidth\paperwidth
578   \fi
579   \ifdim\printpaperheight<\onepoint
580     \global\printpaperheight\paperheight
581   \fi
582   \ifconditional\c_page_target_print_landscape
583     \enforced\global\swapcsvalues\printpaperwidth\printpaperheight
584   \fi
585   % this check can be confusing, so we've added the possibility
586   % to bypass this test: \setuppapersize[option=fit]
587   \edef\m_page_asked_option{\rootlayouttargetparameter\c!option}%
588   \ifx\m_page_asked_option\v!max % \v!fit is
589      \begingroup
590      % we need to pre-swap else we get the wrong paper size
591      \ifnum\c_page_target_paper_orientation=\rightrotationangle
592        \enforced\swapcsvalues\paperwidth\paperheight
593      \orelse\ifnum\c_page_target_paper_orientation=\leftrotationangle
594        \enforced\swapcsvalues\paperwidth\paperheight
595      \fi
596      \ifnum\c_page_target_print_orientation=\rightrotationangle
597        \enforced\swapcsvalues\printpaperwidth\printpaperheight
598      \orelse\ifnum\c_page_target_print_orientation=\leftrotationangle
599        \enforced\swapcsvalues\printpaperwidth\printpaperheight
600      \fi
601      \ifdim\paperheight>\printpaperheight
602        \global\printpaperheight\paperheight
603        \writestatus\m!system{print height forced to paper height}%
604      \fi
605      \ifdim\paperwidth>\printpaperwidth
606        \global\printpaperwidth\paperwidth
607        \writestatus\m!system{print width forced to paper width}%
608      \fi
609      \endgroup
610   \fi
611  %\writestatus{layout target}{(\the\paperwidth,\the\paperheight) -> (\the\printpaperwidth,\the\printpaperheight)}%
612   \page_layouts_synchronize
613   % new but we assume \setuplayout
614   \scrn_canvas_synchronize_only}
615
616\ifdefined\scrn_canvas_synchronize_only \else
617    \let\scrn_canvas_synchronize_only\relax
618\fi
619
620\ifdefined\page_paper_set_offsets \else
621
622  \def\page_paper_set_offsets % will move
623    {\global\paperoffset\v_page_target_offset
624     \global\advance\paperwidth -2\paperoffset
625     \global\advance\paperheight-2\paperoffset}
626
627\fi
628
629\ifdefined\synchronizegridsnapping \else
630    \let\synchronizegridsnapping\relax
631\fi
632
633\let\p_page_layouts_width \empty
634\let\p_page_layouts_height\empty
635
636\def\page_layouts_synchronize
637  {\setups[\layoutparameter\c!preset]\relax
638   \global\leftmarginwidth \layoutparameter\c!leftmargin
639   \global\rightmarginwidth\layoutparameter\c!rightmargin
640   \global\leftedgewidth   \layoutparameter\c!leftedge
641   \global\rightedgewidth  \layoutparameter\c!rightedge
642   \global\headerheight    \layoutparameter\c!header
643   \global\footerheight    \layoutparameter\c!footer
644   \global\bottomheight    \layoutparameter\c!bottom
645   \global\topheight       \layoutparameter\c!top
646   \global\backspace       \layoutparameter\c!backspace
647   \global\topspace        \layoutparameter\c!topspace
648   \page_layouts_set_dimensions
649   \synchronizegridsnapping
650   \usesetupsparameter\layoutparameter % depends on gridsnapping !
651   \synchronizewhitespace
652   \synchronizeblank
653   \setupinterlinespace[\v!reset]% \synchronizegloballinespecs
654   \global\cutspace\layoutparameter\c!cutspace\relax
655   \edef\p_page_layouts_width{\layoutparameter\c!width}%
656   \ifx\p_page_layouts_width\v!middle
657     \ifzeropt\cutspace
658       \global\cutspace\backspace
659     \fi
660     \global\makeupwidth\dimexpr\paperwidth-\backspace-\cutspace\relax
661   \orelse\ifx\p_page_layouts_width\v!fit
662     \ifzeropt\cutspace
663       \global\cutspace\backspace
664     \fi
665     \global\makeupwidth\dimexpr\paperwidth-\cutspace\relax
666     \scratchdimen\dimexpr\backspace
667       -\leftedgewidth  -\leftedgedistance
668       -\leftmarginwidth-\leftmargindistance\relax
669     \ifdim\scratchdimen<\zeropoint
670       \scratchdimen\zeropoint
671     \fi
672     \global\advance\makeupwidth\dimexpr
673       -\rightmargindistance-\rightmarginwidth
674       -\rightedgedistance  -\rightedgewidth
675       -\scratchdimen\relax
676   \else
677     \global\makeupwidth\p_page_layouts_width\relax
678     \ifzeropt\cutspace
679       \global\cutspace\dimexpr\paperwidth-\makeupwidth-\backspace\relax
680   % \else
681       % A kind of inconsistent specification, but used
682       % in for instance s-pre-19.tex; the cutspace is
683       % used only for determining some kind of right
684       % margin; don't use this in doublesided mode
685     \fi
686   \fi
687   \scratchdimen\layoutparameter\c!bottomspace\relax
688  %\ifzeropt\scratchdimen
689  %  \scratchdimen\topspace
690  %\fi
691   \global\bottomspace\layoutparameter\c!bottomspace\relax
692   \global\layoutlines0\number\layoutparameter\c!lines\relax % may be empty
693   \ifcase\layoutlines
694     \edef\p_page_layouts_height{\layoutparameter\c!height}%
695     \ifx\p_page_layouts_height\v!middle
696       \ifzeropt\bottomspace
697         \global\bottomspace\topspace
698       \fi
699       \global\makeupheight\dimexpr\paperheight-\topspace-\bottomspace\relax
700     \orelse\ifx\p_page_layouts_height\v!fit
701       \ifzeropt\bottomspace
702         \global\bottomspace\topspace
703       \fi
704       \global\makeupheight\dimexpr\paperheight-\bottomspace\relax
705       \scratchdimen\dimexpr\topspace-\topheight-\topdistance\relax
706       \ifdim\scratchdimen<\zeropoint
707         \scratchdimen\zeropoint
708       \fi
709       \global\advance\makeupheight\dimexpr-\bottomdistance-\bottomheight-\scratchdimen\relax
710     \else
711       \global\makeupheight\layoutparameter\c!height\relax
712       \ifzeropt\bottomspace
713         \global\bottomspace\dimexpr\paperheight-\makeupheight-\topspace\relax
714     % \else
715         % inconsistent specification
716       \fi
717     \fi
718   \else
719     % beware, when the bodyfont changes (switched) this will change as well; implementing
720     % a global lineheight is tricky: should we take the bodyfont interlinespace or the one set
721     % independent of the bodyfont (before or after a layout spec); way too fuzzy, so we
722     % stick to the current method (after a night of experimenting ...2003/10/13)
723     \global\makeupheight\dimexpr
724        \layoutparameter\c!lines\lineheight-\strutheight+\topskip+
725        \headerdistance+\headerheight+\footerdistance+\footerheight\relax
726   \fi
727   \backoffset\layoutparameter\c!horoffset\relax
728   \topoffset \layoutparameter\c!veroffset\relax
729   \ifdim\makeupwidth<\onepoint
730     \global\makeupwidth\onepoint
731   \fi
732   \ifdim\makeupheight<\onepoint
733     \global\makeupheight\onepoint
734   \fi
735   % handy in page builder
736   \global\totaltextwidth\dimexpr
737      \leftedgetotal
738     +\leftmargintotal
739     +\makeupwidth
740     +\rightmargintotal
741     +\rightedgetotal
742   \relax
743   % \page_layouts_check_next % here ?
744   \page_layouts_check_direction
745   \page_layouts_calculate_extras
746   \page_target_check_centering
747   \calculatehsizes
748   \calculatevsizes
749   \page_layouts_check_pseudo_columns
750   \page_backgrounds_recalculate}
751
752\def\page_layouts_check_direction
753  {\edef\p_direction{\layoutparameter\c!direction}%
754   \ifx\p_direction\v!reverse
755     \enforced\global\swapcsvalues\naturalleftedgedistance  \naturalrightedgedistance
756     \enforced\global\swapcsvalues\naturalleftmargindistance\naturalrightmargindistance
757     \enforced\global\swapcsvalues\leftedgedistance         \rightedgedistance
758     \enforced\global\swapcsvalues\leftmargindistance       \rightmargindistance
759     \enforced\global\swapcsvalues\leftmarginwidth          \rightmarginwidth
760     \enforced\global\swapcsvalues\leftedgewidth            \rightedgewidth
761     \enforced\global\swapcsvalues\backspace                \cutspace
762     \expandafter\setsystemmode
763   \else
764     \expandafter\resetsystemmode
765   \fi{reverselayout}}
766
767\def\page_layouts_check_pseudo_columns
768  {\global\layoutcolumns\layoutparameter\c!columns
769   \global\layoutcolumndistance\layoutparameter\c!columndistance
770   \global\layoutcolumnwidth\dimexpr\makeupwidth-\layoutcolumns\layoutcolumndistance+\layoutcolumndistance\relax
771   \ifnum\layoutcolumns>\plusone
772     \global\divide\layoutcolumnwidth\layoutcolumns
773     \dorecurse\layoutcolumns\page_layouts_check_pseudo_column
774   \fi}
775
776\def\page_layouts_check_pseudo_column
777  {\xdefcsname\??layoutcolumn\recurselevel\endcsname
778     {\the\numexpr\recurselevel-\plusone\relax\dimexpr\layoutcolumnwidth+\layoutcolumndistance\relax}}
779
780\letvalue{\??layoutcolumn0}\zeropoint
781
782\permanent\def\layoutcolumnoffset#1% can travel around so we can't use \lastnamedcs
783  {\csname\??layoutcolumn\ifcsname\??layoutcolumn#1\endcsname#1\else0\fi\endcsname}
784
785\def\page_layouts_synchronize_at_start
786  {\ifdim\makeupheight=\layoutlines\lineheight \else % weird check
787     \page_layouts_synchronize
788   \fi}
789
790\appendtoks
791    \page_layouts_synchronize_at_start % still needed?
792\to \everystarttext
793
794% document:
795%
796% \setuplayout[odd][state=stop] \setuplayout[even][state=stop] \setuplayout[page]
797%
798% \startstandardmakeup[page=blank] ... \stopstandardmakeup
799
800\ifdefined\lastpage \else \let\lastpage\!!plusone \fi
801
802\permanent\protected\def\page_layouts_change#1%
803  {%\writestatus\m!layouts{changing to layout #1}%
804   \xdef\currentlayout{#1}%
805   \page_layouts_synchronize}
806
807\aliased\let\changetolayout\page_layouts_change % also public
808
809\def\v_real_page_normal {\the\realpageno}
810\def\v_real_page_reverse{-\the\numexpr\lastpage-\realpageno\relax}
811
812\def\v_real_page_odd_or_even
813  {\ifodd\pagenoshift
814     \ifodd\realpageno\v!even\else\v!odd \fi
815   \else
816     \ifodd\realpageno\v!odd \else\v!even\fi
817   \fi}
818
819\let\v_real_page_current\v!current
820
821\def\v_real_page_named
822  {\ifnum\lastpage=\realpageno
823     \v!last
824   \orelse\ifnum\plusone=\realpageno
825     \v!first
826   \else
827     \__unknown__
828   \fi}
829
830\let\v_page_layouts_pre_check\relax
831
832\def\page_layouts_check_default_indeed#1%
833  {\edef\m_page_check{#1}
834   \edef\m_page_state{\namedlayoutparameter\m_page_check\c!state}%
835   \ifx\m_page_state\v!start
836     \glet\v_page_layouts_pre_check\currentlayout
837     \glet\currentlayout\m_page_check
838     \page_layouts_synchronize
839   \orelse\ifx\m_page_state\v!repeat
840     \glet\v_page_layouts_pre_check\relax
841     \glet\currentlayout\m_page_check
842     \page_layouts_synchronize
843   \fi}
844
845\def\page_layouts_check_revert
846  {\glet\currentlayout\v_page_layouts_pre_check
847   \glet\v_page_layouts_pre_check\relax
848   \page_layouts_synchronize}
849
850\def\page_layouts_check_default
851  {\ifcsname\namedlayouthash\v_real_page_normal\c!state\endcsname
852     \page_layouts_check_default_indeed\v_real_page_normal
853   \orelse\ifcsname\namedlayouthash\v_real_page_reverse\c!state\endcsname
854     \page_layouts_check_default_indeed\v_real_page_reverse
855   \orelse\ifcsname\namedlayouthash\v_real_page_named\c!state\endcsname
856     \page_layouts_check_default_indeed\v_real_page_named
857   \orelse\ifcsname\namedlayouthash\v_real_page_current\c!state\endcsname
858     \page_layouts_check_default_indeed\v_real_page_current
859   \orelse\ifcsname\namedlayouthash\v_real_page_odd_or_even\c!state\endcsname
860     \page_layouts_check_default_indeed\v_real_page_odd_or_even
861   \orelse\ifrelax\v_page_layouts_pre_check
862     % okay
863   \else
864     \page_layouts_check_revert
865   \fi}
866
867\permanent\protected\def\installlayoutmethod#1#2%
868  {\gdefcsname\??layoutmethod#1\endcsname{#2}}
869
870\installlayoutmethod\v!default{\page_layouts_check_default}
871\installlayoutmethod\v!normal {\page_layouts_check_default}
872
873\permanent\protected\def\page_layouts_check_next
874  {\ifcsname\??layoutmethod\layoutparameter\c!method\endcsname
875     \lastnamedcs
876   \else
877     \page_layouts_check_default
878   \fi}
879
880\aliased\let\checkcurrentlayout\page_layouts_check_next % public and used in naw, so this synonym will stay
881
882% inheritance
883%
884% \definelayout
885%   [test]
886%   [width=12cm,
887%    height=10cm]
888%
889% \definelayout
890%   [more]
891%   [test]
892%   [height=12cm]
893%
894% testcase
895%
896% \setuppagenumbering[alternative=doublesided]
897%
898% \setuplayout         [width=11cm]
899% \definelayout [odd]  [backspace=1cm]
900% \definelayout [even] [backspace=4cm]
901% \definelayout [5]    [backspace=5cm]
902% \definelayout [6]    [backspace=5cm]
903% \definelayout [-2]   [backspace=0cm,cutspace=0cm]
904% \definelayout [last] [backspace=0cm,cutspace=0cm]
905%
906% \checkcurrentlayout \showframe
907%
908% \starttext
909%     \dorecurse{20} {\input knuth \endgraf \input tufte \endgraf}
910% \stoptext
911
912% Because we want to keep the set parameters as they are we use some
913% helpers to communicate between the several page building related
914% mechanism.
915
916\appendtoks \page_layouts_check_next \to \everystarttext
917\appendtoks \page_layouts_check_next \to \everyaftershipout
918
919\newconditional\c_page_layouts_location_is_set
920\newconditional\c_page_layouts_location_is_middle
921
922\def\page_layouts_location_reset % we start in the left top and mirror right pages
923  {\setfalse\c_page_layouts_location_is_set
924   \setfalse\c_page_layouts_location_is_middle
925   \let\v_page_target_left_fill  \relax
926   \let\v_page_target_right_fill \hss  % ? \relax
927   \let\v_page_target_top_fill   \relax
928   \let\v_page_target_bottom_fill\vss} % \relax}
929
930\defcsname\??layoutlocation\v!right\endcsname
931  {\settrue\c_page_layouts_location_is_set
932   \setfalse\c_page_layouts_location_is_middle
933   \let\v_page_target_left_fill \hss
934   \let\v_page_target_right_fill\relax}
935
936\defcsname\??layoutlocation\v!left\endcsname
937  {\settrue\c_page_layouts_location_is_set
938   \setfalse\c_page_layouts_location_is_middle
939   \let\v_page_target_left_fill \relax
940   \let\v_page_target_right_fill\hss}
941
942\defcsname\??layoutlocation\v!bottom\endcsname
943  {\settrue\c_page_layouts_location_is_set
944   \setfalse\c_page_layouts_location_is_middle
945   \let\v_page_target_top_fill   \vss
946   \let\v_page_target_bottom_fill\relax}
947
948\defcsname\??layoutlocation\v!top\endcsname
949  {\settrue\c_page_layouts_location_is_set
950   \setfalse\c_page_layouts_location_is_middle
951   \let\v_page_target_top_fill    \relax
952   \let\v_page_target_bottom_fill\vss}
953
954\defcsname\??layoutlocation\v!middle\endcsname
955  {\settrue\c_page_layouts_location_is_set
956   \settrue\c_page_layouts_location_is_middle
957   \let\v_page_target_left_fill  \hss
958   \let\v_page_target_right_fill \hss
959   \let\v_page_target_top_fill   \vss
960   \let\v_page_target_bottom_fill\vss}
961
962\defcsname\??layoutlocation\empty\endcsname
963  {\setfalse\c_page_layouts_location_is_set % default also signal to scrn_
964   \setfalse\c_page_layouts_location_is_middle
965   \let\v_page_target_right_fill \hss
966   \let\v_page_target_bottom_fill\hss}
967
968\defcsname\??layoutlocation\v!doublesided\endcsname
969  {\settrue\c_page_target_print_doublesided}
970
971\defcsname\??layoutlocation\v!singlesided\endcsname
972  {\setfalse\c_page_target_print_doublesided}
973
974\def\page_target_check_centering_indeed#1%
975  {\begincsname\??layoutlocation#1\endcsname}
976
977\protected\def\page_target_check_centering
978  {\setfalse\c_page_target_print_doublesided
979   \page_layouts_location_reset
980   \processcommacommand[\layoutparameter\c!location]\page_target_check_centering_indeed}
981
982% installers
983
984\permanent\protected\def\installlayoutalternative#1#2%
985  {\gdefcsname\??layoutalternative#1\endcsname{#2}}
986
987\def\page_boxes_construct_content_default#1#2#3% targetbox flusher box
988  {\setbox#1\vpack % was \vbox
989     {\offinterlineskip
990      \begingroup % needed ?
991      \uselayoutstyleandcolor\c!style\c!color
992      \offinterlineskip
993      \page_layouts_insert_elements % zero size
994      \endgroup
995      \page_insert_body#2#3}}% including footnotes
996
997\installlayoutalternative\v!default{\page_boxes_construct_content_default}
998\installlayoutalternative\v!normal {\page_boxes_construct_content_default}
999
1000\def\page_boxes_construct_content % targetbox flusher box
1001  {\ifcsname\??layoutalternative\layoutparameter\c!alternative\endcsname
1002     \expandafter\lastnamedcs
1003   \else
1004     \expandafter\page_boxes_construct_content_default
1005   \fi}
1006
1007%D \macros
1008%D   {adaptlayout}
1009
1010% this will move to lua
1011
1012\installcorenamespace{adaptlayout}
1013\installcorenamespace{pageadaptations}
1014
1015\installsetuponlycommandhandler \??adaptlayout {adaptlayout}
1016
1017\newdimen\d_page_adapts_pushed_text_height
1018\newdimen\d_page_adapts_pushed_footer_height
1019\newdimen\d_page_adapts_height
1020\newdimen\d_page_adapts_delta
1021
1022\appendtoks \global\d_page_adapts_delta\zeropoint \to \everyshipout
1023
1024\permanent\protected\tolerant\def\adaptlayout[#1]#*[#2]%
1025  {\ifparameter#2\or
1026     \processcommalist[#1]{\page_adapts_layout_register{#2}}%
1027     \page_adapts_check
1028   \else
1029     \page_adapts_layout_indeed{#1}%
1030   \fi}
1031
1032\def\page_adapts_layout_register#1#2%
1033  {\gdefcsname\??pageadaptations#2\endcsname{\page_adapts_layout_indeed{#1}}}
1034
1035\let\p_adapts_height\zeropoint
1036\let\p_adapts_lines \zerocount
1037
1038\def\page_adapts_layout_indeed#1% called often
1039  {\setupcurrentadaptlayout[\c!height=\zeropoint,\c!lines=\zerocount,\c!top=\zeropoint,#1]%
1040   \page_adapts_push
1041   \edef\p_adapts_height{\adaptlayoutparameter\c!height}%
1042   \edef\p_adapts_lines {\adaptlayoutparameter\c!lines}%
1043   \ifx\p_adapts_height\v!max
1044     \global\d_page_adapts_height\footerheight
1045   \else
1046     \global\d_page_adapts_height\dimexpr
1047        \ifnum\p_adapts_lines=\zerocount
1048          \p_adapts_height
1049        \else
1050          \p_adapts_lines\openlineheight
1051        \fi
1052      \relax
1053      \ifdim\d_page_adapts_height>\footerheight
1054        \global\d_page_adapts_height\footerheight
1055      \fi
1056   \fi
1057   %
1058   \global\d_page_adapts_delta-\dimexpr\adaptlayoutparameter\c!top\relax
1059   %
1060   \global\advance\textheight   \d_page_adapts_height
1061   \global\advance\footerheight-\d_page_adapts_height
1062   \showmessage\m!layouts1{\the\dimexpr\d_page_adapts_height,\the\realpageno}%
1063   % this will become a better one (do we need insert correction?)
1064   \page_otr_command_set_vsize
1065   %
1066   \page_backgrounds_recalculate
1067   \glet\page_adapts_push\relax
1068   \glet\page_adapts_pop\page_adapts_pop_indeed}
1069
1070\def\page_adapts_check
1071  {\begincsname\??pageadaptations\the\realpageno\endcsname}
1072
1073\def\page_adapts_reset
1074  {\ifcsname\??pageadaptations\the\realpageno\endcsname
1075     \gletcsname\??pageadaptations\the\realpageno\endcsname\relax
1076   \fi}
1077
1078\def\page_adapts_push_indeed
1079  {\global\d_page_adapts_pushed_text_height  \textheight
1080   \global\d_page_adapts_pushed_footer_height\footerheight}
1081
1082\def\page_adapts_pop_indeed
1083  {\global\textheight  \d_page_adapts_pushed_text_height
1084   \global\footerheight\d_page_adapts_pushed_footer_height
1085   \page_layouts_synchronize
1086   \glet\page_adapts_push\page_adapts_push_indeed
1087   \glet\page_adapts_pop\relax}
1088
1089\appendtoks \page_adapts_check \to \everystarttext
1090\appendtoks \page_adapts_reset \to \everyshipout
1091
1092\let\page_adapts_pop \relax
1093\let\page_adapts_push\page_adapts_push_indeed
1094
1095\protected\def\page_adapts_synchronize % used elsewhere
1096  {\page_adapts_pop
1097   \page_adapts_check}
1098
1099\def\page_adapts_status_info % used elsewhere
1100  {\ifrelax\page_adapts_pop \else
1101     \space(adept: \the\d_page_adapts_height)\space
1102   \fi
1103   \the\realpageno}
1104
1105%D \macros
1106%D   {startlayout,stoplayout}
1107
1108\permanent\protected\def\startlayout[#1]%
1109  {\page
1110   \globalpushmacro\currentlayout
1111   \doifelselayoutdefined{#1}{\setuplayout[#1]}\donothing} % {\setuplayout[\currentlayout]}}
1112
1113\permanent\protected\def\stoplayout
1114  {\page
1115   \globalpopmacro\currentlayout
1116   \setuplayout[\currentlayout]}
1117
1118% NOG EENS NAGAAN WANNEER NU GLOBAL EN WANNEER NIET
1119
1120\ifdefined\doifelselayoutsomeline \else % eventually defined in page-txt
1121    \let\doifelselayoutsomeline\secondofthreearguments
1122\fi
1123
1124\permanent\def\compensatevsizeheader             {\advance\textheight-\dimexpr\headerheight+\headerdistance\relax}
1125\permanent\def\compensatevsizefooter             {\advance\textheight-\dimexpr\footerheight+\footerdistance\relax}
1126\permanent\def\globalcompensatevsizeheader{\global\advance\textheight-\dimexpr\headerheight+\headerdistance\relax}
1127\permanent\def\globalcompensatevsizefooter{\global\advance\textheight-\dimexpr\footerheight+\footerdistance\relax}
1128
1129\permanent\def\compensatevsizeheaderzero{\headerheight\zeropoint\page_layouts_set_distances}
1130\permanent\def\compensatevsizefooterzero{\footerheight\zeropoint\page_layouts_set_distances}
1131
1132\def\page_layouts_set_modes
1133  {\ifzeropt\headerheight
1134     \resetsystemmode\v!header
1135   \else
1136     \setsystemmode\v!header
1137   \fi
1138   \ifzeropt\footerheight
1139     \resetsystemmode\v!footer
1140   \else
1141     \setsystemmode\v!footer
1142   \fi}
1143
1144\permanent\protected\def\calculatevsizes % name will change
1145  {\textheight\makeupheight
1146   \doifelselayoutsomeline\v!header\compensatevsizeheader\donothing
1147   \doifelselayoutsomeline\v!footer\compensatevsizefooter\donothing
1148   \page_layouts_set_modes
1149   \resetglobal
1150   \page_otr_command_set_vsize}
1151
1152\permanent\protected\def\calculateglobalvsizes % name will change
1153  {\global\textheight\makeupheight
1154   \doifelselayoutsomeline\v!header\globalcompensatevsizeheader\donothing
1155   \doifelselayoutsomeline\v!footer\globalcompensatevsizefooter\donothing
1156   \page_layouts_set_modes
1157   \page_otr_command_set_vsize}
1158
1159\permanent\protected\def\calculatereducedvsizes % name will change
1160  {\textheight\makeupheight
1161   \doifelselayoutsomeline\v!header\compensatevsizeheader\compensatevsizeheaderzero
1162   \doifelselayoutsomeline\v!footer\compensatevsizefooter\compensatevsizefooterzero}
1163
1164\newdimen\innermakeupwidth  % special purpose
1165\newdimen\innermakeupmargin % special purpose
1166
1167\newconditional\innermakeupcompensation \settrue\innermakeupcompensation
1168
1169\permanent\def\compensatedinnermakeupmargin
1170  {\dimexpr\ifconditional\innermakeupcompensation+\innermakeupmargin\else\zeropoint\fi\relax}
1171
1172\permanent\protected\def\freezetextwidth % name will change % \makeupwidth may be set to \textwidth
1173  {\textwidth\makeupwidth                          % which is a tricky but valid value
1174   \edef\m_currentlayout_text_width {\layoutparameter\c!textwidth }%
1175   \edef\m_currentlayout_text_margin{\layoutparameter\c!textmargin}%
1176   \ifempty\m_currentlayout_text_width \else
1177     \textwidth\m_currentlayout_text_width % local
1178   \fi
1179   \global\innermakeupwidth\textwidth
1180   \ifempty\m_currentlayout_text_margin
1181     \global\innermakeupmargin\zeropoint
1182   \else
1183     \global\innermakeupmargin\m_currentlayout_text_margin\relax
1184   \fi
1185   \scratchdimen\dimexpr\innermakeupmargin+\innermakeupmargin\relax
1186   \global\advance\innermakeupwidth-\scratchdimen
1187   \advance\textwidth-\scratchdimen}   % local
1188
1189\permanent\protected\def\calculatehsizes % name will change
1190  {\freezetextwidth
1191   \page_otr_command_set_hsize}
1192
1193%D When we start at an even page, we need to swap the layout differently. We cannot
1194%D adapt the real page number, since it is used in cross referencing. The next
1195%D switch is set when we start at an even page.
1196
1197% #single #left #right
1198
1199\permanent\def\doifelseoddpage
1200  {\ifodd\pagenoshift
1201     \expandafter\page_layouts_if_odd_else_yes
1202   \else
1203     \expandafter\page_layouts_if_odd_else_nop
1204   \fi}
1205
1206\aliased\let\doifoddpageelse\doifelseoddpage
1207
1208\def\page_layouts_if_odd_else_yes
1209  {\ifodd\realpageno
1210     \expandafter\secondoftwoarguments
1211   \else
1212     \expandafter\firstoftwoarguments
1213   \fi}
1214
1215\def\page_layouts_if_odd_else_nop
1216  {\ifodd\realpageno
1217     \expandafter\firstoftwoarguments
1218   \else
1219     \expandafter\secondoftwoarguments
1220   \fi}
1221
1222\def\page_layouts_if_odd_else_again#1{\doifelseoddpage}
1223
1224\permanent\def\doifbothsidesoverruled
1225  {\ifdoublesided
1226     \expandafter\page_layouts_if_odd_else_again
1227   \else
1228     \expandafter\firstofthreearguments
1229   \fi}
1230
1231\permanent\def\doifbothsides% #1 #2 #3
1232  {\ifdoublesided
1233     \expandafter\page_layouts_if_both_sides
1234   \else
1235     \expandafter\firstofthreearguments
1236   \fi}
1237
1238\def\page_layouts_if_both_sides
1239  {\ifsinglesided
1240     \expandafter\firstofthreearguments
1241   \else
1242     \expandafter\page_layouts_if_odd_else_again
1243   \fi}
1244
1245\newdimen\texthoffset
1246
1247\permanent\protected\def\settexthoffset % name will change
1248  {\texthoffset\doifbothsides\backspace\backspace{\dimexpr\paperwidth-\backspace-\makeupwidth\relax}}
1249
1250\permanent\protected\def\goleftonpage % name will change (we could cache)
1251  {\hkern-\dimexpr\leftmargindistance+\leftmarginwidth+\leftedgedistance+\leftedgewidth\relax}
1252
1253\permanent\def\doifelsemarginswap#1#2% protected?
1254  {\doifbothsides{#1}{#1}{#2}}
1255
1256\aliased\let\doifmarginswapelse\doifelsemarginswap
1257
1258\protected\def\page_layouts_swap_margins % name will change, frozen?
1259  {\doifelsemarginswap\relax\page_layouts_swap_margins_indeed}
1260
1261\protected\def\page_layouts_swap_margins_indeed
1262  {\let\page_layouts_swap_margins       \relax % to prevent local swapping
1263   \let\page_layouts_swap_margins_indeed\relax % to prevent local swapping
1264   \the\everyswapmargins}
1265
1266\permanent\def\rightorleftpageaction
1267  {\ifdoublesided
1268     \expandafter\page_layouts_right_or_left_page_action
1269   \else
1270     \expandafter\firstoftwoarguments
1271   \fi}
1272
1273\def\page_layouts_right_or_left_page_action
1274  {\ifsinglesided
1275     \expandafter\firstoftwoarguments
1276   \else
1277     \expandafter\doifelseoddpage
1278   \fi}
1279
1280% swapping needs frozen
1281
1282\permanent\def\outermarginwidth   {\rightorleftpageaction\rightmarginwidth   \leftmarginwidth }
1283\permanent\def\innermarginwidth   {\rightorleftpageaction\leftmarginwidth    \rightmarginwidth}
1284\permanent\def\outermargindistance{\rightorleftpageaction\rightmargindistance\leftmargindistance }
1285\permanent\def\innermargindistance{\rightorleftpageaction\leftmargindistance \rightmargindistance}
1286
1287\permanent\def\outeredgewidth     {\rightorleftpageaction\rightedgewidth   \leftedgewidth }
1288\permanent\def\inneredgewidth     {\rightorleftpageaction\leftedgewidth    \rightedgewidth}
1289\permanent\def\outeredgedistance  {\rightorleftpageaction\rightedgedistance\leftedgedistance }
1290\permanent\def\inneredgedistance  {\rightorleftpageaction\leftedgedistance \rightedgedistance}
1291
1292\permanent\def\outerspacewidth    {\rightorleftpageaction\cutspace \backspace}
1293\permanent\def\innerspacewidth    {\rightorleftpageaction\backspace\cutspace }
1294
1295\permanent\def\leftmargintotal    {\dimexpr\leftmarginwidth +\leftmargindistance \relax}
1296\permanent\def\rightmargintotal   {\dimexpr\rightmarginwidth+\rightmargindistance\relax}
1297\permanent\def\leftedgetotal      {\dimexpr\leftedgewidth   +\leftedgedistance   \relax}
1298\permanent\def\rightedgetotal     {\dimexpr\rightedgewidth  +\rightedgedistance  \relax}
1299
1300\permanent\def\leftsidetotal      {\dimexpr\leftmarginwidth +\leftedgetotal \relax}
1301\permanent\def\rightsidetotal     {\dimexpr\rightmarginwidth+\rightedgetotal\relax}
1302\permanent\def\leftcombitotal     {\dimexpr\leftmargintotal +\leftedgetotal \relax}
1303\permanent\def\rightcombitotal    {\dimexpr\rightmargintotal+\rightedgetotal\relax}
1304
1305\permanent\def\innermargintotal   {\dimexpr\innermarginwidth+\innermargindistance\relax}
1306\permanent\def\outermargintotal   {\dimexpr\outermarginwidth+\outermargindistance\relax}
1307\permanent\def\inneredgetotal     {\dimexpr\inneredgewidth  +\inneredgedistance  \relax}
1308\permanent\def\outeredgetotal     {\dimexpr\outeredgewidth  +\outeredgedistance  \relax}
1309
1310\permanent\def\innercombitotal    {\dimexpr\innermargintotal+\inneredgetotal\relax}
1311\permanent\def\outercombitotal    {\dimexpr\outermargintotal+\outeredgetotal\relax}
1312\permanent\def\innersidetotal     {\dimexpr\innermarginwidth+\inneredgetotal\relax}
1313\permanent\def\outersidetotal     {\dimexpr\outermarginwidth+\outeredgetotal\relax}
1314
1315%D \macros
1316%D   {startlocallayout}
1317%D
1318%D These macros should be used with care. They permit local layouts (as used in
1319%D fitting pages, see \type {page-app.tex}). This is kind of obsolete now that we
1320%D have \type {\definelayout}, so this hack will disappear in future versions.
1321
1322\permanent\protected\def\startlocallayout
1323  {\globalpushmacro\page_paper_restore
1324   \globalpushmacro\currentlayout}
1325
1326\permanent\protected\def\stoplocallayout
1327  {\globalpopmacro\currentlayout
1328   \globalpopmacro\page_paper_restore
1329   \page_paper_restore
1330   \setuplayout[\currentlayout]\relax} % explicit !
1331
1332%D \macros
1333%D   {showprint, showframe, showlayout, showsetups}
1334%D
1335%D We predefine a couple of tracing macros.
1336%D
1337%D \showsetup{showprint}
1338%D \showsetup{showframe}
1339%D \showsetup{showlayout}
1340%D \showsetup{showsetups}
1341%D %showsetup{showmargins}
1342%D %showsetup{showgrid}
1343%D %showsetup{showusage}
1344
1345\fetchmodulecommand \showprint   \f!page_run
1346\fetchmodulecommand \showframe   \f!page_run
1347\fetchmodulecommand \showlayout  \f!page_run
1348\fetchmodulecommand \showsetups  \f!page_run
1349\fetchmodulecommand \showmargins \f!page_run
1350\fetchmodulecommand \showgrid    \f!page_run
1351
1352\glet\page_grids_add_to_box\gobbleoneargument
1353\glet\page_grids_add_to_one\gobbleoneargument
1354\glet\page_grids_add_to_mix\gobbleoneargument
1355
1356%D The default dimensions are quite old and will not change. The funny fractions
1357%D were introduced when we went from fixed dimensions to relative ones. Since
1358%D \CONTEXT\ is a dutch package, the dimensions are based on the metric system. The
1359%D asymmetrical layout is kind of handy for short quick||and||dirty stapled
1360%D documents.
1361%D
1362%D Although valid, it is not a real good idea to use dimensions based on the \type
1363%D {em} unit. First of all, since there are no fonts loaded yet, this dimension
1364%D makes no sense, and second, you would loose track of values, since they could
1365%D change while going to a new page, depending on the current font setting.
1366
1367\setuplayout
1368  [             \c!topspace=.08417508418\paperheight,  %  2.5cm
1369                     \c!top=\zeropoint,
1370             \c!topdistance=\zeropoint,
1371                  \c!header=.06734006734\paperheight,  %  2.0cm
1372          \c!headerdistance=\zeropoint,
1373                  \c!height=.84175084175\paperheight,  % 25.0cm
1374          \c!footerdistance=\layoutparameter\c!headerdistance,
1375                  \c!footer=.06734006734\paperheight,  %  2.0cm
1376          \c!bottomdistance=\layoutparameter\c!topdistance,
1377                  \c!bottom=\zeropoint,
1378               \c!backspace=.11904761905\paperwidth, %  2.5cm
1379                    \c!edge=\zeropoint,
1380            \c!edgedistance=\layoutparameter\c!margindistance,
1381                  \c!margin=.12649983170\paperwidth, %  snijwit-2*afstand
1382          \c!margindistance=.02008341748\paperwidth, %  12.0pt
1383                \c!leftedge=\layoutparameter\c!edge,
1384        \c!leftedgedistance=\layoutparameter\c!edgedistance,
1385              \c!leftmargin=\layoutparameter\c!margin,
1386      \c!leftmargindistance=\layoutparameter\c!margindistance,
1387                   \c!width=.71428571429\paperwidth, %  15.0cm \dimexpr\
1388     \c!rightmargindistance=\layoutparameter\c!margindistance,
1389             \c!rightmargin=\layoutparameter\c!margin,
1390       \c!rightedgedistance=\layoutparameter\c!edgedistance,
1391               \c!rightedge=\layoutparameter\c!edge,
1392               \c!veroffset=\zeropoint,
1393             \c!bottomspace=\zeropoint,
1394               \c!horoffset=\zeropoint,
1395                \c!cutspace=\zeropoint,
1396               \c!textwidth=, % dangerous option -> centered / local
1397              \c!textmargin=, % dangerous option -> both sides
1398            \c!textdistance=\zeropoint, % shift down on grid
1399                   \c!style=,
1400                   \c!color=,
1401                 \c!marking=\v!off,
1402                \c!location=,% \v!singlesided, but unset is signal (no other default, spoils arrange)
1403                   \c!state=\v!start,
1404                   \c!scale=1,
1405                      \c!sx=1,
1406                      \c!sy=1,
1407                      \c!nx=1,
1408                      \c!ny=1,
1409                      \c!dx=\zeropoint,
1410                      \c!dy=\zeropoint,
1411                    \c!grid=\v!no,
1412               \c!direction=\v!normal,
1413                  \c!preset=,
1414                  \c!setups=\systemsetupsprefix\s!default,
1415              \c!clipoffset=\zeropoint,
1416                   \c!lines=0,
1417                   \c!paper=, % for foxet
1418                    \c!page=, % for foxet
1419                 \c!columns=\plusone,
1420          \c!columndistance=\zeropoint]
1421
1422%D First we define a whole range of (DIN) papersizes, of which the A-series makes
1423%D most sense. We enable checking.
1424
1425\definepapersize [A0]  [\c!width=841mm,\c!height=1189mm]
1426\definepapersize [A1]  [\c!width=594mm,\c!height=841mm]
1427\definepapersize [A2]  [\c!width=420mm,\c!height=594mm]
1428\definepapersize [A3]  [\c!width=297mm,\c!height=420mm]
1429\definepapersize [A4]  [\c!width=210mm,\c!height=297mm]
1430\definepapersize [A5]  [\c!width=148mm,\c!height=210mm]
1431\definepapersize [A6]  [\c!width=105mm,\c!height=148mm]
1432\definepapersize [A7]  [\c!width=74mm,\c!height=105mm]
1433\definepapersize [A8]  [\c!width=52mm,\c!height=74mm]
1434\definepapersize [A9]  [\c!width=37mm,\c!height=52mm]
1435\definepapersize [A10] [\c!width=26mm,\c!height=37mm]
1436
1437\definepapersize [A4/2][\c!width=\dimexpr297mm/2\relax,\c!height=210mm] % 148.5mm
1438%definepapersize [2A5] [\c!width=296mm,\c!height=210mm] % doublewide
1439
1440\definepapersize [B0]  [\c!width=1000mm,\c!height=1414mm]
1441\definepapersize [B1]  [\c!width=707mm,\c!height=1000mm]
1442\definepapersize [B2]  [\c!width=500mm,\c!height=707mm]
1443\definepapersize [B3]  [\c!width=353mm,\c!height=500mm] % [\c!width=354mm,\c!height=500mm]
1444\definepapersize [B4]  [\c!width=250mm,\c!height=353mm] % [\c!width=250mm,\c!height=354mm]
1445\definepapersize [B5]  [\c!width=176mm,\c!height=250mm] % [\c!width=177mm,\c!height=250mm]
1446\definepapersize [B6]  [\c!width=125mm,\c!height=176mm] % [\c!width=125mm,\c!height=177mm]
1447\definepapersize [B7]  [\c!width=88mm,\c!height=125mm]
1448\definepapersize [B8]  [\c!width=62mm,\c!height=88mm]   % [\c!width=63mm,\c!height=88mm]
1449\definepapersize [B9]  [\c!width=44mm,\c!height=62mm]   % [\c!width=44mm,\c!height=63mm]
1450\definepapersize [B10] [\c!width=31mm,\c!height=44mm]
1451
1452\definepapersize [C0]  [\c!width=917mm,\c!height=1297mm]
1453\definepapersize [C1]  [\c!width=648mm,\c!height=917mm] % [\c!width=649mm,\c!height=917mm]
1454\definepapersize [C2]  [\c!width=458mm,\c!height=648mm] % [\c!width=459mm,\c!height=649mm]
1455\definepapersize [C3]  [\c!width=324mm,\c!height=458mm] % [\c!width=324mm,\c!height=459mm]
1456\definepapersize [C4]  [\c!width=229mm,\c!height=324mm]
1457\definepapersize [C5]  [\c!width=162mm,\c!height=229mm]
1458\definepapersize [C6]  [\c!width=114mm,\c!height=162mm] % [\c!width=115mm,\c!height=162mm]
1459\definepapersize [C7]  [\c!width=81mm,\c!height=114mm]  % [\c!width=81mm,\c!height=115mm]
1460\definepapersize [C8]  [\c!width=57mm,\c!height=81mm]
1461\definepapersize [C9]  [\c!width=40mm,\c!height=57mm]
1462\definepapersize [C10] [\c!width=28mm,\c!height=40mm]
1463
1464%D Per August 2004 the rounding of some (seldom used) sizes were corrected top the
1465%D latest DIN specifications. Peter Rolf came up with these and a few more missing
1466%D sizes. Watch out: spaces and slashes!
1467
1468\definepapersize [4 A0]  [\c!width=1682mm,\c!height=2378mm]
1469\definepapersize [2 A0]  [\c!width=1189mm,\c!height=1682mm]
1470\definepapersize [C6/C5] [\c!width=114mm,\c!height=229mm]
1471
1472%D Because there are no standardized screen sizes, we define a bunch of sizes with
1473%D $4:3$ ratios. The \type {S6} size is nearly as wide as a sheet of \type {A4}
1474%D paper.
1475
1476\definepapersize [S3]  [\c!width=300pt,\c!height=225pt]
1477\definepapersize [S4]  [\c!width=400pt,\c!height=300pt]
1478\definepapersize [S5]  [\c!width=500pt,\c!height=375pt]
1479\definepapersize [S6]  [\c!width=600pt,\c!height=450pt]
1480\definepapersize [S8]  [\c!width=800pt,\c!height=600pt]
1481\definepapersize [SL]  [\c!width=640pt,\c!height=400pt] % low
1482\definepapersize [SM]  [\c!width=720pt,\c!height=450pt] % medium
1483\definepapersize [SW]  [\c!width=800pt,\c!height=450pt] % wide
1484\definepapersize [HD]  [\c!width=1920pt,\c!height=1080pt]
1485\definepapersize [HD+] [\c!width=1920pt,\c!height=1200pt]
1486\definepapersize [HD-] [\c!width=960pt,\c!height=540pt]
1487
1488%D These are handy too:
1489
1490\definepapersize [S33] [\c!width=300pt,\c!height=300pt]
1491\definepapersize [S44] [\c!width=400pt,\c!height=400pt]
1492\definepapersize [S55] [\c!width=500pt,\c!height=500pt]
1493\definepapersize [S66] [\c!width=600pt,\c!height=600pt]
1494
1495%D One may wonder if \TEX\ should be used for typesetting \CDROM\ covers, but it
1496%D does not hurt to have the paper size ready.
1497
1498\definepapersize [CD] [\c!width=120mm,\c!height=120mm]
1499
1500%D The next series is for our English speaking friends who decided to stick to non
1501%D metric values. Thanks to Nelson Beebe for completing the inch based list.
1502
1503\definepapersize [letter]    [\c!width=8.5in,\c!height=11in]
1504\definepapersize [ledger]    [\c!width=11in,\c!height=17in]
1505\definepapersize [tabloid]   [\c!width=17in,\c!height=11in]
1506
1507\definepapersize [legal]     [\c!width=8.5in,\c!height=14in]
1508\definepapersize [folio]     [\c!width=8.5in,\c!height=13in]
1509\definepapersize [executive] [\c!width=7.25in,\c!height=10.5in]
1510
1511\definepapersize [A] [\c!width=8.5in,\c!height=11in] % 1 sheet
1512\definepapersize [B] [\c!width=11in,\c!height=17in]  % 2 sheets
1513\definepapersize [C] [\c!width=17in,\c!height=22in]  % 4 sheets
1514
1515%D The next set is for Tobias Burnus, who gave me the sizes.
1516
1517\definepapersize [envelope 9]  [\c!width=8.88in,\c!height=3.88in]
1518\definepapersize [envelope 10] [\c!width=9.5in,\c!height=4.13in]
1519\definepapersize [envelope 11] [\c!width=10.38in,\c!height=4.5in]
1520\definepapersize [envelope 12] [\c!width=11.0in,\c!height=4.75in]
1521\definepapersize [envelope 14] [\c!width=11.5in,\c!height=5.0in]
1522\definepapersize [monarch]     [\c!width=7.5in,\c!height=3.88in]
1523\definepapersize [check]       [\c!width=8.58in,\c!height=3.88in]
1524\definepapersize [DL]          [\c!width=110mm,\c!height=220mm] % [\c!width=220mm,\c!height=110mm]
1525\definepapersize [E4]          [\c!width=280mm,\c!height=400mm]
1526
1527%D The next three sets are supplied by Taco:
1528
1529\definepapersize [RA0]  [\c!width=860mm,\c!height=1220mm]
1530\definepapersize [RA1]  [\c!width=610mm,\c!height=860mm]
1531\definepapersize [RA2]  [\c!width=430mm,\c!height=610mm]
1532\definepapersize [RA3]  [\c!width=305mm,\c!height=430mm]
1533\definepapersize [RA4]  [\c!width=215mm,\c!height=305mm]
1534
1535%D ISO SRA (supplementary raw A) sizes:
1536
1537\definepapersize [SRA0]  [\c!width=900mm,\c!height=1280mm]
1538\definepapersize [SRA1]  [\c!width=640mm,\c!height=900mm]
1539\definepapersize [SRA2]  [\c!width=450mm,\c!height=640mm]
1540\definepapersize [SRA3]  [\c!width=320mm,\c!height=450mm]
1541\definepapersize [SRA4]  [\c!width=225mm,\c!height=320mm]
1542
1543%D Swedish thesis formats:
1544
1545\definepapersize [G5]  [\c!width=169mm,\c!height=239mm]
1546\definepapersize [E5]  [\c!width=155mm,\c!height=220mm]
1547
1548%D Industry invention:
1549
1550\definepapersize [A3plus] [\c!width=329mm,\c!height=483mm]
1551
1552%D For Alan:
1553
1554\definepapersize [business]   [\c!width=85mm,\c!height=55mm]
1555\definepapersize [businessUS] [\c!width=3.5in,\c!height=2in]
1556
1557%D We can now default to a reasonable size. We match the print paper size with the
1558%D typeset paper size. This setting should come after the first layout specification
1559%D (already done).
1560
1561% \definepapersize
1562%   [\v!default]
1563%   [ \c!width=\paperwidth,
1564%    \c!height=\paperheight]
1565
1566% \definepapersize
1567%   [samesized]
1568%   [ \c!width=\paperwidth,
1569%    \c!height=\paperheight]
1570
1571\setuppapersize
1572  [\c!distance=1.5cm] % offset is already taken
1573
1574\definepapersize
1575  [oversized]
1576  [ \c!width=\dimexpr\paperwidth +\layouttargetparameter\c!distance\relax,
1577   \c!height=\dimexpr\paperheight+\layouttargetparameter\c!distance\relax]
1578
1579\definepapersize
1580  [undersized]
1581  [ \c!width=\dimexpr\paperwidth -\layouttargetparameter\c!distance\relax,
1582   \c!height=\dimexpr\paperheight-\layouttargetparameter\c!distance\relax]
1583
1584\definepapersize
1585  [doublesized]
1586  [ \c!width=\dimexpr \paperwidth \relax,
1587   \c!height=\dimexpr2\paperheight\relax]
1588
1589\definepapersize
1590  [doubleoversized]
1591  [ \c!width=\dimexpr \paperwidth +\layouttargetparameter\c!distance\relax,
1592   \c!height=\dimexpr2\paperheight+\layouttargetparameter\c!distance\relax]
1593
1594\definepapersize
1595  [doublewide]
1596  [ \c!width=\dimexpr2\paperwidth \relax,
1597   \c!height=\dimexpr \paperheight\relax]
1598
1599% \setuppapersize
1600%   [A4][A4]
1601
1602\setuppapersize
1603  [A4] % [samesized]
1604
1605%D A few goodies, first a full page layout:
1606
1607\definelayout
1608  [\v!page]
1609
1610\setuplayout
1611  [\v!page]
1612  [\c!backspace=\zeropoint,
1613   \c!cutspace=\zeropoint,
1614   \c!topspace=\zeropoint,
1615   \c!bottomspace=\zeropoint,
1616   \c!margin=\zeropoint,
1617   \c!edge=\zeropoint,
1618   \c!header=\zeropoint,
1619   \c!footer=\zeropoint,
1620   \c!top=\zeropoint,
1621   \c!bottom=\zeropoint,
1622   \c!leftmargin=\zeropoint,
1623   \c!rightmargin=\zeropoint,
1624   \c!leftedge=\zeropoint,
1625   \c!rightedge=\zeropoint,
1626   \c!textdistance=\zeropoint,
1627   \c!width=\v!middle,
1628   \c!height=\v!middle,
1629   \c!lines=0,
1630   \c!grid=\v!no]
1631
1632%D A quick and dirty one:
1633
1634\definelayout
1635  [\v!middle]
1636  [\c!width=\v!middle,
1637   \c!height=\v!middle]
1638
1639%D One for testing examples (5mm is often the non printable area):
1640
1641\definelayout
1642  [\v!tight]
1643
1644\definelayout
1645  [\v!tight]
1646  [\v!page]
1647  [\c!backspace=5mm,
1648   \c!cutspace=5mm,
1649   \c!topspace=5mm,
1650   \c!bottomspace=5mm]
1651
1652\protect \endinput
1653