# xcolor wrong conversion to cmyk color model

This is a MWE:

\documentclass{article}
\usepackage{xcolor}

\begin{document}
\definecolor{mycolor}{HTML}{4CAF50}

\extractcolorspecs{mycolor}{\tmpmodel}{\tmpcolorspec}

My color model: \tmpmodel

My color spec: \tmpcolorspec

\convertcolorspec{\tmpmodel}{\tmpcolorspec}{cmyk}{\cmykcolorspec}

My color in cmyk: \cmykcolorspec

\convertcolorspec{\tmpmodel}{\tmpcolorspec}{HTML}{\htmlcolorspec}

My color in HTML: \htmlcolorspec\\

\colorbox{mycolor}{\parbox[b][5em]{4em}{\tiny mycolor}}
% Change color model
\selectcolormodel{cmyk}
\colorbox{mycolor}{\parbox[b][5em]{4em}{\tiny mycolor cmyk}}
\definecolor{mynewcolor}{cmyk}{0.38821,0,0.37251,0.31374}
\colorbox{mynewcolor}{\parbox[b][5em]{4em}{\tiny mynewcolor}}
\definecolor{mylastcolor}{cmyk}{0.5656,0,0.5429,0.3137}
\colorbox{mylastcolor}{\parbox[b][5em]{4em}{\tiny mylastcolor}}
\end{document}


This is the result:

Notice that mycolor is defined using an HTML model: 4CAF50. The color model selected by xcolor as default is rgb, as we can see from the extracted model. The color specification for this rgb model is 0.29805,0.68626,0.31374, which is indeed the same as that we can get using some online color converter (https://www.colorhexa.com/4caf50). The color specification after a cmyk conversion is 0.38821,0,0.37251,0.31374, which is completely different from almost any conversion performed online, for example, is this site the result is 0.5656,0,0.5429,0.3137. Finally, as you can see, the HTML specification corresponds to the original value, so we can think that rgb-to-HTML conversion is performed properly but rgb-to-cmyk doesn't.

We are working here with two completely different color spaces, it is understandable that the colors look different from one space to another, you can see the same think in applications like Adobe Photoshop as well. The problem here is the apparent error in the color conversion when we go from rgb to cmyk.

Why is this happening? How can I correct it? Is there some parameter that I am missing?

I get your cmyk-values with the following calculation steps:

  c= 1-r = 0.70195
m= 1-g = 0.31374
y= 1-b = 0.68626

k = min(c,m,y) = 0.31374

c = c-k = 0.38821
m = m-k = 0
y = y-k = 0.37252


This rather simple conversion method is described in the postscript manual (https://www.adobe.com/content/dam/acom/en/devnet/actionscript/articles/psrefman.pdf, page 305 ff). It is certainly one possibility to calculate the conversion.

• perhaps add a pointer to xcolor doc which says page 50 Conversion cmy to cmyk. This is probably the hardest of our conversion tasks: many sources emphasize that there does not exist any universal conversion algorithm for this case because of device-dependence. And it seems rgb -> cmyk is done as rgb -> cmy -> cmyk. (guessing) – user4686 Jun 12 '18 at 9:33
• Oh, I see... So it is not a wrong calculation, is it? :) I've made the question because I saw this: tex.stackexchange.com/questions/371958/…, in which the OP assumes the conversion produces bad color definitions. – osjerick Jun 12 '18 at 10:01

Not really an answer. Just a code to visualize better the difference. As you can see below there is consistency across conversions. About the conversion in cmyk, as jfbu states in his/her comment, doesn't exist only one conversion algorithm because of device dependence.

\documentclass[border=10pt]{standalone}
\usepackage{xcolor}
\begin{document}
\sffamily
\begin{testcolors}[rgb,cmyk,hsb,HTML]
\testcolor[HTML]{4CAF50}
\testcolor[rgb]{0.29805,0.68626,0.31374}
\testcolor[cmyk]{0.38821,0,0.37251,0.31374}
\testcolor[cmyk]{0.5656,0,0.5429,0.3137}
\end{testcolors}
\end{document}

• Unfortunately I think that in order to have the best result is to print a sample page with all the colors you use in your palette (and maybe some variants) and based on the result eventually modify the palette in your document. – gvgramazio Jun 12 '18 at 10:10