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.
= Warning 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
It is also possible to use RGB or CMYK or hex values to color text. The syntax for these is
</texcode>
|
|<context mode=mkiv>\starttext
Three \colored[r=0.1, g=0.8, b=0.8]{colorful} cats
\stoptext
</context>
|}
etc.
= Disable = Changing color of entire document == To change the main text color of the document use <texcode>\setupcolors[textcolor=defined-color]</texcode> For example, {| ! width="45%"| ! width="10%"| ! width="45%"||-|<texcode>\setupcolors[textcolor=blue]\samplefile{tufte} </texcode>||<context>\setupcolors[textcolor=blue]\input tufte</context>|} == Changing background color of page == The background color of the page can be changed using<texcode>\setupbackgrounds[page][background=color,backgroundcolor=defined-color]</texcode> For example,{| ! width="45%"| ! width="10%"| ! width="45%"| |- | <texcode>\setuppapersize[A8, landscape]\setupbackgrounds[page][background=color,backgroundcolor=blue]\setupcolors[textcolor=white] \starttext\input ward\stoptext</texcode>||<context>\setuppapersize[A8, landscape]\setupbackgrounds[page][background=color,backgroundcolor=blue]\setupcolors[textcolor=white] \starttext\samplefile{ward}\stoptext</context>|} = Defining New Colors =
If you want to disable 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). New colors may be defined in the following ways {| class="wikitable"! Name !! Syntax (and Example) !! Explanation|-| style="width:20%;" | RGB color model| style="width:40%;" | <texcode>\definecolor[...][r=..., g=..., b=...]</texcode> For example,<texcode>\definecolor[lime][r=0.75, g=1, b=0] This is \color[lime]{a new color}that we defined</texcode>| The values for <code>r</code>, <code>g</code>, and <code>b</code> are floating point number between <code>0</code> and <code>1</code>. |-| CMYK color model| <texcode>\definecolor[...][c=.., m=.., y=.., k=..]</texcode> For example,<texcode>\definecolor[lime][c=0.25, m=0, y=1, k=0] This is \color[lime]{a new color}that we defined</texcode>| 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>. |-| HSV/HSL color model|<texcode>\definecolor[...][h=.., s=.., v=..]</texcode> For example,<texcode>\definecolor[lime][h=75, s=1, v=1] This is \color[lime]{a new color}that we defined</texcode>| 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>. |-| HWB color model|<texcode>\definecolor[...][h=.., w=.., b=..]</texcode> For example,<texcode>\definecolor[something][h=75, w=0.5, b=.1] This is \color[something]{a new color}that we defined</texcode>| 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 documentnew color}that we defined</texcode>| The value for <code>x</code> is a three-byte hexadecimal number where the bytes represent the red, usegreen, and blue values. This follows the HTML and CSS style of defining colors.|-|Gray scale|<texcode>\setupcolorsdefinecolor[...][states=stop...]</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).|} == Cloning existing colors == You can ''clone'' an existing color using<texcode>\definecolor[new-color][old-color]</texcode> For example{|| width="45%"| <texcode>\usecolors[xwi]\definecolor[highlight][yellow]\defineframed [important] [location=low, frame=off, background=color, backgroundcolor=highlight] This is an \important{important}word. \definecolor[highlight][lavenderblush]This is a \important{important}word.</texcode>| width="10%"|| width="45%"| <context mode=mkiv>\usecolors[xwi]\definecolor[highlight][yellow]\defineframed[important][location=low, frame=off, background=color, backgroundcolor=highlight] This is an \important{important}word. \definecolor[highlight][lavenderblush]This is an \important{important}word.</context>|} == Adapting existing colors == {{todo | add details about this}}
= Pre-defined colors =
== Default pre-defined colors ==
The following colors are pre-defined in ConTeXt (see {{src|colo-imp-rgb.mkiv}}).
| 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.
|}
'''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 color is defined Tips and Tricks =
To test if == Calculating RGB Values == An example of how to use LMTX to calculate RGB values is the following: <texcode>% Use a color picker to get red, green and blue values of a color is defined:% Example: RAL 2005: red = 255, green = 35, blue = 1% Create variables from the values: \setvariables[ColorName][r=255,g=35, useb=1] % Do some magic: \usemodule[mathfun] % Define the actual color based 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: \setvariables[ColorName][r=255,g=35,b=1] % Do some magic: \usemodule[mathfun] % Define the actual color based on variables: \definecolor[ColorName][% r={\mathexpr[.3N]{\getvariable{ColorName}{r}/255}}, g={\mathexpr[.3N]{\getvariable{ColorName}{g}/255}}, b={\mathexpr[.3N]{\getvariable{ColorName}{b}/255}},]% % Test it: \startTEXpage[offset=5mm] \framed[foregroundcolor=white, background=color, backgroundcolor=ColorName]{Hello WORLD!} \\\colorcomponents{ColorName}\stopTEXpage</context>
* [[Color/Palet|Color Palettes]]* [[Color/Transparency|Transparency]] * [[Color/Spot_Colors|Spot Colors]]= 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]]