summaryrefslogtreecommitdiff
path: root/doc/context/sources/general/manuals/details/details-pseudocolumns.tex
blob: f30ffaeab1bce2c9208d5f8a128a0fb5410a4e2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
% language=uk

\environment details-environment

\startcomponent details-pseudocolumns

\start \page[right]

\definelayout
  [temp]
  [columndistance=12pt,
   columns=3]

\setuplayout
  [temp]

\startchapter[title={Pseudo columns}]

\index {grid snapping+columns}
\index {pseudo columns}
\index {layers}
\index {backgrounds}

In desk top publishing applications the grid is pretty dominant in defining
layouts. On the other hand, \TEX\ is pretty good defining layouts in terms of
relative dimensions. This means that mapping a desk top publishing layout into
its \TEX\ (or \CONTEXT) counterpart takes some effort. For what it's worth,
personally I don't like grids that much, specially not in complex documents,
unless one makes sure that all elements are suitable sized for the grid used.

We not only have to deal with vertical grids, but also with horizontal ones. Here
we focus on the second category. When implementing designs, it is best first to
look into the normal page layout areas. For most documents these are sufficient,
but occasionally we need a more detailed approach.

When playing with grids, you need to make sure that grid snapping is turned on.
It helps if you turn on the grid so that you can see where things end up. When a
horizontal grid is defined, gray vertical rules show their boundaries.

\starttyping
\setuplayout[grid=yes] \showgrid
\stoptyping

The \type {\setuplayout} command has a few settings that have to do with so
called pseudo columns. These are in no sense related to multi|-|column
typesetting and only play a role in placing text on specific locations.

\starttyping
\setuplayout
  [columndistance=12pt,
   columns=3]
\stoptyping

You can use \type {\layoutcolumnoffset} for positioning relative to the left
boundary of the running text:

\startbuffer
\hskip\layoutcolumnoffset{2}{\red Text positioned in column 2!}
\stopbuffer

\typebuffer \getbuffer

This mechanism is actually meant to ease the definition of complicated (title)
pages where many text and graphic elements need to be anchored at well defined
places. The layer mechanism is the most natural candidate for this.

\startbuffer
\definelayer [text] \setupbackgrounds [text] [background=text]
\stopbuffer

\typebuffer

When anchoring elements on a layer, you can specify absolute positions using the
\type {x} and \type {y} keys but grid based positioning is possible with the
\type {column} and \type {line} keys. We need to pass \type {grid} as location
specifier.

\startbuffer
\setlayer[text][column=1,line=48,location=grid]{these are not}
\setlayer[text][column=2,line=47,location=grid]{real columns}
\setlayer[text][column=3,line=48,location=grid]{but fake ones}
\stopbuffer

\typebuffer \getbuffer

\page

\startbuffer
\setlayer [text] [column=1,line=32,location=grid]
  {\ruledvtop {\hsize\layoutcolumnwidth
     \style[regular:3]{nitty\par gritty}}}

\setlayer [text] [column=2,line=37,location=grid]
  {\ruledvbox {\hsize\layoutcolumnwidth
     \style[regular:3]{nitty\par gritty}}}

\setlayer [text] [column=3,line=42,location=grid]
  {\ruledvcenter {\hsize\layoutcolumnwidth
     \style[regular:3]{nitty\par gritty}}}
\stopbuffer

\typebuffer \getbuffer

The data that goes into the layer is collected and flushed as soon as \TEX\
builds the page. The buffer associated to the layer is then ready for new data
(for the next page).

In this example, you can see that the baselines of the boxes (here visualized by
dashed rules) are put at the specified lines. You can use the \TEX\ box commands
\type {\vbox}, \type {\vtop} and \type {\vcenter} to specify where the main
baseline of the box content is positioned (at the top or bottom line, or
centered).

\startbuffer
\setlayer
  [text]
  [column=2,line=48,x=\layoutcolumnwidth,location=left]
  {\framed
     [background=color,backgroundcolor=red,
      foregroundstyle=regular:2,foregroundcolor=white,
      frame=off]
     {Why ain't I framed?}}
\stopbuffer

\typebuffer \getbuffer

\page

On the previous page we demonstrated a more complicated call to \type {\setlayer}
and more features will be introduced in later chapters. We position the framed
text in column~2 and at line~48. In addition we shift the text over the pseudo
column width, i.e. we position the text at the right of the column. The location
specifier aligns the text left from the point of positioning.

When we have set up the pseudo columns, we have access to a couple of variables:

\starttabulate[|l|l|l|]
\NC \type {\layoutcolumns}         \NC counter   \NC number of columns    \NC \NR
\NC \type {\layoutlines}           \NC counter   \NC number of gridlines  \NC \NR
\NC \type {\layoutcolumnwidth}     \NC dimension \NC width of one column  \NC \NR
\NC \type {\layoutcolumnoffset{n}} \NC macro     \NC position of column n \NC \NR
\stoptabulate

This is typically a feature that has been there for quite a while but that I forget
about. It's probably because I never have to use grids myself.

In the examples before we used some predefined (font) styles:

\typebuffer[regular:sizes]

\page \setuplayout[reset] \stop

\stopchapter

\stopcomponent