details-pseudocolumns.tex /size: 5095 b    last modification: 2023-12-21 09:43
1% language=us
2
3\environment details-environment
4
5\startcomponent details-pseudocolumns
6
7\start \page[right]
8
9\definelayout
10  [temp]
11  [columndistance=12pt,
12   columns=3]
13
14\setuplayout
15  [temp]
16
17\startchapter[title={Pseudo columns}]
18
19\index {grid snapping+columns}
20\index {pseudo columns}
21\index {layers}
22\index {backgrounds}
23
24In desk top publishing applications the grid is pretty dominant in defining
25layouts. On the other hand, \TEX\ is pretty good defining layouts in terms of
26relative dimensions. This means that mapping a desk top publishing layout into
27its \TEX\ (or \CONTEXT) counterpart takes some effort. For what it's worth,
28personally I don't like grids that much, specially not in complex documents,
29unless one makes sure that all elements are suitable sized for the grid used.
30
31We not only have to deal with vertical grids, but also with horizontal ones. Here
32we focus on the second category. When implementing designs, it is best first to
33look into the normal page layout areas. For most documents these are sufficient,
34but occasionally we need a more detailed approach.
35
36When playing with grids, you need to make sure that grid snapping is turned on.
37It helps if you turn on the grid so that you can see where things end up. When a
38horizontal grid is defined, gray vertical rules show their boundaries.
39
40\starttyping
41\setuplayout[grid=yes] \showgrid
42\stoptyping
43
44The \type {\setuplayout} command has a few settings that have to do with so
45called pseudo columns. These are in no sense related to multi|-|column
46typesetting and only play a role in placing text on specific locations.
47
48\starttyping
49\setuplayout
50  [columndistance=12pt,
51   columns=3]
52\stoptyping
53
54You can use \type {\layoutcolumnoffset} for positioning relative to the left
55boundary of the running text:
56
57\startbuffer
58\hskip\layoutcolumnoffset{2}{\red Text positioned in column 2!}
59\stopbuffer
60
61\typebuffer \getbuffer
62
63This mechanism is actually meant to ease the definition of complicated (title)
64pages where many text and graphic elements need to be anchored at well defined
65places. The layer mechanism is the most natural candidate for this.
66
67\startbuffer
68\definelayer [text] \setupbackgrounds [text] [background=text]
69\stopbuffer
70
71\typebuffer
72
73When anchoring elements on a layer, you can specify absolute positions using the
74\type {x} and \type {y} keys but grid based positioning is possible with the
75\type {column} and \type {line} keys. We need to pass \type {grid} as location
76specifier.
77
78\startbuffer
79\setlayer[text][column=1,line=48,location=grid]{these are not}
80\setlayer[text][column=2,line=47,location=grid]{real columns}
81\setlayer[text][column=3,line=48,location=grid]{but fake ones}
82\stopbuffer
83
84\typebuffer \getbuffer
85
86\page
87
88\startbuffer
89\setlayer [text] [column=1,line=32,location=grid]
90  {\ruledvtop {\hsize\layoutcolumnwidth
91     \style[regular:3]{nitty\par gritty}}}
92
93\setlayer [text] [column=2,line=37,location=grid]
94  {\ruledvbox {\hsize\layoutcolumnwidth
95     \style[regular:3]{nitty\par gritty}}}
96
97\setlayer [text] [column=3,line=42,location=grid]
98  {\ruledvcenter {\hsize\layoutcolumnwidth
99     \style[regular:3]{nitty\par gritty}}}
100\stopbuffer
101
102\typebuffer \getbuffer
103
104The data that goes into the layer is collected and flushed as soon as \TEX\
105builds the page. The buffer associated to the layer is then ready for new data
106(for the next page).
107
108In this example, you can see that the baselines of the boxes (here visualized by
109dashed rules) are put at the specified lines. You can use the \TEX\ box commands
110\type {\vbox}, \type {\vtop} and \type {\vcenter} to specify where the main
111baseline of the box content is positioned (at the top or bottom line, or
112centered).
113
114\startbuffer
115\setlayer
116  [text]
117  [column=2,line=48,x=\layoutcolumnwidth,location=left]
118  {\framed
119     [background=color,backgroundcolor=red,
120      foregroundstyle=regular:2,foregroundcolor=white,
121      frame=off]
122     {Why ain't I framed?}}
123\stopbuffer
124
125\typebuffer \getbuffer
126
127\page
128
129On the previous page we demonstrated a more complicated call to \type {\setlayer}
130and more features will be introduced in later chapters. We position the framed
131text in column~2 and at line~48. In addition we shift the text over the pseudo
132column width, i.e. we position the text at the right of the column. The location
133specifier aligns the text left from the point of positioning.
134
135When we have set up the pseudo columns, we have access to a couple of variables:
136
137\starttabulate[|l|l|l|]
138\NC \type {\layoutcolumns}         \NC counter   \NC number of columns    \NC \NR
139\NC \type {\layoutlines}           \NC counter   \NC number of gridlines  \NC \NR
140\NC \type {\layoutcolumnwidth}     \NC dimension \NC width of one column  \NC \NR
141\NC \type {\layoutcolumnoffset{n}} \NC macro     \NC position of column n \NC \NR
142\stoptabulate
143
144This is typically a feature that has been there for quite a while but that I forget
145about. It's probably because I never have to use grids myself.
146
147In the examples before we used some predefined (font) styles:
148
149\typebuffer[regular:sizes]
150
151\page \setuplayout[reset] \stop
152
153\stopchapter
154
155\stopcomponent
156