Hi Aditya,
Thanks for the help -- I think I now see why there is such trouble with
colors in pgf and context. It looks like one can systematically
transform LaTeX-like PGF examples of \color into ConTeXt examples.
The reason why this came up is that I'm trying to go through Till
Tantau's "Example for Karl's Students" tutorial in the PGF/TikZ manual.
Has anyone managed to ConTeXt-ify that example? The closest that I've come is
\usemodule[tikz]
\setupcolors[state=start]
\starttext
\starttikzpicture
[scale=3,
line cap=thin,
%Styles
axes/.style=,
important line/.style={very thick},
information text/.style={rounded corners,fill=red!10,inner sep=1ex}]
% Local definitions
\def\costhirty{0.8660256}
% The graphic
\draw[help lines,step=0.5cm] (-1.4,-1.4) grid (1.4,1.4);
\draw (0,0) circle (1cm);
\startscope[axes]
\draw[->] (-1.5,0) -- (1.5,0) node[right] {$x$} coordinate(x axis);
\draw[->] (0,-1.5) -- (0,1.5) node[above] {$y$} coordinate(y axis);
\foreach \x/\xtext in {-1, -.5/-\frac{1}{2}, 1}
\draw[xshift=\x cm] (0pt,1pt) -- (0pt,-1pt) node[below,fill=white] {$\xtext$};
\foreach \y/\ytext in {-1, -.5/-\frac{1}{2}, .5/\frac{1}{2}, 1}
\draw[yshift=\y cm] (1pt,0pt) -- (-1pt,0pt) node[left,fill=white] {$\ytext$};
\stopscope
\filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0pt) arc(0:30:3mm);
\draw (15:2mm) node[green!50!black] {$\alpha$};
\draw[important line,red]
(30:1cm) -- node[left=1pt,fill=white] {$\sin \alpha$} (30:1cm |- x axis);
\draw[important line,orange!80!black] (1,0) -- node[right=1pt,fill=white] {
$\displaystyle \tan \alpha \color[black]{=}
\frac{\color[red]{\sin \alpha}}{\color[blue]{\cos \alpha}}$}
(intersection of 0,0--30:1cm and 1,0--1,1) coordinate (t);
\draw (0,0) -- (t);
\draw[xshift=1.85cm]
node[right,text width=6cm,information text]
{
The \color[green!50!black]{angle $\alpha$} is $30^\circ$ in the
example ($\pi/6$ in radians). The \color[red]{sine of
$\alpha$}, which is the height of the red line, is
\startformula
\color[red]{\sin \alpha} = 1/2.
\stopformula
By the Theorem of Pythagoras ...
};
\stoptikzpicture
\stoptext
The example features some \definecolor's which I just did away with
(sadly) by simply substituting their defining values for their
occurences. (This is unfortunate, but perhaps necessary until some
other mechanism is produced.) The problem is that the text box to the
right of the picture is supposed to be colored, and with rounded
corners. But the box is missing. Look at p. 20 of
http://altermundus.com/downloads/pgfmanual_cvs.pdf
to see what I mean. Also, the phrase "angle $\alpha$" is supposed to be
in a kind of green, but that's not working either. What might be
happening?
Thanks,
Jesse
Aditya Mahajan
I am CCing to the context list also.
On Mon, 18 Feb 2008, Jesse Alama wrote:
Hi Aditya,
I recently came across a thread on the PGF users mailing list in which you mention some problems with ConTeXt, PGF and colors. For example:
http://article.gmane.org/gmane.comp.tex.pgf.user/38
Have these issues beein resolved for your? I just downloaded PFG 1.18 from the modules part of the contextgarden, installed it, and, when trying to compile the following example PGF code
\starttikzpicture[scale=3] \clip (-2,-0.2) rectangle (2,0.8); \draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4); \filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm) arc (0:30:3mm) -- cycle; \draw[->] (-1.5,0) -- (1.5,0) coordinate (x axis); \draw[->] (0,-1.5) -- (0,1.5) coordinate (y axis); \draw (0,0) circle (1cm);
\draw[very thick,red] (30:1cm) -- node[left=1pt,fill=white] {$\sin \alpha$} (30:1cm |- x axis); \draw[very thick,blue] (30:1cm |- x axis) -- node[below=2pt,fill=white] {$\cos \alpha$} (0,0); \draw[very thick,orange] (1,0) -- node [right=1pt,fill=white] {$\displaystyle \tan \alpha \color{black}= \frac{{\color[red]\sin \alpha}}{{\color[blue]\cos \alpha}}$} (intersection of 0,0--30:1cm and 1,0--1,1) coordinate (t);
\draw (0,0) -- (t); \foreach \x/\xtext in {-1, -0.5/-\frac{1}{2}, 1} \draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north,fill=white] {$\xtext$}; \foreach \y/\ytext in {-1, -0.5/-\frac{1}{2}, 0.5/\frac{1}{2}, 1} \draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east,fill=white] {$\ytext$}; \stoptikzpicture
(which is taken from the PGF manual), I get
! Use of \color doesn't match its definition. \tikz@temp ...{$\displaystyle \tan \alpha \color { black}= \frac {{\color {re...
\tikz@invoke@collected@onpath ...mmand \tikz@temp \pgf@stop \tikz@node@is@a@...
\tikz@scan@next@command ...nvoke@collected@onpath \fi \afterassignment \tikz... l.86 ...(intersection of 0,0--30:1cm and 1,0--1,1) coordinate (t); ?
The problem does seem to be that PGF and ConTeXt both want to define \color.
Any ideas how to get around the problem? As it stands, it seems safe to say that, if colors don't work, then PGF is quite crippled in ConTeXt.
No, the reason for the error is more subtle. PGF does try its best to work with ConTeXt colors. However, there is a difference between latex and context color usage, that gives rise to the error. The culprit in this case is:
{$\displaystyle \tan \alpha \color{black}= \frac{{\color[red]\sin \alpha}}{{\color[blue]\cos \alpha}}$}
Try this in a standalong context file (no pgf) and you will get an error. First you need to change \color{black} to \color[black]. Even then you will get an error. You need to use
{$\displaystyle \tan \alpha {\color[black]= \frac{{\color[red]\sin \alpha}}{{\color[blue]\cos \alpha}}}$}
(Notice the {...} around \color[black]). Then everything works fine. Here is a working example (latest pgf from cvs, but should also work with 1.18).
\usemodule[tikz] \setupcolors[state=start]
\starttext
\starttikzpicture[scale=3] \clip (-2,-0.2) rectangle (2,0.8); \draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4); \filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm) arc (0:30:3mm) -- cycle; \draw[->] (-1.5,0) -- (1.5,0) coordinate (x axis); \draw[->] (0,-1.5) -- (0,1.5) coordinate (y axis); \draw (0,0) circle (1cm); \draw[very thick,red] (30:1cm) -- node[left=1pt,fill=white] {$\sin \alpha$} (30:1cm |- x axis); \draw[very thick,blue] (30:1cm |- x axis) -- node[below=2pt,fill=white] {$\cos \alpha$} (0,0); \draw[very thick,orange] (1,0) -- node [right=1pt,fill=white] {$\displaystyle \tan \alpha {\color[black]= \frac{{\color[red]\sin \alpha}}{{\color[blue]\cos \alpha}}}$} (intersection of 0,0--30:1cm and 1,0--1,1) coordinate (t); \draw (0,0) -- (t); \foreach \x/\xtext in {-1, -0.5/-\frac{1}{2}, 1} \draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north,fill=white] {$\xtext$}; \foreach \y/\ytext in {-1, -0.5/-\frac{1}{2}, 0.5/\frac{1}{2}, 1} \draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east,fill=white] {$\ytext$}; \stoptikzpicture \stoptext
Aditya
-- Jesse Alama (alama@stanford.edu)