columnsets.tex /size: 20 Kb    last modification: 2023-12-21 09:43
1% author    : Hans Hagen
2% copyright : ConTeXt Development Team
3% license   : Creative Commons Attribution ShareAlike 4.0 International
4% reference : pragma-ade.nl | contextgarden.net | texlive (related) distributions
5% origin    : the ConTeXt distribution
6%
7% comment   : Because this manual is distributed with TeX distributions it comes with a rather
8%             liberal license. We try to adapt these documents to upgrades in the (sub)systems
9%             that they describe. Using parts of the content otherwise can therefore conflict
10%             with existing functionality and we cannot be held responsible for that. Many of
11%             the manuals contain characteristic graphics and personal notes or examples that
12%             make no sense when used out-of-context.
13%
14% comment   : Some chapters might have been published in TugBoat, the NTG Maps, the ConTeXt
15%             Group journal or otherwise. Thanks to the editors for corrections. Also thanks
16%             to users for testing, feedback and corrections.
17
18\dontcomplain
19
20\definepagebreak[mine][yes]
21
22% A complete otf optima pack is too expensive for this (I only have the
23% type one set).
24%
25% \usetypescriptfile
26%   [type-ghz]
27%
28% \usetypescript
29%   [sans]
30%   [optima-nova]
31%
32% \setupbodyfont
33%   [optima-nova,11pt]
34%
35% \definefont[QuiteLarge][SansBold sa 3]
36% \definefont[NotSoLarge][SansBold sa 1.5]
37%
38% So we could use:
39%
40% \setupbodyfont
41%   [pagella,11pt]
42%
43% \definefont[QuiteLarge][Bold sa 2.50]
44% \definefont[NotSoLarge][Bold sa 1.25]
45%
46% But this one has a matching sans:
47
48\setupbodyfont
49  [dejavu,11pt]
50
51\definefont[QuiteLarge][SansBold sa 2.50]
52\definefont[NotSoLarge][SansBold sa 1.25]
53
54\setuplayout
55  [backspace=.1\paperwidth,
56   topspace=.025\paperheight,
57   header=0.025\paperheight,
58   footer=0.025\paperheight,
59   headerdistance=0.025\paperheight,
60   footerdistance=0.025\paperheight,
61   width=middle,
62   height=middle]
63
64\setuppagenumbering
65  [alternative=doublesided,
66   location=]
67
68\setupwhitespace
69  [line]
70
71\setupblank
72  [line]
73
74\setuptyping
75  [blank=halfline]
76
77\startsetups [pagenumber]
78    \hbox to .2\paperwidth {
79        \hss
80        Page \pagenumber
81        \hss
82    }
83\stopsetups
84
85\setupfooter [before=\vfill,after=\vfill,style=\bf,color=color-4]
86\setupheader [before=\vfill,after=\vfill,style=\bf,color=color-4]
87
88\setupfootertexts [] [\setups{pagenumber}]
89\setupheadertexts [] [\setups{chapterhead}]
90
91\startsetups [chapterhead]
92    \hbox to .2\paperwidth {
93        \hss
94        \getmarking[chapter]
95        \hss
96    }
97\stopsetups
98
99\setuphead
100  [chapter]
101  [header=empty]
102
103\definecolor[color-1][.5(red,green)]
104\definecolor[color-2][.5(green,blue)]
105\definecolor[color-3][.5(blue,red)]
106\definecolor[color-4][.5(white,black)]
107\definecolor[color-5][.5(white,color-4)]
108\definecolor[color-6][.2(white,color-4)]
109
110\usemodule[typesetting]
111
112\setupcombination
113  [style=mono]
114
115\startuseMPgraphic{page}
116StartPage ;
117    path p ;
118    numeric n; n := PageNumber ;
119    numeric w; w := bbwidth(Page) ;
120    numeric h; h := bbheight(Page) ;
121    def DrawBit (expr bit, dx, dy) =
122        path p ; p := unitsquare xyscaled(w/5,h/40) shifted (dx*w/10,dy*(h-h/40)) ;
123        if n div bit > 0 :
124            n := n - (n div bit)*bit ;
125            fill p withcolor \MPcolor{color-1} ;
126        else :
127            fill p withcolor \MPcolor{color-2} ;
128        fi ;
129    enddef ;
130    DrawBit(32,7,1) ;
131    DrawBit(16,4,1) ;
132    DrawBit( 8,1,1) ;
133    DrawBit( 4,7,0) ;
134    DrawBit( 2,4,0) ;
135    DrawBit( 1,1,0) ;
136StopPage ;
137\stopuseMPgraphic
138
139\startuniqueMPgraphic{frame}
140    fill OverlayBox withcolor \MPcolor{color-5} ;
141\stopuniqueMPgraphic
142
143\startuniqueMPgraphic{contrast}
144    fill OverlayBox withcolor \MPcolor{color-4} ;
145\stopuniqueMPgraphic
146
147\defineoverlay[page]    [\useMPgraphic{page}]
148\defineoverlay[frame]   [\useMPgraphic{frame}]
149\defineoverlay[contrast][\useMPgraphic{contrast}]
150
151\setuphead
152  [chapter]
153  [style=\QuiteLarge,
154   color=color-3,
155   number=no]
156
157\setuplist
158  [chapter]
159  [command=\MyListCommand,
160   alternative=command]
161
162\starttexdefinition unexpanded MyListCommand #1#2#3
163    \snaptogrid
164        [line,-line]\vbox {
165            \tfb
166            \setstrut
167            \strut#2
168            \quad#3
169        }
170\stoptexdefinition
171
172\setupmargindata
173  [style=\tttf,
174   color=color-3]
175
176\starttexdefinition unexpanded ShowFile #1
177    \margintext
178        {\cldcontext{string.match("#1","\letterpercent d+")}}
179    \typefile
180        [range={environment}]
181        {#1}
182\stoptexdefinition
183
184% \typefile[range=4]  {...}
185% \typefile[range={=}]{...} % start after comment lines
186
187\starttexdefinition unexpanded ShowEnvironmentFile #1
188    \margintext
189        {\cldcontext{string.match("#1","\letterpercent d+")}}
190    \typefile
191        [range={=startenvironment}]
192        {#1}
193\stoptexdefinition
194
195\startdocument
196
197\startMPpage
198StartPage ;
199    path p ; numeric w, h, d ; picture q ;
200    if true :
201        q := image(draw textext.urt("\ssbf COLUMNS") withcolor \MPcolor{color-6}) ;
202    else :
203        q := image(draw textext.urt("\ssbf COLUMNSETS") withcolor \MPcolor{color-6}) ;
204    fi ;
205    w := bbwidth(Page) ;
206    h := bbheight(Page) ;
207    d := h/100 ;
208    fill Page withcolor \MPcolor{color-1} ;
209    p := Page xysized (w,d) ;
210    for i := 5d step 2d until h-5d :
211        fill p shifted (0,i) withcolor \MPcolor{color-2} ;
212    endfor
213    p := Page xysized(w/10,h) ;
214    for i = 0, .3, .6, .9 :
215        fill p shifted (i*w,0) withcolor \MPcolor{color-1} withtransparency(1,.75) ;
216    endfor ;
217    def do_it(expr sz, sh) =
218        p := Page xysized sz ;
219        fill p shifted sh withcolor \MPcolor{color-3} withtransparency(1,.5) ;
220        draw q xysized (bbwidth(p),bbheight(p)) shifted sh ;
221    enddef ;
222    do_it ((2w/10,17d),(.1w,20d)) ;
223    do_it ((2w/10,15d),(.1w,56d)) ;
224    do_it ((2w/10,21d),(.4w,66d)) ;
225    do_it ((2w/10,13d),(.7w,38d)) ;
226    do_it ((5w/10,13d),(.4w,13d)) ;
227    draw textext.urt("\ssbf Hans Hagen")
228        xysized (5w/10,5d)
229        shifted (.4w,6d)
230        withcolor \MPcolor{color-5} ;
231StopPage ;
232\stopMPpage
233
234\page[empty] \setuppagenumber[number=1]
235
236\setupbackgrounds
237  [page]
238  [background=page]
239
240\starttitle[title=Contents]
241
242    \placelist[chapter]
243
244\stoptitle
245
246\startchapter[title=Introduction]
247
248This manual introduces {\em column sets}, one of the output routines of \CONTEXT.
249Although column sets are mainly meant for typesetting journals in a
250semi||automated way, you can also use them for books. We assume that the user is
251familiar with \CONTEXT\ and only discuss the commands that are related to column
252sets.
253
254This mechanism performs okay but it needs to be used with care: an occasional
255manual intervention is needed to get optimal results. After all, we're operating
256in the area where normally click and point desktop publishing is used.
257
258{\bf For the moment you need to load the new code with: \type{\usemodule[newcolumnsets]}}
259
260\startlines
261Hans Hagen
262PRAGMA ADE
263Hasselt, 2003\endash2016
264\stoplines
265
266\stopchapter
267
268\startchapter[title=Basics]
269
270As soon as enough content is collected to build a page, \TEX\ will invoke the
271output routine. This is not a fixed piece of code, but a collection of macro
272calls. The default output routine is a meant for typesetting a single column, as
273in this document. A multi||column output routine is available as well. This
274routine mixes well with the single column one, and is activated by:
275
276\starttyping
277\startcolumns
278some text ...
279\stopcolumns
280\stoptyping
281
282In \MKIV\ a new mixed column mechanism has been introduced that will be
283developped further and eventually replace the old multi column handler. In \MKII\
284there is also a columnset mechanism that can be used to construct complex multi
285column pages. In \MKIV\ this gets replaced by grid columns. All these multi
286column mechanisms have in common that the output routine is more complex because
287now a page is in fact a collection of pages wrapped onto one. Each column is
288(from \TEX's perspective) similar to a one narrow column page. Here we focus on
289columnsets (page grids).
290
291There are some limitations to what you can do with this kind of multi columns,
292which is why we have a third routine at out disposal: {\em column sets}. This
293routine can be used for rather complex layouts with graphics all over the place,
294and text spanning columns or even spreads. There are of course some shortcomings,
295which we will discuss later.
296
297In the examples that follow we use the following style to set up the layout. The
298number in the margin serves a reference to the file where this snippet of \TEX\
299is stored.
300
301\ShowEnvironmentFile{columnsets-000}
302
303\page[mine]
304
305Before we will demonstrate more complex layouts, we will introduce a few
306features. In the next series of examples we use fake text. You can enlarge the
307pages in your viewer if you want to see more detail.
308
309\FourSpread{columnsets-001}
310
311These pages were typeset with the following code:
312
313\ShowFile{columnsets-001}
314
315We will showmost examples on a spread, so we don't show a first page. On a
316spread like above we number columns from~1 to~4, which in practice means that in
317this case columns starting on right page start with column~3!
318
319\SixPages{columnsets-001}
320
321\page[mine]
322
323The number of columns is not fixed to two. You can even have a different number
324of columns on left and right pages.
325
326\FourSpread{columnsets-002}
327
328This time the input is:
329
330\ShowFile{columnsets-002}
331
332Again, we started on a right page but showed the spreads. You can see it from the
333positioning of the header texts.
334
335\SixPages{columnsets-002}
336
337\page[mine]
338
339In order to get the balancing you want, you can manually influence the height of
340a column.
341
342\FourSpread{columnsets-003}
343
344When you set the number of column lines to a positive value, that will be the
345number of lines. A negative value will be subtracted from the maximum number of
346lines.
347
348\ShowFile{columnsets-003}
349
350\page[mine]
351
352In articles you may want to let the introduction span multiple columns. A column
353span is defined independent of a column set and shows up as follows:
354
355\FourSpread{columnsets-004}
356
357Here we've given the span a background so that it stands out.
358
359\ShowFile{columnsets-004}
360
361\page[mine]
362
363A column span can be positioned like any graphic. Later we will discuss the
364placement options in more detail, for the moment all you need to know is that
365\type {btlr} tells \CONTEXT\ to place the graphic in the left bottom of the the
366text area.
367
368\FourSpread{columnsets-005}
369
370Here we pass the \type {default} placement as parameter to the span, but you can
371also set it at definition time. We use a brute force simple column splitter to
372fake columns inside the span.
373
374\ShowFile{columnsets-005}
375
376\page[mine]
377
378You are not limited to one column span. In this sense a span is like a graphic:
379as long as there is room, it will be placed where you want it to be placed. The
380main difference between a span and a graphic is that a span expects text and
381tries to align the baselines with the rest of the text. In many ways a column
382span behaves like a framed text.
383
384\FourSpread{columnsets-006}
385
386This time we flushed one of the spans from bottom to top, starting at the right
387edge: \type {btrl}.
388
389\ShowFile{columnsets-006}
390
391\page[mine]
392
393Column spans are treated like graphics, which means that they will float if
394needed. In the process, the width is limited to the available space, which in
395some cases may lead to a smaller span than you may expect. Think of a column
396span, calculated (and prepared) in the last column and ending up on the next page
397in the first column, where a broader span would have been possible.
398
399\FourSpread{columnsets-007}
400
401\ShowFile{columnsets-007}
402
403\stopchapter
404
405\startchapter[title=Graphics]
406
407Most documents have graphics, and therefore column sets can contain them. The
408main thing that you have to keep in mind when placing graphics, is that column
409sets are based on grids. Therefore spacing around graphics is also grid based.
410
411\FourSpread{columnsets-101}
412
413\ShowFile{columnsets-101}
414
415\page[mine]
416
417You can tell \CONTEXT\ where it should place the graphic, but this will only be
418honored when there is still place.
419
420\EightSpread{columnsets-102}
421
422The prefered location is passed as a four character directive:
423
424\ShowFile{columnsets-102}
425
426\page[mine]
427
428The following directives are available:
429
430\starttabulate[|lT|p|]
431\NC btlr     \NC flush from bottom to top    and left to right  \NC \NR
432\NC btrl     \NC flush from bottom to top    and right to left  \NC \NR
433\NC tblr     \NC flush from top    to bottom and left to right  \NC \NR
434\NC tbrl     \NC flush from top    to bottom and right to left  \NC \NR
435\NC lrbt     \NC flush from left   to right  and bottom to top  \NC \NR
436\NC lrtb     \NC flush from left   to right  and top to bottom  \NC \NR
437\NC rlbt     \NC flush from right  to left   and bottom to top  \NC \NR
438\NC rltb     \NC flush from right  to left   and top to bottom  \NC \NR
439\NC here     \NC try to place the graphic here                  \NC \NR
440\NC fixd     \NC force the graphic here and don't float         \NC \NR
441\NC fxtb:c*r \NC place the graphic at (c,r) or lower if needed  \NC \NR
442\NC fxbt:c*r \NC place the graphic at (c,r) or higher if needed \NC \NR
443\NC tops     \NC place the graphic at the top of the page       \NC \NR
444\NC bots     \NC place the graphic at the bottom of the page    \NC \NR
445\NC page     \NC place the graphic at a separate page           \NC \NR
446\stoptabulate
447
448In the next example we show the directional locations:
449
450\OneSpread{columnsets-103}
451
452\ShowFile{columnsets-103}
453
454\stopchapter
455
456\startchapter[title=Areas]
457
458So far we have seen texts and graphics that span multiple columns using span
459commands and floats placement commands. We have also seen that you can define a
460different number of columns for left and right pages. Now that we have arrives at
461column areas you will see how we can span information over not only a page but
462also over pages in a spread.
463
464\FourSpread{columnsets-201}
465
466Being a framed text, by default an area is aligned at the baseline. You can lower
467an area by setting the \type {location} to \type {depth}.
468
469\ShowFile{columnsets-201}
470
471\page[mine]
472
473You can position areas on the left, right or next page or on both pages. When you
474set \type {state} to \type {repeat}, an area is repeated, otherwise it is only
475placed once.
476
477\FourSpread{columnsets-202}
478
479Here we just repeat the areas. Normally this only make sense when the content is
480worth repeating.
481
482\ShowFile{columnsets-202}
483
484\page[mine]
485
486Areas can span a spread, as is demonstrated in the next example.
487
488\FourSpread{columnsets-203}
489
490\ShowFile{columnsets-203}
491
492\page[mine]
493
494An application of a spread area is a title. In the next example we show two
495spread pages.
496
497\FourSpread{columnsets-204}
498
499Watch how we explicitly go to a left page.
500
501\ShowFile{columnsets-204}
502
503\page[mine]
504
505The \type {\GapText} macro is an experimental fun macro and is used to make sure
506that we don't end up with a clipped character.
507
508\startlinecorrection[blank]
509\startcombination
510  {\scale[width=.4\textwidth]{\clip
511     [nx=2,ny=6,x=2,y=2]
512     {\typesetfile[columnsets-204.tex][page=2]}}}
513  {left page}
514  {\scale[width=.4\textwidth]{\clip
515     [nx=2,ny=6,x=1,y=2]
516     {\typesetfile[columnsets-204.tex][page=3]}}}
517  {right page}
518\stopcombination
519\stoplinecorrection
520
521This is a typical example of the kind of optimizations that are needed when you
522make documents of styles with text that spans a spread. In the next clip we
523visualize the gap.
524
525\startlinecorrection[blank]
526\startcombination
527  {\scale[width=.4\textwidth]{\clip
528     [nx=2,ny=6,x=2,y=2]
529     {\typesetfile[columnsets-205.tex][page=2]}}}
530  {left page}
531  {\scale[width=.4\textwidth]{\clip
532     [nx=2,ny=6,x=1,y=2]
533     {\typesetfile[columnsets-205.tex][page=3]}}}
534  {right page}
535\stopcombination
536\stoplinecorrection
537
538At some moment you may want to set up an area in advance as we have done in the
539following example.
540
541\FourSpread{columnsets-206}
542
543The \type {page} key is used to specify the page in the column set that the area
544should go into. Column set pages start numbering at~1. The \type {fixed} stands
545for left or right, whatever comes first.
546
547\ShowFile{columnsets-206}
548
549\stopchapter
550
551\startchapter[title=Columns]
552
553You can use \type {\page} to go to a new page in a column set. Likewise you can
554use \type {\column} to force a column break.
555
556\FourPages{columnsets-301}
557
558This example demonstrates that you can supply \type {\column} with explicit
559directives.
560
561\ShowFile{columnsets-301}
562
563You can use \type {\column[page]} as an alternative for \type {\page}.
564
565\stopchapter
566
567\startchapter[title=Details]
568
569This chapter will cover a couple of cosmetic details of column sets. {\em Some
570features need to be improved, especially in combination with areas, graphics and
571alike. We will also provide side floats etc.}
572
573\FourSpread{columnsets-401}
574
575You can set the distance between columns for each pair of columns. {\em Todo:
576left and right page distances and margins.}
577
578\ShowFile{columnsets-401}
579
580\page[mine]
581
582When you can the distance of the first column as well. This creates a margin.
583
584\FourSpread{columnsets-402}
585
586This time we used equal distances:
587
588\ShowFile{columnsets-402}
589
590\page[mine]
591
592The width of columns is normally calculated automatically, but you can also set
593the width explicitly:
594
595\FourSpread{columnsets-403}
596
597In code:
598
599\ShowFile{columnsets-403}
600
601\page[mine]
602
603For special effects, you can set the width per column. In that case you need to
604be aware of the fact that \TEX\ works its way through the document per paragraph.
605Changing the width halfway a paragraph is possible but will affect the whole
606paragraph. Therefore, this feature works best when you also goto the next column
607explicitly.
608
609\FourSpread{columnsets-404}
610
611In code:
612
613\ShowFile{columnsets-404}
614
615\page[mine]
616
617If you really want to change the width in the middle of a paragraph, you can do a
618trial run and include a breakpoint at the palce where you want it to occur:
619
620\FourSpread{columnsets-405}
621
622In the second spread you see how the narrow hsize carries on in the wider
623column. A \type {\column} command will synchronize the hsize.
624
625\ShowFile{columnsets-405}
626
627% \page[mine]
628
629\stopchapter
630
631\startchapter[title=Directions]
632
633\FourSpread{columnsets-601}
634
635The direction of flushing columns is determined by the \type {direction}
636parameters as demonstrated below.
637
638\ShowFile{columnsets-601}
639
640% \page[mine]
641
642\stopchapter
643
644\startchapter[title=Backgrounds]
645
646As with many \CONTEXT\ components, column sets can have backgrounds.
647
648\FourSpread{columnsets-701}
649
650Watch how we use the \type {each} keyword to tell \CONTEXT\ that we want to apply
651the background to each column of the set.
652
653\ShowFile{columnsets-701}
654
655\page[mine]
656
657Normally, if you apply backgrounds this way, you will also set the background
658offset. In a similar fashion you can apply backgrounds to areas and spans. Such
659backgrounds can be a color, or any overlay or layer you want.
660
661\FourSpread{columnsets-702}
662
663Here we've set the background offset as well as the frame.
664
665\ShowFile{columnsets-702}
666
667\page[mine]
668
669When dealing with areas, you need to be aware of the fact that they are clipped,
670the content as well as the background.
671
672\FourSpread{columnsets-703}
673
674De default clip offset is two times the lineheight, except in the binding, where
675it is set to zero points. You can set the clip offset with the \type {clipoffset}
676parameter.
677
678\ShowFile{columnsets-703}
679
680\page[mine]
681
682The text background mechanism is rather well adapted to column sets. The
683following example is a variant on an example shown in the manual titled
684{details}.
685
686\EightSpread{columnsets-704}
687
688Watch how we adapt the background to the fact and extent that the text spans one
689or more columns.
690
691\ShowFile{columnsets-704}
692
693Backgrounds that follow the paragraph shape also work ok in column sets.
694
695{\em todo: an example of a bleeding graphic with column feed back (from
696techniek)}
697
698% \page[mine]
699
700\stopchapter
701
702\startchapter[title=Numbering lines]
703
704\FourSpread{columnsets-901}
705
706This example shows how numbering lines in columns works out. In a two column
707layout the numbers end up in the outer margins by default. If you want you can
708set the \type {location} to for instance \type {left} or \type {right}.
709
710\ShowFile{columnsets-901}
711
712\page[mine]
713
714\FourSpread{columnsets-902}
715
716In a three column setup the numbers end up in the left margins.Make sure you make
717the distance large enough.
718
719\ShowFile{columnsets-902}
720
721% \page[mine]
722%
723% \FourSpread{columnsets-903}
724%
725% This example shows again lune numbers but here we made sure that there is no
726% stretch in the whitespace.
727%
728% \ShowFile{columnsets-903}
729
730\stopchapter
731
732% \startchapter[title=Spanning and More]
733%
734% {\em todo: explanation} \page
735%
736% \TwoPages{columnsets-801} \ShowFile{columnsets-801} \page[mine]
737% \TwoPages{columnsets-802} \ShowFile{columnsets-802} \page[mine]
738% \TwoPages{columnsets-803} \ShowFile{columnsets-803} \page[mine]
739% \TwoPages{columnsets-804} \ShowFile{columnsets-804} \page[mine]
740% \TwoPages{columnsets-805} \ShowFile{columnsets-805} \page[mine]
741% \TwoPages{columnsets-806} \ShowFile{columnsets-806} \page[mine]
742%
743% \stopchapter
744
745\stopdocument
746