1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Page Macros Layout Specification}
15
16
17
18
19
20
21
22
23\unprotect
24
25
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
37\newdimension\makeupwidth
38
39\newdimension\textheight
40\newdimension\textwidth
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
77
78
79
80
81
82
83
84\newuserunit \lineheight lh
85\newuserunit \layoutcolumnwidth lc
86\newuserunit \layoutrowheight lr
87
88
89
90\newdimension\margindistance
91\newdimension\edgedistance
92\newdimension\marginwidth
93\newdimension\edgewidth
94
95
96
97
98
99
100\newdimension\leftedgedistance
101\newdimension\rightedgedistance
102\newdimension\leftmargindistance
103\newdimension\rightmargindistance
104
105
106
107\newdimension\topdistance
108\newdimension\headerdistance
109\newdimension\textdistance
110\newdimension\footerdistance
111\newdimension\bottomdistance
112
113\newdimension\textovershoot
114
115
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
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
145
146
147 \let\page_layouts_define\definelayout
148
149 \permanent\protected\def\definelayout[#1]
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
165 \or
166 \ifx\previouslayout\currentlayout
167 \letlayoutparameter\c!state\v!normal
168 \let\currentlayout\currentlayout
169 \page_layouts_synchronize
170 \page_layouts_check_next
171 \fi
172 \or
173
174 \letlayoutparameter\c!state\v!normal
175 \let\currentlayout\previouslayout
176 \page_layouts_synchronize
177 \page_layouts_check_next
178 \or
179 \ifx\currentlayout\v!reset
180 \lettonothing\currentlayout
181 \fi
182 \letlayoutparameter\c!state\v!normal
183 \glet\currentlayout\currentlayout
184 \page_layouts_synchronize
185 \page_layouts_check_next
186 \or
187 \letlayoutparameter\c!state\v!normal
188 \glettonothing\currentlayout
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
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
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
253 {\headerdistance\layoutdistance\headerheight\naturalheaderdistance
254 \footerdistance\layoutdistance\footerheight\naturalfooterdistance}
255
256
257
258\newtoks\extralayoutcalculations
259
260\def\page_layouts_calculate_extras
261 {\expand\extralayoutcalculations}
262
263\newtoks\everyswapmargins
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335\installcorenamespace{layouttarget}
336\installcorenamespace{layoutpaper}
337\installcorenamespace{layoutprint}
338\installcorenamespace{layoutcurrent}
339
340\installcommandhandler \??layouttarget {layouttarget} \??layouttarget
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
383
384
385\setuplayouttarget
386 [
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
411
412
413\permanent\tolerant\protected\def\definepapersize[#1]#*[#S#2]#*[#S#3]
414 {\cdef\currentlayouttarget{#1}
415 \ifempty\currentlayouttarget
416
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
436
437
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]
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
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
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}
591 \edef\m_page_asked_print{#2}
592
593 \page_paper_set_restore\m_page_asked_paper\m_page_asked_print
594
595
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
617 \normalexpanded{\setlayouttargetparameter\c!height{\the\paperheight}}
618 \normalexpanded{\setlayouttargetparameter\c!width {\the\paperwidth }}
619 \fi
620
621 \page_paper_set_offsets
622
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
640
641 \ifcstok{\rootlayouttargetparameter\c!option}\v!max
642 \begingroup
643
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
665 \page_layouts_synchronize
666
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
676 {\global\paperoffset\v_page_target_offset
677 \global\advanceby\paperwidth 2\paperoffset
678 \global\advanceby\paperheight2\paperoffset}
679
680\fi
681
682\ifdefined\synchronizegridsnapping \else
683 \let\synchronizegridsnapping\relax
684\fi
685
686
687
688
689
690
691
692
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
764
765
766
767
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
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}
794 \global\topspace {\layoutparameter\c!topspace}
795 \global\bottomspace {\layoutparameter\c!bottomspace}
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
803 \synchronizewhitespace
804 \synchronizeblank
805 \setupinterlinespace[\v!reset]
806
807
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
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
841 \global\totaltextwidth{
842 \leftedgetotal
843 \leftmargintotal
844 \makeupwidth
845 \rightmargintotal
846 \rightedgetotal
847 }
848
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
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
894 {\csname\??layoutcolumn\ifcsname\??layoutcolumn#1\endcsname#1\else0\fi\endcsname}
895
896
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
918 {\csname\??layoutrow\ifcsname\??layoutrow#1\endcsname#1\else0\fi\endcsname}
919
920
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
927 \page_layouts_synchronize
928 \fi}
929
930\appendtoks
931 \page_layouts_synchronize_at_start
932\to \everystarttext
933
934
935
936
937
938
939
940\ifdefined\lastpage \else \let\lastpage\!!plusone \fi
941
942\permanent\protected\def\page_layouts_change#1
943 {
944 \xdef\currentlayout{#1}
945 \page_layouts_synchronize}
946
947\aliased\let\changetolayout\page_layouts_change
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
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019\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
1034
1035
1036
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
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088\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
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
1099 \let\v_page_target_top_fill \relax
1100 \let\v_page_target_bottom_fill\vss}
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
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
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
1160 {\setbox#1\vpack
1161 {\offinterlineskip
1162 \begingroup
1163 \uselayoutstyleandcolor\c!style\c!color
1164 \offinterlineskip
1165 \page_layouts_insert_elements
1166 \endgroup
1167 \page_insert_body#2#3}}
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
1173 {\ifcsname\??layoutalternative\layoutparameter\c!alternative\endcsname
1174 \expandafter\lastnamedcs
1175 \else
1176 \expandafter\page_boxes_construct_content_default
1177 \fi}
1178
1179
1180
1181
1182
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
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
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
1262 {\page_adapts_pop
1263 \page_adapts_check}
1264
1265\def\page_adapts_status_info
1266 {\ifrelax\page_adapts_pop \else
1267 \space(adept: \the\d_page_adapts_height)\space
1268 \fi
1269 \the\realpageno}
1270
1271
1272
1273
1274\permanent\protected\def\startlayout[#S#1]
1275 {\page
1276 \globalpushmacro\currentlayout
1277 \doifelselayoutdefined{#1}{\setuplayout[#1]}\donothing}
1278
1279\permanent\protected\def\stoplayout
1280 {\page
1281 \globalpopmacro\currentlayout
1282 \setuplayout[\currentlayout]}
1283
1284
1285
1286\ifdefined\doifelselayoutsomeline \else
1287 \let\doifelselayoutsomeline\secondofthreearguments
1288\fi
1289
1290
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
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
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
1328 {\textheight\makeupheight
1329 \doifelselayoutsomeline\v!header\compensatevsizeheader\compensatevsizeheaderzero
1330 \doifelselayoutsomeline\v!footer\compensatevsizefooter\compensatevsizefooterzero}
1331
1332\newdimension\innermakeupwidth
1333\newdimension\innermakeupmargin
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\innermakeupwidth2\innermakeupmargin
1353 \advanceby\textwidth2\innermakeupmargin}
1354
1355\permanent\protected\def\calculatehsizes
1356 {\freezetextwidth
1357 \page_otr_command_set_hsize}
1358
1359
1360
1361
1362
1363
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
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
1414 {\texthoffset\doifbothsides\backspace\backspace{\dimexpr\paperwidth\backspace\makeupwidth\relax}}
1415
1416\permanent\protected\def\goleftonpage
1417 {\hkern{(\leftmargindistance\leftmarginwidth\leftedgedistance\leftedgewidth)}}
1418
1419\permanent\def\doifelsemarginswap#1#2
1420 {\doifbothsides{#1}{#1}{#2}}
1421
1422\aliased\let\doifmarginswapelse\doifelsemarginswap
1423
1424\protected\def\page_layouts_swap_margins
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
1429
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
1443
1444
1445
1446
1447
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
1459
1460
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
1496
1497
1498
1499
1500
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}
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
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
1538
1539\appendtoks
1540 \ifnum\realpageno>\plusone
1541 \page[\v!odd]
1542 \setuplayout
1543 \fi
1544\to \everysetuppagenumbering
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557\setuplayout
1558 [ \c!topspace=.08417508418\paperheight,
1559 \c!top=\zeropoint,
1560 \c!topdistance=\zeropoint,
1561 \c!header=.06734006734\paperheight,
1562 \c!headerdistance=\zeropoint,
1563 \c!height=.84175084175\paperheight,
1564 \c!footerdistance=\layoutparameter\c!headerdistance,
1565 \c!footer=.06734006734\paperheight,
1566 \c!bottomdistance=\layoutparameter\c!topdistance,
1567 \c!bottom=\zeropoint,
1568 \c!backspace=.11904761905\paperwidth,
1569 \c!edge=\zeropoint,
1570 \c!edgedistance=\layoutparameter\c!margindistance,
1571 \c!margin=.12649983170\paperwidth,
1572 \c!margindistance=.02008341748\paperwidth,
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,
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=,
1587 \c!textmargin=,
1588 \c!textdistance=\zeropoint,
1589 \c!style=,
1590 \c!color=,
1591 \c!marking=\v!off,
1592 \c!location=,
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,
1610 \c!limitstretch=\v!auto,
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
1623 \newuserunit \vsize vs
1624\popoverloadmode
1625
1626
1627
1628
1629
1630
1631
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 [A42][\c!width=\dimexpr297mm2\relax,\c!height=210mm]
1646
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]
1652\definepapersize [B4] [\c!width=250mm,\c!height=353mm]
1653\definepapersize [B5] [\c!width=176mm,\c!height=250mm]
1654\definepapersize [B6] [\c!width=125mm,\c!height=176mm]
1655\definepapersize [B7] [\c!width=88mm,\c!height=125mm]
1656\definepapersize [B8] [\c!width=62mm,\c!height=88mm]
1657\definepapersize [B9] [\c!width=44mm,\c!height=62mm]
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]
1662\definepapersize [C2] [\c!width=458mm,\c!height=648mm]
1663\definepapersize [C3] [\c!width=324mm,\c!height=458mm]
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]
1667\definepapersize [C7] [\c!width=81mm,\c!height=114mm]
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
1673
1674
1675
1676\definepapersize [4 A0] [\c!width=1682mm,\c!height=2378mm]
1677\definepapersize [2 A0] [\c!width=1189mm,\c!height=1682mm]
1678\definepapersize [C6C5] [\c!width=114mm,\c!height=229mm]
1679
1680
1681
1682
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]
1690\definepapersize [SM] [\c!width=720pt,\c!height=450pt]
1691\definepapersize [SW] [\c!width=800pt,\c!height=450pt]
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
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
1704
1705
1706\definepapersize [CD] [\c!width=120mm,\c!height=120mm]
1707
1708
1709
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]
1720\definepapersize [B] [\c!width=11in,\c!height=17in]
1721\definepapersize [C] [\c!width=17in,\c!height=22in]
1722
1723
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]
1733\definepapersize [E4] [\c!width=280mm,\c!height=400mm]
1734
1735
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
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
1752
1753\definepapersize [G5] [\c!width=169mm,\c!height=239mm]
1754\definepapersize [E5] [\c!width=155mm,\c!height=220mm]
1755
1756
1757
1758\definepapersize [A3plus] [\c!width=329mm,\c!height=483mm]
1759
1760
1761
1762\definepapersize [business] [\c!width=85mm,\c!height=55mm]
1763\definepapersize [businessUS] [\c!width=3.5in,\c!height=2in]
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779\setuppapersize
1780 [\c!distance=1.5cm]
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
1808
1809
1810\setuppapersize
1811 [A4]
1812
1813
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
1841
1842\definelayout
1843 [\v!middle]
1844 [\c!width=\v!middle,
1845 \c!height=\v!middle]
1846
1847
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 |