pagecolumns.tex /size: 12 Kb    last modification: 2023-12-21 09:43
1% macros=mkvi language=us
2
3\definemeasure[onecolumn]   [\columnwidth]
4\definemeasure[twocolumns]  [\dimexpr\plustwo  \columnwidth+          \columndistance\relax]
5\definemeasure[threecolumns][\dimexpr\plusthree\columnwidth+\plustwo  \columndistance\relax]
6\definemeasure[fourcolumns] [\dimexpr\plusfour \columnwidth+\plusthree\columndistance\relax]
7
8\usemodule[abr-04]
9
10\setupbodyfont
11  [dejavu,11pt]
12
13\definefont[QuiteLarge][SansBold sa 2.50]
14\definefont[NotSoLarge][SansBold sa 1.25]
15
16\setuplayout
17  [backspace=.1\paperwidth,
18   topspace=.025\paperheight,
19   header=0.025\paperheight,
20   footer=0.025\paperheight,
21   headerdistance=0.025\paperheight,
22   footerdistance=0.025\paperheight,
23   width=middle,
24   height=middle]
25
26\setuppagenumbering
27  [alternative=doublesided,
28   location=]
29
30\setupwhitespace
31  [line]
32
33\setupblank
34  [line]
35
36\setuptyping
37  [blank=halfline]
38
39\startsetups [pagenumber]
40    \hbox to .2\paperwidth {
41        \hss
42        Page \pagenumber
43        \hss
44    }
45\stopsetups
46
47\setupfooter [before=\vfill,after=\vfill,style=\bf,color=color-4]
48\setupheader [before=\vfill,after=\vfill,style=\bf,color=color-4]
49
50\setupfootertexts [] [\setups{pagenumber}]
51\setupheadertexts [] [\setups{chapterhead}]
52
53\startsetups [chapterhead]
54    \hbox to .2\paperwidth {
55        \hss
56        \getmarking[chapter]
57        \hss
58    }
59\stopsetups
60
61\setuphead
62  [chapter]
63  [header=empty]
64
65\definecolor[color-3][.5(red,black)]
66\definecolor[color-2][.5(green,black)]
67\definecolor[color-1][.5(blue,black)]
68\definecolor[color-4][.5(white,black)]
69\definecolor[color-5][.5(white,color-4)]
70\definecolor[color-6][.2(white,color-4)]
71
72\definecolor[fakerulecolor][white]
73
74\usemodule[typesetting]
75
76\setupcombination
77  [style=mono]
78
79\startuseMPgraphic{page}
80StartPage ;
81    path p ;
82    numeric n; n := PageNumber ;
83    numeric w; w := bbwidth(Page) ;
84    numeric h; h := bbheight(Page) ;
85    def DrawBit (expr bit, dx, dy) =
86        path p ; p := unitsquare xyscaled(w/5,h/40) shifted (dx*w/10,dy*(h-h/40)) ;
87        if n div bit > 0 :
88            n := n - (n div bit)*bit ;
89            fill p withcolor \MPcolor{color-1} ;
90        else :
91            fill p withcolor \MPcolor{color-2} ;
92        fi ;
93    enddef ;
94    DrawBit(32,7,1) ;
95    DrawBit(16,4,1) ;
96    DrawBit( 8,1,1) ;
97    DrawBit( 4,7,0) ;
98    DrawBit( 2,4,0) ;
99    DrawBit( 1,1,0) ;
100StopPage ;
101\stopuseMPgraphic
102
103\startuniqueMPgraphic{frame}
104    fill OverlayBox withcolor \MPcolor{color-5} ;
105\stopuniqueMPgraphic
106
107\startuniqueMPgraphic{contrast}
108    fill OverlayBox withcolor \MPcolor{color-4} ;
109\stopuniqueMPgraphic
110
111\defineoverlay[page]    [\useMPgraphic{page}]
112\defineoverlay[frame]   [\useMPgraphic{frame}]
113\defineoverlay[contrast][\useMPgraphic{contrast}]
114
115\setuphead
116  [chapter]
117  [style=\QuiteLarge,
118   color=color-3,
119   number=no]
120
121\setuplist
122  [chapter]
123  [command=\MyListCommand,
124   alternative=command]
125
126\starttexdefinition unexpanded MyListCommand #1#2#3
127    \snaptogrid
128        [line,-line]\vbox {
129            \tfb
130            \setstrut
131            \strut#2
132            \quad#3
133        }
134\stoptexdefinition
135
136\setupmargindata
137  [style=\tttf,
138   color=color-3]
139
140\starttexdefinition unexpanded ShowFile #1
141    \margintext
142        {\cldcontext{string.match("#1","\letterpercent d+")}}
143    \typefile
144        [range={environment}]
145        {#1}
146\stoptexdefinition
147
148% \typefile[range=4]  {...}
149% \typefile[range={=}]{...} % start after comment lines
150
151\starttexdefinition unexpanded ShowEnvironmentFile #1
152    \margintext
153        {\cldcontext{string.match("#1","\letterpercent d+")}}
154    \typefile
155        [range={=startenvironment}]
156        {#1}
157\stoptexdefinition
158
159\startdocument
160
161\startMPpage
162StartPage ;
163    path p ; numeric w, h, d ; picture q ;
164    if true :
165        q := image(draw textext.urt("\ssbf PAGES") withcolor \MPcolor{color-6}) ;
166    else :
167        q := image(draw textext.urt("\ssbf PAGECOLUMNS") withcolor \MPcolor{color-6}) ;
168    fi ;
169    w := bbwidth(Page) ;
170    h := bbheight(Page) ;
171    d := h/100 ;
172    fill Page withcolor \MPcolor{color-1} ;
173    p := Page xysized (w,d) ;
174    for i := 5d step 2d until h-5d :
175        fill p shifted (0,i) withcolor \MPcolor{color-2} ;
176    endfor
177    p := Page xysized(w/10,h) ;
178    for i = 0, .3, .6, .9 :
179        fill p shifted (i*w,0) withcolor \MPcolor{color-1} withtransparency(1,.75) ;
180    endfor ;
181    def do_it(expr sz, sh) =
182        p := Page xysized sz ;
183        fill p shifted sh withcolor \MPcolor{color-3} withtransparency(1,.5) ;
184        draw q xysized (bbwidth(p),bbheight(p)) shifted sh ;
185    enddef ;
186    do_it ((8w/10,13d),(.1w,81d)) ;
187    do_it ((5w/10,13d),(.4w,67d)) ;
188    do_it ((2w/10,17d),(.1w,20d)) ;
189    do_it ((2w/10,15d),(.1w,56d)) ;
190    do_it ((1w/10,10d),(.4w,40d)) ;
191    do_it ((2w/10,13d),(.7w,27d)) ;
192    draw textext.urt("\ssbf Hans Hagen")
193        xysized (5w/10,5d)
194        shifted (.4w,6d)
195        withcolor \MPcolor{color-5} ;
196StopPage ;
197\stopMPpage
198
199\page[empty] \setuppagenumber[number=1]
200
201\setupbackgrounds
202  [page]
203  [background=page]
204
205\starttitle[title=Contents]
206
207    \placelist[chapter]
208
209\stoptitle
210
211\startchapter[title=Introduction]
212
213{\em This manual as well as the mechanism it describes is under construction. Don't
214use page columns in production. Experimenting is of course fine.}
215
216The \TEX\ engine is a progressive typesetter: it takes input and does something
217with it and can do that for quite a while. It can process massive input and
218produce massive output. In that process it never looks back. Now, it is of course
219possible to collect content and delay some aspects of the rendering but to what
220extent that content can be manipulated is limited. In \LUATEX\ one can do a bit
221more but even then the basic typesetting process is mostly linear.
222
223When a text gets typeset there are several properties that play a role:
224
225\startitemize
226\startitem
227    the width of the lines in a paragraph which is the main unit of processing
228\stopitem
229\startitem
230    the target height of what gets output, normally this is the height of the
231    text area, excluding headers and footers
232\stopitem
233\startitem
234    the parameters that determine when the so called output routine gets called,
235    for instance successive broken lines, widow and club penalties
236\stopitem
237\startitem
238    the presence of so called inserts, for instance footnotes or floating bodies
239\stopitem
240\startitem
241    the space between lines and paragraphs
242\stopitem
243\startitem
244    explicitly entered elements or spacing or injected by macros hooked into for
245    instance \type {\everypar}
246\stopitem
247\stopitemize
248
249It is important to realize that \TEX\ has no concept of what a page is. It takes
250input and occasionally hand over the intermediate result to the output routine.
251There decisions are made to flush out a page, either of not with ornaments like
252headers, footers, content left over from previous encounters, footnotes as well
253as maybe specific trickery liked by the backend that targets at some viewer.
254
255That said, so called multi|-|column layouts are {\em not} part of the concepts
256present in \TEX. As far as the engine is concerned there is only one column.
257Among the reasons for not having a native mechanism for columns is that it is
258very hard to come up with a mechanism for splitting them in ways that suits
259everybody. In fact, the amount of control needed would make such a mechanism very
260complex and still limited. You can compare this to math typesetting. That
261subspace has some fixed characteristics if only because otherwise mathematicians
262could not communicate. However, there is some control over spacing and one can to
263some extend intervene. In \LUATEX\ some of the hard coded properties are made
264configureable but still one gets pretty much what the engine considers right.
265Such an approach would not work with columns. In fact, it doesn't even work well
266with tables, for which \TEX\ provides the alignment mechanism: different kind of
267tables demand different solutions, which is why in \CONTEXT\ we have old
268fashioned tables, tabulated tables (that span pages and can contain paragraphs),
269natural as well as extreme tables that resemble \HTML\ tables, line tables and
270framed tables.
271
272So, when we want to support columns we need to write something in \TEX\ lingua
273and for that the \type {\vsplit} operation can be of help. So far we have in
274\CONTEXT\ four mechanisms:
275
276\startitemize[n]
277\startitem
278    the original \MKII\ mechanism that permits mixed single and multi|-|column
279    text flows, with limited support for floating bodies
280\stopitem
281\startitem
282    a reimplementation of mixed columns in a mix of \TEX\ and \LUA, a bit better
283    with balancing and penalties for keeping section heads with the text, but
284    with very limited support for floating bodies; it works ok with grids
285\stopitem
286\startitem
287    a reimplementation of \MKII\ columnsets, a mechanism that is meant for
288    magazine like layouts where floats can span columns and positioned at will:
289    this one assumes relative simple text flows but as a bonus provides spreads;
290    this one is strongly grid based
291\stopitem
292\startitem
293    page based columns, where we use the normal (single column) page builder to
294    collect columns that then get combined into a page: this one is quite robust
295    but one has to keep an eye on floats as we don't span across columns
296    otherwise than in top or bottom floats but, on the other hand, one can use so
297    called side floats; this one is still experimental
298\stopitem
299\stopitemize
300
301Given specific demands one can come up with alternatives but it's very hard to
302combine all demands into one mechanismn simply because anything can be part of
303the text flow. Because it is not much fun to write such mechanisms and because
304no project ever pays for fundamental development, one just has to accept what
305\CONTEXT\ provides, be it with limitations.
306
307The first mechanism is more or less obsolete and replaced by the second. For
308instance, we now use the second one when we have an itemize that demands columns.
309I must admit that I don't like columns and never use them. I was involved in
310projects where the designer wanted columns but in the end the complexity of the
311content didn't work well with that that decision: inconsistent whitespace (due to
312many small sections, lots of images, many tables, math formulas, etc) as well as
313the result having more pages that the single column variant with side and margin
314floats. Occasionally I use columned itemize or columned tables of contents and of
315course registers are often in columns.
316
317One can wonder why columns are supported anyway. It's mostly useful for
318newspapers that have wide pages or journals that have small print. For magazines
319and special layout it's fine too although it can look bad when columns are narrow
320and fancy layout tricks are used. I guess that at some point their use will
321disappear. A document on a phone or tablet is one narrow columns. An internet
322page is one long column. A printed book, given that there will be such items in
323the future is normally typeset in one column. And journals as well as newspapers
324more and more get replaced by media that better serve their purpose. So, apart
325from an intellectual challenge, implementing extensive multi|-|column support is
326a waste of energy. Which is why we can accept limitations.
327
328\stopchapter
329
330\startchapter[title=Just text]
331
332As with the other mechanism you can define a column instance and use that later.
333You can also directly pass the settings with the \type {\startpagecolumns} command
334but best is to define an instance.
335
336\FourPages{pagecolumns-001}
337
338\ShowFile{pagecolumns-001}
339
340We always start at a new page and end on a new one. Footnotes and such don't span
341columns and we don't balance. When the number of columns equals one you get the
342normal routine but with the requested settings.
343
344\stopchapter
345
346\startchapter[title=Floats]
347
348You can have floating bodies in columns. When a float doesn't fit it will be
349flushed at the top of the next page.
350
351\FourPages{pagecolumns-002}
352
353\ShowFile{pagecolumns-002}
354
355\SixPages{pagecolumns-007}
356
357\ShowFile{pagecolumns-007}
358
359Side floats are also supported but we don't treat them special so you get the
360same behaviour as with single column layouts.
361
362\FourPages{pagecolumns-005}
363
364\ShowFile{pagecolumns-005}
365
366\FourPages{pagecolumns-003}
367
368\ShowFile{pagecolumns-003}
369
370
371\stopchapter
372
373\startchapter[title=Footnotes]
374
375Footnotes are supported but we assume sane usage. You can always revert to
376endnotes if needed.
377
378\FourPages{pagecolumns-004}
379
380\ShowFile{pagecolumns-004}
381
382\stopchapter
383
384\startchapter[title=Pages]
385
386Going to a new page happens with \type {\page} and progressing to the next column
387with \type {\column}.
388
389\FourSpread{pagecolumns-006}
390
391\ShowFile{pagecolumns-006}
392
393\stopchapter
394
395\stopdocument
396