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