ConTeXt supports two color models: [http://en.wikipedia.org/wiki/RGB_color_model RGB] (typically used for screen display) and [http://en.wikipedia.org/wiki/CMYK_color_model CMYK] (typically used for printing). There is also support for [http://en.wikipedia.org/wiki/Spot_color spot colors] (typically used for offset printing) and transparencies.
= Before you start ... =
1. It is It’s usually a bad style to use explicit color switches in the text. It is It’s better to define a semantic command that takes care of the color switching. For example, instead of using <code>\color[red]{important text}</code>, define
<texcode>
\definehighlight[important][color=red]
and then use <code>\important{important text}</code> in the text.
2. Colors are not enabled by default in MkII. To enabled enable colors in MkII, use
<texcode>\setupcolors[state=start]</texcode>
3. To disable colors in a document, use
<texcode>\setupcolors[state=stop]</texcode>
Last [[Documentation|manual dedicated to color]] was issued in 2016
ConTeXt Defining New Colors|supports several color models:
* [https://en.wikipedia.org/wiki/CMYK_color_model CMYK], typically used for printing
* [https://en.wikipedia.org/wiki/RGB_color_model RGB], [https://en.wikipedia.org/wiki/HSL_and_HSV HSV/HSL] and [https://en.wikipedia.org/wiki/HWB_color_model HWB], typically used for screen display,
* [[Transparency]] ([https://en.wikipedia.org/wiki/Transparency_(graphic) Transparency] on wikipedia).
* [[Spot Colors]] typically used for offset printing ([https://en.wikipedia.org/wiki/Spot_color Spot colors] on wikipedia).
| The values for <code>c</code>, <code>m</code>, <code>y</code> and <code>k</code> are floating point number between <code>0</code> and <code>1</code>.
| The value for <code>h</code> (hue) is between <code>0</code> and <code>360</code>; the values for <code>s</code> (saturation), <code>v</code> (value/brightness) are floating point numbers between <code>0</code> and <code>1</code>.
| The value for <code>h</code> (hue) is between <code>0</code> and <code>360</code>; the values for <code>w</code> (whiteness), <code>b</code> (blackness) are floating point numbers between <code>0</code> and <code>1</code>. This mostly unknown color model is also used in CSS3/SVG.
|-
| Hex
| <texcode>\definecolor[...][x=...]</texcode>
For example,
<texcode>\definecolor[lime][x=BFFF00]
This is \color[lime]{a new color}
that we defined</texcode>
| The value for <code>x</code> is a three-byte hexadecimal number where the bytes represent the red, green, and blue values. This follows the HTML and CSS style of defining colors.
|-
|Gray scale
|<texcode>\definecolor[...][s=...]</texcode>
For example,
<texcode>\definecolor[screen][s=0.5]
This is \color[screen]{a new color}
that we defined</texcode>
| The value for <code>s</code> is a floating point number between <code>0</code> and <code>1</code>, representing the grayness value (1 represents white, 0 represents black).
| The values for <code>c</code>, <code>m</code>, <code>y</code> and <code>k</code> are floating point number between <code>0</code> and <code>1</code>.
| The value for <code>h</code> is between <code>0</code> and <code>360</code>; the values for <code>s</code>, <code>v</code> are floating point numbers between <code>0</code> and <code>1</code>.
|-
| Hex
| <texcode>\definecolor[...][h=...]</texcode>
For example,
<texcode>\definecolor[lime][h=BFFF00]
This is \color[lime]{a new color}
that we defined</texcode>
| The value for <code>x</code> is a three-byte hexadecimal number where the bytes represent the red, green, and blue values. This follows the HTML and CSS style of defining colors.
|-
|Gray scale
|<texcode>\definecolor[...][s=...]</texcode>
For example,
<texcode>\definecolor[screen][g=0.5]
This is \color[screen]{a new color}
that we defined</texcode>
| The value for <code>s</code> is a floating point number between <code>0</code> and <code>1</code>, representing the grayness value (1 represents white, 0 represents black).
|}
'''Note''': The key-values are overloaded. For example, <code>h</code> is used for both HSV model and Hex model; <code>s</code> is used for both HSV model and grayscale model. The distinction is made based on the presence or absence of the <code>v</code> key.
\doifcolorelse{color-name}{... if branch ...}{... else branch ...}
</texcode>
== Using colors in TikZ ==
= Viewing pre-defined color =
|}
= Testing if Tips and Tricks = == Calculating RGB Values == An example of how to use LMTX to calculate RGB values is the following: <texcode>% Use a color is defined picker to get red, green and blue values of a color:% Example: RAL 2005: red = 255, green = 35, blue = 1% Create variables from the values: \setvariables[ColorName][r=255,g=35,b=1]
To test if a % Do some magic: \usemodule[mathfun] % Define the actual color is defined, usebased on variables:
<texcode>\startTEXpage[offset=5mm] \doifcolor{framed[foregroundcolor=white, background=color-name}, backgroundcolor=ColorName]{... if branch ... Hello WORLD!} \\doifcolorelse{color-name}\colorcomponents{... if branch ...}{... else branch ...ColorName}\stopTEXpage
</texcode>
<context>% Use a color picker to get red, green and blue values of a color:% Example: RAL 2005: red = Specialized topics 255, green =35, blue = 1% Create variables from the values:
* \usemodule[http://paletton.com Palettonmathfun] - Website to choose color palettes* [http://colorbrewer2.org/ ColorBrewer] - website to choose colors for maps and graphics.
* Tina Sutton% Define the actual color based on variables: \definecolor[ColorName][% r={\mathexpr[.3N]{\getvariable{ColorName}{r}/255}}, Bride M Whelan: The Complete Color Harmony g={\mathexpr[. Rockport Publishers (2004)3N]{\getvariable{ColorName}{g}/255}}, b={\mathexpr[. ISBN 978-1592530311 (recommanded in the mailing list)3N]{\getvariable{ColorName}{b}/255}},]% % Test it: \startTEXpage[offset=5mm] \framed[foregroundcolor=white, background=color, backgroundcolor=ColorName]{Hello WORLD!} \\\colorcomponents{ColorName}\stopTEXpage</context>
= Further reading and specialized topics =
* [[Transparency]]
* [[Spot Colors]]
* References
** [http://paletton.com Paletton] - website to choose color palettes
** [http://colorbrewer2.org/ ColorBrewer] - website to choose colors for maps and graphics
** Tina Sutton, Bride M Whelan: The Complete Color Harmony. Rockport Publishers (2004). ISBN 978-1592530311 (recommended in the mailing list)
{{Getting started navbox}}[[Category:Color]][[Category:Graphics]]