Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Colors defined via the internal \definecolor macro in ConTeXt cannot be used in TikZ when the CMYK system is used.

Is there a way to convert them or tick a setting so that TikZ can use them?

Minimal example:

\usemodule[tikz]
\definecolor[c][c=1]
\starttext
\tikz\node[c]{t};
\stoptext

Expected: cyan “t”
Received: black “t” and Package pgf: Error! Color c has an unsupported color model..


Edit: TikZ does use ConTeXt colors defined with the RGB color model:

\definecolor[r][r=1]
\tikz\node[r]{t};

This gives me a red “t” as expected. So I don’t want to know how to define colors explicitly for use in TikZ, but what code I have to add somewhere add to make the two lines\definecolor[c][c=1] and \tikz\node[c]{t}; from the minimal example work together.

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

It seems that pgf does not have any built-in support for cmyk when using ConTeXt. As a result, the macro \pgfutil@registercolor, which chooses colour models, is hard-coded not to try anything other than rgb and gray. Thus we need alter that macro and provide the necessary internal conversion:

\usemodule[tikz]
\definecolor[c][c=1]
\starttext
\unprotect
\def\pgfutil@registercolor#1{%
  \edef\pgf@temp{\PDFcolor{#1}}%
  \edef\pgf@marshal{\noexpand\pgfutil@in@{g}{\pgf@temp}}%
  \pgf@marshal
  \ifpgfutil@in@
    \expandafter\pgfutil@context@parse@gray\pgf@temp\pgf@stop{#1}%
  \else
    \edef\pgf@marshal{\noexpand\pgfutil@in@{rg}{\pgf@temp}}%
    \pgf@marshal
    \ifpgfutil@in@
      \expandafter\pgfutil@context@parse@rgb\pgf@temp\pgf@stop{#1}%
    \else
      \edef\pgf@marshal{\noexpand\pgfutil@in@{k}{\pgf@temp}}%
      \pgf@marshal
      \ifpgfutil@in@
        \expandafter\pgfutil@context@parse@cmyk\pgf@temp\pgf@stop{#1}%
      \else 
        \PackageError{pgf}{Color #1 has an unsupported color model.}{}%
        \pgfutil@definecolor{#1}{gray}{0}%
      \fi
    \fi
  \fi
}
\def\pgfutil@context@parse@cmyk#1 #2 #3 #4k#5\pgf@stop #6{%
  \pgfutil@definecolor{#6}{cmyk}{#1,#2,#3,#4}%
}
\def\pgfutil@emu@cmyk#1#2,#3,#4,#5\@nil{%
  \expandafter\def\csname\string\color@#1\endcsname
    {\xcolor@{}{}{cmyk}{#2,#3,#4,#5}}%
}

\protect
\tikz\node[c]{t};
\stoptext

Original answer (to a slightly different question!)

Two things are going on here. First, pgf does not support ConTeXt's \definecolor: there is a note to the effect in the manual. So you need to use \pgfutil@definecolor instead. Secondly, there is no built-in code for a cmyk model when working with ConTeXt. However, this does not seem to be too hard to emulate:

\usemodule[tikz]
\unprotect
\def\pgfutil@emu@cmyk#1#2,#3,#4,#5\@nil{%
  \expandafter\def\csname\string\color@#1\endcsname
    {\xcolor@{}{}{cmyk}{#2,#3,#4,#5}}%
}
\pgfutil@definecolor{c}{cmyk}{1,0,0,0}
\protect
\starttext
\tikz\node[c]{t};
\stoptext
share|improve this answer
    
It’s a nice answer on how to define CMYK-colors for TikZ from inside a ConTeXt document. But my question was what code i should add at one position to enable TikZ to use ConTeXt’s colors. –  flying sheep Sep 9 '11 at 12:41
    
@flying sheep: That may be rather more tricky - while pgf is usable in plain and ConTeXt, it's pretty clear that the colour support is tied quite closely to LaTeX's approach. –  Joseph Wright Sep 9 '11 at 12:45
    
See my edited answer on what works already and thus tells me that there must be a way to create hybrid ConTeXt/TikZ colors. I don’t need them to be CMYK internally, just defined via CMYK. Also: Isn’t \unprotect \dosomethingwith@inside \protect the canonical way? –  flying sheep Sep 9 '11 at 12:49
1  
@flying sheep: Answer updated to reflect altered question. On \unprotect, as I'm not a ConTeXt regular I was not sure if that was for @ or only for !, etc.: I've altered the code. –  Joseph Wright Sep 9 '11 at 13:11
1  
@flying sheep: I've updated the answer again, and it should now work with both MkII and MkIV. –  Joseph Wright Sep 9 '11 at 15:25
show 9 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.