ConText, TikZ and definecolor: undefined control sequence
Hi, I've been trying to get colors to work in TikZ, and found a nice fix by Aditya here: http://archive.contextgarden.net/message/20100120.220124.f2d3f8bc.en.html The problem is that the lua script doesn't work: I get a problem with 'colors'. LuaTeX error <main ctx instance>:13: attempt to index global 'colors' (a nil value) stack traceback: <main ctx instance>:13: in function 'registercolor' <main ctx instance>:1: in main chunk. The input file from Aditya (called colorfix.tex) is \startluacode pgfutil = pgfutil or { } local texsprint, format = tex.sprint, string.format local prtcatcodes = tex.prtcatcodes function pgfutil.unsupported_color(name) texsprint(prtcatcodes,format("\\PackageError{pgf}{color %s has unsupported model}{}", name)) texsprint(prtcatcodes,format("\\pgfutil@definecolor{%s}{gray}{0}", name)) end function pgfutil.registercolor(name, attributes) print(name, attributes) local cv = colors.value(attributes) if cv then local model = cv[1] if model == 1 then print("model=1") texsprint(prtcatcodes,format("\\pgfutil@definecolor{%s}{gray}{% 1.3f}", name, cv[2])) elseif model == 3 then print("model=2") texsprint(prtcatcodes,format("\\pgfutil@definecolor{%s}{rgb}{% 1.3f,%1.3f,%1.3f}", name, cv[3], cv[4], cv[5])) else print("no model") pgfutil.unsupported_color(name) end else print("no color") pgfutil.unsupported_color(name) end end \stopluacode \unprotect \def\pgfutil@registercolor#1% {\ctxlua{pgfutil.registercolor("#1",\thecolorattribute {#1})}} \protect and my test file is \usemodule[tikz] \input colorfix \definecolor[mycolor][r=1,g=0,b=1] \starttext \starttikzpicture \fill[mycolor] (0,0) circle (1); \stoptikzpicture \stoptext I'm running the latest beta.
Hi,
Same problem here with the latest TikZ 2.10.
Regards.
-- Cédric
On Tue, Oct 26, 2010 at 12:20, Michael Murphy
Hi,
I've been trying to get colors to work in TikZ, and found a nice fix by Aditya here:
http://archive.contextgarden.net/message/20100120.220124.f2d3f8bc.en.html
The problem is that the lua script doesn't work: I get a problem with 'colors'.
LuaTeX error <main ctx instance>:13: attempt to index global 'colors' (a nil value) stack traceback: <main ctx instance>:13: in function 'registercolor' <main ctx instance>:1: in main chunk.
The input file from Aditya (called colorfix.tex) is
\startluacode pgfutil = pgfutil or { } local texsprint, format = tex.sprint, string.format local prtcatcodes = tex.prtcatcodes
function pgfutil.unsupported_color(name) texsprint(prtcatcodes,format("\\PackageError{pgf}{color %s has unsupported model}{}", name)) texsprint(prtcatcodes,format("\\pgfutil@definecolor{%s}{gray}{0}", name)) end
function pgfutil.registercolor(name, attributes) print(name, attributes) local cv = colors.value(attributes) if cv then local model = cv[1] if model == 1 then print("model=1") texsprint(prtcatcodes,format("\\pgfutil@definecolor{%s}{gray}{% 1.3f}", name, cv[2])) elseif model == 3 then print("model=2") texsprint(prtcatcodes,format("\\pgfutil@definecolor{%s}{rgb}{% 1.3f,%1.3f,%1.3f}", name, cv[3], cv[4], cv[5])) else print("no model") pgfutil.unsupported_color(name) end else print("no color") pgfutil.unsupported_color(name) end end \stopluacode
\unprotect \def\pgfutil@registercolor#1% {\ctxlua{pgfutil.registercolor("#1",\thecolorattribute {#1})}} \protect
and my test file is
\usemodule[tikz] \input colorfix
\definecolor[mycolor][r=1,g=0,b=1]
\starttext \starttikzpicture \fill[mycolor] (0,0) circle (1); \stoptikzpicture \stoptext
I'm running the latest beta.
___________________________________________________________________________________ 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 ___________________________________________________________________________________
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
If you want to fix script, you need to change line:
local cv = colors.value(attributes)
into
local cv = attributes.colors.values
Just guess, untested.
Regards,
Marius
On 27 October 2010 15:49, Cedric Mauclair
Hi,
Same problem here with the latest TikZ 2.10.
Regards.
-- Cédric
On Tue, Oct 26, 2010 at 12:20, Michael Murphy
wrote: Hi,
I've been trying to get colors to work in TikZ, and found a nice fix by Aditya here:
http://archive.contextgarden.net/message/20100120.220124.f2d3f8bc.en.html
The problem is that the lua script doesn't work: I get a problem with 'colors'.
LuaTeX error <main ctx instance>:13: attempt to index global 'colors' (a nil value) stack traceback: <main ctx instance>:13: in function 'registercolor' <main ctx instance>:1: in main chunk.
The input file from Aditya (called colorfix.tex) is
\startluacode pgfutil = pgfutil or { } local texsprint, format = tex.sprint, string.format local prtcatcodes = tex.prtcatcodes
function pgfutil.unsupported_color(name) texsprint(prtcatcodes,format("\\PackageError{pgf}{color %s has unsupported model}{}", name)) texsprint(prtcatcodes,format("\\pgfutil@definecolor{%s}{gray}{0}", name)) end
function pgfutil.registercolor(name, attributes) print(name, attributes) local cv = colors.value(attributes) if cv then local model = cv[1] if model == 1 then print("model=1") texsprint(prtcatcodes,format("\\pgfutil@definecolor{%s}{gray}{% 1.3f}", name, cv[2])) elseif model == 3 then print("model=2") texsprint(prtcatcodes,format("\\pgfutil@definecolor{%s}{rgb}{% 1.3f,%1.3f,%1.3f}", name, cv[3], cv[4], cv[5])) else print("no model") pgfutil.unsupported_color(name) end else print("no color") pgfutil.unsupported_color(name) end end \stopluacode
\unprotect \def\pgfutil@registercolor#1% {\ctxlua{pgfutil.registercolor("#1",\thecolorattribute {#1})}} \protect
and my test file is
\usemodule[tikz] \input colorfix
\definecolor[mycolor][r=1,g=0,b=1]
\starttext \starttikzpicture \fill[mycolor] (0,0) circle (1); \stoptikzpicture \stoptext
I'm running the latest beta.
___________________________________________________________________________________ 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 ___________________________________________________________________________________
___________________________________________________________________________________ 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 ___________________________________________________________________________________
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)
into
local cv = attributes.colors.values
Just guess, untested.
Nope, doesn't work. Using local colors = colors or { } gets me a little further, but then complains that 'value' is a nil value. I don't know enough Lua to fix this either. Strangely, it seems to work on some older MkIV versions of ConTeXt... Michael.
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
On Wed, Oct 27, 2010 at 22:08, Michael Murphy
into
local cv = attributes.colors.values
Just guess, untested.
Nope, doesn't work. Using
local colors = colors or { }
gets me a little further, but then complains that 'value' is a nil value. I don't know enough Lua to fix this either. Strangely, it seems to work on some older MkIV versions of ConTeXt...
Michael. ___________________________________________________________________________________ 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 ___________________________________________________________________________________
Actually, the opacity works great!
-- Cédric
On Thu, Oct 28, 2010 at 09:54, Cedric Mauclair
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
On Wed, Oct 27, 2010 at 22:08, Michael Murphy
wrote: that. 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?
Regards.
-- Cédric
into
local cv = attributes.colors.values
Just guess, untested.
Nope, doesn't work. Using
local colors = colors or { }
gets me a little further, but then complains that 'value' is a nil value. I don't know enough Lua to fix this either. Strangely, it seems to work on some older MkIV versions of ConTeXt...
Michael. ___________________________________________________________________________________ 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 ___________________________________________________________________________________
On 28-10-2010 10:24, Cedric Mauclair wrote:
Actually, the opacity works great!
Officially it could hook into the context transparency model but I guess that that is too much hassle. 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 -----------------------------------------------------------------
On 28-10-2010 9:54, Cedric Mauclair 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
On Wed, Oct 27, 2010 at 22:08, Michael Murphy
wrote: 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 -----------------------------------------------------------------
Sadly no. I once tried to modify it to make it work and I ended up
with what I proposed. Not very nice, but worked for me.
Thanks for your solution.
-- Cédric
On Thu, Oct 28, 2010 at 13:46, Hans Hagen
\ifdefined\PDFcolor \else
\ctxlua{function lpdf.pdfcolor(attribute) context(lpdf.color(1,attribute)) end}
\def\PDFcolor#1{\ctxlua{lpdf.pdfcolor(\thecolorattribute{#1})}}
\fi
Here is the fixed script.
On 27 October 2010 23:08, Michael Murphy
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)
into
local cv = attributes.colors.values
Just guess, untested.
Nope, doesn't work. Using
local colors = colors or { }
gets me a little further, but then complains that 'value' is a nil value. I don't know enough Lua to fix this either. Strangely, it seems to work on some older MkIV versions of ConTeXt...
Michael. ___________________________________________________________________________________ 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 ___________________________________________________________________________________
Hi,
I've been having some problems with tikz figures. When I define a new
tikz figure, I normally put it in a buffer:
\startbuffer[mypic]
\starttikzfigure
...
\stoptikzfigure
\stopbuffer
which I use later when I place the figure
\placefigure{My picture}{\getbuffer[mypic]}
The problem is that the figure is not centred: it is always aligned with
the left side of the document. I guess this has something to do with
Context not being able to get the image bounds, since it works fine for
tikz images that are already precompiled into PDFs:
\placefigure{My picture}{\externalimage[mypic.pdf]}
Minimal example is attached.
Michael.
--
Michael Murphy
2010/11/11 Michael Murphy
Hi,
I've been having some problems with tikz figures. When I define a new tikz figure, I normally put it in a buffer:
\startbuffer[mypic] \starttikzfigure ... \stoptikzfigure \stopbuffer
which I use later when I place the figure
\placefigure{My picture}{\getbuffer[mypic]}
The problem is that the figure is not centred: it is always aligned with the left side of the document. I guess this has something to do with Context not being able to get the image bounds, since it works fine for tikz images that are already precompiled into PDFs:
\placefigure{My picture}{\externalimage[mypic.pdf]}
Minimal example is attached.
Michael.
You have to wrap up the picture inside of a \hbox, e.g. \hbox{\starttikzfigure ... \stoptikzfigure} Regards, -- Vedran Miletić
On Thu, 2010-11-11 at 12:14 +0100, Vedran Miletić wrote:
2010/11/11 Michael Murphy
Hi, I've been having some problems with tikz figures. When I define a new tikz figure, I normally put it in a buffer:
\startbuffer[mypic] \starttikzfigure ... \stoptikzfigure \stopbuffer
which I use later when I place the figure
\placefigure{My picture}{\getbuffer[mypic]}
The problem is that the figure is not centred: it is always aligned with the left side of the document. I guess this has something to do with Context not being able to get the image bounds, since it works fine for tikz images that are already precompiled into PDFs:
\placefigure{My picture}{\externalimage[mypic.pdf]}
Minimal example is attached.
Michael.
You have to wrap up the picture inside of a \hbox, e.g.
\hbox{\starttikzfigure ... \stoptikzfigure}
Regards,
-- Vedran Miletić
Hmm, why didn't I think of that... Thanks!
--
Michael Murphy
On Thu, 11 Nov 2010, Michael Murphy wrote:
On Thu, 2010-11-11 at 12:14 +0100, Vedran Miletić wrote:
2010/11/11 Michael Murphy
Hi, I've been having some problems with tikz figures. When I define a new tikz figure, I normally put it in a buffer:
\startbuffer[mypic] \starttikzfigure ... \stoptikzfigure \stopbuffer
which I use later when I place the figure
\placefigure{My picture}{\getbuffer[mypic]}
The problem is that the figure is not centred: it is always aligned with the left side of the document. I guess this has something to do with Context not being able to get the image bounds, since it works fine for tikz images that are already precompiled into PDFs:
\placefigure{My picture}{\externalimage[mypic.pdf]}
Minimal example is attached.
Michael.
You have to wrap up the picture inside of a \hbox, e.g.
\hbox{\starttikzfigure ... \stoptikzfigure}
Regards,
-- Vedran Miletić
Hmm, why didn't I think of that... Thanks!
See http://archive.contextgarden.net/thread/20090722.010815.d9c051d3.en.html for an old discussion on this. Aditya
participants (6)
-
Aditya Mahajan
-
Cedric Mauclair
-
Hans Hagen
-
Marius
-
Michael Murphy
-
Vedran Miletić