summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/context/manuals/reference/en/co-colors.tex
blob: 42502d167ba2ecd03344d216fa8d4816f25e66aa (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
\startcomponent co-colors

\environment contextref-env
\product contextref

\startbuffer[colo-1]
\setupblackrules[width=.25\hsize,height=2ex,depth=0cm]
\setupcombinations[inbetween=]
\startcombination[3*7]
  {\color[red]           {\blackrule}} {\translate[en=red,          nl=rood]}
  {\color[green]         {\blackrule}} {\translate[en=green,        nl=groen]}
  {\color[blue]          {\blackrule}} {\translate[en=blue,         nl=blauw]}
  {\color[middlered]     {\blackrule}} {\translate[en=middlered,    nl=middenrood]}
  {\color[middlegreen]   {\blackrule}} {\translate[en=middlegreen,  nl=middengroen]}
  {\color[middleblue]    {\blackrule}} {\translate[en=middleblue,   nl=middenblauw]}
  {\color[darkred]       {\blackrule}} {\translate[en=darkred,      nl=donkerrood]}
  {\color[darkgreen]     {\blackrule}} {\translate[en=darkgreen,    nl=donkergroen]}
  {\color[darkblue]      {\blackrule}} {\translate[en=darkblue,     nl=donkerblauw]}
  {\color[yellow]        {\blackrule}} {\translate[en=yellow,       nl=geel]}
  {\color[magenta]       {\blackrule}} {\translate[en=magenta,      nl=magenta]}
  {\color[cyan]          {\blackrule}} {\translate[en=cyan,         nl=cyaan]}
  {\color[middleyellow]  {\blackrule}} {\translate[en=middleyellow, nl=middelgeel]}
  {\color[middlemagenta] {\blackrule}} {\translate[en=middlemagenta,nl=middelmagenta]}
  {\color[middlecyan]    {\blackrule}} {\translate[en=middlecyan,   nl=middelcyaan]}
  {\color[darkyellow]    {\blackrule}} {\translate[en=darkyellow,   nl=donkergeel]}
  {\color[darkmagenta]   {\blackrule}} {\translate[en=darkmagenta,  nl=donkermagenta]}
  {\color[darkcyan]      {\blackrule}} {\translate[en=darkcyan,     nl=donkercyaan]}
  {\color[lightgray]     {\blackrule}} {\translate[en=lightgray,    nl=lichtgrijs]}
  {\color[darkgray]      {\blackrule}} {\translate[en=darkergray,   nl=donkergrijs]}
  {\color[black]         {\blackrule}} {\translate[en=black,        nl=zwart]}
\stopcombination
\stopbuffer

\startbuffer[colo-2]
\setupblackrules[width=.25\hsize,height=\ht\strutbox,depth=\dp\strutbox]
\startcombination[3*2]
  {\color    [cyaan:x]{\blackrule}} {\colorvalue{cyaan:x}}
  {\color    [cyaan:y]{\blackrule}} {\colorvalue{cyaan:y}}
  {\color    [cyaan:z]{\blackrule}} {\colorvalue{cyaan:z}}
  {\graycolor[cyaan:x]{\blackrule}} {\grayvalue {cyaan:x}}
  {\graycolor[cyaan:y]{\blackrule}} {\grayvalue {cyaan:y}}
  {\graycolor[cyaan:z]{\blackrule}} {\grayvalue {cyaan:z}}
\stopcombination
\stopbuffer

\startbuffer[colo-3]
\offinterlineskip
\halign
  {\hss#\cr
   \showcolorgroup[red]    [horizontal,name,number]\cr
   \showcolorgroup[green]  [horizontal,name]\cr
   \showcolorgroup[blue]   [horizontal,name]\cr
   \showcolorgroup[yellow] [horizontal,name]\cr
   \showcolorgroup[magenta][horizontal,name]\cr
   \showcolorgroup[cyan]   [horizontal,name]\cr}
\stopbuffer

\startbuffer[colo-4]
\hbox
  {\showcolorgroup[red]     [vertical,name,number]%
   \showcolorgroup[green]   [vertical,name]%
   \showcolorgroup[blue]    [vertical,name]%
   \showcolorgroup[yellow]  [vertical,name]%
   \showcolorgroup[magenta] [vertical,name]%
   \showcolorgroup[cyan]    [vertical,name]}
\stopbuffer

\startbuffer[colo-5]
\vbox
  {\forgetall
   \ttx
   \def\y{screen}
   \def\n{}
   \offinterlineskip
   \def\rijtjenamen#1#2#3#4#5#6#7#8
     {\hbox
        {\framed[width=4em,frame=off]{#1}%
         \hskip.25em
         \framed[background=#3,backgroundscreen=.9]{#2{leftedge}}%
         \hskip.25em
         \framed[background=#4,backgroundscreen=.9]{#2{leftmargin}}%
         \hskip.25em
         \framed[background=#5,backgroundscreen=#8]{#2{text}}%
         \hskip.25em
         \framed[background=#6,backgroundscreen=.9]{#2{rightmargin}}%
         \hskip.25em
         \framed[background=#7,backgroundscreen=.9]{#2{rightedge}}}}%
   \setupframed[width=6.5em]
   \bgroup
   \setupframed[frame=off]
   \rijtjenamen{}\hbox \n\n\n\n\n .9
   \egroup
   \vskip.125em
   \rijtjenamen{top}\hphantom \n\n\n\n\n .9
   \vskip.25em
   \rijtjenamen{header}\hphantom \n\y\y\y\n .9
   \vskip.25em
   \rijtjenamen{text}\hphantom \n\y\y\y\n .5
   \vskip.25em
   \rijtjenamen{footer} \hphantom \n\y\y\y\n .9
   \vskip.25em
   \rijtjenamen{bottom}\hphantom \n\n\n\n\n .9
   \vskip.25em}
\stopbuffer

\chapter[color]{Colors}

\section{Introduction}

Judicious use of color can enhance your document's layout.
For example. in interactive documents color can be used to
indicate hyperlinks or other aspects that have no meaning in
paper documents, or background colors can be used to
indicate screen areas that are used for specific information
components.

In this chapter we describe the \CONTEXT\ color support. We
will also pay attention to backgrounds and overlays because
these are related to the color mechanism.

\section[color]{Color}
\index{color}
\index[rgb]{\RGB}
\index[cmyk]{\CMYK}
\index{gray conversion}
\macro{\tex{definecolor}}
\macro{\tex{setupcolors}}
\macro{\tex{setupcolors}}
\macro{\tex{color}}
\macro{\tex{startcolor}}
\macro{\tex{showcolor}}

One of the problems in typesetting color is that different
colors may result in identical gray shades. We did some
research in the past on this subject and we will describe
the \CONTEXT\ facilities on this matter and the way
\CONTEXT\ forces us to use color consistently. Color should
not be used indiscriminately, therefore you first have to
activate the color mechanism:

\startexample
\starttyping
\setupcolors[state=start]
\stoptyping
\stopexample

Other color parameters are also available:

\showsetup{setupcolors}

The parameter \type {state} can also be set at \type {local}
or \type {global}. If you do not know whether the use of
color will cross a page boundary, then you should use \type
{global} or \type {start} to keep track of the color. We use
\type {local} in documents where color will never cross a
page border, as is the case in many screen documents. This
will also result in a higher processing speed. (For most
documents it does not hurt that much when one simply uses
\type {start}).

By default both the \RGB\ and \CMYK\ colorspaces are
supported. When the parameter \type {cmyk} is set at \type
{no}, then the \CMYK\ color specifications are automatically
converted to \RGB. The reverse is done when \type {rgb=no}.
When no color is allowed the colors are automatically
converted to weighted grayshades. You can set this conversion
with \type {conversion}. When set to \type {always}, all
colors are converted to gray, when set to \type {yes}, only
gray colors are converted.

Colors must be defined. For some default color spaces, this
is done in the file \type{colo-<<xxx>>.tex}. After
definition the colors can be recalled with their mnemonic
name \type {<<xxx>>}. By default the file \type {colo-rgb.tex} is
loaded. In this file we find definitions like:

\startexample
\starttyping
\definecolor [darkred]   [r=.5, g=.0, b=.0]
\definecolor [darkgreen] [r=.0, g=.5, b=.0]
............ ...........  ..................
\stoptyping
\stopexample

A file with color definitions is loaded with:

\startexample
\starttyping
\setupcolor[rgb]
\stoptyping
\stopexample

Be aware of the fact that there is also a command \type
{\setupcolors} that has a different meaning. The \type {rgb}
file is loaded by default.

Color must be activated like this:

\startexample
\starttyping
\startcolor[darkgreen]
We can use as many colors as we like. But we do have to take into
account that the reader is possibly \color [darkred] {colorblind}. The
use of color in the running text should always be carefully considered.
The reader easily tires while reading multi||color documents.
\stopcolor
\stoptyping
\stopexample

In the same way you can define \CMYK\ colors and grayshades:

\startexample
\starttyping
\definecolor [cyan] [c=1,m=0,y=0,k=0]
\definecolor [gray] [s=0.75]
\stoptyping
\stopexample

gray can also be defined like this:

\startexample
\starttyping
\definecolor [gray] [r=0.75,r=0.75,b=0.75]
\stoptyping
\stopexample

When the parameter \type {conversion} is set at \type {yes}
the color definitions are automatically downgraded to the
\type{s}||form: \type {[s=.75]}. The~\type {s} stands for
\quote {screen}. When \type {reduction} is \type {yes}, the
black component of a \CMYK\ color is distilled from the
other components.

One of the facillities of color definition is the heritage
mechanism:

\startbuffer
\definecolor [important] [red]
\stopbuffer

\getbuffer

\startexample
\typebuffer
\stopexample

These definitions enable you to use colors consistently.
Furthermore it is possible to give all \color [marked]
{important} issues a different color, and change colors
afterwards or even in the middle of a document.

So, next to \type {\setupcolors} we have the following
commands for defining colors:

\showsetup{definecolor}

A color definition file is loaded with:

\showsetup{setupcolor}

Typesetting color is done with:

\showsetup{color}

\showsetup{startcolor}

A complete palette of colors is generated with:

\showsetup{showcolor}

\in{Figure}[fig:some colors] shows the colors that are
standard available (see \type {colo-rgb.tex}).

\placefigure
  [][fig:some colors]
  {Some examples of colors.}
  {\getbuffer[colo-1]}

\startcolor[darkgreen] The use of color in \TEX\ is not
trivial. \TEX\ itself has no color support. Currently color
support is implemented using \TEX's low level \type
{\mark}'s and \type {\special}'s. This means that there are
some limitations, but in most cases these go unnoticed.

It is possible to cross page boundaries with colors. The
headers and footers and the floating figures or tables will
stil be set in the correct colors. However, the mechanism is
not robust.

In this sentence we use colors within colors. Aesthetically
this is bad.

As soon as a color is defined it is also available as a
command. So there is a command \type {\darkred}. These
commands do obey grouping. So we can say {\darkred \type
{{\darkred this is typeset in dark red}}}.

\stopcolor

There are a number of commands that have the parameter \type
{color}. In general, when a \type {style} can be set, \type
{color} can also be set.

The default color setup is:

\starttyping
\setupcolors [conversion=yes, reduction=no, rgb=yes, cmyk=yes]
\stoptyping

This means that both colorspaces are supported and that the
$k$||component in \CMYK\ colors is maintained. When \type
{reduction=yes}, the $k$||component is \quote {reduced}. With
\type{conversion=no} equal color components are converted to
gray shades.

\section[gray]{Grayscales}
\index{grayscales}
\macro{\tex{graycolor}}
\macro{\tex{grayvalue}}
\macro{\tex{colorvalue}}

When we print a document on a black and white printer we
observe that the differences between somes colors are gone.
\in{Figure}[fig:cyan] illustrates this effect.

\placefigure
  [][fig:cyan]
  {Three cyan variations with equal gray shades.}
  {\getbuffer[colo-2]}

In a black and white print all blocks look the same but
the three upper blocks have different cyan based colors. The
lower blocks simulate grayshades. We use the following
conversion formula:

\placeformula[-]
\startformula
\rm gray = .30 \times red   +
           .59 \times green +
           .11 \times blue
\stopformula

A color can be displayed in gray with the command:

\showsetup{graycolor}

The actual values of a color can be recalled by the commands
\type{\colorvalue{<<name>>}} and
\type{\grayvalue{<<name>>}}.

We can automatically convert all used colors in weighted
grayshades.

\starttyping
\setupcolors [conversion=always]
\stoptyping

\section[colorgroups,palettes]{Colorgroups and palettes}
\index{colorgroups}
\index{palettes}
\macro{\tex{definepalet}}
\macro{\tex{definecolorgroup}}
\macro{\tex{setuppalet}}
\macro{\tex{showpalet}}
\macro{\tex{showcolorgroup}}
\macro{\tex{comparepalet}}
\macro{\tex{comparecolorgroup}}

\TEX\ itself has hardly any built||in graphical features.
However the \CONTEXT\ color mechanism is designed by looking
at the way colors in pictures are used. One of the problems
is the effect we described in the last section. On a color
printer the picure may look fine, but in black and white
the results may be disappointing.

In \TEX\ we can aproach this problem systematically.
Therefore we designed a color mechanism that can be compared
with that in graphical packages.

We differentiate between individual colors and colorgroups.
A colorgroup contains a number of gradations of a color.
By default the following colorgroups are defined.

\placefigure{none}{\getbuffer[colo-3]}

The different gradations within a colorgroup are represented
by a number. A colorgroup is defined with:

\showsetup{definecolorgroup}

An example of a part of the \RGB\ definition is:

\startexample
\starttyping
\definecolorgroup
  [blue][rgb]
  [1.00:1.00:1.00,
   0.90:0.90:1.00,
   ..............,
   0.40:0.40:1.00,
   0.30:0.30:1.00]
\stoptyping
\stopexample

The \type {[rgb]} is not mandatory in this case, because
\CONTEXT\ expects \RGB\ anyway. This command can be viewed
as a range of color definitions.

\startexample
\starttyping
\definecolor [blue:1] [r=1.00, g=1.00, b=1.00]
\definecolor [blue:2] [r=0.90, g=0.90, b=1.00]
..............
\definecolor [blue:7] [r=0.40, g=0.40, b=1.00]
\definecolor [blue:8] [r=0.30, g=0.30, b=1.00]
\stoptyping
\stopexample

A color within a colorgroup can be recalled with
\type{<<name>>:<<number>>}, for example: \type{blue:4}.

There is no maximum to the number of gradations within a
colorgroup, but on the bases of some experiments we advise
you to stay within 6~to 8~gradations. We can explain this.
Next to colorgroups we have palettes. A pallet consists of a
limited number of {\em logical} colors. Logical means that
we indicate a color with a name. An example of a palette is:

\placefigure[force][]{none}
  {\showpalet[alfa][horizontal,name,number]}

The idea behind palettes is that we have to avoid colors
that are indistinguishable in black and white print. A
palette is defined by:

\startexample
\starttyping
\definepalet
  [example]
  [strange=red:3,
       top=green:1,
        .....
    bottom=yellow:8]
\stoptyping
\stopexample

We define a palette with the command:

\showsetup{definepalet}

\CONTEXT\ contains a number of predefined palettes. Within a
palette we use the somewhat abstract names of quarks: {\em
top}, {\em bottom}, {\em up}, {\em down}, {\em strange} and
{\em charm}. There is also {\em friend} and {\em rude}
because we ran out of names. Be aware of the fact that these
are just examples in the \RGB\ definition file and based on
our own experiments. Any name is permitted.

The system of colorgroups and palettes is based on the idea
that we compose a palette from the elements of a colorgroup
with different numbers. Therefore the prerequisite is that
equal numbers should have an equal grayshade.

\placefigure[force][]{none}{\getbuffer[colo-4]}

When a palette is composed we can use the command:

\showsetup{setuppalet}

After that we can use the colors of the chosen palette. The
logical name can be used in for example \type
{\color[strange]{is this not strange}}.

An example of the use of palettes is shown in the verbatim
typesetting of \TEX\ code. Within this mechanism colors
with names like \type {prettyone}, \type {prettytwo}, etc.
are used. There are two palettes, one for color and one for
gray:

\startexample
\starttyping
\definecolor [colorprettyone] [r=.9, g=.0, b=.0]
\definecolor [grayprettyone]  [s=.3]
\stoptyping
\stopexample

These palettes are combined into one with:

\startexample
\starttyping
\definepalet
  [colorpretty]
  [  prettyone=colorprettyone,    prettytwo=colorprettytwo,
   prettythree=colorprettythree, prettyfour=colorprettyfour]

\definepalet
  [graypretty]
  [  prettyone=grayprettyone,     prettytwo=grayprettytwo,
   prettythree=grayprettythree,  prettyfour=grayprettyfour]
\stoptyping
\stopexample

Now we can change all colors by resetting the palette with:

\startexample
\starttyping
\setuptyping[palet=colorpretty]
\stoptyping
\stopexample

Each filter can be set differently:

\startexample
\starttyping
\definepalet [MPcolorpretty] [colorpretty]
\definepalet [MPgraypretty]  [graypretty]
\stoptyping
\stopexample

As you can see a palette can inherit its properties from
another palette. This example shows something of the color
philosophy in \CONTEXT: you can treat colors as abstractions
and group them into palettes and change these when
necessary.

On behalf of the composition of colorgroups and palettes
there are some commands available to test whether the colors
are distinguishable.

\showsetup{showcolorgroup}

\showsetup{showpalet}

\showsetup{comparecolorgroup}

\showsetup{comparepalet}

The overviews we have shown thusfar are generated by the
first two commands and the gray values are placed below the
baseline. On the left there are the colors of the grayshades.

\placefigure[force][]{none}{\comparecolorgroup[green]}

This overview is made with \type {\comparecolorgroup[green]}
and the one below with \type {\comparepalet[gamma]}.

\placefigure[force][]{none}{\comparepalet[gamma]}

The standard colorgroups and palettes are composed very
carefully and used systematically for coloring pictures.
These can be displayed adequately in color and black and
white.

\placefigure
  {Some examples of the use of color.}
  \startcombination[4*1]
    {\externalfigure[vew1179]} {}
    {\externalfigure[vew1182]} {}
    {\externalfigure[vew1218]} {}
    {\externalfigure[spin016]} {}
  \stopcombination

\stopcomponent