Difference between revisions of "Command/definecolor"

From Wiki
Jump to navigation Jump to search
(Create reference page)
 
(25 intermediate revisions by 7 users not shown)
Line 1: Line 1:
<!-- please remove this and the following line if you have checked this page -->
 
{{Reference_Cleanup}}
 
 
{{Reference
 
{{Reference
 
|name=definecolor
 
|name=definecolor
Line 6: Line 4:
 
}}
 
}}
  
 +
== [[Help:Reference|Syntax]] (autogenerated) ==
 +
<syntax>definecolor</syntax>
 
== [[Help:Reference|Syntax]] ==
 
== [[Help:Reference|Syntax]] ==
 
<table cellspacing="4" cellpadding="2" class="cmd">
 
<table cellspacing="4" cellpadding="2" class="cmd">
Line 16: Line 16:
 
   </tr>
 
   </tr>
 
   <tr valign="top" class="second">
 
   <tr valign="top" class="second">
     <td class="cmd">[[Reference/en/keyword:r|r]]</td>
+
     <td class="cmd">[[Command/keyword:r|r]]</td>
     <td>[[Reference/en/value:text|text]] </td>
+
     <td>[[Command/value:number|number]] red channel (RGB)</td>
 
   </tr>
 
   </tr>
 
   <tr valign="top" class="second">
 
   <tr valign="top" class="second">
     <td class="cmd">[[Reference/en/keyword:g|g]]</td>
+
     <td class="cmd">[[Command/keyword:g|g]]</td>
     <td>[[Reference/en/value:text|text]] </td>
+
     <td>[[Command/value:number|number]] green channel (RGB)</td>
 
   </tr>
 
   </tr>
 
   <tr valign="top" class="second">
 
   <tr valign="top" class="second">
     <td class="cmd">[[Reference/en/keyword:b|b]]</td>
+
     <td class="cmd">[[Command/keyword:b|b]]</td>
     <td>[[Reference/en/value:text|text]] </td>
+
     <td>[[Command/value:number|number]] blue channel (RGB)</td>
 
   </tr>
 
   </tr>
 
   <tr valign="top" class="second">
 
   <tr valign="top" class="second">
     <td class="cmd">[[Reference/en/keyword:c|c]]</td>
+
     <td class="cmd">[[Command/keyword:c|c]]</td>
     <td>[[Reference/en/value:text|text]] </td>
+
     <td>[[Command/value:number|number]] cyan channel (CMYK)</td>
 
   </tr>
 
   </tr>
 
   <tr valign="top" class="second">
 
   <tr valign="top" class="second">
     <td class="cmd">[[Reference/en/keyword:m|m]]</td>
+
     <td class="cmd">[[Command/keyword:m|m]]</td>
     <td>[[Reference/en/value:text|text]] </td>
+
     <td>[[Command/value:number|number]] magenta channel (CMYK)</td>
 
   </tr>
 
   </tr>
 
   <tr valign="top" class="second">
 
   <tr valign="top" class="second">
     <td class="cmd">[[Reference/en/keyword:y|y]]</td>
+
     <td class="cmd">[[Command/keyword:y|y]]</td>
     <td>[[Reference/en/value:text|text]] </td>
+
     <td>[[Command/value:number|number]] yellow channel (CMYK)</td>
 
   </tr>
 
   </tr>
 
   <tr valign="top" class="second">
 
   <tr valign="top" class="second">
     <td class="cmd">[[Reference/en/keyword:k|k]]</td>
+
     <td class="cmd">[[Command/keyword:k|k]]</td>
     <td>[[Reference/en/value:text|text]] </td>
+
     <td>[[Command/value:number|number]] black channel (CMYK)</td>
 
   </tr>
 
   </tr>
 
   <tr valign="top" class="second">
 
   <tr valign="top" class="second">
     <td class="cmd">[[Reference/en/keyword:s|s]]</td>
+
     <td class="cmd">[[Command/keyword:s|s]]</td>
     <td>[[Reference/en/value:text|text]] </td>
+
     <td>[[Command/value:number|number]] gray value (Grayscale), if v isn't set</td>
 
   </tr>
 
   </tr>
 
   <tr valign="top" class="second">
 
   <tr valign="top" class="second">
     <td class="cmd">[[Reference/en/keyword:h|h]]</td>
+
     <td class="cmd">[[Command/keyword:h|h]]</td>
     <td>[[Reference/en/value:text|text]] </td>
+
     <td>[[Command/value:number|number]] hue (HSB)</td>
 
   </tr>
 
   </tr>
 
   <tr valign="top" class="second">
 
   <tr valign="top" class="second">
     <td class="cmd">[[Reference/en/keyword:t|t]]</td>
+
     <td class="cmd">[[Command/keyword:s|s]]</td>
     <td>[[Reference/en/value:text|text]] </td>
+
     <td>[[Command/value:number|number]] saturation (HSB)</td>
 
   </tr>
 
   </tr>
 
   <tr valign="top" class="second">
 
   <tr valign="top" class="second">
     <td class="cmd">[[Reference/en/keyword:a|a]]</td>
+
     <td class="cmd">[[Command/keyword:v|v]]</td>
     <td>[[Reference/en/value:text|text]] </td>
+
     <td>[[Command/value:number|number]] brightness/value (HSB)</td>
 
   </tr>
 
   </tr>
 
   <tr valign="top" class="second">
 
   <tr valign="top" class="second">
     <td class="cmd">[[Reference/en/keyword:p|p]]</td>
+
     <td class="cmd">[[Command/keyword:t|t]]</td>
     <td>[[Reference/en/value:text|text]] </td>
+
     <td>[[Command/value:number|number]] transparency factor</td>
 
   </tr>
 
   </tr>
 
   <tr valign="top" class="second">
 
   <tr valign="top" class="second">
     <td class="cmd">[[Reference/en/keyword:e|e]]</td>
+
     <td class="cmd">[[Command/keyword:a|a]]</td>
     <td>[[Reference/en/value:text|text]] </td>
+
    <td>[[Command/value:number|number]] alternative (transparency method)</td>
 +
  </tr>
 +
  <tr valign="top" class="second">
 +
    <td class="cmd">[[Command/keyword:p|p]]</td>
 +
    <td>[[Command/value:number|number]] spotcolor percentage</td>
 +
  </tr>
 +
  <tr valign="top" class="second">
 +
    <td class="cmd">[[Command/keyword:e|e]]</td>
 +
     <td>[[Command/value:text|text]] spotcolor name</td>
 +
  </tr>
 +
  <tr valign="top" class="second">
 +
    <td class="cmd">[[Command/keyword:x|x]]</td>
 +
    <td>[[Command/value:text|text]] Hexadecimal RGB value (like in HTML), only with hex module</td>
 
   </tr>
 
   </tr>
 
</table>
 
</table>
 
  
 
== Description ==  
 
== Description ==  
<pre>
+
<code>\definecolor</code> associates a name with a color, for later use with the
\definecolor associated a name with a color, for later use with the
+
<code>\color</code> command.
\color command.
 
</pre>
 
  
To use hexadecimal colors you need to load the proper module first:
+
To use hexadecimal colors in mkii you need to load the proper module first:
  
<pre>
+
<texcode>
 
\setupcolor[hex]
 
\setupcolor[hex]
</pre>
+
</texcode>
  
 
Then the colors can be specified with
 
Then the colors can be specified with
<pre>
+
<texcode>
 
\definecolor[hex-red][h=FF0000]
 
\definecolor[hex-red][h=FF0000]
</pre>
+
</texcode>
  
 +
Regarding the key {{code|a}}, which means transparency alternative method, there are a certain number of values (actually at least 13, from 0 to 12) whose meanings can be seen from below:
  
 +
<texcode>
 +
\definetransparency [none]        [0]
 +
\definetransparency [normal]      [1]
 +
\definetransparency [multiply]    [2]
 +
\definetransparency [screen]      [3]
 +
\definetransparency [overlay]    [4]
 +
\definetransparency [softlight]  [5]
 +
\definetransparency [hardlight]  [6]
 +
\definetransparency [colordodge]  [7]
 +
\definetransparency [colorburn]  [8]
 +
\definetransparency [darken]      [9]
 +
\definetransparency [lighten]    [10]
 +
\definetransparency [difference] [11]
 +
\definetransparency [exclusion]  [12]
 +
</texcode>
 +
 +
=== Defining derivative colors ===
 +
 +
Colors defined in terms of other colors are processed at the Lua end, unless they are direct clones. In that case, the new name is never told to Lua. That means that this does not work:
 +
 +
<texcode>
 +
% direct clone, processed by TeX
 +
\definecolor[ColorA][red]
 +
% fails, ColorA not known to Lua
 +
\definecolor[ColorB][.5(ColorA)]
 +
</texcode>
 +
 +
Writing it as a fake fraction works.
 +
 +
<texcode>
 +
% definition involves a fraction, processed by Lua.
 +
\definecolor[ColorA][1.0(red)]
 +
% succeeds
 +
\definecolor[ColorB][.5(ColorA)]
 +
</texcode>
  
 
== Example ==
 
== Example ==
<!-- Please fill in an example if you can -->
+
<context source=yes mode=mkiv>
 +
% mode=mkiv
 +
 
 +
% rgb
 +
\definecolor[bluu][r=.25, g = .1, b=1]
 +
Hey, \color[bluu]{look at that!}
 +
 
 +
% hex
 +
%\setupcolor[hex] % needed in mkii only
 +
\definecolor[salmon][h=AB5757]
 +
Hey, \color[salmon]{look at that!}
 +
</context>
  
 
== See also ==
 
== See also ==
<!-- something like [[cmd:goto|\goto]] -->
+
* [[Color]]
 +
* {{cmd|definetransparency}}
 +
 
 +
== Help from ConTeXt-Mailinglist/Forum ==
 +
All issues with:
 +
{{Forum|{{SUBPAGENAME}}}}
  
[[Category:Reference/en|definecolor]]
+
[[Category:Command/Colors|definecolor]]

Revision as of 13:35, 13 October 2019

\definecolor

Syntax (autogenerated)

\definecolor[...][...=...,...]
[...]name
rnumber
gnumber
bnumber
cnumber
mnumber
ynumber
knumber
hnumber
snumber
vnumber
wnumber
xnumber
anumber none normal multiply screen overlay softlight hardlight colordodge colorburn darken lighten difference exclusion hue saturation color luminosity
tnumber


\definecolor[...][...]
[...]name
[...]color


Syntax

\definecolor[...][...,...=...,...]
[...] name
r number red channel (RGB)
g number green channel (RGB)
b number blue channel (RGB)
c number cyan channel (CMYK)
m number magenta channel (CMYK)
y number yellow channel (CMYK)
k number black channel (CMYK)
s number gray value (Grayscale), if v isn't set
h number hue (HSB)
s number saturation (HSB)
v number brightness/value (HSB)
t number transparency factor
a number alternative (transparency method)
p number spotcolor percentage
e text spotcolor name
x text Hexadecimal RGB value (like in HTML), only with hex module

Description

\definecolor associates a name with a color, for later use with the \color command.

To use hexadecimal colors in mkii you need to load the proper module first:

\setupcolor[hex]

Then the colors can be specified with

\definecolor[hex-red][h=FF0000]

Regarding the key a, which means transparency alternative method, there are a certain number of values (actually at least 13, from 0 to 12) whose meanings can be seen from below:

\definetransparency [none]        [0]
\definetransparency [normal]      [1]
\definetransparency [multiply]    [2]
\definetransparency [screen]      [3]
\definetransparency [overlay]     [4]
\definetransparency [softlight]   [5]
\definetransparency [hardlight]   [6]
\definetransparency [colordodge]  [7]
\definetransparency [colorburn]   [8]
\definetransparency [darken]      [9]
\definetransparency [lighten]    [10]
\definetransparency [difference] [11]
\definetransparency [exclusion]  [12]

Defining derivative colors

Colors defined in terms of other colors are processed at the Lua end, unless they are direct clones. In that case, the new name is never told to Lua. That means that this does not work:

% direct clone, processed by TeX
\definecolor[ColorA][red]
% fails, ColorA not known to Lua
\definecolor[ColorB][.5(ColorA)]

Writing it as a fake fraction works.

% definition involves a fraction, processed by Lua.
\definecolor[ColorA][1.0(red)]
% succeeds
\definecolor[ColorB][.5(ColorA)]

Example

% mode=mkiv

% rgb
\definecolor[bluu][r=.25, g = .1, b=1]
Hey, \color[bluu]{look at that!}

% hex
%\setupcolor[hex] % needed in mkii only
\definecolor[salmon][h=AB5757]
Hey, \color[salmon]{look at that!}

See also

Help from ConTeXt-Mailinglist/Forum

All issues with: