summaryrefslogtreecommitdiff
path: root/tex/context/base/colo-ini.tex
blob: bb896e0fad4e5ede15191e6e1c8e5fa27e6151ec (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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
%D \module
%D   [       file=colo-ini,
%D        version=1997.4.1,
%D          title=\CONTEXT\ Color Macros,
%D       subtitle=Initialization,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for 
%C details. 

\writestatus{loading}{Context Color Macros}

%D To do: stroke versus fill color 

\unprotect

%D Color support is not present in \TEX. Colorful output can 
%D however be accomplished by using specials. This also means 
%D that this support depends on the \DVI\ driver used. At the 
%D moment this module was written, still no decent standard on 
%D color specials has been agreed upon. We therefore decided to 
%D implement a mechanism that is as independant as possible of 
%D drivers. 
%D 
%D Color support shares with fonts that is must be implemented
%D in a way that permits processing of individual \DVI\ pages.
%D Furthermore it should honour grouping. The first condition
%D forces us to use a scheme that keeps track of colors at
%D page boundaries. This can be done by means of \TEX's
%D marking mechanism (\type{\mark}). 
%D 
%D When building pages, \TEX\ periodically looks at the
%D accumulated typeset contents and breaks the page when
%D suitable. At that moment, control is transfered to the
%D output routine. This routine takes care of building the
%D pagebody and for instance adds headers and footers. The page
%D can be broken in the middle of some colored text, but
%D headers and footers are often in black upon white or
%D background. If colors are applied there, they definitely
%D are used local, which means that they don't cross page
%D borders. 
%D 
%D Boxes are handled as a whole, which means that when we 
%D apply colors inside a box, those colors don't cross page 
%D boundaries, unless of course boxes are split or unboxed. 
%D Especially in interactive texts, colors are often used in 
%D such a local way: in boxes (buttons and navigational tools) 
%D or in the pagebody (backgrounds). 
%D 
%D So we can distinguish local colors, that don't cross
%D pages from global colors, of which we can end many pages 
%D later. The color macros will treat both types in a different 
%D way, thus gaining some speed.   
%D 
%D This module also deals with gray scales. Because similar
%D colors can end up in the same gray scale when printed in
%D black and white, we also implement a palet system that deals
%D with these matters. Because of fundamental differences
%D between color and gray scale printing, in \CONTEXT\ we also
%D differ between these. For historic reasons |<|we first
%D implemented gray scales using patterns of tiny periods|>| 
%D and therefore called them {\em rasters}. So don't be 
%D surprised if this term shows up.

\startmessages  dutch  library: colors
  title: kleur
      1: systeem -- is globaal actief
      2: systeem -- is lokaal actief
      3: -- is niet gedefinieerd
      4: systeem -- wordt geladen
      5: onbekend systeem --
      6: palet -- is beschikbaar
      7: palet -- is niet beschikbaar
      8: specificatie -- bij -- wordt zwart
      9: -- kleurruimte wordt niet ondersteund
     10: -- kleurruimte wordt ondersteund
     11: kleur wordt vertaald in grijs
\stopmessages

\startmessages  english  library: colors
  title: color
      1: system -- is global activated 
      2: system -- is local activated 
      3: -- is not defined
      4: system -- is loaded
      5: unknown system --
      6: palette -- is available
      7: palette -- is not available 
      8: specification -- at color -- becomes black
      9: -- color space is not supported 
     10: -- color space is supported 
     11: color is converted to gray
\stopmessages

\startmessages  german  library: colors
  title: farbe
      1: system -- ist global aktiviert
      2: system -- ist lokal aktiviert
      3: -- ist undefiniert
      4: system -- ist geladen
      5: unbekanntes System --
      6: palette -- ist verfuegbar
      7: palette -- ist nicht verfuegbar
      8: Spezifikation -- bei Farbe -- wird schwarz
      9: -- Farbraum wird nicht unterstuetzt
     10: -- Farbraum wird unterstuetzt 
     11: Farbe wird in Grau umgewandelt
\stopmessages

\startmessages  czech  library: colors
  title: barva
      1: system -- je globalne aktivovana
      2: system -- je lokalne activovana
      3: -- neni definovana
      4: system -- je nacten
      5: neznamy system --
      6: palette -- je k dispozici
      7: palette -- neni k dispozici
      8: specifikace -- v barve -- bude cerna
      9: -- prostor barev neni podporovan
     10: -- prostor barev je podporovan
     11: barva je prevedena na sed
\stopmessages

\startmessages  italian  library: colors
  title: colore
      1: sistema -- attivato globalmente
      2: sistema -- attivato localmente
      3: -- non definito
      4: sistema -- caricato
      5: sistema -- sconosciuto 
      6: tavolozza -- resa disponibile
      7: tavolozza -- non disponibile
      8: specifica -- del colore -- convertita in nero
      9: spazio dei colori -- non supportato
     10: spazio dei colori -- supportato
     11: il colore è convertito in grigio
\stopmessages

\startmessages  norwegian  library: colors
  title: farge
      1: system -- er aktivert globalt
      2: system -- er aktivert lokalt
      3: -- er udefinert
      4: system -- er lest inn 
      5: ukjent system --
      6: palett -- er tilgjengelig
      7: palett -- er ikke tilgjengelig
      8: spesifikasjon -- for farge -- gir kun svart
      9: -- fargerom er ikke støttet
     10: -- fargerom er støttet 
     11: fargen vil bli vist som grå
\stopmessages

\startmessages  romanian  library: colors
  title: culori
      1: sistem -- este activata global 
      2: sistem -- este activata local
      3: -- nu este definita
      4: sistem -- este incarcata
      5: sistem -- necunoscuta
      6: paleta -- este disponibila
      7: palette -- nu este disponibila 
      8: specificatia -- la culoarea -- devine neagra
      9: spatiul de culoare -- nu este suportat
     10: spatiul de culoare -- este suportat 
     11: culoarea este convertita la gri
\stopmessages

%D \macros
%D   {definecolor}
%D
%D We will enable users to specify colors in \kap{RGB} and 
%D \kap{CMYK} color spaces or gray scales using 
%D
%D \showsetup{\y!definecolor}
%D
%D For example:
%D
%D \starttypen
%D \definecolor [SomeKindOfRed] [r=.8,g=.05,b=.05]
%D \stoptypen
%D 
%D Such color specifications are saved in a macro in the 
%D following way:
%D 
%D \starttypen 
%D \setvalue{\??cr name}{R:r:g:b}
%D \setvalue{\??cr name}{C:c:m:y:k}
%D \setvalue{\??cr name}{S:s}
%D \stoptypen
%D
%D Gray scales are specified with the \type{s} parameter, 
%D where the is derived from screen.

\def\colorlist{}

\def\@@cl@@z{0} 
\def\@@cl@@o{1} 

\def\definecolor%
  {\dodoubleargument\dodefinecolor}

\def\dodefinecolor[#1][#2]%
  {% beware
\saveglobal % ? \dodoglobal  
     \addtocommalist{#1}\colorlist
\restoreglobal
   \doifassignmentelse{#2}
     {\let\@@cl@@r=\@@cl@@z\let\@@cl@@g=\@@cl@@z\let\@@cl@@b=\@@cl@@z
      \let\@@cl@@c=\@@cl@@z\let\@@cl@@m=\@@cl@@z\let\@@cl@@y=\@@cl@@z
      \let\@@cl@@k=\@@cl@@z\let\@@cl@@s=\@@cl@@z
      \getparameters[\??cl @@][#2]%
      \doifelse{\@@cl@@r\@@cl@@g\@@cl@@b}{\@@cl@@z\@@cl@@z\@@cl@@z}
        {\doifelse{\@@cl@@c\@@cl@@m\@@cl@@y\@@cl@@k}{\@@cl@@z\@@cl@@z\@@cl@@z\@@cl@@z}
           {\doifelse{\@@cl@@s}{\@@cl@@z}
              {\showmessage{\m!colors}{8}{{[#2]},#1}%
               \redoglobal\setevalue{\??cr#1}{S:\@@cl@@z}}
              {\redoglobal\setevalue{\??cr#1}{S:\@@cl@@s}}}
           {\redoglobal\setevalue{\??cr#1}{C:\@@cl@@c:\@@cl@@m:\@@cl@@y:\@@cl@@k}}}
        {\redoglobal\setevalue{\??cr#1}{R:\@@cl@@r:\@@cl@@g:\@@cl@@b}}}
     {\doifdefinedelse{\??cr#2}
        {\redoglobal\setevalue{\??cr#1}{\getvalue{\??cr#2}}}
        {\showmessage{\m!colors}{3}{#1}}}%
   \dodoglobal\setvalue{#1}{\color[#1]}}

%D The names of colors are stored in a comma separated list 
%D only for the purpose of showing them with \type{\showcolor}.
%D 
%D Colors can be defined global by using \type{\doglobal}, 
%D like in 
%D 
%D \startbuffer
%D \doglobal\definecolor [SomeKindOfRed] [r=.8,g=.05,b=.05]
%D \stopbuffer
%D
%D \typebuffer
%D
%D \haalbuffer
%D 
%D This color shows up as \color[SomeKindOfRed]{some kind 
%D of red}.

%D \macros
%D   {setupcolor}
%D
%D Color definitions can be grouped in files with the name: 
%D
%D \starttypen
%D \f!colorprefix-identifier.tex
%D \stoptypen
%D
%D where \type{\f!colorprefix} is \unprotect {\tttf \f!colorprefix}. 
%D Loading such a file is done by \protect
%D
%D \showsetup{\y!setupcolor} 
%D
%D Some default colors are specified in \type{colo-rgb.tex},
%D which is loaded into the format by: 
%D
%D \starttypen
%D \setupcolor[rgb]
%D \stoptypen
 
\def\colorstyle{}

\def\setupcolor%
  {\dosingleargument\dosetupcolor}

\def\dosetupcolor[#1]%
  {\doifnot{#1}{\colorstyle}
     {\def\colorstyle{#1}%
      \def\dodosetupcolor##1%
        {\makeshortfilename[\f!colorprefix\truefilename{##1}]%
         \readsysfile{\shortfilename}%
           {\showmessage{\m!colors}{4}{\colorstyle}}
           {\showmessage{\m!colors}{5}{\colorstyle}}}%
      \processcommalist[#1]\dodosetupcolor}}

%D When typesetting for paper, we prefer using the \kap{CMYK} 
%D color space, but for on||screen viewing we prefer \kap{RGB} 
%D (the previous implementation supported only this scheme). 
%D Independant of such specifications, we support some automatic 
%D conversions: 
%D 
%D \startopsomming[opelkaar]
%D \som  convert all colors to \kap{RGB}
%D \som  convert all colors to \kap{CMYK}
%D \som  convert all colors to gray scales
%D \stopopsomming
%D 
%D We also support optimization of colors to gray scales. 
%D 
%D \startopsomming[verder]
%D \som  reduce gray colors to gray scales
%D \som  reduce \kap{CMY} components to \kap{K}
%D \stopopsomming
%D 
%D These options are communicated by means of: 

\newif\ifRGBsupported
\newif\ifCMYKsupported
\newif\ifconverttoGRAY % obsolete
\newif\ifpreferGRAY
\newif\ifGRAYprefered
\newif\ifreduceCMYK

%D needs: 

% \newif\ifMPgraphics
% \newif\ifinpagebody

%D The last boolean controls reduction of \kap{CMYK} to 
%D \kap{CMY} colors. When set to true, the black component 
%D is added to the other ones. 

%D Color modes are entered using the next set of commands. 
%D The \type{\stop} alternatives are implemented in a way 
%D that permits non||grouped use. 
%D
%D The, for this module redundant, check if we are in color 
%D mode is needed when we use these macros in other modules.  

\def\dostartcolormodeR#1:#2:#3\od%
  {\bgroup
   %\def\@@cl@@r{#1}\def \@@cl@@g{#2}\def \@@cl@@b{#3}%
   \edef\@@cl@@r{#1}\edef\@@cl@@g{#2}\edef\@@cl@@b{#3}%
   \ifpreferGRAY\ifx\@@cl@@r\@@cr@@g\ifx\@@cl@@r\@@cl@@b
     \GRAYpreferedtrue
   \fi\fi\fi
   \ifincolor\else\RGBsupportedfalse\CMYKsupportedfalse\fi
   \ifGRAYprefered
     \dostartgraycolormode\@@cl@@r
   \else\ifRGBsupported
     \dostartrgbcolormode\@@cl@@r\@@cl@@g\@@cl@@b
   \else\ifCMYKsupported
     \convertRGBtoCMYK\@@cl@@r\@@cl@@g\@@cl@@b
     \dostartcmykcolormode\@@cl@@c\@@cl@@m\@@cl@@y\@@cl@@k
   \else
     \convertRGBtoGRAY\@@cl@@r\@@cl@@g\@@cl@@b
     \dostartgraycolormode\@@cl@@s
   \fi\fi\fi
   \egroup}

\def\dostartcolormodeC#1:#2:#3:#4\od%
  {\bgroup
   %\def\@@cl@@c{#1}\def \@@cl@@m{#2}\def \@@cl@@y{#3}\def \@@cl@@k{#4}%
   \edef\@@cl@@c{#1}\edef\@@cl@@m{#2}\edef\@@cl@@y{#3}\edef\@@cl@@k{#4}%
   \ifpreferGRAY\ifx\@@cl@@k\@@cl@@z\ifx\@@cl@@c\@@cr@@m\ifx\@@cl@@c\@@cl@@y
     \GRAYpreferedtrue
   \fi\fi\fi\fi
   \ifincolor\else\RGBsupportedfalse\CMYKsupportedfalse\fi 
   \ifGRAYprefered
     \dostartgraycolormode\@@cl@@c
   \else\ifCMYKsupported
     \ifreduceCMYK
       \convertCMYKtoCMY\@@cl@@c\@@cl@@m\@@cl@@y\@@cl@@k
       \dostartcmykcolormode\@@cl@@c\@@cl@@m\@@cl@@y\@@cl@@k
     \else
       \dostartcmykcolormode\@@cl@@c\@@cl@@m\@@cl@@y\@@cl@@k
     \fi
   \else\ifRGBsupported
     \convertCMYKtoRGB\@@cl@@c\@@cl@@m\@@cl@@y\@@cl@@k
     \dostartrgbcolormode\@@cl@@r\@@cl@@g\@@cl@@b
   \else
     \convertCMYKtoGRAY\@@cl@@c\@@cl@@m\@@cl@@y\@@cl@@k
     \dostartgraycolormode\@@cl@@s
   \fi\fi\fi
   \egroup}

\def\dostartcolormodeS#1\od%
  {\dostartgraycolormode{#1}}

%D Prefering gray is not the same as converting to gray. Conversion treats 
%D each color components  in a different way, while prefering is just a 
%D reduction and thus a space||saving option.

%D \macros
%D   {startcolormode,stopcolormode,permitcolormode}
%D 
%D We use \type{\stopcolormode} to reset the color in 
%D whatever color space and do so by calling the corresponding
%D special. Both commands can be used for fast color 
%D switching, like in colored verbatim,

\newif\ifpermitcolormode \permitcolormodetrue

\def\dostartcolormode#1:%
  {\getvalue{dostartcolormode#1}}  

\def\startcolormode#1% 
  {\ifincolor\ifpermitcolormode 
     \doifcolorelse{#1}
       {\getcurrentcolorspecs{#1}%
        \expandafter\dostartcolormode\currentcolorspecs\od}
       {\dostopcolormode}%
   \fi\fi}

\def\stopcolormode%
  {\ifincolor\ifpermitcolormode\dostopcolormode\fi\fi}

%D \macros
%D   {startregistercolor,stopregistercolor,permitcolormode}
%D
%D If you only want to register a color, the switch \type 
%D {\ifpermitcolormode} can be used. That way the nested 
%D colors know where to go back to. 

\def\startregistercolor[#1]%
  {\permitcolormodefalse\startcolor[#1]\permitcolormodetrue}

\def\stopregistercolor%
  {\permitcolormodefalse\stopcolor\permitcolormodetrue}

%D We use some reserved names for local color components. 
%D Consistent use of these scratch variables saves us 
%D unneccessary hash entries. 
%D 
%D \starttypen 
%D \@@cl@@r \@@cl@@g \@@cl@@b
%D \@@cl@@c \@@cl@@m \@@cl@@y \@@cl@@k
%D \@@cl@@s
%D \stoptypen
%D 
%D We implement several conversion routines. 
%D
%D \starttypen
%D \convertRGBtoCMYK  {r} {g} {b} 
%D \convertRGBtoGRAY  {r} {g} {b} 
%D \convertCMYKtoRGB  {c} {m} {y} {k} 
%D \convertCMYKtoGRAY {c} {m} {y} {k}
%D \convertCMYKtoCMY  {c} {m} {y} {k}
%D \stoptypen
%D 
%D The relation between \kap{Gray}, \kap{RGB} and \kap{CMYK} 
%D is: 
%D 
%D \plaatsformule[-]
%D   \startformule
%D   G = .30r + .59g + .11b 
%D     = 1.0 - \min(1.0,\ .30c + .59m + .11y + k)
%D   \stopformule
%D 
%D When converting from \kap{CMYK} to \kap{RGB} we use the 
%D formula: 
%D 
%D \plaatsformule[-]
%D   \startformule
%D   \eqalign
%D     {r &= 1.0 - \min(1.0,\ c+k) \cr
%D      g &= 1.0 - \min(1.0,\ m+k) \cr
%D      b &= 1.0 - \min(1.0,\ y+k)}
%D   \stopformule
%D 
%D In the conversion routine the color components are calculated 
%D in three digits precision. 

\def\realcolorvalue#1%  
  {\ifnum     #1<10   0.00\the#1%
   \else\ifnum#1<100  0.0\the#1%
   \else\ifnum#1<1000 0.\the#1%
   \else              1\fi\fi\fi}

% \def\doconvertCMYKtoRGB#1\k#2\to#3%
%   {\scratchdimen=#1\s!pt
%    \advance\scratchdimen by #2\s!pt\relax
%    \ifdim\scratchdimen>1\s!pt
%      \scratchdimen=-1\s!pt
%    \else
%      \scratchdimen=-\scratchdimen
%    \fi
%    \advance\scratchdimen by 1\s!pt
%    \multiply\scratchdimen by 1000
%    \scratchcounter=\scratchdimen
%    \advance\scratchcounter by \!!medcard
%    \divide\scratchcounter by \!!maxcard
%    \edef#3{\realcolorvalue\scratchcounter}}

\def\doconvertCMYKtoRGB#1\k#2\to#3%
  {\ifdim#2\s!pt<#1\s!pt  % k>color
     \scratchdimen=1\s!pt
     \advance\scratchdimen -#1\s!pt
     \advance\scratchdimen -#2\s!pt
     \multiply\scratchdimen by 1000
     \scratchcounter=\scratchdimen
     \advance\scratchcounter by \!!medcard
     \divide\scratchcounter by \!!maxcard
     \edef#3{\realcolorvalue\scratchcounter}%
   \else
     \edef#3{0}%
   \fi}

\def\convertCMYKtoRGB#1#2#3#4%
  {\doconvertCMYKtoRGB#1\k#4\to\@@cl@@r
   \doconvertCMYKtoRGB#2\k#4\to\@@cl@@g
   \doconvertCMYKtoRGB#3\k#4\to\@@cl@@b}

\def\doconvertRGBtoCMYK#1\to#2%
  {\scratchdimen=#1\s!pt
   \multiply\scratchdimen by 1000
   \scratchcounter=\scratchdimen
   \advance\scratchcounter by \!!medcard
   \divide\scratchcounter by \!!maxcard
   \scratchcounter=-\scratchcounter
   \advance\scratchcounter by 1000
   \edef#2{\realcolorvalue\scratchcounter}}

\def\convertRGBtoCMYK#1#2#3%
  {\doconvertRGBtoCMYK#1\to\@@cl@@c
   \doconvertRGBtoCMYK#2\to\@@cl@@m
   \doconvertRGBtoCMYK#3\to\@@cl@@y
   \let\@@cl@@k=\@@cl@@z}

%D The following switch is mainly meant for (hidden) 
%D documentation purposes. 

\newif\ifweightGRAY \weightGRAYtrue

\def\nGRAYfactor{333.333}
\def\rGRAYfactor{\ifweightGRAY300\else\nGRAYfactor\fi}
\def\gGRAYfactor{\ifweightGRAY590\else\nGRAYfactor\fi}
\def\bGRAYfactor{\ifweightGRAY110\else\nGRAYfactor\fi}

\def\convertRGBtoGRAY#1#2#3%  
  {\scratchdimen=#1\s!pt
   \scratchdimen=\rGRAYfactor\scratchdimen
   \scratchcounter=\scratchdimen
   \scratchdimen=#2\s!pt
   \scratchdimen=\gGRAYfactor\scratchdimen
   \advance\scratchcounter by \scratchdimen
   \scratchdimen=#3\s!pt
   \scratchdimen=\bGRAYfactor\scratchdimen
   \advance\scratchcounter by \scratchdimen
   \advance\scratchcounter by \!!medcard
   \divide\scratchcounter by \!!maxcard 
   \edef\@@cl@@s{\realcolorvalue\scratchcounter}}

\def\convertCMYKtoGRAY#1#2#3#4%  
  {\convertCMYKtoRGB{#1}{#2}{#3}{#4}%
   \convertRGBtoGRAY\@@cl@@r\@@cl@@g\@@cl@@b}

\def\doconvertCMYKtoCMY#1\k#2\to#3%
  {\scratchdimen=#1\s!pt
   \advance\scratchdimen by #2\s!pt\relax
   \ifdim\scratchdimen>1\s!pt
     \scratchdimen=1\s!pt
   \else
     \scratchdimen=\scratchdimen
   \fi
   \multiply\scratchdimen by 1000
   \scratchcounter=\scratchdimen
   \advance\scratchcounter by \!!medcard
   \divide\scratchcounter by \!!maxcard
   \edef#3{\realcolorvalue\scratchcounter}}

\def\convertCMYKtoCMY#1#2#3#4%
  {\doconvertCMYKtoCMY#1\k#4\to\@@cl@@c
   \doconvertCMYKtoCMY#2\k#4\to\@@cl@@m
   \doconvertCMYKtoCMY#3\k#4\to\@@cl@@y
   \let\@@cl@@k=\@@cl@@z}

%D Before we present the color macros, we first define the 
%D setup command. This command takes care of setting up the 
%D booleans that control local and global behavior (more on 
%D that later) and conversion to other color spaces. 

\newif\ifincolor
\newif\iflocalcolor

\def\setupcolors%
  {\dosingleargument\dosetupcolors}

\def\dosetupcolors[#1]%
 {\getparameters[\??cl][#1]%
  \doifelse{\@@clreductie}{\v!ja}
    {\reduceCMYKtrue}
    {\reduceCMYKfalse}% 
  \doifelse{\@@clrgb}{\v!nee}
    {\showmessage{\m!colors}{9}{\v!rgb}\RGBsupportedfalse} 
    {\showmessage{\m!colors}{10}{\v!rgb}\RGBsupportedtrue}%
  \doifelse{\@@clcmyk}{\v!nee}
    {\showmessage{\m!colors}{9}{\v!cmyk}\CMYKsupportedfalse}
    {\showmessage{\m!colors}{10}{\v!cmyk}\CMYKsupportedtrue}%
  \doifelse{\@@clmpcmyk}{\v!nee}
    {\showmessage{\m!colors}{9} {\v!mp\v!cmyk}\MPcmykfalse}
    {\showmessage{\m!colors}{10}{\v!mp\v!cmyk}\MPcmyktrue}%
  \processaction
    [\@@clconversie]
    [    \v!ja=>\preferGRAYtrue,
        \v!nee=>\preferGRAYfalse,
     \v!altijd=>\preferGRAYtrue
                \RGBsupportedfalse
                \CMYKsupportedfalse,
    \s!default=>\preferGRAYfalse,
    \s!unknown=>\preferGRAYfalse]%
  \ifRGBsupported 
    \converttoGRAYfalse
    \forcegrayMPcolorsfalse
  \else\ifCMYKsupported
    \converttoGRAYfalse
    \forcegrayMPcolorsfalse
    \convertMPcolorstrue
    \ifreduceCMYK
      \reduceMPcolorstrue
    \fi
  \else
    \converttoGRAYtrue
    \forcegrayMPcolorstrue
    \convertMPcolorsfalse
    \reduceMPcolorsfalse
    \showmessage{\m!colors}{11}{}%
  \fi\fi
  \processaction
    [\@@clstatus]
    [\v!globaal=>\incolortrue\localcolorfalse
                 \showmessage{\m!colors}{1}{\colorstyle}, 
      \v!lokaal=>\incolortrue\localcolortrue
                 \showmessage{\m!colors}{2}{\colorstyle}, 
       \v!start=>\let\@@clstatus=\v!globaal
                 \incolortrue\localcolorfalse
                 \showmessage{\m!colors}{1}{\colorstyle}, 
        \v!stop=>\incolorfalse\localcolorfalse
                 \forcegrayMPcolorstrue]}

%D \macros
%D   {doifcolorelse}
%D
%D Switching to a color is done by means of the following 
%D command. Later on we will explain the use of palets.  We 
%D define ourselves a color conditional first.  

% \let\currentpalet\empty
% 
% \def\doifcolorelse#1%
%   {\doifdefinedelse{\??cr\currentpalet#1}}
% 
% \def\getcurrentcolorspecs#1%
%   {\edef\currentcolorspecs{\getvalue{\??cr\currentpalet#1}}}

\let\currentpalet\empty

\beginETEX \ifcsname

\def\doifcolorelse#1%
  {\ifcsname\??cr\ifcsname\??cr\currentpalet#1\endcsname\currentpalet\fi#1\endcsname
     \expandafter\firstoftwoarguments
   \else
     \expandafter\secondoftwoarguments
   \fi}

\def\getcurrentcolorspecs#1%
  {\edef\currentcolorspecs%
     {\csname\??cr
        \ifcsname\??cr\currentpalet#1\endcsname\currentpalet\fi
      #1\endcsname}}

\endETEX

\beginTEX 

\def\colorcsname#1\endcsname
  {\csname\??cr
     \@EA\ifx\csname\??cr\currentpalet#1\endcsname\relax\else\currentpalet\fi
   #1\endcsname}

\def\doifcolorelse#1%
  {\@EA\ifx\colorcsname#1\endcsname
     \expandafter\secondoftwoarguments
   \else
     \expandafter\firstoftwoarguments
   \fi}

\def\getcurrentcolorspecs#1%
  {\edef\currentcolorspecs{\colorcsname#1\endcsname}}

\endTEX

%D \macros
%D   {localstartcolor,localstopcolor}
%D
%D Simple color support, that is without nesting, is provided 
%D by:

\def\localstartcolor[#1]% 
  {\ifincolor
     \localcolortrue
     \doglobalstartcolor[#1]%
   \fi}

\def\localstopcolor%
  {\ifincolor
     \doglobalstopcolor
   \fi}

%D \macros
%D   {startcolor,stopcolor}
%D
%D The more save method, the one that saves the current color 
%D state and returns to this state afterward, is activated by: 
%D
%D \showsetup{\y!startcolor}

\def\startcolor[#1]%
  {\ifincolor
     \doglobalstartcolor[#1]%
   \fi}

\def\stopcolor%
  {\ifincolor
     \doglobalstopcolor
   \fi}

%D This macros call the global color switching ones. Starting 
%D a global, i.e. a possible page boundary crossing, color 
%D mode also sets a \type{\mark} in \TEX's internal list. 

\newcount\colorlevel

\setvalue{\??cl0C}{}  % saved color 
\setvalue{\??cl0S}{}  % stop command

%D We keep a positive color stack for foreground colors, and 
%D a negative one for backgrounds. Not that brilliant a 
%D solution, but it suits. The signs are swapped when the 
%D page ornaments are typeset. 

\def\@@colorplus {+}  
\def\@@colorminus{-}

\def\dodoglobalstartcolor[#1]%
  {\xdef\currentcolor{\getvalue{\??cl\the\colorlevel C}}%
   \global\advance\colorlevel by \@@colorplus1
   \setxvalue{\??cl\the\colorlevel C}{#1}%
  %\debuggerinfo{\m!colors}
  %  {start #1 at level \the\colorlevel}%
   \doifelsenothing{#1}
     {\setxvalue{\??cl\the\colorlevel C}{\currentcolor}%
      \setgvalue{\??cl\the\colorlevel S}{\donoglobalstopcolor}}
     {\doifelse{#1}{\currentcolor}
        {\setgvalue{\??cl\the\colorlevel S}{\donoglobalstopcolor}}
        {\doifcolorelse{#1}
           {\docolormark{#1}%
            \setgvalue{\??cl\the\colorlevel S}{\dodoglobalstopcolor}%
            \startcolormode{#1}}
           {\setgvalue{\??cl\the\colorlevel S}{\donoglobalstopcolor}%
            \showmessage{\m!colors}{3}{#1}}}}}

\def\doglobalstartcolor[#1]%
  {\ifnum\colorlevel=0
     \doifelsenothing{#1}
       {\setgvalue{\??cl\the\colorlevel S}{}}
       {\dodoglobalstartcolor[#1]}%
   \else
     \dodoglobalstartcolor[#1]%
   \fi
   \ignorespaces}

\def\donoglobalstopcolor%
  {\ifnum\colorlevel=0 \else
     \xdef\currentcolor{\getvalue{\??cl\the\colorlevel C}}%
    %\debuggerinfo{\m!colors}
    %  {stop \currentcolor\normalspace at level \the\colorlevel}%
     \global\advance\colorlevel by \@@colorminus1
   \fi}

\def\dodoglobalstopcolor%
  {\ifnum\colorlevel=0 \else
     \donoglobalstopcolor
     \xdef\previouscolor{\getvalue{\??cl\the\colorlevel C}}%
     \ifnum\colorlevel=0
       \docolormark{}%
       \stopcolormode
     \else % let's do a bit redundant testing here
       \docolormark{\previouscolor}% 
       \doifelsenothing{\previouscolor}
         {\dostopcolormode}
         {\doifcolorelse{\previouscolor} 
            {\doifnot{\currentcolor}{\previouscolor}
               {\startcolormode{\previouscolor}}} 
            {\dostopcolormode}}%
     \fi
   \fi}

\def\doglobalstopcolor%
  {\getvalue{\??cl\the\colorlevel S}}

%D We don't use grouping and save each stop alternative. This 
%D permits be especially useful in for instance local color 
%D support in verbatim. Using \type{\bgroup}||\type{\egroup} 
%D pairs could interfere with calling commands 

%D This color mechanism takes care of nested colors, like in:
%D
%D \startbuffer
%D \kleur[groen]{groen \kleur[groen]{groen \kleur[rood]{rood}} groen}
%D \kleur[groen]{groen \kleur[]{groen \kleur[rood]{rood}} groen}
%D \kleur[groen]{groen \kleur[rood]{rood \kleur[rood]{rood}} groen}
%D \kleur[groen]{groen \kleur[groen]{groen \kleur[]{groen}} groen}
%D \kleur[groen]{groen \kleur[rood]{rood} groen}
%D \kleur[groen]{groen \kleur[]{groen} groen}
%D \kleur[]{zwart \kleur[rood]{rood} zwart}
%D \kleur[]{zwart}
%D \stopbuffer
%D 
%D \typebuffer
%D 
%D or 
%D 
%D \startvoorbeeld
%D \startregels
%D \haalbuffer
%D \stopregels
%D \stopvoorbeeld
%D
%D Crossing page boundaries is of course also handled. 
%D Undefined or empty color specifications are treated as 
%D efficient as possible.  
%D 
%D \startbuffer
%D \startkleur[groen]
%D   [groen] \input tufte [groen] \par 
%D   \startkleur[]
%D     [groen] \input knuth [groen] \par 
%D     \startkleur[rood]
%D       [rood] \input tufte [rood] \par 
%D       \startkleur[geel]
%D         [geel] \input knuth [geel] \par 
%D       \stopkleur
%D       [rood] \input tufte [rood] \par 
%D     \stopkleur
%D     [groen] \input knuth [groen] \par 
%D   \stopkleur
%D   [groen] \input tufte [groen] \par 
%D \stopkleur
%D \stopbuffer
%D 
%D \startopelkaar
%D \haalbuffer
%D \stopopelkaar
%D 
%D These quotes are typeset by saying:
%D 
%D \typebuffer
 
%D We already mentioned that colors interfere with building
%D the pagebody. This means that when the page is composed,
%D the colors temporary have to be reset. After the page is
%D shipped out, we have to revive the current color. 
%D 
%D We use \type{\marks} to keep track of colors across page 
%D boundaries. Unfortunately standard \TEX\ supports only one mark, 
%D and using this one for color support only would be a waste. 
%D We therefore use an adapted version of J.~Fox's multiple mark
%D mechanism as (re|)|implemented in \module{supp-mrk}. 

\doifdefinedelse{newmark}
  {\newmark\colormark}  
  {\def\colormark#1{}}

%D Using this mark mechanism with lots of colors has one 
%D major drawback: \TEX's memory tends to overflow when 
%D very colorful text is stored in a global box. Even worse is that
%D the processing time grows considerably. We therefore support
%D local as well as global color switching. 
%D 
%D Of the next macros, \type{\popcolor} is to be used after
%D the actual \type{\shipout} and \type{\startcolorpage} and
%D \type{\stopcolorpage} are called when entering and leaving
%D the \type{\pagebody} builder. In case of emergencies
%D \type{\pushcolor} can be used to undo the current color, 
%D for instance when insertions are appended to the page.  
%D
%D Out of efficiency we only use marks when needed. The next 
%D macro tries to find out if indeed a mark should be set. 
%D This macro uses the boolean \type{\ifinpagebody}, which can 
%D be defined and set in the module that handles the pagebody. 

\def\docolormark#1%
  {\iflocalcolor \else \ifinpagebody \else \ifinframed \else 
     \dodocolormark{#1}%
   \fi \fi \fi}

\let\lastcolormark=\empty

\def\dodocolormark#1%
  {\doifnot{#1}{\lastcolormark}
     {\xdef\lastcolormark{#1}%
      \expandafter\setmark\expandafter\colormark\expandafter{\lastcolormark}}}

%D \macros
%D   {pushcolor, popcolor}
%D
%D Pushing the current state in the output routine simply comes 
%D to resetting the color to black, while popping restores the 
%D color state to that of before the break. 

\def\pushcolor%
  {\stopcolormode} 

\def\popcolor%
  {\doifsomething{\getbotmark\colormark}
     {%\debuggerinfo{\m!colors}{popping \getbotmark\colormark}%
      \startcolormode{\getbotmark\colormark}}}

\def\popsplitcolor% 
  {\getsplitmarks\colormark  % hier wel 
   \doifsomething{\getsplitbotmark\colormark}
     {%\debuggerinfo{\m!colors}{split popping \getsplitbotmark\colormark}%
      \startcolormode{\getsplitbotmark\colormark}}}

%D \macros
%D   {startcolorpage, stopcolorpage}
%D
%D Local use can be forced with the next two macros. Nesting 
%D is still supported but colors are no longer marked. 

%D \starttypen
%D \def\startcolorpage%    
%D   {\bgroup
%D    \let\docolormark=\gobbleoneargument
%D    \edef\savedcolorlevel{\the\colorlevel}%
%D    \ifnum\colorlevel>0
%D      \stopcolormode
%D    \fi
%D    \global\colorlevel=1000\relax} % a save offset 
%D 
%D \def\stopcolorpage%
%D   {\global\colorlevel=\savedcolorlevel\relax
%D    \egroup}
%D \stoptypen

%D The next alternative makes (simple) color separation more 
%D easy. It also supports nested colors in page backgrounds 
%D and texts. 

\def\startcolorpage%    
  {\bgroup
   \def\@@colorplus{-}%
   \def\@@colorminus{+}%
   \let\docolormark=\gobbleoneargument
   \edef\savedcolorlevel{\the\colorlevel}%
   \global\colorlevel=0       % before \localstartcolor of  
   \localstartcolor[black]}   % course, ugly bug removed

\def\stopcolorpage%
  {\localstopcolor
   \global\colorlevel=\savedcolorlevel\relax
   \egroup}

%D \macros
%D   {color,graycolor}
%D 
%D This leaves the simple color command: 
%D
%D \showsetup{\y!color}
%D \showsetup{\y!graycolor}
%D
%D Which can be used straightforward: \color[groen]{green as gras}. 
%D We want color support to be similar to font support and 
%D therefore implement \type{\color} as:

\unexpanded\def\color[#1]%
  {\groupedcommand
     {\startcolor[#1]} 
     {\stopcolor}}

\unexpanded\def\graycolor[#1]% not \gray because this is a color
  {\groupedcommand
     {\RGBsupportedfalse\CMYKsupportedfalse\startcolor[#1]}
     {\stopcolor}}

\let\grey\graycolor

%D This implementation enables use of defined colors like:
%D
%D \starttypen
%D Look at the {\brightgreen bright} side of life and get 
%D yourself no \red{red} head!
%D \stoptypen

%D \macros 
%D   {colorvalue, grayvalue}
%D 
%D We can typeset the color components using \type{\colorvalue} and 
%D \type{\grayvalue}. The commands: 
%D
%D \startbuffer
%D color value of SomeKindOfRed: \colorvalue{SomeKindOfRed} \crlf
%D gray value of SomeKindOfRed: \grayvalue{SomeKindOfRed}
%D \stopbuffer
%D
%D \typebuffer
%D
%D show us: 
%D
%D \startvoorbeeld
%D \haalbuffer
%D \stopvoorbeeld

\def\realcolorformat#1% 
  {\ifnum#1<10        0.00\the#1%
   \else\ifnum#1<100  0.0\the#1%
   \else\ifnum#1<1000 0.\the#1%
   \else              1.000\fi\fi\fi}

\def\colorformatseparator{ }

\def\dodoformatcolor#1%
  {\scratchdimen=#1\s!pt\relax
   \ifdim\scratchdimen>1\s!pt
     \scratchdimen=1\s!pt
   \fi
   \multiply\scratchdimen by 1000
   \scratchcounter=\scratchdimen
   \advance\scratchcounter by \!!medcard
   \divide\scratchcounter by \!!maxcard \relax
   \realcolorformat\scratchcounter}

\def\doformatcolorR#1:#2:#3\od%
  {\dodoformatcolor{#1}\colorformatseparator
   \dodoformatcolor{#2}\colorformatseparator 
   \dodoformatcolor{#3}}

\def\doformatcolorC#1:#2:#3:#4\od%
  {\dodoformatcolor{#1}\colorformatseparator 
   \dodoformatcolor{#2}\colorformatseparator 
   \dodoformatcolor{#3}\colorformatseparator 
   \dodoformatcolor{#4}}

\def\doformatcolorS#1\od%
  {\dodoformatcolor{#1}}

\def\doformatcolor#1:%
  {\getvalue{doformatcolor#1}}  

\def\colorvalue#1% 
  {\doifcolorelse{#1}
     {\getcurrentcolorspecs{#1}%
      \expandafter\doformatcolor\currentcolorspecs\od}
     {}}

\def\doformatgrayR#1:#2:#3\od%
  {\convertRGBtoGRAY{#1}{#2}{#3}%
   \dodoformatcolor\@@cl@@s}

\def\doformatgrayC#1:#2:#3:#4\od%
  {\convertCMYKtoGRAY{#1}{#2}{#3}{#4}%
   \dodoformatcolor\@@cl@@s}

\def\doformatgrayS#1\od%
  {\dodoformatcolor{#1}}

\def\doformatgray#1:%
  {\getvalue{doformatgray#1}}  

\def\grayvalue#1% 
  {\doifcolorelse{#1}
     {\getcurrentcolorspecs{#1}%
      \expandafter\doformatgray\currentcolorspecs\od}
     {}}

%D \macros
%D   {localstartraster,localstopraster,
%D    startraster,stopraster}   
%D 
%D The previous conversions are not linear and treat each color
%D component according to human perception curves. Pure gray
%D (we call them rasters) has equal color components. In
%D \CONTEXT\ rasters are only used as backgrounds and these
%D don't cross page boundaries in the way color does. Therefore
%D we don't need stacks and marks. Just to be compatible with
%D color support we offer both 'global' and 'local' commands.  

\def\localstartraster[#1]%       
 %{\doifinstringelse{.}{#1} % no, we also want 0 and 1  
  {\doifelsenothing{#1}
     {\dostartgraymode{\@@rsraster}}
     {\dostartgraymode{#1}}}

\def\localstopraster%        
  {\dostopgraymode}

\def\startraster%
  {\localstartraster}

\def\stopraster%
  {\localstopraster}

%D In this documentation we will not go into too much details
%D on palets. Curious users can find more information on this
%D topic in \uit[use of color]. 
%D 
%D At the moment we implemented color in \CONTEXT\ color
%D printing was not yet on the desktop. In spite of this lack our
%D graphics designer made colorfull illustrations. When printed
%D on a black and white printer, distinctive colors can come
%D out equally gray. We therefore decided to use only colors
%D that were distinctive in colors as well as in black and
%D white print. 
%D 
%D Although none of the graphic packages we used supported
%D logical colors and global color redefition, we build this
%D support into \CONTEXT. This enabled us to experiment and
%D also prepared us for the future. 

%D \macros
%D   {definepalet}
%D 
%D Colors are grouped in palets. The colors in such a palet can
%D have colorful names, but best is to use names that specify
%D their use, like {\em important} or {\em danger}. As a sort
%D of example \CONTEXT\ has some palets predefined, 
%D like:\voetnoot{At the time I wrote the palet support, I was 
%D reading 'A hort history of time' of S.~Hawkins, so that's
%D why we stuck to quarks.} 
%D 
%D \starttypen
%D \definepalet    
%D   [alfa]
%D   [     top=rood:7,
%D      bottom=groen:6,
%D          up=blauw:5,
%D        down=cyaan:4,
%D     strange=magenta:3,
%D       charm=geel:2]
%D \stoptypen
%D
%D It's formal definition is: 
%D 
%D \showsetup{\y!definepalet}
%D
%D Visualized, such a palet looks like: 
%D 
%D \startbuffer[palet]
%D \showpalet [alfa] [horizontaal,naam,nummer,waarde]
%D \stopbuffer
%D 
%D \startregelcorrectie
%D \haalbuffer[palet]
%D \stopregelcorrectie
%D
%D This bar shows both the color and gray alternatives of the 
%D palet components (not visible in black and white print).
%D
%D When needed, one can copy a palet by saying:
%D
%D \starttypen
%D \definepalet [TEXcolorpretty] [colorpretty]
%D \stoptypen
%D
%D This saves us some typing in for instance the modules that
%D deal with pretty verbatim typesetting.

\def\definepalet%
  {\dodoubleargument\dodefinepalet}

\def\dodefinepalet[#1][#2]%
  {\doifassignmentelse{#2}
     {\setvalue{\??pa#1}{}%
      \setevalue{\??pa\??pa#1}{#2}%
      \showmessage{\m!colors}{6}{#1}%
      \def\dodododefinepalet[##1=##2]%
        {\doifvaluesomething{\??pa#1}
           {\setevalue{\??pa#1}{\getvalue{\??pa#1},}}%
         \setevalue{\??pa#1}{\getvalue{\??pa#1}##1}%
         \doifdefinedelse{\??cr##2}
           {\setevalue{\??cr#1:##1}{\getvalue{\??cr##2}}}
           {\setevalue{\??cr#1:##1}{S:0}}}%
      \def\dododefinepalet##1%
        {\dodododefinepalet[##1]}%
      \processcommalist[#2]\dododefinepalet}
     {\doifdefined{\??pa#2}
        {\expanded{\dodefinepalet[#1][\getvalue{\??pa\??pa#2}]}}}}

%D \macros 
%D   {setuppalet}
%D
%D Colors are taken from the current palet, if defined. 
%D Setting the current palet is done by:
%D
%D \showsetup{\y!setuppalet}

\let\currentpalet\empty

\def\setuppalet%
  {\dosingleempty\dosetuppalet}

\def\dosetuppalet[#1]%
  {\doifelsenothing{#1}
     {\let\currentpalet\empty}
     {\doifelsevaluenothing{\??pa#1}
        {\showmessage{\m!colors}{7}{#1}%
         \let\currentpalet\empty}
        {\def\currentpalet{#1:}}}}

%D \macros 
%D   {showpalet}
%D 
%D The previous visualization was typeset with: 
%D 
%D \typebuffer[palet]
%D
%D This commands is defined as: 
%D
%D \showsetup{\y!showpalet}

\fetchruntimecommand \showpalet {\f!colorprefix\s!run}

%D \macros
%D   {definecolorgroup}
%D
%D The naming of the colors in this palet suggests some 
%D ordening, which in turn is suported by color grouping. 
%D 
%D \starttypen
%D \definecolorgroup
%D   [rood]
%D   [1.00:0.90:0.90,
%D    1.00:0.80:0.80,
%D    1.00:0.70:0.70,
%D    1.00:0.55:0.55,
%D    1.00:0.40:0.40,
%D    1.00:0.25:0.25,
%D    1.00:0.15:0.15,
%D    0.90:0.00:0.00]
%D \stoptypen
%D 
%D In such a color group colors are numbered from~$1$ to~$n$. 
%D
%D \showsetup{\y!definecolorgroup}
%D
%D This kind of specification is not only more compact than 
%D defining each color separate, it also loads faster and takes 
%D less bytes. 

\def\definecolorgroup%
  {\dotripleempty\dodefinecolorgroup}

\def\dodefinecolorgroup[#1][#2][#3]%
  {\ifthirdargument
     \processaction
       [#2]
       [    \v!cmyk=>\edef\currentcolorspace{C},
             \v!rgb=>\edef\currentcolorspace{R},
            \v!gray=>\edef\currentcolorspace{S},
               \v!s=>\edef\currentcolorspace{S},
         \s!unknown=>\edef\currentcolorspace{R}]%
     \scratchcounter=0
     \def\dododefinecolorgroup##1%
       {\advance\scratchcounter by 1
        \setevalue{\??cr#1:\the\scratchcounter}{\currentcolorspace:##1}}%
     \processcommalist[#3]\dododefinecolorgroup
   \else
     \doifinstringelse{:}{#2}
       {\definecolorgroup[#1][\v!rgb][#2]}
       {\doloop
          {\doifdefinedelse{\??cr#2:\recurselevel}
             {\setevalue{\??cr#1:\recurselevel}%
                {\getvalue{\??cr#2:\recurselevel}}}
             {\exitloop}}}%
   \fi}

%D \macros
%D   {showcolorgroup}
%D 
%D We can show the group by:
%D 
%D \startbuffer
%D \showcolorgroup [blauw] [horizontaal,naam,nummer,waarde]
%D \stopbuffer
%D 
%D \typebuffer
%D 
%D or in color: 
%D 
%D \startregelcorrectie
%D \haalbuffer
%D \stopregelcorrectie
%D
%D which uses: 
%D
%D \showsetup{\y!showcolorgroup}

\fetchruntimecommand \showcolorgroup {\f!colorprefix\s!run}

%D There are ten predefined color groups, like
%D \color[groen]{\em groen}, \color[rood]{\em rood},
%D \color[blauw]{\em blauw}, \color[cyaan]{\em cyaan},
%D \color[magenta]{\em magenta} and \color[geel]{\em geel}. 
%D 
%D \startregelcorrectie
%D \hbox to \hsize
%D   {\hss
%D    \showcolorgroup [rood]    [vertikaal,naam,nummer]\hss
%D    \showcolorgroup [groen]   [vertikaal,naam]\hss
%D    \showcolorgroup [blauw]   [vertikaal,naam]\hss
%D    \showcolorgroup [cyaan]   [vertikaal,naam]\hss
%D    \showcolorgroup [magenta] [vertikaal,naam]\hss
%D    \showcolorgroup [geel]    [vertikaal,naam]\hss}
%D \stopregelcorrectie
%D 
%D These groups are used to define palets {\em alfa} upto {\em
%D zeta}. As long as we don't use colors from the same row, we
%D get ourselves distinctive palets. By activating such a palet
%D one gains access to its members {\em top} to {\em charm} (of
%D course one should use more suitable names than these). 
%D 
%D \startregelcorrectie
%D \hbox to \hsize
%D   {\showpalet [alfa]    [vertikaal,naam,nummer]\hss
%D    \showpalet [beta]    [vertikaal,naam]\hss
%D    \showpalet [gamma]   [vertikaal,naam]\hss
%D    \showpalet [delta]   [vertikaal,naam]\hss
%D    \showpalet [epsilon] [vertikaal,naam]\hss
%D    \showpalet [zeta]    [vertikaal,naam]}
%D \stopregelcorrectie
%D  
%D By using the keyword \type{\v!waarde} the individual color
%D components are shown too. When printed in color, these
%D showcases show both the colors and the gray value. 

%D \macros
%D   {comparepalet}
%D 
%D There are some more testing macros available:
%D 
%D \startbuffer
%D \comparepalet [alfa]
%D \stopbuffer
%D 
%D \typebuffer
%D 
%D shows the palet colors against a background:
%D 
%D \startregelcorrectie
%D \haalbuffer
%D \stopregelcorrectie
%D
%D The formal definition is: 
%D 
%D \showsetup{\y!comparepalet}

\fetchruntimecommand \comparepalet {\f!colorprefix\s!run}

%D \macros
%D   {comparecolorgroup}
%D
%D The similar command: 
%D
%D \startbuffer
%D \comparecolorgroup [blauw]
%D \stopbuffer
%D 
%D \typebuffer
%D 
%D shows color groups:
%D 
%D \startregelcorrectie
%D \haalbuffer
%D \stopregelcorrectie
%D
%D this commands are defined as: 
%D
%D \showsetup{\y!comparecolorgroup}

\fetchruntimecommand \comparecolorgroup {\f!colorprefix\s!run}

%D \macros 
%D   {showcolor}
%D 
%D But let's not forget that we also have the more traditional 
%D non||related colors. These show up after: 
%D 
%D \starttypen
%D \showcolor [name]
%D \stoptypen
%D 
%D Where \type{name} for instance can be \type{rgb}. 
%D
%D \showsetup{\y!showcolor}

\fetchruntimecommand \showcolor {\f!colorprefix\s!run}

%D \macros
%D   {negativecolorbox}
%D
%D Sometimes, especially when we deal with typesetting 
%D devices, we want to reverse the color scheme. Instead of 
%D recalculating all those colors, we use a quick and dirty 
%D approach: 
%D 
%D \starttypen
%D \negativecolorbox0
%D \stoptypen
%D 
%D will negate the colors in box zero. 

\def\negatecolorbox#1%
  {\setbox#1=\hbox
     {\dostartnegative  
      \localstartcolor[white]%
      \vrule\!!height\ht#1\!!depth\dp#1\!!width\wd#1%
      \localstopcolor
      \hskip-\wd#1%
      \box#1\dostopnegative}}

%D \macros 
%D   {ifMPgraphics, ifMPcmyk, MPcolor}
%D 
%D A very special macro is \type{\MPcolor}. This one can be 
%D used to pass a \CONTEXT\ color to \METAPOST. 
%D
%D \starttypen
%D \MPcolor{my own red}
%D \stoptypen
%D
%D This macro returns a \METAPOST\ triplet \type{(R,G,B)}. 
%D Unless \CMYK\ color support is turned on with \type 
%D {MPcmyk}, only \kap{RGB} colors and gray scales are 
%D supported. 

\newif\ifMPcmyk % \MPcmykfalse

% \def\MPcolor#1%
%   {\ifMPgraphics
%      \@EA\@EA\@EA\doMPcolor\csname\??cr#1\endcsname:::::\end
%    \else
%      #1%
%    \fi}

\beginTEX 

\def\MPcolor#1%
  {\ifMPgraphics
     \@EA\@EA\@EA\doMPcolor\colorcsname#1\endcsname:::::\end
   \else
     #1%
   \fi}

\endTEX

\beginETEX \ifcsname

\def\MPcolor#1%
  {\ifMPgraphics
     \@EA\@EA\@EA\doMPcolor
       \csname\??cr
         \ifcsname\??cr\currentpalet#1\endcsname\currentpalet\fi
       #1\endcsname
     :::::\end
   \else
     #1%
   \fi}

\endETEX


\def\doMPcolor#1:#2:#3:#4:#5:#6\end
  {\if     #1R(#2,#3,#4)%
   \else\if#1C\ifMPcmyk cmyk(#2,#3,#4,#5)\else(1-#2-#5,1-#3-#5,1-#4-#5)\fi
   \else\if#1S(#2,#2,#2)%
   \else      (0,0,0)%
   \fi\fi\fi}

%D \macros 
%D   {PDFcolor,FDFcolor}
%D 
%D Similar alternatives are avaliable for \PDF:

\def\PDFcolor#1%
  {\@EA\@EA\@EA\doPDFcolor\csname\??cr#1\endcsname:::::\end}
   
\def\doPDFcolor#1:#2:#3:#4:#5:#6\end%
  {\if     #1R#2 #3 #4 rg%
   \else\if#1C#2 #3 #4 #5 k%
   \else\if#1S#2 g%
   \else      0 g%
   \fi\fi\fi}

\def\FDFcolor#1%
  {\@EA\@EA\@EA\doFDFcolor\csname\??cr#1\endcsname:::::\end}
   
\def\doFDFcolor#1:#2:#3:#4:#5:#6\end%
  {[\if     #1R#2 #3 #4%
    \else\if#1C#2 #3 #4 #5%
    \else\if#1S#2%
    \else      0%
    \fi\fi\fi]}

%D We default to the colors defined in \module{colo-rgb} and
%D support both \kap{RGB} and \kap{CMYK} output. 

\setupcolors
  [\c!status=\v!stop,
   \c!conversie=\v!ja,
   \c!reductie=\v!nee,
   \c!rgb=\v!ja,
   \c!cmyk=\v!ja,
   \c!mp\c!cmyk=\@@clcmyk]

\setupcolor
  [\v!rgb]

%D As we can see, color support is turned off by default. 
%D Reduction of gray colors to gray scales is turned on. 

\protect \endinput