Difference between revisions of "Color"

From Wiki
Jump to navigation Jump to search
(→‎Multitones: example update)
(Correct command links. Shrink a few examples.)
Line 6: Line 6:
  
 
In older versions, colors must be enabled using
 
In older versions, colors must be enabled using
<cmd>setupcolors</cmd><tt>[state=start]</tt>
+
    {{cmd|setupcolors}}<tt>[state=start]</tt>
  
 
=Defining Colors=
 
=Defining Colors=
Line 16: Line 16:
 
* Normally all colors are defined in RGB ''and'' CMYK and get converted if needed.
 
* Normally all colors are defined in RGB ''and'' CMYK and get converted if needed.
  
== Using predefined colors: <cmd>setupcolor</cmd> ==
+
== Using predefined colors: {{cmd|setupcolor}} ==
  
You find lists of predefined colors in the files <tt>colo-xxx.tex</tt>, load them with <cmd>setupcolor</cmd><tt>[xxx]</tt>:
+
You find lists of predefined colors in the files <tt>colo-xxx.tex</tt>, load them with {{cmd|setupcolor}}<tt>[xxx]</tt>:
 
* rgb: some simple colors, loaded by default (with translations for the different interface languages!)
 
* rgb: some simple colors, loaded by default (with translations for the different interface languages!)
 
* xwi: X-Windows-colors
 
* xwi: X-Windows-colors
Line 24: Line 24:
 
* ema: Emacs colors
 
* ema: Emacs colors
  
* Try the magic <cmd>showcolor</cmd><tt>[xxx]</tt>!
+
* Try the magic {{cmd|showcolor}}<tt>[xxx]</tt>! For example,
 
+
<context source="yes" text="yields this:">
{|
 
! width="25%"|
 
! width="10%"|
 
! width="65%"|
 
|-
 
| <texcode>
 
\showcolor[rgb]
 
</texcode>
 
|
 
| <context>
 
 
\setupcolors[state=start]
 
\setupcolors[state=start]
 
\showcolor[rgb]
 
\showcolor[rgb]
 
</context>
 
</context>
|}
 
  
== Defining colors: <cmd>definecolor</cmd> ==
+
== Defining colors: {{cmd|definecolor}} ==
  
<cmd>definecolor</cmd><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!).
+
{{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!).
 
See also [[Command/definecolor]].
 
See also [[Command/definecolor]].
  
Line 139: Line 128:
 
|}
 
|}
  
== Defining color schemes: <cmd>definecolorgroup</cmd> and <cmd>definepalet</cmd>==
+
== Defining color schemes: {{cmd|definecolorgroup}} and {{cmd|definepalet}}==
<cmd>definecolorgroup</cmd><tt>[name][system][values]</tt>
+
{{cmd|definecolorgroup}}<tt>[name][system][values]</tt>
  
<cmd>definepalet</cmd><tt>[palettename][colorname1=groupcolor:1, colorname2=groupcolor:2, ...]</tt>
+
{{cmd|definepalet}}<tt>[palettename][colorname1=groupcolor:1, colorname2=groupcolor:2, ...]</tt>
  
 
Very interesting feature, see also the manual and here on the wiki [[Command/definecolor]]
 
Very interesting feature, see also the manual and here on the wiki [[Command/definecolor]]
Line 165: Line 154:
 
== With text ==
 
== With text ==
  
Typeset single text elements with <cmd>color</cmd><tt>[colorname]{nice blue text}</tt>:
+
Typeset single text elements with {{cmd|color}}<tt>[colorname]{nice blue text}</tt>:
  
 
{|
 
{|
Line 184: Line 173:
 
|}
 
|}
  
Alternatively, typeset text elements with <cmd>colored</cmd><tt>[rgb values]{colored text}</tt> (suggested on NTG-ConTeXt: [http://www.ntg.nl/pipermail/ntg-context/2010/046563.html]):
+
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]):
  
 
{|
 
{|
Line 204: Line 193:
  
  
Typeset longer sections with <cmd>startcolor</cmd><tt>[colorname] ...</tt> <cmd>stopcolor</cmd>:
+
Typeset longer sections with {{cmd|startcolor}}<tt>[colorname] ...</tt> {{cmd|stopcolor}}:
  
 
{|
 
{|
Line 212: Line 201:
 
  |-
 
  |-
 
  | <texcode>
 
  | <texcode>
 +
\setuppapersize[A6]
 
\starttext
 
\starttext
 
\startcolor[orange]
 
\startcolor[orange]
Line 220: Line 210:
 
|
 
|
 
|<context>
 
|<context>
 +
\setuppapersize[A6]
 
\setupcolors[state=start]
 
\setupcolors[state=start]
 
\starttext
 
\starttext
Line 262: Line 253:
 
  |-
 
  |-
 
  | <texcode>
 
  | <texcode>
 +
\setuppapersize[A10]
 
\setupbackgrounds[page][background=color,backgroundcolor=blue]
 
\setupbackgrounds[page][background=color,backgroundcolor=blue]
  
Line 270: Line 262:
 
|
 
|
 
|<context>
 
|<context>
 +
\setuppapersize[A10]
 
\setupcolors[state=start]
 
\setupcolors[state=start]
  
Line 319: Line 312:
 
To produce a file ready for a clean PDF separation process at your print house, start with:
 
To produce a file ready for a clean PDF separation process at your print house, start with:
  
<cmd>setupcolors</cmd><tt>[rgb=no,cmyk=yes,spot=yes,state=start,overprint=yes]</tt>
+
{{cmd|setupcolors}}<tt>[rgb=no,cmyk=yes,spot=yes,state=start,overprint=yes]</tt>
  
 
which will set things up for spot colors with CMYK allowed. The last setting ensures that black overprinting your spot colour tints will not knock out the colour - this is important for some types of commercial printing.
 
which will set things up for spot colors with CMYK allowed. The last setting ensures that black overprinting your spot colour tints will not knock out the colour - this is important for some types of commercial printing.
Line 325: Line 318:
 
Then define your basic spot colour. Note that the name cannot contain spaces or numbers (but we come to that later):
 
Then define your basic spot colour. Note that the name cannot contain spaces or numbers (but we come to that later):
  
<cmd>definecolor</cmd><tt>[PantoneTwoNineFour][c=1,m=.56,y=0,k=.18]</tt>
+
{{cmd|definecolor}}<tt>[PantoneTwoNineFour][c=1,m=.56,y=0,k=.18]</tt>
  
 
Now you can define the tints of this ink that you are actually going to use in your document. Let's say you'll have a 100% for headings:
 
Now you can define the tints of this ink that you are actually going to use in your document. Let's say you'll have a 100% for headings:
  
<cmd>definespotcolor</cmd><tt>[MyBlue][PantoneTwoNineFour][p=1]</tt>
+
{{cmd|definespotcolor}}<tt>[MyBlue][PantoneTwoNineFour][p=1]</tt>
  
 
And then a 20% tint for nice display boxes:
 
And then a 20% tint for nice display boxes:
  
<cmd>definespotcolor</cmd><tt>[MyBlueTint][PantoneTwoNineFour][p=.2]</tt>
+
{{cmd|definespotcolor}}<tt>[MyBlueTint][PantoneTwoNineFour][p=.2]</tt>
  
 
And now you can happily use these named colours:
 
And now you can happily use these named colours:
Line 374: Line 367:
 
to be true across the board now?)
 
to be true across the board now?)
  
Any text between a <cmd>startcolor[DarkBlue]</cmd> and <cmd>stopcolor</cmd> should now be assigned to the correct spot colour channel - Pantone 308 CV - on output.  More importantly if  you include an external figure containing areas of this colour then your text and those parts of the graphic which have the same colour should now appear together in the 'Pantone 308 CV' colour channel on colour separation.  
+
Any text between a {{cmd|startcolor[DarkBlue]}} and {{cmd|stopcolor}} should now be assigned to the correct spot colour channel - Pantone 308 CV - on output.  More importantly if  you include an external figure containing areas of this colour then your text and those parts of the graphic which have the same colour should now appear together in the 'Pantone 308 CV' colour channel on colour separation.  
  
 
For example, if your original graphic is an EPS file containing the following lines:
 
For example, if your original graphic is an EPS file containing the following lines:

Revision as of 15:48, 19 May 2012

< Visuals | Graphics >

Enabling colors

In current versions (newer than 11.05.2009) of ConTeXt mkiv, colors are enabled by default.

In older versions, colors must be enabled using

   \setupcolors[state=start]

Defining Colors

Choosing a color model

  • RGB and CMYK are enabled by default. If you want only RGB or only CMYK color, use cmyk=no or rgb=no. 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.

Using predefined colors: \setupcolor

You find lists of predefined colors in the files colo-xxx.tex, load them with \setupcolor[xxx]:

  • rgb: some simple colors, loaded by default (with translations for the different interface languages!)
  • xwi: X-Windows-colors
  • pra: PRAGMA ADE company colors
  • ema: Emacs colors
\setupcolors[state=start]
\showcolor[rgb]

yields this:

Defining colors: \definecolor

\definecolor[blablue][r=.1, g=.1, b=1, c=1, m=.1, y=0, k=0, s=.2] (definition for RGB, CMYK and Grey!). See also Command/definecolor.


\definecolor[blablue][r=.25, g=.1, b=1, c=1, m=.1, y=0, k=0, s=.2]

Here's some \color[blablue]{blue text} inbetween!

Colors with Hexadecimal Numbers

You can also use hexadecimal numers to specify colors. You need to load the hex color module first:

\setupcolor[hex]
\definecolor[salmon][h=AB5757]

Hey, \color[salmon]{look at that!}

Transparent Colors

You can define transparent colors through setting t, e.g. t=0.5. Beware, some PDF viewers and printshops can't handle PDF transparences!

Hans Hagen posted the following sample code for transparent colors on the mailing list on 2005-07-13; the yellow blocks have been added to demonstrate the order in which the blocks are drawn on the page; the first yellow block is behind the transparent red and blue blocks, while the second is in front of them.

\definecolor [transparentred]  [r=1,t=.5,a=1]
\definecolor [transparentblue] [b=1,t=.5,a=1]
\definecolor [solidyellow]  [y=1,t=1,a=1]

\starttext

\startTEXpage
This is some sample text that goes behind the rectangles\hskip-8cm
\blackrule[width=2cm,height=1cm,depth=1cm,color=solidyellow]\hskip-0.67cm
\blackrule[width=2cm,height=2cm,color=transparentred]\hskip-0.67cm
\blackrule[width=2cm,height=1cm,depth=1cm,color=transparentblue]\hskip-0.67cm
\blackrule[width=2cm,height=2cm,color=solidyellow]\hskip2cm.
\stopTEXpage

\stoptext

Defining color schemes: \definecolorgroup and \definepalet

\definecolorgroup[name][system][values]

\definepalet[palettename][colorname1=groupcolor:1, colorname2=groupcolor:2, ...]

Very interesting feature, see also the manual and here on the wiki Command/definecolor

Choosing a color scheme

There are three basic strategies to select color combinations for a particular design

  1. Create a color scheme by picking several colors found within the objects to be used (photographs, pictures, etc)
  2. Create colors derived from those found in the objects to be used
  3. Create a color scheme based on the message to convey / the psychological effects of color

See for additional help & reference:

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


Using Colors

  • Use the color name like [color=blablue] in some \setup... command.

With text

Typeset single text elements with \color[colorname]{nice blue text}:

Three \color[red]{cool} cats

Alternatively, typeset text elements with \colored[rgb values]{colored text} (suggested on NTG-ConTeXt: [1]):

Three \colored[r=.4, g=.4, b=.9]{colorful} kittens.


Typeset longer sections with \startcolor[colorname] ... \stopcolor:

\setuppapersize[A6]
\starttext
\startcolor[orange]
\input tufte
\stopcolor
\stoptext

In titles

See Titles#Using_colors_in_chapters_and_sections

With frames

\framed[background=color, backgroundcolor=green]{bla}
\framed[background=color, backgroundcolor=yellow, corner=00]{bla}

Background of the page

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

\starttext
text
\stoptext

Background of cells in tables

See

In Metapost

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

In TikZ

\usemodule[tikz]
\starttext
\tikz\shade[ball color=red!40!yellow] (0,0) circle (.15cm);
\stoptext
internal error: convert failed

Spot colours

To produce a file ready for a clean PDF separation process at your print house, start with:

\setupcolors[rgb=no,cmyk=yes,spot=yes,state=start,overprint=yes]

which will set things up for spot colors with CMYK allowed. The last setting ensures that black overprinting your spot colour tints will not knock out the colour - this is important for some types of commercial printing.

Then define your basic spot colour. Note that the name cannot contain spaces or numbers (but we come to that later):

\definecolor[PantoneTwoNineFour][c=1,m=.56,y=0,k=.18]

Now you can define the tints of this ink that you are actually going to use in your document. Let's say you'll have a 100% for headings:

\definespotcolor[MyBlue][PantoneTwoNineFour][p=1]

And then a 20% tint for nice display boxes:

\definespotcolor[MyBlueTint][PantoneTwoNineFour][p=.2]

And now you can happily use these named colours:

\starttext
   \color[MyBlue]{Interesting}
\stoptext

If you are including graphics made by an external program, you might want to match the colour name used in the graphic with the colour name in your ConTeXt set-up so that only one colour space is used in the final file. Unfortunately Pantone names and others tend to have spaces and numbers in them, so you need to do some extra work.

Using the 'e' key to \definespotcolor to specify a spot colour name with spaces

You can use the 'e' key when defining your spot colours in order to specify the precise colour names to be used by your ConTeXt set-up in the output file. For example:

% set up the cmyk fallbacks
\definecolor
   [PantoneThreeZeroEight]
   [c=1,m=.05,y=0,k=.47]

\definecolor
   [PantoneTwoNineEight]
   [c=.69,m=.07,y=0,k=0]

% Define tints of spot colours to be used in document for colouring text
\definespotcolor
   [DarkBlue]
   [PantoneThreeZeroEight]
   [p=1,e=PANTONE 308 CV]

\definespotcolor
   [LightBlue]
   [PantoneTwoNineEight]
   [p=1,e=PANTONE 298 CV]

(Tested only on minimal Linux distribution dated 8 May 2010 - can others confirm this to be true across the board now?)

Any text between a [[Command/startcolor[DarkBlue]|\startcolor[DarkBlue]]] and \stopcolor should now be assigned to the correct spot colour channel - Pantone 308 CV - on output. More importantly if you include an external figure containing areas of this colour then your text and those parts of the graphic which have the same colour should now appear together in the 'Pantone 308 CV' colour channel on colour separation.

For example, if your original graphic is an EPS file containing the following lines:

%%DocumentCustomColors: (PANTONE 298 CV)
%%+ (PANTONE 308 CV)
%%CMYKCustomColor: 0.69 0.07 0 0 (PANTONE 298 CV)
%%+ 1 0.05 0 0.47 (PANTONE 308 CV)

and you convert this to a PDF using ps2pdf for inclusion in your ConTeXt document your PDF graphic will then contain something like:


8 0 obj
[/Separation
/PANTONE#20308#20CV
/DeviceCMYK
9 0 R]endobj
10 0 obj
[/Separation
/PANTONE#20298#20CV
/DeviceCMYK
11 0 R]endobj

Note how the space characters in the colour name are now encoded as '#20', but the colour names are essentially identical between the original EPS graphic, the new PDF graphic and your text.

A good way of testing colour separation if you don't have access to expensive pre-flight PDF validation tools is to use the following GhostScript command:

gs \
  -dBATCH \
  -dNOPAUSE \
  -sDEVICE=tiffsep \
  -dDOINTERPOLATE \
  -dTextAlphaBits=4 \
  -dGraphicsAlphaBits=4 \
  -sOutputFile=output.tif \
  -r120 \
  -MaxSeparations=8 \
  input.pdf

This renders a PDF file input.pdf as a set of TIFF files:

  output.tif              - Composite including CMYK approximations to spot colours
  output.tif.Black.tif    - K channel
  output.tif.Cyan.tif     - C channel
  output.tif.Magenta.tif  - M channel
  output.tif.Yellow.tif   - Y channel
  output.tif.s0.tif       - Pantone 308 CV
  output.tif.s1.tif       - Pantone 298 CV

Multitones

Hans posted this example about spot and multitone colors on the mailinglist (2012-05-07). The interface has slightly changed in comparison to older versions. It is important to define the colorants as spot colors first (\definespotcolor).

\definecolor         [xcyan]   [c=1]
\definecolor         [xmagenta][m=1]
\definecolor         [xyellow] [y=1]

\definespotcolor     [scyan]   [xcyan]   [p=1]
\definespotcolor     [smagenta][xmagenta][p=1]
\definespotcolor     [syellow] [xyellow] [p=1]

\definemultitonecolor[scombi] [xcyan=.2,xmagenta=.4,xyellow=.6][c=.2,m=.4,y=.6]

\startTEXpage
    \hbox \bgroup
        \blackrule[color=scyan,   width=1cm,height=1cm,depth=0cm]%
        \blackrule[color=smagenta,width=1cm,height=1cm,depth=0cm]%
        \blackrule[color=syellow, width=1cm,height=1cm,depth=0cm]%
        \blackrule[color=scombi,  width=1cm,height=1cm,depth=0cm]%
    \egroup
\stopTEXpage

(The CMYK color spec is the fall back color used on screen; one can preview separations in full Acrobat 7.)

Colorizing Grayscale Pictures

Another sample by Hans (mailing list 2005-11-16) demonstrates a lot of different possibilities:

\setuplayout[header=0pt,footer=0pt,width=middle,height=middle,backspace=1cm,topspace=1cm]
\setupcolors[state=start]

\startbuffer
\definecolor [blue]   [c=1, m=.38, y=0, k=.64]
\definecolor [yellow] [c=0, m=.28, y=1, k=.06]

\definespotcolor [blue-100]   [blue]   [p=1]
\definespotcolor [yellow-100] [yellow] [p=1]

\definemultitonecolor [combicolor]   [blue=.12, yellow=.28] [c=.1, m=.1, y=.3, k=.1]

\definemultitonecolor [combicolor-b] [blue=1]   [c=1, m=.38, y=0, k=.64] % force multitone
\definemultitonecolor [combicolor-y] [yellow=1] [c=0, m=.28, y=1, k=.06] % force multitone

\useexternalfigure[demo-a][mill.png]     [object=no, width=.2\textwidth]
\useexternalfigure[demo-b][hacker-bw.jpg][object=no, width=.2\textwidth]

\startbaselinecorrection
\startcombination[4*1]
 {\externalfigure[demo-a]}                                {no color}
 {\externalfigure[demo-a][color=combicolor]}   {indexed duotone}
 {\externalfigure[demo-a][color=combicolor-b]} {spot color}
 {\externalfigure[demo-a][color=combicolor-y]} {spot color}
\stopcombination
\stopbaselinecorrection

\startbaselinecorrection
\startcombination[4*1]
 {\externalfigure[demo-b]}                     {no color}
 {\externalfigure[demo-b][color=combicolor]}   {indexed duotone}
 {\externalfigure[demo-b][color=combicolor-b]} {spot color}
 {\externalfigure[demo-b][color=combicolor-y]} {spot color}
\stopcombination
\stopbaselinecorrection

\startbaselinecorrection
\startcombination[4*1]
 {\externalfigure[demo-a]}                     {no color}
 {\externalfigure[demo-a][color=combicolor]}   {indexed duotone}
 {\externalfigure[demo-a][color=blue-100]}     {spot color}
 {\externalfigure[demo-a][color=yellow-100]}   {spot color}
\stopcombination
\stopbaselinecorrection

\startbaselinecorrection
\startcombination[4*1]
 {\externalfigure[demo-b]}                     {no color}
 {\externalfigure[demo-b][color=combicolor]}   {indexed duotone}
 {\externalfigure[demo-b][color=blue-100]}     {spot color}
 {\externalfigure[demo-b][color=yellow-100]}   {spot color}
\stopcombination
\stopbaselinecorrection
\stopbuffer

\getbuffer \typebuffer

\stoptext

References

See "Color and Background" in the manual