Difference between revisions of "Color"

From Wiki
Jump to navigation Jump to search
m (Moved to a separate page)
m
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
< [[Visuals]] | [[Graphics]] >
+
{{Color navbox}}
 +
 
 +
 
 +
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.
  
= Enabling colors =
+
= Before you start ... =  
  
In current versions (newer than 11.05.2009) of ConTeXt mkiv, colors are enabled by default.
+
1. It is usually a bad style to use explicit color switches in the text. It is 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]
 +
</texcode>
 +
and then use <code>\important{important text}</code> in the text.
  
In older versions, colors must be enabled using
+
2. Colors are not enabled by default in MkII. To enabled colors in MkII, use
    {{cmd|setupcolors}}<tt>[state=start]</tt>
+
<texcode>\setupcolors[state=start]</texcode>
  
= Defining Colors =
+
3. To disable colors in a document, use
 +
<texcode>\setupcolors[state=stop]</texcode>
  
== Choosing a color model ==
+
= Basic Usage =
  
* RGB and CMYK are enabled by default. If you want only RGB or only CMYK color, use <tt>cmyk=no</tt> or <tt>rgb=no</tt>. Multitone colors see below.
 
* For spot colors, say spot=yes. To eliminate everything except spot colours, leaving a clean file for professional printing, accompany this with rgb=no,cmyk=no. See spot colours below for more details.
 
* Normally all colors are defined in RGB ''and'' CMYK and get converted if needed.
 
  
 +
To color text, use
  
== Using predefined colors: {{cmd|setupcolor}} ==
+
<texcode>\color[defined-color]{ ... text ... }</texcode>
  
Colors have identifiers, some of which are grouped in more or less
+
or  
widely known sets. The primary example of these possibly are the
 
[http://www.w3.org/TR/2002/WD-css3-color-20020219/#x11-color named colors of the X Windowing System],
 
a set of RGB vectors.
 
With the growth of the WWW this list of definitions eventually achieved
 
the rank of the default ''Web colors''.
 
For convenience the X11 colors, along with a couple others, are
 
pre-defined in Context in the form of a loadable module.
 
  
''NB'': there are two sets representing the web colors:
+
<texcode>\startcolor[defined-color]
<code>xwi</code> and <code>x11</code>. The main difference between them
+
  ... text ...  
is that the latter defines variations for many keywords.
+
\stopcolor</texcode>
For instance, instead of having only one color ''deepskyblue'' with
 
<code>xwi</code>, you get another four colors ''deepskyblue1'',
 
''deepskyblue2'' ''deepskyblue3'' and ''deepskyblue4'' with the
 
<code>x11</code> set.
 
(Another technical aspect is that the latter are specified using
 
hexadecimal RGB values whereas the former rely on decimal values.)
 
  
To use them and any of the others listed below, pass the respective
+
where <code>defined-color</code> is a color defined using {{cmd|definecolor}}. For example, <code>red</code> is one of the predefined colors. So, we can use:
definition identifier to {{cmd|setupcolor}}:
 
  
<texcode>
+
{|
\setupcolor[x11]
+
! width="45%"|
 +
! width="10%"|
 +
! width="45%"|
 +
|-
 +
| <texcode>
 +
Three \color[red]{cool} cats
 
</texcode>
 
</texcode>
 +
|
 +
|<context mode=mkiv>
 +
\starttext
 +
Three \color[red]{cool} cats
 +
\stoptext
 +
</context>
 +
|}
  
The macro {{cmd|showcolor}} pretty prints a the list of all named
+
or
colors in a definition set.
 
  
<context mode="mkiv" source="yes" text="yields several pages of this:">
+
{|
\showcolor[rgb]
+
! width="45%"|
 +
! width="10%"|
 +
! width="45%"|
 +
|-
 +
| <texcode>
 +
\starttext
 +
\startcolor[red]
 +
\input tufte
 +
\stopcolor
 +
\stoptext
 +
</texcode>
 +
|
 +
|<context mode=mkiv>
 +
\setuppapersize[A5]
 +
\starttext
 +
\startcolor[red]
 +
\input tufte
 +
\stopcolor
 +
\stoptext
 
</context>
 
</context>
 +
|}
  
=== MkIV ===
+
It is also possible to use RGB or CMYK or hex values to color text. The syntax for these is
 +
<texcode>\colored[settings]{... text ...}</texcode>
 +
where <code>settings</code> are the same settings as used by {{cmd|definecolor}}. For example:
  
The definitions reside in the files prefixed <code>colo-imp-</code>, to
 
separate them from the color functionality that is implemented in
 
<code>colo-xxx.mkiv</code>.
 
  
 
{|
 
{|
! id !! source !! description
+
! width="45%"|
 +
! width="10%"|
 +
! width="45%"|
 +
|-
 +
| <texcode>
 +
Three \colored[r=0.1, g=0.8, b=0.8]{colorful} cats
 +
</texcode>
 +
|
 +
|<context mode=mkiv>
 +
\starttext
 +
Three \colored[r=0.1, g=0.8, b=0.8]{colorful} cats
 +
\stoptext
 +
</context>
 +
|}
 +
 
 +
 
 +
'''Note'''. There is no need to use the color commands directly. Almost all ConTeXt commands accept a <code>color</code> key, and you can use <code>color=defined-color</code>. For example,
 +
 
 +
* To color the section titles red, use
 +
<texcode>\setuphead[color=red]</texcode>
 +
 
 +
* To color the footnotes red, use
 +
<texcode>\setupfootnotes[color=red]</texcode>
 +
 
 +
etc.
 +
 
 +
 
 +
= Pre-defined colors =
 +
 
 +
 
 +
== Default pre-defined colors ==
 +
 
 +
The following colors are pre-defined in ConTeXt (see {{src|colo-imp-rgb.mkiv}}).
 +
 
 +
 
 +
{| style="text-align: right; padding-right: 20px;"
 +
!| Name !! Color
 +
!style="width: 80px;"| Name !! Color
 +
!style="width: 100px;"| Name !! Color
 +
!style="width: 100px;"| Name !! Color
 
|-
 
|-
| rgb || {{src|colo-imp-rgb.mkiv}} || some simple colors, loaded by default (with translations for the different interface languages!)
+
|black||bgcolor="#000"| &nbsp;
 +
|white||bgcolor="#FFF"| &nbsp;
 
|-
 
|-
| xwi || {{src|colo-imp-xwi.mkiv}}
+
|gray||bgcolor="#E6E6E6"| &nbsp;
| Xorg color keywords (WWW), defined in decimal RGB
+
|lightgray||bgcolor="#D6D6D6"| &nbsp;
 +
|middlegray||bgcolor="#B9B9B9"| &nbsp;
 +
|darkgray||bgcolor="#999999"| &nbsp;
 +
|-  
 +
|red||bgcolor="#FF0000"| &nbsp;
 +
|lightred||bgcolor="#FF0000"| &nbsp;
 +
|middlered||bgcolor="#CC0000"| &nbsp;
 +
|darkred||bgcolor="#990000"| &nbsp;
 
|-
 
|-
| x11 || {{src|colo-imp-x11.mkiv}}
+
|green||bgcolor="#00FF00"| &nbsp;
| extended Xorg color keywords (WWW), defined in hex RGB
+
|lightgreen||bgcolor="#00FF00"| &nbsp;
 +
|middlegreen||bgcolor="#00CC00"| &nbsp;
 +
|darkgreen||bgcolor="#009900"| &nbsp;
 
|-
 
|-
| ema || {{src|colo-imp-ema.mkiv}} || Emacs colors
+
|blue||bgcolor="#0000FF"| &nbsp;
 +
|lightblue||bgcolor="#0000FF"| &nbsp;
 +
|middleblue||bgcolor="#0000CC"| &nbsp;
 +
|darkblue||bgcolor="#000099"| &nbsp;
 
|-
 
|-
| dem || {{src|colo-imp-dem.mkiv}}
+
|cyan||bgcolor="#00FFFF" | &nbsp;
| color groups and palets for different language interfaces
+
| &nbsp; ||bgcolor=| &nbsp;
 +
|middlecyan||bgcolor="#00CCCC" | &nbsp;
 +
|darkcyan||bgcolor="#006666" | &nbsp;
 +
|-
 +
|magenta||bgcolor="#FF00FF" | &nbsp;
 +
| &nbsp; ||bgcolor=| &nbsp;
 +
|middlemagenta||bgcolor="CC00CC" | &nbsp;
 +
|darkmagenta||bgcolor="660066" | &nbsp;
 +
|-
 +
|yellow||bgcolor="#FFFF00" | &nbsp;
 +
| &nbsp; ||bgcolor=| &nbsp;
 +
|middleyellow||bgcolor="CCCC00" | &nbsp;
 +
|darkyellow||bgcolor="666600" | &nbsp;
 +
 
 
|}
 
|}
  
=== MkII ===
+
== X11 Colors ==
 +
 
 +
In addition to the above basic color, ConTeXt also includes a definition of the [http://www.w3.org/TR/2002/WD-css3-color-20020219/#x11-color X11 colors]. To load this list ({{src|colo-imp-xwi.mkiv}}), use
 +
 
 +
<texcode>\usecolors[xwi]</texcode>
 +
 
 +
This loads the following additional colors:
  
You will find lists of predefined colors in the files
+
{| style="text-align: right; padding-right: 20px;"
<tt>colo-xxx.mkii</tt>, load them with
+
!| Name !! Color
{{cmd|setupcolor}}<tt>[xxx]</tt>.
+
!style="width: 80px;"| Name !! Color
{|
+
!style="width: 100px;"| Name !! Color
! id !! source !! description
+
!style="width: 100px;"| Name !! Color
 +
|-
 +
|-
 +
|aliceblue||bgcolor="#EFF7FF"|&nbsp;
 +
|antiquewhite||bgcolor="#F9EAD6"|&nbsp;
 +
|aquamarine||bgcolor="#7FFFD3"|&nbsp;
 +
|azure||bgcolor="#EFFFFF"|&nbsp;
 +
|-
 +
|beige||bgcolor="#F4F4DB"|&nbsp;
 +
|bisque||bgcolor="#FFE2C4"|&nbsp;
 +
|black||bgcolor="#000000"|&nbsp;
 +
|blanchedalmond||bgcolor="#FFEACC"|&nbsp;
 +
|-
 +
|blue||bgcolor="#0000FF"|&nbsp;
 +
|blueviolet||bgcolor="#892BE2"|&nbsp;
 +
|brown||bgcolor="#A52828"|&nbsp;
 +
|burlywood||bgcolor="#DDB787"|&nbsp;
 +
|-
 +
|cadetblue||bgcolor="#5E9EA0"|&nbsp;
 +
|chartreuse||bgcolor="#7FFF00"|&nbsp;
 +
|chocolate||bgcolor="#D1681E"|&nbsp;
 +
|coral||bgcolor="#FF7F4F"|&nbsp;
 +
|-
 +
|cornflowerblue||bgcolor="#6393ED"|&nbsp;
 +
|cornsilk||bgcolor="#FFF7DB"|&nbsp;
 +
|cyan||bgcolor="#00FFFF"|&nbsp;
 +
|darkgoldenrod||bgcolor="#B7870A"|&nbsp;
 +
|-
 +
|darkgreen||bgcolor="#006300"|&nbsp;
 +
|darkkhaki||bgcolor="#BCB76B"|&nbsp;
 +
|darkolivegreen||bgcolor="#546B2D"|&nbsp;
 +
|darkorange||bgcolor="#FF8C00"|&nbsp;
 +
|-
 +
|darkorchid||bgcolor="#9933CC"|&nbsp;
 +
|darksalmon||bgcolor="#E8967A"|&nbsp;
 +
|darkseagreen||bgcolor="#8EBC8E"|&nbsp;
 +
|darkslateblue||bgcolor="#473D8C"|&nbsp;
 +
|-
 +
|darkturquoise||bgcolor="#00CED1"|&nbsp;
 +
|darkviolet||bgcolor="#9300D3"|&nbsp;
 +
|deeppink||bgcolor="#FF1493"|&nbsp;
 +
|deepskyblue||bgcolor="#00BFFF"|&nbsp;
 +
|-
 +
|dodgerblue||bgcolor="#1E8EFF"|&nbsp;
 +
|firebrick||bgcolor="#B22121"|&nbsp;
 +
|floralwhite||bgcolor="#FFF9EF"|&nbsp;
 +
|forestgreen||bgcolor="#218C21"|&nbsp;
 +
|-
 +
|gainsboro||bgcolor="#DBDBDB"|&nbsp;
 +
|ghostwhite||bgcolor="#F7F7FF"|&nbsp;
 +
|gold||bgcolor="#FFD600"|&nbsp;
 +
|goldenrod||bgcolor="#D8A521"|&nbsp;
 +
|-
 +
|green||bgcolor="#00FF00"|&nbsp;
 +
|greenyellow||bgcolor="#ADFF2D"|&nbsp;
 +
|honeydew||bgcolor="#EFFFEF"|&nbsp;
 +
|hotpink||bgcolor="#FF68B5"|&nbsp;
 +
|-
 +
|indianred||bgcolor="#CC5B5B"|&nbsp;
 +
|ivory||bgcolor="#FFFFEF"|&nbsp;
 +
|khaki||bgcolor="#EFE58C"|&nbsp;
 +
|lavender||bgcolor="#E5E5F9"|&nbsp;
 +
|-
 +
|lavenderblush||bgcolor="#FFEFF4"|&nbsp;
 +
|lawngreen||bgcolor="#7CFC00"|&nbsp;
 +
|lemonchiffon||bgcolor="#FFF9CC"|&nbsp;
 +
|lightblue||bgcolor="#ADD8E5"|&nbsp;
 +
|-
 +
|lightcoral||bgcolor="#EF7F7F"|&nbsp;
 +
|lightcyan||bgcolor="#E0FFFF"|&nbsp;
 +
|lightgoldenrod||bgcolor="#EDDD82"|&nbsp;
 +
|lightgoldenrodyellow||bgcolor="#F9F9D1"|&nbsp;
 +
|-
 +
|lightpink||bgcolor="#FFB5C1"|&nbsp;
 +
|lightsalmon||bgcolor="#FFA07A"|&nbsp;
 +
|lightseagreen||bgcolor="#21B2AA"|&nbsp;
 +
|lightskyblue||bgcolor="#87CEF9"|&nbsp;
 +
|-
 +
|lightslateblue||bgcolor="#8470FF"|&nbsp;
 +
|lightsteelblue||bgcolor="#AFC4DD"|&nbsp;
 +
|lightyellow||bgcolor="#FFFFE0"|&nbsp;
 +
|limegreen||bgcolor="#33CC33"|&nbsp;
 +
|-
 +
|linen||bgcolor="#F9EFE5"|&nbsp;
 +
|magenta||bgcolor="#FF00FF"|&nbsp;
 +
|maroon||bgcolor="#AF3060"|&nbsp;
 +
|mediumaquamarine||bgcolor="#66CCAA"|&nbsp;
 +
|-
 +
|mediumblue||bgcolor="#0000CC"|&nbsp;
 +
|mediumorchid||bgcolor="#BA54D3"|&nbsp;
 +
|mediumpurple||bgcolor="#9370DB"|&nbsp;
 +
|mediumseagreen||bgcolor="#3DB270"|&nbsp;
 +
|-
 +
|mediumslateblue||bgcolor="#7A68ED"|&nbsp;
 +
|mediumspringgreen||bgcolor="#00F999"|&nbsp;
 +
|mediumturquoise||bgcolor="#47D1CC"|&nbsp;
 +
|mediumvioletred||bgcolor="#C61484"|&nbsp;
 +
|-
 +
|midnightblue||bgcolor="#191970"|&nbsp;
 +
|mintcream||bgcolor="#F4FFF9"|&nbsp;
 +
|mistyrose||bgcolor="#FFE2E0"|&nbsp;
 +
|moccasin||bgcolor="#FFE2B5"|&nbsp;
 +
|-
 +
|navajowhite||bgcolor="#FFDDAD"|&nbsp;
 +
|navy||bgcolor="#00007F"|&nbsp;
 +
|navyblue||bgcolor="#00007F"|&nbsp;
 +
|oldlace||bgcolor="#FCF4E5"|&nbsp;
 +
|-
 +
|olivedrab||bgcolor="#6B8E23"|&nbsp;
 +
|orange||bgcolor="#FFA500"|&nbsp;
 +
|orangered||bgcolor="#FF4400"|&nbsp;
 +
|orchid||bgcolor="#D870D6"|&nbsp;
 +
|-
 +
|palegoldenrod||bgcolor="#EDE8AA"|&nbsp;
 +
|palegreen||bgcolor="#99F999"|&nbsp;
 +
|paleturquoise||bgcolor="#AFEDED"|&nbsp;
 +
|palevioletred||bgcolor="#DB7093"|&nbsp;
 +
|-
 +
|papayawhip||bgcolor="#FFEFD6"|&nbsp;
 +
|peachpuff||bgcolor="#FFD8BA"|&nbsp;
 +
|peru||bgcolor="#CC843F"|&nbsp;
 +
|pink||bgcolor="#FFBFCC"|&nbsp;
 +
|-
 +
|plum||bgcolor="#DDA0DD"|&nbsp;
 +
|powderblue||bgcolor="#AFE0E5"|&nbsp;
 +
|purple||bgcolor="#A021EF"|&nbsp;
 +
|red ||bgcolor="#FF0000"|&nbsp;
 +
|-
 +
|rosybrown||bgcolor="#BC8E8E"|&nbsp;
 +
|royalblue||bgcolor="#3F68E0"|&nbsp;
 +
|saddlebrown||bgcolor="#8C4411"|&nbsp;
 +
|salmon||bgcolor="#F97F72"|&nbsp;
 
|-
 
|-
| rgb || {{src|colo-rgb.mkii}} || some simple colors, loaded by default (with translations for the different interface languages!)
+
|sandybrown||bgcolor="#F4A360"|&nbsp;
 +
|seagreen||bgcolor="#2D8C56"|&nbsp;
 +
|seashell||bgcolor="#FFF4ED"|&nbsp;
 +
|sienna||bgcolor="#A0512D"|&nbsp;
 
|-
 
|-
| x11 || {{src|colo-x11.mkii}} || Xorg-colors (hex)
+
|skyblue||bgcolor="#87CEEA"|&nbsp;
 +
|slateblue||bgcolor="#6B59CC"|&nbsp;
 +
|snow||bgcolor="#FFF9F9"|&nbsp;
 +
|springgreen||bgcolor="#00FF7F"|&nbsp;
 
|-
 
|-
| xwi || {{src|colo-xwi.mkii}}  || Xorg-colors (decimal)
+
|steelblue||bgcolor="#4482B5"|&nbsp;
 +
|tan ||bgcolor="#D1B58C"|&nbsp;
 +
|thistle||bgcolor="#D8BFD8"|&nbsp;
 +
|tomato||bgcolor="#FF6347"|&nbsp;
 
|-
 
|-
| pra || {{src|colo-???.mkii|link=no}}
+
|turquoise||bgcolor="#3FE0D1"|&nbsp;
| PRAGMA ADE corporate design (not included in the distribution?)
+
|violet||bgcolor="#ED82ED"|&nbsp;
 +
|violetred||bgcolor="#D1218E"|&nbsp;
 +
|wheat||bgcolor="#F4DDB2"|&nbsp;
 
|-
 
|-
| ema || {{src|colo-ema.mkii}} || Emacs colors
+
|white||bgcolor="#FFFFFF"|&nbsp;
 +
|whitesmoke||bgcolor="#F4F4F4"|&nbsp;
 +
|yellow||bgcolor="#FFFF00"|&nbsp;
 +
|yellowgreen||bgcolor="#99CC33"|&nbsp;
 
|}
 
|}
  
=== Alternatives ===
+
== Additional pre-defined colors ==
  
You can generate an alternative definition set based on the results of
+
In addition to the above, there are two other sets of pre-defined colors.
the [http://blog.xkcd.com/2010/05/03/color-survey-results/ xkcd color survey]
+
 
with the
+
{| class="wikitable"
[https://bitbucket.org/phg/xcs-colors <code>xcs-colors.lua</code> script].
+
| x11 || <code>\usecolors[x11]</code>
 +
| {{src|colo-imp-x11.mkiv}}
 +
| 658 extended Xorg color keywords (WWW), defined in hex RGB
 +
|-
 +
| crayola || <code>\usecolors[crayola] </code>
 +
| {src|colo-imp-crayola.mkiv} || 235 Crayola (Binney & Smith) colors
 +
|-
 +
| ema || <code>\usecolors[ema]</code>
 +
| {{src|colo-imp-ema.mkiv}} || 549 Emacs colors
 +
|-
 +
| RAL || <code>\usecolors[ral]</code>
 +
| {{src|colo-imp-ral.mkiv}} || 213 RAL color system (Deutsches Institut für Gütesicherung und Kennzeichnung)
 +
|-
 +
| Solarized || <code>\usecolors[solarized]</code>
 +
| {{src|colo-imp-solarized.mkiv}} || 16 solarized colors
 +
|}
  
== Defining colors: {{cmd|definecolor}} ==
 
  
{{cmd|definecolor}}<tt>[blablue][r=.1, g=.1, b=1, c=1, m=.1, y=0, k=0, s=.2]</tt> (definition for RGB, CMYK and Grey!).
+
= Defining New Colors =
See also [[Command/definecolor]].
 
  
 +
New colors may be defined in the following ways
  
{|
+
{| class="wikitable"
! width="45%"|
+
! Name !! Sytanx (and Example) !! Explanation
! width="10%"|
+
|-
! width="45%"|
+
| RGB color model
|-
+
| <texcode>\definecolor[...][r=..., g=..., b=...]</texcode>  
| <texcode>
+
For example,
\definecolor[blablue][r=.25, g=.1, b=1, c=1, m=.1, y=0, k=0, s=.2]
+
<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 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> 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).
 +
|}
  
Here's some \color[blablue]{blue text} inbetween!
+
'''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.
</texcode>
 
|
 
| <context>
 
\setupcolors[state=start]
 
\definecolor[blablue][r=.1, g=.1, b=1, c=1, m=.1, y=0, k=0, s=.2]
 
  
Here's some \color[blablue]{blue text} inbetween!
+
== Cloning existing colors ==
</context>
 
|}
 
  
=== Colors with Hexadecimal Numbers ===
+
You can ''clone'' an existing color using
 +
<texcode>\definecolor[new-color][old-color]</texcode>
  
You can also use hexadecimal numers to specify colors. You need to load the '''hex''' color module first:
+
For example
 
{|
 
{|
 
  ! width="45%"|
 
  ! width="45%"|
 
  ! width="10%"|
 
  ! width="10%"|
 
  ! width="45%"|
 
  ! width="45%"|
|-
+
|<texcode>\usecolors[xwi]
| <texcode>
+
\definecolor[highlight][yellow]
\setupcolor[hex]
+
\defineframed
\definecolor[salmon][h=AB5757]
+
    [important]
 +
    [location=low, frame=off, background=color, backgroundcolor=highlight]
 +
 
 +
This is a \important{important}word.
  
Hey, \color[salmon]{look at that!}
+
\definecolor[highlight][lavenderblush]
 +
This is a \important{important}word.
 
</texcode>
 
</texcode>
 
|
 
|
|<context>
+
|<context mode=mkiv>\usecolors[xwi]
\setupcolors[state=start]
+
\definecolor[highlight][yellow]
\setupcolor[hex]
+
\defineframed[important][location=low, frame=off, background=color, backgroundcolor=highlight]
\definecolor[salmon][h=AB5757]
+
 
 +
This is a \important{important}word.
  
Hey, \color[salmon]{look at that!}
+
\definecolor[highlight][lavenderblush]
 +
This is a \important{important}word.
 
</context>
 
</context>
 
|}
 
|}
  
 +
== Adapting existing colors ==
  
 +
{{todo | add details about this}}
  
=Choosing a color scheme=
+
= Advanced Usage =
 
 
There are three basic strategies to select color combinations for a particular design
 
 
 
# Create a color scheme by picking several colors found within the objects to be used (photographs, pictures, etc)
 
# Create colors derived from those found in the objects to be used
 
# Create a color scheme based on the message to convey / the psychological effects of color
 
  
See for additional help & reference:
+
== Changing color of entire document ==
* [http://colorschemedesigner.com/ colorschemedesigner.com] - Useful site to help choose a color scheme in rgb color space
 
* Tina Sutton, Bride M Whelan: The Complete Color Harmony. Rockport Publishers (2004). ISBN 978-1592530311 (recommanded in the mailing list)
 
  
 +
To change the main text color of the document use
  
=Using Colors=
+
<texcode>\setupcolors[textcolor=defined-color]</texcode>
  
* Use the color name like <tt>[color=blablue]</tt> in some <tt>\setup...</tt> command.
+
For example,
 
 
== With text ==
 
 
 
Typeset single text elements with {{cmd|color}}<tt>[colorname]{nice blue text}</tt>:
 
  
 
{|
 
{|
Line 178: Line 456:
 
  ! width="10%"|
 
  ! width="10%"|
 
  ! width="45%"|
 
  ! width="45%"|
|-
+
|-
| <texcode>
+
|<texcode>\setupcolors[textcolor=blue]
Three \color[red]{cool} cats
 
</texcode>
 
|
 
|<context>
 
\setupcolors[state=start]
 
 
\starttext
 
\starttext
Three \color[red]{cool} cats
+
text
 
\stoptext
 
\stoptext
</context>
 
|}
 
 
Alternatively, typeset text elements with {{cmd|colored}}<tt>[rgb values]{colored text}</tt> (suggested on NTG-ConTeXt: [http://www.ntg.nl/pipermail/ntg-context/2010/046563.html]):
 
 
{|
 
! width="45%"|
 
! width="10%"|
 
! width="45%"|
 
|-
 
| <texcode>
 
Three \colored[r=.4, g=.4, b=.9]{colorful} kittens.
 
 
</texcode>
 
</texcode>
 
|
 
|
|<context>
+
|<context mode=mkiv>
\setupcolors[state=start]
+
\setupcolors[textcolor=blue]
 
\starttext
 
\starttext
Three \colored[r=.4, g=.4, b=.9]{colorful} kittens.
+
text
 
\stoptext
 
\stoptext
 
</context>
 
</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>
  
Typeset longer sections with {{cmd|startcolor}}<tt>[colorname] ...</tt> {{cmd|stopcolor}}:
 
  
 +
For example,
 
{|
 
{|
 
  ! width="45%"|
 
  ! width="45%"|
Line 219: Line 484:
 
  |-
 
  |-
 
  | <texcode>
 
  | <texcode>
\setuppapersize[A6]
+
\setuppapersize[A10]
 +
\setupbackgrounds[page][background=color,backgroundcolor=blue]
 +
 
 
\starttext
 
\starttext
\startcolor[orange]
+
text
\input tufte
 
\stopcolor
 
 
\stoptext
 
\stoptext
 
</texcode>
 
</texcode>
 
|
 
|
 
|<context>
 
|<context>
\setuppapersize[A6]
+
\setuppapersize[A10]
 
\setupcolors[state=start]
 
\setupcolors[state=start]
 +
 +
\setupbackgrounds[page][background=color,backgroundcolor=blue]
 +
 
\starttext
 
\starttext
\startcolor[orange]
+
text
\input tufte
 
\stopcolor
 
 
\stoptext
 
\stoptext
 
</context>
 
</context>
 
|}
 
|}
  
== In titles ==
 
  
See [[Titles#Using_colors_in_chapters_and_sections]]
 
  
== With frames ==
+
 
 +
== Using colors in MetaPost ==
 +
 
 +
A color defined in TeX is available in MetaPost using `\MPcolor{...}`. For example:
  
 
{|
 
{|
! width="45%"|
+
|-
! width="10%"|
+
|<texcode>
! width="45%"|
+
\definecolor[highlight][r=0.8,g=0.8,b=0]
|-
+
\starttext
| <texcode>
+
\color[highlight]{Highlighted text in TeX}
\framed[background=color, backgroundcolor=green]{bla}
+
 
\framed[background=color, backgroundcolor=yellow, corner=00]{bla}
+
\startMPcode
 +
label("Highlighted text in MetaPost", origin)
 +
    withcolor \MPcolor{highlight};
 +
\stopMPcode
 
</texcode>
 
</texcode>
|
+
|<context mode=mkiv>
|<context>
+
\definecolor[highlight][r=0.8,g=0.8,b=0]
\setupcolors[state=start]
+
\starttext
 +
\color[highlight]{Highlighted text in TeX}
  
\starttext
+
\startMPcode
\framed[background=color, backgroundcolor=green]{bla}
+
label("Highlighted text in MetaPost", origin)
\framed[background=color, backgroundcolor=yellow, corner=00]{bla}
+
    withcolor \MPcolor{highlight};
 +
\stopMPcode
 
</context>
 
</context>
 
|}
 
|}
  
== Background of the page ==
+
Note that `\MPcolor{...}` behaves similar to a `color` primitive in MetaPost. For example, the following is valid MetaPost code.
 +
<texcode>color myColor; myColor = 0.5[\MPcolor{highlight}, white];</texcode>
 +
 
 +
 
 +
== Using colors in TikZ ==
  
{|
+
= Viewing pre-defined color =
! width="45%"|
 
! width="10%"|
 
! width="45%"|
 
|-
 
| <texcode>
 
\setuppapersize[A10]
 
\setupbackgrounds[page][background=color,backgroundcolor=blue]
 
  
\starttext
+
== View all defined colors ==
text
 
\stoptext
 
</texcode>
 
|
 
|<context>
 
\setuppapersize[A10]
 
\setupcolors[state=start]
 
  
\setupbackgrounds[page][background=color,backgroundcolor=blue]
+
To view pre-defined colors, you can use {{cmd|showcolor}}. For example, to see all the colors defined in {{src|colo-imp-x11.mkiv}}, use (output truncated for display here ...)
  
\starttext
+
{|
text
+
|-
\stoptext
+
|<texcode>\showcolor[x11]</texcode>
</context>
+
|<context mode=mkiv>\startTEXpage[height=5cm]\showcolor[x11]\stopTEXpage</context>
 
|}
 
|}
  
== Background of cells in tables ==
+
If you use {{cmd|showcolor}} without any argument, all currently defined colors are shown.
 +
 
 +
== View specific defined colors ==
 +
 
 +
To view the components of a defined color, you can use:
  
See
+
* {{cmd|showcolorcomponents}}
* [[Table#Background Colors]]
+
<texcode>\showcolorcomponents[color-1, color-2]</texcode>
* [[TABLE#Round_corners]]
 
  
== In Metapost ==
+
For example,
  
Metapost in MkIV is different from MkII and all labels are typeset
+
{|
and colored in TeX, if you want a label use
+
|-
  label(textext("\blue RED"),origin) ;
+
|<texcode>\showcolorcomponents[red,middlered,darkred]</texcode>
 +
|<context mode=mkiv>\showcolorcomponents[red,middlered,darkred]</context>
 +
|}
  
== In TikZ ==
+
* {{cmd|colorcomponents}}
 +
* {{cmd|transparencycomponents}}
 +
* {{cmd|processcolorcomponents}}
 +
<texcode>\colorcompoents{defined-color}
 +
\tranparencycomponents{defined-color}
 +
\processcolorcomponents{defined-color}
 +
</texcode>
  
 +
For example,
 
{|
 
{|
! width="45%"|
+
|-
! width="10%"|
+
|<texcode>
! width="45%"|
+
\startlines
|-
+
\colorcomponents{red}
| <texcode>
+
\transparencycomponents{red}
\usemodule[tikz]
+
\processcolorcomponents{red}
\starttext
+
\stoplines
\tikz\shade[ball color=red!40!yellow] (0,0) circle (.15cm);
 
\stoptext
 
 
</texcode>
 
</texcode>
 
|
 
|
|<context>
+
<context mode=mkiv>
\setupcolors[state=start]
+
\startlines
\usemodule[tikz]
+
\colorcomponents{red}
\starttext
+
\transparencycomponents{red}
\tikz\shade[ball color=red!40!yellow] (0,0) circle (.15cm);
+
\processcolorcomponents{red}
\stoptext
+
\stoplines
 
</context>
 
</context>
 
|}
 
|}
  
 +
= Testing if color is defined =
 +
 +
To test if a color is defined, use
 +
 +
* {{cmd|doifcolor}}
 +
* {{cmd|doifcolorelse}}
 +
 +
Usage:
 +
 +
<texcode>
 +
\doifcolor{color-name}{... if branch ... }
 +
\doifcolorelse{color-name}{... if branch ...}{... else branch ...}
 +
</texcode>
 +
 +
= Specialized topics =
 +
 +
* [[Color/Palet|Color Palettes]]
 +
* [[Color/Transparency|Transparency]]
 +
* [[Color/Spot_Colors|Spot Colors]]
  
 
= References =
 
= References =
  
{{Color navbox}}
+
* [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 (recommanded in the mailing list)
 +
 
 +
 
  
 
{{Getting started navbox}}
 
{{Getting started navbox}}
 
[[Category:Graphics]]
 

Revision as of 05:00, 18 September 2018


ConTeXt supports two color models: RGB (typically used for screen display) and CMYK (typically used for printing). There is also support for spot colors (typically used for offset printing) and transparencies.

Before you start ...

1. It is usually a bad style to use explicit color switches in the text. It is better to define a semantic command that takes care of the color switching. For example, instead of using \color[red]{important text}, define

\definehighlight[important][color=red]

and then use \important{important text} in the text.

2. Colors are not enabled by default in MkII. To enabled colors in MkII, use

\setupcolors[state=start]

3. To disable colors in a document, use

\setupcolors[state=stop]

Basic Usage

To color text, use

\color[defined-color]{ ... text ... }

or

\startcolor[defined-color] 
   ... text ... 
\stopcolor

where defined-color is a color defined using \definecolor. For example, red is one of the predefined colors. So, we can use:

Three \color[red]{cool} cats

or

\starttext
\startcolor[red]
\input tufte
\stopcolor
\stoptext

It is also possible to use RGB or CMYK or hex values to color text. The syntax for these is

\colored[settings]{... text ...}

where settings are the same settings as used by \definecolor. For example:


Three \colored[r=0.1, g=0.8, b=0.8]{colorful} cats


Note. There is no need to use the color commands directly. Almost all ConTeXt commands accept a color key, and you can use color=defined-color. For example,

  • To color the section titles red, use
\setuphead[color=red]
  • To color the footnotes red, use
\setupfootnotes[color=red]

etc.


Pre-defined colors

Default pre-defined colors

The following colors are pre-defined in ConTeXt (see colo-imp-rgb.mkiv).


Name Color Name Color Name Color Name Color
black   white  
gray   lightgray   middlegray   darkgray  
red   lightred   middlered   darkred  
green   lightgreen   middlegreen   darkgreen  
blue   lightblue   middleblue   darkblue  
cyan       middlecyan   darkcyan  
magenta       middlemagenta   darkmagenta  
yellow       middleyellow   darkyellow  

X11 Colors

In addition to the above basic color, ConTeXt also includes a definition of the X11 colors. To load this list (colo-imp-xwi.mkiv), use

\usecolors[xwi]

This loads the following additional colors:

Name Color Name Color Name Color Name Color
aliceblue   antiquewhite   aquamarine   azure  
beige   bisque   black   blanchedalmond  
blue   blueviolet   brown   burlywood  
cadetblue   chartreuse   chocolate   coral  
cornflowerblue   cornsilk   cyan   darkgoldenrod  
darkgreen   darkkhaki   darkolivegreen   darkorange  
darkorchid   darksalmon   darkseagreen   darkslateblue  
darkturquoise   darkviolet   deeppink   deepskyblue  
dodgerblue   firebrick   floralwhite   forestgreen  
gainsboro   ghostwhite   gold   goldenrod  
green   greenyellow   honeydew   hotpink  
indianred   ivory   khaki   lavender  
lavenderblush   lawngreen   lemonchiffon   lightblue  
lightcoral   lightcyan   lightgoldenrod   lightgoldenrodyellow  
lightpink   lightsalmon   lightseagreen   lightskyblue  
lightslateblue   lightsteelblue   lightyellow   limegreen  
linen   magenta   maroon   mediumaquamarine  
mediumblue   mediumorchid   mediumpurple   mediumseagreen  
mediumslateblue   mediumspringgreen   mediumturquoise   mediumvioletred  
midnightblue   mintcream   mistyrose   moccasin  
navajowhite   navy   navyblue   oldlace  
olivedrab   orange   orangered   orchid  
palegoldenrod   palegreen   paleturquoise   palevioletred  
papayawhip   peachpuff   peru   pink  
plum   powderblue   purple   red  
rosybrown   royalblue   saddlebrown   salmon  
sandybrown   seagreen   seashell   sienna  
skyblue   slateblue   snow   springgreen  
steelblue   tan   thistle   tomato  
turquoise   violet   violetred   wheat  
white   whitesmoke   yellow   yellowgreen  

Additional pre-defined colors

In addition to the above, there are two other sets of pre-defined colors.

x11 \usecolors[x11] colo-imp-x11.mkiv 658 extended Xorg color keywords (WWW), defined in hex RGB
crayola \usecolors[crayola] colo-imp-crayola.mkiv} 235 Crayola (Binney & Smith) colors
ema \usecolors[ema] colo-imp-ema.mkiv 549 Emacs colors
RAL \usecolors[ral] colo-imp-ral.mkiv 213 RAL color system (Deutsches Institut für Gütesicherung und Kennzeichnung)
Solarized \usecolors[solarized] colo-imp-solarized.mkiv 16 solarized colors


Defining New Colors

New colors may be defined in the following ways

Name Sytanx (and Example) Explanation
RGB color model
\definecolor[...][r=..., g=..., b=...]

For example,

\definecolor[lime][r=0.75, g=1, b=0] 
This is \color[lime]{a new color}
that we defined
The values for r, g, and b are floating point number between 0 and 1.
CMYK color model
\definecolor[...][c=.., m=.., y=.., k=..]

For example,

\definecolor[lime][c=0.25, m=0, y=1, k=0] 
This is \color[lime]{a new color}
that we defined
The values for c, m, y and k are floating point number between 0 and 1.
HSV color model
\definecolor[...][h=.., s=.., v=..]

For example,

\definecolor[lime][h=75, s=1, v=1] 
This is \color[lime]{a new color}
that we defined
The value for h is between 0 and 360; the values for s, v are floating point numbers between 0 and 1.
Hex
\definecolor[...][h=...]

For example,

\definecolor[lime][h=BFFF00] 
This is \color[lime]{a new color}
that we defined
The value for x 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
\definecolor[...][s=...]

For example,

\definecolor[screen][g=0.5] 
This is \color[screen]{a new color}
that we defined
The value for s is a floating point number between 0 and 1, representing the grayness value (1 represents white, 0 represents black).

Note: The key-values are overloaded. For example, h is used for both HSV model and Hex model; s is used for both HSV model and grayscale model. The distinction is made based on the presence or absence of the v key.

Cloning existing colors

You can clone an existing color using

\definecolor[new-color][old-color]

For example

\usecolors[xwi]
\definecolor[highlight][yellow]
\defineframed
    [important]
    [location=low, frame=off, background=color, backgroundcolor=highlight]

This is a \important{important}word.

\definecolor[highlight][lavenderblush]
This is a \important{important}word.

Adapting existing colors


TODO: add details about this (See: To-Do List)


Advanced Usage

Changing color of entire document

To change the main text color of the document use

\setupcolors[textcolor=defined-color]

For example,

\setupcolors[textcolor=blue]
\starttext
text
\stoptext

Changing background color of page

The background color of the page can be changed using

\setupbackgrounds[page][background=color,backgroundcolor=defined-color]


For example,

\setuppapersize[A10]
\setupbackgrounds[page][background=color,backgroundcolor=blue]

\starttext
text
\stoptext



Using colors in MetaPost

A color defined in TeX is available in MetaPost using \MPcolor{...}. For example:

\definecolor[highlight][r=0.8,g=0.8,b=0]
\starttext
\color[highlight]{Highlighted text in TeX}

\startMPcode
label("Highlighted text in MetaPost", origin)
    withcolor \MPcolor{highlight};
\stopMPcode

Note that \MPcolor{...} behaves similar to a color primitive in MetaPost. For example, the following is valid MetaPost code.

color myColor; myColor = 0.5[\MPcolor{highlight}, white];


Using colors in TikZ

Viewing pre-defined color

View all defined colors

To view pre-defined colors, you can use \showcolor. For example, to see all the colors defined in colo-imp-x11.mkiv, use (output truncated for display here ...)

\showcolor[x11]

If you use \showcolor without any argument, all currently defined colors are shown.

View specific defined colors

To view the components of a defined color, you can use:

\showcolorcomponents[color-1, color-2]

For example,

\showcolorcomponents[red,middlered,darkred]
\colorcompoents{defined-color}
\tranparencycomponents{defined-color}
\processcolorcomponents{defined-color}

For example,

\startlines
\colorcomponents{red}
\transparencycomponents{red}
\processcolorcomponents{red}
\stoplines

Testing if color is defined

To test if a color is defined, use

Usage:

\doifcolor{color-name}{... if branch ... }
\doifcolorelse{color-name}{... if branch ...}{... else branch ...}

Specialized topics

References

  • Paletton - Website to choose color palettes
  • ColorBrewer - website to choose colors for maps and graphics.
  • Tina Sutton, Bride M Whelan: The Complete Color Harmony. Rockport Publishers (2004). ISBN 978-1592530311 (recommanded in the mailing list)


Template:Getting started navbox