14

\selectcolormodel{gray} doesn't work for the duck hair, but it works for the other parts of the ducks, why?

\documentclass{ltugboat} 
\usepackage{microtype} 
\usepackage{graphicx}

\usepackage{ifthen}
\newboolean{grayscale}   
\setboolean{grayscale}{true}% for the black & white version   
%\setboolean{grayscale}{false}% for the colored version   

\usepackage{tikzducks}
\usetikzlibrary{positioning}

\newenvironment{mytikz}{%
    \begin{tikzpicture}
    \ifthenelse{\boolean{grayscale}}{\selectcolormodel{gray}}{} 
    }
    {\end{tikzpicture}}

\usepackage{ifpdf} 
\ifpdf 
\usepackage[breaklinks,hidelinks]{hyperref} 
\else \usepackage{url} \fi 

\begin{document} 
    Why \textbackslash\texttt{selectcolormodel\string{gray\string}} does not work for the duck hair?

    Black and white version:    

    \begin{mytikz}
        \begin{scope}[xscale=-1]
            \duck[longhair=pink]
        \end{scope}
        \begin{scope}[xshift=10pt]
            \duck[crazyhair=orange]
        \end{scope}
    \end{mytikz}

    Colored version:
    \setboolean{grayscale}{false}

    \begin{mytikz}
        \begin{scope}[xscale=-1]
            \duck[longhair=pink]
        \end{scope}
        \begin{scope}[xshift=10pt]
            \duck[crazyhair=orange]
        \end{scope}
    \end{mytikz}
\end{document}

enter image description here

Henri Menke
  • 109,596
CarLaTeX
  • 62,716

3 Answers3

15

\selectcolormodel works fine but tikz is doing a lot of color assignments by mapping internal commands with \let and this bypasses the color conversion in a number of cases. E.g. a color (or a command expanding to a color) used directly works, but not with the fill key. And \colorlet doesn't work either.

\documentclass{article}

\usepackage{tikz}

\begin{document}


    \textcolor{red}{RED}

    \selectcolormodel{gray} 
    Black and white version:

    \def\mycmdcolor{red}
    \colorlet{mynewletcolor}{red}    
    \definecolor{mynewdefcolor}{rgb}{1,0,0}


    \textcolor{red}{RED} 

    \textcolor{\mycmdcolor}{MYCMDCOLOR}

    \textcolor{mynewletcolor}{MYNEWLETCOLOR}

    \textcolor{mynewdefcolor}{MYNEWDEFCOLOR}


    \begin{tikzpicture}    


    \fill[\mycmdcolor] (0,0) rectangle (1,1);

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

    \draw[fill=mynewletcolor] (4,0) rectangle (5,1);        

    \draw[fill=mynewdefcolor] (6,0) rectangle (7,1);

    \end{tikzpicture}

\end{document}

enter image description here

Imho the only way out is to load xcolor directly with the gray model. Everything else is only curing the symptoms.

CarLaTeX
  • 62,716
Ulrike Fischer
  • 327,261
10

This seems to be a bug in tikz, see

I followed the advice of Ulrike Fischer and changed the code to avoid fill=.... It is fixed in version 0.3 and newer.

If you still encounter this problem, please update your tex distribution or get an up to date package version from https://www.ctan.org/pkg/tikzducks or https://github.com/samcarter/tikzducks

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/