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

  • Seems to be a problem with \selectcolormodel. Switching to gray as package option (xcolor) works. Have you tried different positioning of the switching command? – TeXnician Aug 7 '17 at 7:20
  • @TeXnician Should I set it after \begin{document}? I'm going to work now, I'll try tonight and let you know. – CarLaTeX Aug 7 '17 at 7:30
  • @CarLaTeX yeah, a tikzducks tag :) – user36296 Aug 7 '17 at 11:35
  • Related question: tex.stackexchange.com/questions/272222/… -> According to Joseph Wright it seems to be a bug in tikz – user36296 Aug 7 '17 at 11:36
  • @samcarter A tikzducks tag is mandatory! Yes, Ulrike said more or less the same thing in her answer. <3 – CarLaTeX Aug 7 '17 at 11:44
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.

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

0

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/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.