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