Difference between revisions of "Color"
m (Material included in the new page) |
(Copying the new page from colors/sandbox) |
||
Line 1: | Line 1: | ||
− | + | {{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. | |
− | + | = Warning = | |
− | |||
− | = | + | 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. | ||
− | = | + | 2. Colors are not enabled by default in MkII. To enabled colors in MkII, use |
+ | <texcode>\setupcolors[state=start]</texcode> | ||
− | + | = Basic Usage = | |
− | |||
− | |||
− | |||
− | + | To color text, use | |
− | |||
− | |||
− | |||
− | + | <texcode>\color[defined-color]{ ... text ... }</texcode> | |
− | + | or | |
− | |||
+ | <texcode>\startcolor[defined-color] | ||
+ | ... text ... | ||
+ | \stopcolor</texcode> | ||
+ | |||
+ | 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: | ||
{| | {| | ||
Line 35: | Line 36: | ||
|- | |- | ||
| <texcode> | | <texcode> | ||
− | + | Three \color[red]{cool} cats | |
− | |||
− | |||
</texcode> | </texcode> | ||
| | | | ||
− | | <context> | + | |<context mode=mkiv> |
− | \ | + | \starttext |
− | + | Three \color[red]{cool} cats | |
− | + | \stoptext | |
− | |||
</context> | </context> | ||
|} | |} | ||
− | + | or | |
− | |||
{| | {| | ||
! width="45%"| | ! width="45%"| | ||
Line 57: | Line 54: | ||
|- | |- | ||
| <texcode> | | <texcode> | ||
− | \ | + | \starttext |
− | \ | + | \startcolor[red] |
− | + | \input tufte | |
− | + | \stopcolor | |
+ | \stoptext | ||
</texcode> | </texcode> | ||
| | | | ||
− | |<context> | + | |<context mode=mkiv> |
− | \ | + | \setuppapersize[A5] |
− | \ | + | \starttext |
− | \ | + | \startcolor[red] |
− | + | \input tufte | |
− | + | \stopcolor | |
+ | \stoptext | ||
</context> | </context> | ||
|} | |} | ||
+ | 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: | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
{| | {| | ||
Line 101: | Line 82: | ||
|- | |- | ||
| <texcode> | | <texcode> | ||
− | Three \ | + | Three \colored[r=0.1, g=0.8, b=0.8]{colorful} cats |
</texcode> | </texcode> | ||
| | | | ||
− | |<context> | + | |<context mode=mkiv> |
− | |||
\starttext | \starttext | ||
− | Three \ | + | Three \colored[r=0.1, g=0.8, b=0.8]{colorful} cats |
\stoptext | \stoptext | ||
</context> | </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. | ||
+ | |||
+ | = Disable color = | ||
+ | |||
+ | If you want to disable colors in a document, use | ||
+ | <texcode>\setupcolors[state=stop]</texcode> | ||
+ | |||
+ | = 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 | ||
+ | |- | ||
+ | |black||bgcolor="#000"| | ||
+ | |white||bgcolor="#FFF"| | ||
+ | |- | ||
+ | |gray||bgcolor="#E6E6E6"| | ||
+ | |lightgray||bgcolor="#D6D6D6"| | ||
+ | |middlegray||bgcolor="#B9B9B9"| | ||
+ | |darkgray||bgcolor="#999999"| | ||
+ | |- | ||
+ | |red||bgcolor="#FF0000"| | ||
+ | |lightred||bgcolor="#FF0000"| | ||
+ | |middlered||bgcolor="#CC0000"| | ||
+ | |darkred||bgcolor="#990000"| | ||
+ | |- | ||
+ | |green||bgcolor="#00FF00"| | ||
+ | |lightgreen||bgcolor="#00FF00"| | ||
+ | |middlegreen||bgcolor="#00CC00"| | ||
+ | |darkgreen||bgcolor="#009900"| | ||
+ | |- | ||
+ | |blue||bgcolor="#0000FF"| | ||
+ | |lightblue||bgcolor="#0000FF"| | ||
+ | |middleblue||bgcolor="#0000CC"| | ||
+ | |darkblue||bgcolor="#000099"| | ||
+ | |- | ||
+ | |cyan||bgcolor="#00FFFF" | | ||
+ | | ||bgcolor=| | ||
+ | |middlecyan||bgcolor="#00CCCC" | | ||
+ | |darkcyan||bgcolor="#006666" | | ||
+ | |- | ||
+ | |magenta||bgcolor="#FF00FF" | | ||
+ | | ||bgcolor=| | ||
+ | |middlemagenta||bgcolor="CC00CC" | | ||
+ | |darkmagenta||bgcolor="660066" | | ||
+ | |- | ||
+ | |yellow||bgcolor="#FFFF00" | | ||
+ | | ||bgcolor=| | ||
+ | |middleyellow||bgcolor="CCCC00" | | ||
+ | |darkyellow||bgcolor="666600" | | ||
+ | |||
+ | |} | ||
+ | |||
+ | == 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: | ||
+ | |||
+ | {| style="text-align: right; padding-right: 20px;" | ||
+ | !| Name !! Color | ||
+ | !style="width: 80px;"| Name !! Color | ||
+ | !style="width: 100px;"| Name !! Color | ||
+ | !style="width: 100px;"| Name !! Color | ||
+ | |- | ||
+ | |- | ||
+ | |aliceblue||bgcolor="#EFF7FF"| | ||
+ | |antiquewhite||bgcolor="#F9EAD6"| | ||
+ | |aquamarine||bgcolor="#7FFFD3"| | ||
+ | |azure||bgcolor="#EFFFFF"| | ||
+ | |- | ||
+ | |beige||bgcolor="#F4F4DB"| | ||
+ | |bisque||bgcolor="#FFE2C4"| | ||
+ | |black||bgcolor="#000000"| | ||
+ | |blanchedalmond||bgcolor="#FFEACC"| | ||
+ | |- | ||
+ | |blue||bgcolor="#0000FF"| | ||
+ | |blueviolet||bgcolor="#892BE2"| | ||
+ | |brown||bgcolor="#A52828"| | ||
+ | |burlywood||bgcolor="#DDB787"| | ||
+ | |- | ||
+ | |cadetblue||bgcolor="#5E9EA0"| | ||
+ | |chartreuse||bgcolor="#7FFF00"| | ||
+ | |chocolate||bgcolor="#D1681E"| | ||
+ | |coral||bgcolor="#FF7F4F"| | ||
+ | |- | ||
+ | |cornflowerblue||bgcolor="#6393ED"| | ||
+ | |cornsilk||bgcolor="#FFF7DB"| | ||
+ | |cyan||bgcolor="#00FFFF"| | ||
+ | |darkgoldenrod||bgcolor="#B7870A"| | ||
+ | |- | ||
+ | |darkgreen||bgcolor="#006300"| | ||
+ | |darkkhaki||bgcolor="#BCB76B"| | ||
+ | |darkolivegreen||bgcolor="#546B2D"| | ||
+ | |darkorange||bgcolor="#FF8C00"| | ||
+ | |- | ||
+ | |darkorchid||bgcolor="#9933CC"| | ||
+ | |darksalmon||bgcolor="#E8967A"| | ||
+ | |darkseagreen||bgcolor="#8EBC8E"| | ||
+ | |darkslateblue||bgcolor="#473D8C"| | ||
+ | |- | ||
+ | |darkturquoise||bgcolor="#00CED1"| | ||
+ | |darkviolet||bgcolor="#9300D3"| | ||
+ | |deeppink||bgcolor="#FF1493"| | ||
+ | |deepskyblue||bgcolor="#00BFFF"| | ||
+ | |- | ||
+ | |dodgerblue||bgcolor="#1E8EFF"| | ||
+ | |firebrick||bgcolor="#B22121"| | ||
+ | |floralwhite||bgcolor="#FFF9EF"| | ||
+ | |forestgreen||bgcolor="#218C21"| | ||
+ | |- | ||
+ | |gainsboro||bgcolor="#DBDBDB"| | ||
+ | |ghostwhite||bgcolor="#F7F7FF"| | ||
+ | |gold||bgcolor="#FFD600"| | ||
+ | |goldenrod||bgcolor="#D8A521"| | ||
+ | |- | ||
+ | |green||bgcolor="#00FF00"| | ||
+ | |greenyellow||bgcolor="#ADFF2D"| | ||
+ | |honeydew||bgcolor="#EFFFEF"| | ||
+ | |hotpink||bgcolor="#FF68B5"| | ||
+ | |- | ||
+ | |indianred||bgcolor="#CC5B5B"| | ||
+ | |ivory||bgcolor="#FFFFEF"| | ||
+ | |khaki||bgcolor="#EFE58C"| | ||
+ | |lavender||bgcolor="#E5E5F9"| | ||
+ | |- | ||
+ | |lavenderblush||bgcolor="#FFEFF4"| | ||
+ | |lawngreen||bgcolor="#7CFC00"| | ||
+ | |lemonchiffon||bgcolor="#FFF9CC"| | ||
+ | |lightblue||bgcolor="#ADD8E5"| | ||
+ | |- | ||
+ | |lightcoral||bgcolor="#EF7F7F"| | ||
+ | |lightcyan||bgcolor="#E0FFFF"| | ||
+ | |lightgoldenrod||bgcolor="#EDDD82"| | ||
+ | |lightgoldenrodyellow||bgcolor="#F9F9D1"| | ||
+ | |- | ||
+ | |lightpink||bgcolor="#FFB5C1"| | ||
+ | |lightsalmon||bgcolor="#FFA07A"| | ||
+ | |lightseagreen||bgcolor="#21B2AA"| | ||
+ | |lightskyblue||bgcolor="#87CEF9"| | ||
+ | |- | ||
+ | |lightslateblue||bgcolor="#8470FF"| | ||
+ | |lightsteelblue||bgcolor="#AFC4DD"| | ||
+ | |lightyellow||bgcolor="#FFFFE0"| | ||
+ | |limegreen||bgcolor="#33CC33"| | ||
+ | |- | ||
+ | |linen||bgcolor="#F9EFE5"| | ||
+ | |magenta||bgcolor="#FF00FF"| | ||
+ | |maroon||bgcolor="#AF3060"| | ||
+ | |mediumaquamarine||bgcolor="#66CCAA"| | ||
+ | |- | ||
+ | |mediumblue||bgcolor="#0000CC"| | ||
+ | |mediumorchid||bgcolor="#BA54D3"| | ||
+ | |mediumpurple||bgcolor="#9370DB"| | ||
+ | |mediumseagreen||bgcolor="#3DB270"| | ||
+ | |- | ||
+ | |mediumslateblue||bgcolor="#7A68ED"| | ||
+ | |mediumspringgreen||bgcolor="#00F999"| | ||
+ | |mediumturquoise||bgcolor="#47D1CC"| | ||
+ | |mediumvioletred||bgcolor="#C61484"| | ||
+ | |- | ||
+ | |midnightblue||bgcolor="#191970"| | ||
+ | |mintcream||bgcolor="#F4FFF9"| | ||
+ | |mistyrose||bgcolor="#FFE2E0"| | ||
+ | |moccasin||bgcolor="#FFE2B5"| | ||
+ | |- | ||
+ | |navajowhite||bgcolor="#FFDDAD"| | ||
+ | |navy||bgcolor="#00007F"| | ||
+ | |navyblue||bgcolor="#00007F"| | ||
+ | |oldlace||bgcolor="#FCF4E5"| | ||
+ | |- | ||
+ | |olivedrab||bgcolor="#6B8E23"| | ||
+ | |orange||bgcolor="#FFA500"| | ||
+ | |orangered||bgcolor="#FF4400"| | ||
+ | |orchid||bgcolor="#D870D6"| | ||
+ | |- | ||
+ | |palegoldenrod||bgcolor="#EDE8AA"| | ||
+ | |palegreen||bgcolor="#99F999"| | ||
+ | |paleturquoise||bgcolor="#AFEDED"| | ||
+ | |palevioletred||bgcolor="#DB7093"| | ||
+ | |- | ||
+ | |papayawhip||bgcolor="#FFEFD6"| | ||
+ | |peachpuff||bgcolor="#FFD8BA"| | ||
+ | |peru||bgcolor="#CC843F"| | ||
+ | |pink||bgcolor="#FFBFCC"| | ||
+ | |- | ||
+ | |plum||bgcolor="#DDA0DD"| | ||
+ | |powderblue||bgcolor="#AFE0E5"| | ||
+ | |purple||bgcolor="#A021EF"| | ||
+ | |red ||bgcolor="#FF0000"| | ||
+ | |- | ||
+ | |rosybrown||bgcolor="#BC8E8E"| | ||
+ | |royalblue||bgcolor="#3F68E0"| | ||
+ | |saddlebrown||bgcolor="#8C4411"| | ||
+ | |salmon||bgcolor="#F97F72"| | ||
+ | |- | ||
+ | |sandybrown||bgcolor="#F4A360"| | ||
+ | |seagreen||bgcolor="#2D8C56"| | ||
+ | |seashell||bgcolor="#FFF4ED"| | ||
+ | |sienna||bgcolor="#A0512D"| | ||
+ | |- | ||
+ | |skyblue||bgcolor="#87CEEA"| | ||
+ | |slateblue||bgcolor="#6B59CC"| | ||
+ | |snow||bgcolor="#FFF9F9"| | ||
+ | |springgreen||bgcolor="#00FF7F"| | ||
+ | |- | ||
+ | |steelblue||bgcolor="#4482B5"| | ||
+ | |tan ||bgcolor="#D1B58C"| | ||
+ | |thistle||bgcolor="#D8BFD8"| | ||
+ | |tomato||bgcolor="#FF6347"| | ||
+ | |- | ||
+ | |turquoise||bgcolor="#3FE0D1"| | ||
+ | |violet||bgcolor="#ED82ED"| | ||
+ | |violetred||bgcolor="#D1218E"| | ||
+ | |wheat||bgcolor="#F4DDB2"| | ||
+ | |- | ||
+ | |white||bgcolor="#FFFFFF"| | ||
+ | |whitesmoke||bgcolor="#F4F4F4"| | ||
+ | |yellow||bgcolor="#FFFF00"| | ||
+ | |yellowgreen||bgcolor="#99CC33"| | ||
+ | |} | ||
+ | |||
+ | == Additional pre-defined colors == | ||
+ | |||
+ | In addition to the above, there are two other sets of pre-defined colors. | ||
+ | |||
+ | {| class="wikitable" | ||
+ | | x11 || <code>\usecolors[x11]</code> | ||
+ | | {{src|colo-imp-x11.mkiv}} | ||
+ | | 658 extended Xorg color keywords (WWW), defined in hex RGB | ||
+ | |- | ||
+ | | ema || <code>\usecolors[ema]</code> | ||
+ | | {{src|colo-imp-ema.mkiv}} || 549 Emacs colors | ||
+ | |} | ||
+ | |||
+ | |||
+ | = Defining New Colors = | ||
+ | |||
+ | New colors may be defined in the following ways | ||
+ | |||
+ | {| class="wikitable" | ||
+ | ! Name !! Sytanx (and Example) !! Explanation | ||
+ | |- | ||
+ | | RGB color model | ||
+ | | <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 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. | ||
+ | |} | ||
+ | |||
+ | '''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. | ||
+ | |||
+ | == Cloning existing colors == | ||
+ | |||
+ | You can ''clone'' an existing color using | ||
+ | <texcode>\definecolor[new-color][old-color]</texcode> | ||
+ | |||
+ | For example | ||
{| | {| | ||
! width="45%"| | ! width="45%"| | ||
! width="10%"| | ! width="10%"| | ||
! width="45%"| | ! width="45%"| | ||
− | + | |<texcode>\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. | ||
</texcode> | </texcode> | ||
| | | | ||
− | |<context> | + | |<context mode=mkiv>\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. | ||
</context> | </context> | ||
|} | |} | ||
+ | == Adapting existing colors == | ||
+ | |||
+ | {{todo | add details about this}} | ||
+ | |||
+ | = Advanced Usage = | ||
+ | |||
+ | == Changing color of entire document == | ||
+ | |||
+ | To change the main text color of the document use | ||
+ | |||
+ | <texcode>\setupcolors[textcolor=defined-color]</texcode> | ||
− | + | For example, | |
{| | {| | ||
Line 138: | Line 448: | ||
! width="10%"| | ! width="10%"| | ||
! width="45%"| | ! width="45%"| | ||
− | + | |- | |
− | + | |<texcode>\setupcolors[textcolor=blue] | |
− | \ | ||
\starttext | \starttext | ||
− | + | text | |
− | |||
− | |||
\stoptext | \stoptext | ||
</texcode> | </texcode> | ||
| | | | ||
− | |<context> | + | |<context mode=mkiv> |
− | + | \setupcolors[textcolor=blue] | |
− | \setupcolors[ | ||
\starttext | \starttext | ||
− | + | 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> |
− | |||
− | </ | ||
− | |||
− | |||
+ | For example, | ||
{| | {| | ||
! width="45%"| | ! width="45%"| | ||
Line 212: | Line 496: | ||
|} | |} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | == Using colors in MetaPost == | |
− | |||
− | |||
− | + | A color defined in TeX is available in MetaPost using `\MPcolor{...}`. For example: | |
{| | {| | ||
− | + | |- | |
− | + | |<texcode> | |
− | + | \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 | ||
+ | </texcode> | ||
+ | |<context mode=mkiv> | ||
+ | \definecolor[highlight][r=0.8,g=0.8,b=0] | ||
\starttext | \starttext | ||
− | \ | + | \color[highlight]{Highlighted text in TeX} |
− | \ | + | |
+ | \startMPcode | ||
+ | label("Highlighted text in MetaPost", origin) | ||
+ | withcolor \MPcolor{highlight}; | ||
+ | \stopMPcode | ||
+ | </context> | ||
+ | |} | ||
+ | |||
+ | 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 = | ||
+ | |||
+ | == View all defined colors == | ||
+ | |||
+ | 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 ...) | ||
+ | |||
+ | {| | ||
+ | |- | ||
+ | |<texcode>\showcolor[x11]</texcode> | ||
+ | |<context mode=mkiv>\startTEXpage[height=5cm]\showcolor[x11]\stopTEXpage</context> | ||
+ | |} | ||
+ | |||
+ | 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: | ||
+ | |||
+ | * {{cmd|showcolorcomponents}} | ||
+ | <texcode>\showcolorcomponents[color-1, color-2]</texcode> | ||
+ | |||
+ | For example, | ||
+ | |||
+ | {| | ||
+ | |- | ||
+ | |<texcode>\showcolorcomponents[red,middlered,darkred]</texcode> | ||
+ | |<context mode=mkiv>\showcolorcomponents[red,middlered,darkred]</context> | ||
+ | |} | ||
+ | |||
+ | * {{cmd|colorcomponents}} | ||
+ | * {{cmd|transparencycomponents}} | ||
+ | * {{cmd|processcolorcomponents}} | ||
+ | <texcode>\colorcompoents{defined-color} | ||
+ | \tranparencycomponents{defined-color} | ||
+ | \processcolorcomponents{defined-color} | ||
+ | </texcode> | ||
+ | |||
+ | For example, | ||
+ | {| | ||
+ | |- | ||
+ | |<texcode> | ||
+ | \startlines | ||
+ | \colorcomponents{red} | ||
+ | \transparencycomponents{red} | ||
+ | \processcolorcomponents{red} | ||
+ | \stoplines | ||
</texcode> | </texcode> | ||
| | | | ||
− | + | <context mode=mkiv> | |
− | \ | + | \startlines |
− | \ | + | \colorcomponents{red} |
− | \ | + | \transparencycomponents{red} |
− | \ | + | \processcolorcomponents{red} |
− | \ | + | \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]] | ||
− | |||
{{Getting started navbox}} | {{Getting started navbox}} | ||
− | |||
− |
Revision as of 20:50, 15 June 2015
|
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.
Contents
Warning
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]
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.
Disable color
If you want to disable colors in a document, use
\setupcolors[state=stop]
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 |
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 .
|
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.
|
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 ...}