ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen <pragma@wxs.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: ConText, TikZ and definecolor: undefined control sequence
Date: Thu, 28 Oct 2010 13:46:25 +0200	[thread overview]
Message-ID: <4CC96291.9010508@wxs.nl> (raw)
In-Reply-To: <AANLkTik2m+_h2BYzFM2499mdAy6av_oGmOKFRk_Y8hf=@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4694 bytes --]

On 28-10-2010 9:54, Cedric Mauclair wrote:
> On Wed, Oct 27, 2010 at 22:08, Michael Murphy<michael.murphy@uni-ulm.de>  wrote:
>> On 27/10/2010 19:18, Marius wrote:
>>>
>>> Hello,
>>> I had the same problem, so I desided to define colors by hand.
>>>
>>> \definecolor [lightgray] [h=D3D3D3]
>>>
>>> \usemodule[tikz]
>>>
>>> \unprotect
>>> \pgfutil@definecolor{black}{gray}{0}
>>> \pgfutil@definecolor{gray}{gray}{0.5}
>>> \pgfutil@definecolor{lightgray}{gray}{0.9}
>>> \pgfutil@definecolor{white}{gray}{1}
>>> \protect
>>
>> Yes, this is what I've resorted to. But it would be nice to define things
>> properly.
>>
>>> If you want to fix script, you need to change line:
>>>
>>> local cv = colors.value(attributes)
> The table "colors" is expected to have a function named "value" that
> take the "attributes" parameter as its sole parameter itself. It then
> assigns the result to the local variable cv. After some research,
> adding  "local colors = global.attributes.colors" below the line
> "local prtcatcodes = tex.prtcatcodes" works. There is a catch however,
> you can't use opacity on these colors. I suppose we have to generate
> all the transparency level by using spot colors or something like
> that.

There are several solutions to the problem.

\usemodule[tikz]

\startmode[mkiv]

\startluacode
thirddata     = thirddata     or { }
thirddata.pgf = thirddata.pgf or { }

local texsprint, prtcatcodes, format = tex.sprint, tex.prtcatcodes, 
string.format

local function unsupported_color(name)
     texsprint(prtcatcodes,format("\\PackageError{pgf}{color %s has 
unsupported model}{}", name))
     texsprint(prtcatcodes,format("\\pgfutil@definecolor{%s}{gray}{0}", 
name))
end

local colors = attributes.colors

function thirddata.pgf.registercolor(name,attribute) -- solution 1
     local cv = colors.value(attribute)
     if cv then
         local model = colors.forcedmodel(cv[1])
         if model > 3 then
             model = 3 -- no cmyk or spot or multitone
         end
         if model == 2 then
 
texsprint(prtcatcodes,format("\\pgfutil@definecolor{%s}{gray}{%1.3f}", 
name, cv[2]))
         elseif model == 3 then
 
texsprint(prtcatcodes,format("\\pgfutil@definecolor{%s}{rgb}{%1.3f,%1.3f,%1.3f}", 
name, cv[3], cv[4], cv[5]))
         else
             unsupported_color(name)
         end
     else
         unsupported_color(name)
     end
end

function lpdf.pdfcolor(attribute)
     context(lpdf.color(1,attribute))
end
\stopluacode

\stopmode

\unprotect

% solution 1 (also fallback when cmyk is used):

% \def\PDFcolor#1%
%   {\ctxlua{thirddata.pgf.pdfcolor(\thecolorattribute{#1})}}

% solution 2 (faster as less parsing at the tex end):

% \def\pgfutil@registercolor#1%
%   {\ctxlua{thirddata.pgf.registercolor("#1",\thecolorattribute{#1})}}

% solution 3 (backward compatible):

\def\PDFcolor#1%
   {\ctxlua{lpdf.pdfcolor(\thecolorattribute{#1})}}

\protect

\definecolor[mycolora][r=1,g=0,b=1]
\definecolor[mycolorb][m=1]

\starttext
     \starttikzpicture
         \fill[mycolora] (0,0) circle (2);
         \fill[mycolorb] (0,0) circle (1);
     \stoptikzpicture
\stoptext

I'll define \pdfcolor for this purpose as that's what tikz expects.

> However, I still need to
> add"\let\appendtoPDFdocumentcolorspaces\gobbleoneargument"
> "\let\appendtoPDFdocumentextgstates\gobbleoneargument" and
> "\let\PDFcolor\gobbleoneargument" before loading the TikZ module in
> order for my documents to build without errors. These macros used to
> be defined in mkii (spec-fdf.mkii) and TikZ relies on them
> (tex/generic/pgf/utilities/pgfutil-context.def) but not anymore in
> mkiv since the color support has changed between mkii and mkiv. I
> suppose they had to do with the color support for PDF files, but
> letting them gobble their argument still seems to work. On what side
> should this problem be looked into: ConTeXt or TikZ?

In pgfutil-context.def there should be no such commands called when mkiv 
is used. Isn't there a

\doifmodeelse {mkiv} { ...

section? anyhow, in that section one can add

\ifdefined\PDFcolor \else

   \ctxlua{function lpdf.pdfcolor(attribute) 
context(lpdf.color(1,attribute)) end}

   \def\PDFcolor#1{\ctxlua{lpdf.pdfcolor(\thecolorattribute{#1})}}

\fi

(in the next beta this is not needed as \PDFcolor is defined then)

Hans


-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------

[-- Attachment #2: t-tikz-hans.tex --]
[-- Type: text/x-tex, Size: 9876 bytes --]

% Copyright 2006 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.

% The aux files, needed for reading back coordinates

\def\pgfutil@aux@read@hook{
  \pgfutil@IfFileExists{\jobname.pgf}{\input \jobname.pgf\relax}{}
  \csname newwrite\endcsname\pgfutil@auxout
  \csname openout\endcsname\pgfutil@auxout\jobname.pgf
}

% XColor-like support for ConTeXt

\def\pgfutil@definecolor#1#2#3{\csname pgfutil@emu@#2\endcsname{#1}#3\@nil}

\def\pgfutil@emu@rgb#1#2,#3,#4\@nil{\expandafter\def\csname\string\color@#1\endcsname{\xcolor@{}{}{rgb}{#2,#3,#4}}}
\def\pgfutil@emu@gray#1#2\@nil{\expandafter\def\csname\string\color@#1\endcsname{\xcolor@{}{}{rgb}{#2,#2,#2}}}

\pgfutil@definecolor{white}{gray}{1}
\pgfutil@definecolor{black}{gray}{0}
\pgfutil@definecolor{gray}{gray}{0.5}
\pgfutil@definecolor{red}{rgb}{1,0,0}
\pgfutil@definecolor{green}{rgb}{0,1,0}
\pgfutil@definecolor{blue}{rgb}{0,0,1}
\pgfutil@definecolor{cyan}{rgb}{0,1,1}
\pgfutil@definecolor{magenta}{rgb}{1,0,1}
\pgfutil@definecolor{yellow}{rgb}{1,1,0}
\pgfutil@definecolor{orange}{rgb}{1,0.5,0}
\pgfutil@definecolor{violet}{rgb}{0.5,0,0.5}
\pgfutil@definecolor{purple}{rgb}{0.75,0,0.25}
\pgfutil@definecolor{brown}{rgb}{0.75,0.5,0.25}

\def\pgfutil@color#1{%
  \pgfutil@colorlet{.}{#1}%
  \pgfsysprotocol@getcurrentprotocol\pgfutil@emu@temp%
  {%
    \pgfsysprotocol@setcurrentprotocol\pgfutil@empty%
    \pgfsysprotocol@bufferedtrue%
    \pgfsetcolor{.}%
    \expandafter\pgfsys@outerinvoke\expandafter{\pgfsysprotocol@currentprotocol}%
  }%
  \pgfsysprotocol@setcurrentprotocol\pgfutil@emu@temp%
  \aftergroup\pgfutil@reset@color%
}

\def\pgfutil@extractcolorspec#1#2{%
  \def#2{{#1}}%
}

\def\pgfutil@convertcolorspec#1#2#3{%
  \edef#3{\expandafter\expandafter\expandafter\pgfutil@emu@select\csname\string\color@#1\endcsname}%
}


\def\pgfutil@doifcolorelse#1#2#3{%
  \expandafter\ifx\csname\string\color@#1\endcsname\relax%
    \doifcolorelse{#1}{\let\pgf@next=\pgfutil@firstoftwo}{\let\pgf@next=\pgfutil@secondoftwo}%
  \else
    \let\pgf@next=\pgfutil@firstoftwo%
  \fi%
  \pgf@next{#2}{#3}%
}


\def\pgfutil@reset@color{%
  \pgfsysprotocol@getcurrentprotocol\pgfutil@emu@temp%
  {%
    \pgfsysprotocol@setcurrentprotocol\pgfutil@empty%
    \pgfsysprotocol@bufferedtrue%
    \pgfsetcolor{.}%
    \expandafter\pgfsys@outerinvoke\expandafter{\pgfsysprotocol@currentprotocol}%
  }%
  \pgfsysprotocol@setcurrentprotocol\pgfutil@emu@temp%
}
\expandafter\def\csname\string\color@.\endcsname{\xcolor@{}{}{rgb}{0,0,0}}

\def\pgfutil@colorlet#1#2{%
  \edef\pgf@marshal{#2}%
  \expandafter\pgfutil@in@\expandafter!\expandafter{\pgf@marshal}%
  \ifpgfutil@in@%
    % compute mixture
    {%
      \expandafter\pgfutil@emu@mix\pgf@marshal!white!\@nil%
      \xdef\pgf@marshal{\noexpand\def\expandafter\noexpand\csname\string\color@#1\endcsname{%
          \noexpand\xcolor@{}{}{rgb}{\pgf@sys@tonumber\pgf@xa,\pgf@sys@tonumber\pgf@xb,\pgf@sys@tonumber\pgf@xc}}}%
    }%
    \pgf@marshal%
  \else%
    \expandafter\ifx\csname\string\color@#2\endcsname\relax%
      \pgfutil@registercolor{#2}%
    \fi%
    \edef\pgf@marshal{\noexpand\let\expandafter\noexpand\csname\string\color@#1\endcsname=%
                      \expandafter\noexpand\csname\string\color@#2\endcsname}%
    \pgf@marshal%
  \fi%
}
\def\pgfutil@emu@mix#1!#2!#3!#4\@nil{%
  \expandafter\ifx\csname\string\color@#1\endcsname\relax%
    \pgfutil@registercolor{#1}%
  \fi%
  \expandafter\ifx\csname\string\color@#3\endcsname\relax%
    \pgfutil@registercolor{#3}%
  \fi%
  \expandafter\expandafter\expandafter\pgfutil@emu@unpack\csname\string\color@#1\endcsname%
  \pgf@ya=\pgf@xa%
  \pgf@yb=\pgf@xb%
  \pgf@yc=\pgf@xc%
  \expandafter\expandafter\expandafter\pgfutil@emu@unpack\csname\string\color@#3\endcsname%
  \c@pgf@counta=#2\relax%
  \c@pgf@countb=100\relax%
  \advance\c@pgf@countb by-\c@pgf@counta\relax%
  \pgf@xa=\c@pgf@countb\pgf@xa%
  \advance\pgf@xa by\c@pgf@counta\pgf@ya%
  \divide\pgf@xa by 100\relax%
  \pgf@xb=\c@pgf@countb\pgf@xb%
  \advance\pgf@xb by\c@pgf@counta\pgf@yb%
  \divide\pgf@xb by 100\relax%
  \pgf@xc=\c@pgf@countb\pgf@xc%
  \advance\pgf@xc by\c@pgf@counta\pgf@yc%
  \divide\pgf@xc by 100\relax%
}
\def\pgfutil@emu@unpack#1#2#3#4#5{%
  \pgfutil@emu@@unpack#5\@nil%
}
\def\pgfutil@emu@@unpack#1,#2,#3\@nil{%
  \pgf@xa=#1pt%
  \pgf@xb=#2pt%
  \pgf@xc=#3pt%
}

\def\pgfutil@emu@select#1#2#3#4#5{#5}


\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%
      \PackageError{pgf}{Color #1 has an unsupported color model.}{}%
      \pgfutil@definecolor{#1}{gray}{0}
    \fi%
  \fi%
}

\def\pgfutil@context@parse@gray#1 g#2\pgf@stop#3{%
  \pgfutil@definecolor{#3}{gray}{#1}
}

\def\pgfutil@context@parse@rgb#1 #2 #3 rg#4\pgf@stop#5{%
  \pgfutil@definecolor{#5}{rgb}{#1,#2,#3}
}

% Make this command available in general:
\let\colorlet=\pgfutil@colorlet


% pgfutil@minipage

\def\pgfutil@minipage[#1]#2{%
  \hbox to#2\bgroup%
    \hsize=#2\relax%
    \vbox\bgroup\leavevmode%
}
\def\pgfutil@endminipage{\egroup\egroup}



% Driver detector (how should we do this in ConTeXt?) :

\ifx\pdfoutput\@undefined\newcount\pdfoutput\fi
\ifx\pdfoutput\relax\newcount\pdfoutput\fi

\def\pgfutil@guessdriver{
  \ifx\XeTeXversion\@undefined
    \ifx\preloadedspecials\@undefined%
      \ifcase\pdfoutput%
        \def\pgfsysdriver{pgfsys-dvips.def}%
      \else%
        \def\pgfsysdriver{pgfsys-pdftex.def}% pdfTeX & LuaTeX
      \fi%
    \else%
      \pgfutil@driver@if@in{postscript}{pgfsys-dvips.def}
      \pgfutil@driver@if@in{tpd}{pgfsys-pdftex.def}
      \pgfutil@driver@if@in{dpm}{pgfsys-dvipdfm.def}
      \pgfutil@driver@if@in{dpx}{pgfsys-dvipdfmx.def}
      \pgfutil@driver@if@in{xetex}{pgfsys-xetex.def}
      \ifx\pgfsysdriver\relax%
        \PackageWarning{pgf}{I was not able to discern the driver, the
          preloaded specials were \preloadedspecials. I am going to use
          pgfsys-dvips.def}%
        \def\pgfsysdriver{pgfsys-dvips.def}
      \fi%
    \fi
  \else
    \def\pgfsysdriver{pgfsys-xetex.def}% should be right
  \fi
}
\def\pgfutil@driver@if@in#1#2{%
  \edef\pgf@marshal{\noexpand\pgfutil@in@{#1}{\preloadedspecials}}
  \pgf@marshal
  \ifpgfutil@in@%
    \def\pgfsysdriver{#2}%
  \fi%
}


% Global colors

\let\pgfutil@globalcolorsfalse=\relax
\let\pgfutil@globalcolorstrue=\relax



% Font stuff

\def\pgfutil@font@tiny{\tfxx}
\def\pgfutil@font@scriptsize{\tfxx}
\def\pgfutil@font@footnotesize{\tfx}
\def\pgfutil@font@small{\tfx}
\def\pgfutil@font@normalsize{\tf}
\def\pgfutil@font@large{\tfa}
\def\pgfutil@font@Large{\tfb}
\def\pgfutil@font@huge{\tfc}
\def\pgfutil@font@Huge{\tfc}

\def\pgfutil@font@itshape{\it}
\def\pgfutil@font@bfseries{\bf}

\let\pgfutil@font@normalfont=\tf

\let\pgfutil@selectfont=\tf


% Extra counters, registers, boxes

\newcount\pgfutil@tempcnta
\newcount\pgfutil@tempcntb

\newbox\pgfutil@tempboxa

\newdimen\pgfutil@tempdima
\newdimen\pgfutil@tempdimb

\newbox  \pgfutil@voidb@x
\newtoks \pgfutil@toks@

% Module stuff

\def\pgfutil@usemodule#1{\usemodule[#1]}

% % % % begin patches by HH % % % %

\let\pgfutil@insertatbegincurrentpagefrombox\flushatshipout
\let\pgfutil@insertatbegincurrentpage       \flushatshipout
\def\pgfutil@insertatbegineverypage         #1{\appendtoks#1\to\everyshipout} % space removed after #1

\let\pgfutil@setuppdfresources \relax

\doifmodeelse {mkiv} {

    \def\pgf@sys@pdf@pdfbackendset@one#1#2%
      {\normalexpanded{\noexpand\pgf@sys@pdf@pdfbackendset@two\noexpand#1#2\relax}}

    \def\pgf@sys@pdf@pdfbackendset@two#1/#2 #3\relax
      {#1{#2}{#3}}

    \def\pgf@sys@pdf@addtopageresource@pattern   {\pgf@sys@pdf@pdfbackendset@one\pdfbackendsetpattern}
    \def\pgf@sys@pdf@addtopageresource@colorspace{\pgf@sys@pdf@pdfbackendset@one\pdfbackendsetcolorspace}
    \def\pgf@sys@pdf@addtopageresource@extgstate {\pgf@sys@pdf@pdfbackendset@one\pdfbackendsetextgstate}
    \def\pgf@sys@pdf@possible@resources          {\pdfbackendcurrentresources}
    \def\pgf@sys@pdf@check@resources             {}

    \ifdefined\PDFcolor \else

        \ctxlua{function lpdf.pdfcolor(attribute) context(lpdf.color(1,attribute)) end}

        \def\PDFcolor#1{\ctxlua{lpdf.pdfcolor(\thecolorattribute{#1})}}

    \fi

} {

    \def\pgf@sys@pdf@addtopageresource@extgstate  {\appendtoPDFdocumentextgstates }
    \def\pgf@sys@pdf@addtopageresource@colorspace {\appendtoPDFdocumentcolorspaces}
    \def\pgf@sys@pdf@addtopageresource@pattern    {\appendtoPDFdocumentpatterns   }
    \def\pgf@sys@pdf@possible@resources           {\currentPDFresources}
    \def\pgf@sys@pdf@check@resources              {}

}

\let\pgf@sys@addpdfresource@extgs@plain      \pgf@sys@pdf@addtopageresource@extgstate
\let\pgf@sys@addpdfresource@patterns@plain   \pgf@sys@pdf@addtopageresource@pattern
\let\pgf@sys@addpdfresource@colorspaces@plain\pgf@sys@pdf@addtopageresource@colorspace
\let\pgf@sys@pdf@check@resources@plain       \pgf@sys@pdf@check@resources

\pgf@sys@addpdfresource@colorspaces@plain{/pgfprgb [/Pattern /DeviceRGB]}

% % % % end patches by HH % % % %

% Do something at the end of a job

\appendtoks \the\pgfutil@everybye \to \everybye

% The following is still messy and needs to be cleanup up (everything
% prefixed by pgfutil@):

\def\PackageInfo#1#2{}
\def\PackageWarning#1#2{\immediate\write17{Package #1: Warning! #2.}}%
\def\PackageError#1#2#3{\immediate\write17{Package #1: Error! #2.}}%
\long\def\AtBeginDocument#1{#1}%

\endinput

[-- Attachment #3: Type: text/plain, Size: 486 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  parent reply	other threads:[~2010-10-28 11:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-26 10:20 Michael Murphy
2010-10-27 12:49 ` Cedric Mauclair
2010-10-27 17:18   ` Marius
2010-10-27 20:08     ` Michael Murphy
2010-10-28  7:54       ` Cedric Mauclair
2010-10-28  8:24         ` Cedric Mauclair
2010-10-28 11:47           ` Hans Hagen
2010-10-28 11:46         ` Hans Hagen [this message]
2010-10-28 12:14           ` Cedric Mauclair
2010-10-28  9:44       ` Marius
2010-11-11 11:07 ` Tikz figures not centred Michael Murphy
2010-11-11 11:14   ` Vedran Miletić
2010-11-11 16:18     ` Michael Murphy
2010-11-11 19:34       ` Aditya Mahajan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4CC96291.9010508@wxs.nl \
    --to=pragma@wxs.nl \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).