colo-grp.mkxl /size: 4825 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=colo-grp,
3%D        version=2011.12.27, % moved from colo-ini
4%D          title=\CONTEXT\ Color Macros,
5%D       subtitle=Groups,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D Regular colors and palets are used most, contrary to groups which is why we
15%D define their support in a separate module.
16
17\writestatus{loading}{ConTeXt Color Macros / Groups}
18
19\unprotect
20
21%D \macros
22%D   {definecolorgroup}
23%D
24%D The naming of the colors in this palet suggests some ordening, which in turn is
25%D suported by color grouping.
26%D
27%D \starttyping
28%D \definecolorgroup
29%D   [red]
30%D   [1.00:0.90:0.90,
31%D    1.00:0.80:0.80,
32%D    1.00:0.70:0.70,
33%D    1.00:0.55:0.55,
34%D    1.00:0.40:0.40,
35%D    1.00:0.25:0.25,
36%D    1.00:0.15:0.15,
37%D    0.90:0.00:0.00]
38%D \stoptyping
39%D
40%D In such a color group colors are numbered from~$1$ to~$n$.
41%D
42%D \showsetup{definecolorgroup}
43%D
44%D This kind of specification is not only more compact than defining each color
45%D separate, it also loads faster and takes less bytes.
46
47\installcorenamespace{colorgroup}
48\installcorenamespace{colorgroupsetter}
49
50\newinteger\c_colo_groups_n % scratch counter
51
52\permanent\tolerant\protected\def\definecolorgroup[#1]#*[#2]#*[#3]% % sort of obsolete, just use palets directly
53  {\ifarguments\or\or
54     \ifhastok:{#2}%
55       \colo_groups_define_normal[#1][\v!rgb][#2]
56     \else
57       \colo_groups_define_checked[#1][#2][]%
58     \fi
59   \else
60     \colo_groups_define_normal[#1][#2][#3]%
61   \fi}
62
63\def\colo_groups_define_normal[#1][#2][#3]%
64  {\c_colo_groups_n\zerocount
65   \processcommalist[#3]{\colo_groups_define_entry{#1}{#2}}}
66
67\def\colo_groups_define_checked[#1][#2][#3]%
68  {\doloop % inherited
69     {\ifcsname#2:##1\endcsname
70        \definecolor[#1:##1][#2:##1]%
71      \else
72        \exitloop
73      \fi}}
74
75\def\colo_groups_define_entry#1#2#3% name mode specification
76  {\advanceby\c_colo_groups_n\plusone
77   \csname\??colorgroupsetter\ifcsname\??colorgroupsetter#2\endcsname#2\else\s!rgb\fi\endcsname[#1:\the\c_colo_groups_n][#3:0:0:0:0]}
78
79\defcsname\??colorgroupsetter\s!gray\endcsname[#1][#2:#3]{\definecolor[#1][s=#2]}
80\defcsname\??colorgroupsetter\s!rgb \endcsname[#1][#2:#3:#4:#5]{\definecolor[#1][r=#2,g=#3,b=#4]}
81\defcsname\??colorgroupsetter\s!cmyk\endcsname[#1][#2:#3:#4:#5:#6]{\definecolor[#1][c=#2,m=#3=,y=#4,k=#5]}
82\defcsname\??colorgroupsetter\s!spot\endcsname[#1][#2:#3:#4]{\definespotcolor[#1][#2][p=#3]}
83
84%D \macros
85%D   {showcolorgroup}
86%D
87%D We can show the group by:
88%D
89%D \startbuffer
90%D \showcolorgroup [blue] [horizontal,name,number,value]
91%D \stopbuffer
92%D
93%D \typebuffer
94%D
95%D or in color:
96%D
97%D \startlinecorrection
98%D \getbuffer
99%D \stoplinecorrection
100%D
101%D which uses:
102%D
103%D \showsetup{showcolorgroup}
104
105\fetchmodulecommand \showcolorgroup \f!colo_run
106
107%D There are ten predefined color groups, like \color [green] {\em groen}, \color
108%D [red] {\em rood}, \color [blue] {\em blauw}, \color [cyan] {\em cyaan}, \color
109%D [magenta] {\em magenta} and \color [yellow] {\em geel}.
110%D
111%D \startlinecorrection
112%D \hbox to \hsize
113%D   {\hss
114%D    \showcolorgroup [red]    [vertical,name,number]\hss
115%D    \showcolorgroup [green]  [vertical,name]\hss
116%D    \showcolorgroup [blue]   [vertical,name]\hss
117%D    \showcolorgroup [cyan]   [vertical,name]\hss
118%D    \showcolorgroup [magenta][vertical,name]\hss
119%D    \showcolorgroup [yellow] [vertical,name]\hss}
120%D \stoplinecorrection
121%D
122%D These groups are used to define palets {\em alfa} upto {\em zeta}. As long as we
123%D don't use colors from the same row, we get ourselves distinctive palets. By
124%D activating such a palet one gains access to its members {\em top} to {\em charm}
125%D (of course one should use more suitable names than these).
126%D
127%D \startlinecorrection
128%D \hbox to \hsize
129%D   {\showpalet [alfa]    [vertical,name,number]\hss
130%D    \showpalet [beta]    [vertical,name]\hss
131%D    \showpalet [gamma]   [vertical,name]\hss
132%D    \showpalet [delta]   [vertical,name]\hss
133%D    \showpalet [epsilon] [vertical,name]\hss
134%D    \showpalet [zeta]    [vertical,name]}
135%D \stoplinecorrection
136%D
137%D By using the keyword \type {value} the individual color components are shown too.
138%D When printed in color, these showcases show both the colors and the gray value.
139
140%D \macros
141%D   {comparecolorgroup}
142%D
143%D The similar command:
144%D
145%D \startbuffer
146%D \comparecolorgroup [blue]
147%D \stopbuffer
148%D
149%D \typebuffer
150%D
151%D shows color groups:
152%D
153%D \startlinecorrection
154%D \getbuffer
155%D \stoplinecorrection
156%D
157%D this commands are defined as:
158%D
159%D \showsetup{comparecolorgroup}
160
161\fetchmodulecommand \comparecolorgroup \f!colo_run
162
163\protect \endinput
164