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