From Wiki
Revision as of 20:50, 15 June 2015 by Adityam (talk | contribs) (Copying the new page from colors/sandbox)
Jump to navigation Jump to search

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.


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


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

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


Basic Usage

To color text, use

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


   ... text ... 

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


\input tufte

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
  • To color the footnotes red, use


Disable color

If you want to disable colors in a document, use


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


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
ema \usecolors[ema] colo-imp-ema.mkiv 549 Emacs 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.

For example,

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

For example,

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.

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


For example

    [location=low, frame=off, background=color, backgroundcolor=highlight]

This is a \important{important}word.

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


For example,


Changing background color of page

The background color of the page can be changed using


For example,



Using colors in MetaPost

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

\color[highlight]{Highlighted text in TeX}

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

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 ...)


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,


For example,


Testing if color is defined

To test if a color is defined, use


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

Specialized topics

Template:Getting started navbox