12

Today I found something weird. When I use \selectcolormodel{} in a TikZ drawing the model is only applied to \fill and not to \draw[fill=]. Does anyone know why?

\documentclass{article}

%\usepackage[gray]{xcolor} % all draws or fills become gray
\usepackage{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}

    \draw [fill=cyan] (0,0) rectangle (1,1);
    \fill [cyan] (2,0) rectangle (3,1);

\end{tikzpicture}

\selectcolormodel{gray}

\begin{tikzpicture}

    \draw [fill=cyan] (0,0) rectangle (1,1); % expected this one to change
    \fill [cyan] (2,0) rectangle (3,1);

\end{tikzpicture}

\end{document}

And the result is the one below.

Result

cacamailg
  • 8,405

2 Answers2

7

The following workaround redefines the color in the current target color model via \colorlet[named]{<color>}{<color>}. A \colorlet without [named] does not redefine the color in the target color model, which seems also the problem with the TikZ, which uses \colorlet in \pgfsetfillcolor. As "unknown" option, TikZ uses \color instead, which converts the color on usage (depending on switch \ifconvertcolorU).

\documentclass{article}

\usepackage{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}

    \draw [fill=cyan] (0,0) rectangle (1,1);
    \fill [cyan] (2,0) rectangle (3,1);

\end{tikzpicture}

\selectcolormodel{gray}

\begin{tikzpicture}

    % \colorlet{cyan}{cyan} alone does not convert the color space
    \colorlet[named]{cyan}{cyan}%

    \draw [fill=cyan] (0,0) rectangle (1,1);
    \fill [cyan] (2,0) rectangle (3,1);

\end{tikzpicture}

\end{document}

Result

Heiko Oberdiek
  • 271,626
  • 1
    Did you have an idea why \usepackage[gray]{xcolor} is working well and why it is not equivalent to \selectcolormodel{gray} ? – Kpym Sep 15 '16 at 09:12
1

Meanwhile this bug has been fixed (or worked around) in the commit 83b22a available from the development repository of pgf/tikz https://sourceforge.net/projects/pgf/

enter image description here