colo-grp.mkxl /size: 4907 b    last modification: 2025-02-21 11:03
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!hex \endcsname[#1][#2:#3]{\definecolor[#1][x=#2]}
81\defcsname\??colorgroupsetter\s!rgb \endcsname[#1][#2:#3:#4:#5]{\definecolor[#1][r=#2,g=#3,b=#4]}
82\defcsname\??colorgroupsetter\s!cmyk\endcsname[#1][#2:#3:#4:#5:#6]{\definecolor[#1][c=#2,m=#3=,y=#4,k=#5]}
83\defcsname\??colorgroupsetter\s!spot\endcsname[#1][#2:#3:#4]{\definespotcolor[#1][#2][p=#3]}
84
85%D \macros
86%D   {showcolorgroup}
87%D
88%D We can show the group by:
89%D
90%D \startbuffer
91%D \showcolorgroup [blue] [horizontal,name,number,value]
92%D \stopbuffer
93%D
94%D \typebuffer
95%D
96%D or in color:
97%D
98%D \startlinecorrection
99%D \getbuffer
100%D \stoplinecorrection
101%D
102%D which uses:
103%D
104%D \showsetup{showcolorgroup}
105
106\fetchmodulecommand \showcolorgroup \f!colo_run
107
108%D There are ten predefined color groups, like \color [green] {\em groen}, \color
109%D [red] {\em rood}, \color [blue] {\em blauw}, \color [cyan] {\em cyaan}, \color
110%D [magenta] {\em magenta} and \color [yellow] {\em geel}.
111%D
112%D \startlinecorrection
113%D \hbox to \hsize
114%D   {\hss
115%D    \showcolorgroup [red]    [vertical,name,number]\hss
116%D    \showcolorgroup [green]  [vertical,name]\hss
117%D    \showcolorgroup [blue]   [vertical,name]\hss
118%D    \showcolorgroup [cyan]   [vertical,name]\hss
119%D    \showcolorgroup [magenta][vertical,name]\hss
120%D    \showcolorgroup [yellow] [vertical,name]\hss}
121%D \stoplinecorrection
122%D
123%D These groups are used to define palets {\em alfa} upto {\em zeta}. As long as we
124%D don't use colors from the same row, we get ourselves distinctive palets. By
125%D activating such a palet one gains access to its members {\em top} to {\em charm}
126%D (of course one should use more suitable names than these).
127%D
128%D \startlinecorrection
129%D \hbox to \hsize
130%D   {\showpalet [alfa]    [vertical,name,number]\hss
131%D    \showpalet [beta]    [vertical,name]\hss
132%D    \showpalet [gamma]   [vertical,name]\hss
133%D    \showpalet [delta]   [vertical,name]\hss
134%D    \showpalet [epsilon] [vertical,name]\hss
135%D    \showpalet [zeta]    [vertical,name]}
136%D \stoplinecorrection
137%D
138%D By using the keyword \type {value} the individual color components are shown too.
139%D When printed in color, these showcases show both the colors and the gray value.
140
141%D \macros
142%D   {comparecolorgroup}
143%D
144%D The similar command:
145%D
146%D \startbuffer
147%D \comparecolorgroup [blue]
148%D \stopbuffer
149%D
150%D \typebuffer
151%D
152%D shows color groups:
153%D
154%D \startlinecorrection
155%D \getbuffer
156%D \stoplinecorrection
157%D
158%D this commands are defined as:
159%D
160%D \showsetup{comparecolorgroup}
161
162\fetchmodulecommand \comparecolorgroup \f!colo_run
163
164\protect \endinput
165