# Colors in the PDF Output - convert rgb rich gray to pure gray (xcolor, tikzs, pgplots)

When using the following minimal example to draw 3 lines with pgfplots respectivly tikzs, you will obtain a pdf with three lines:

 \documentclass[12pt,a4paper,tikz]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{tikz,pgfplots,grffile,amsmath}
\definecolor{parula01}{rgb}{0.00600,0.39650,0.88330}%
\definecolor{parulagray01}{rgb}{0.33527,0.33527,0.33527}% same color as parula01, just converted to greyscale with a MATLAB algorithm - weighted sum: 0.2989 * R + 0.5870 * G + 0.1140 * B --> the result is about 33.527 % black
\definecolor{parulagray02}{gray}{0.33527}% probably the same color as parulagray01, just defined as a gray scale color with only one percentage argument for the grey level
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
]
\addplot [line width=0.8pt, color=parula01, forget plot]
table[row sep=crcr]{%
1  1\\
100    100\\
};
\addplot [line width=0.8pt, color=parulagray01, forget plot]
table[row sep=crcr]{%
1  5\\
100    105\\
};
\addplot [line width=0.8pt, color=parulagray02, forget plot]
table[row sep=crcr]{%
1  10\\
100    110\\
};
\end{axis}
\end{tikzpicture}%
\end{document}


The Result (Adobe Acrobat XI Pro.) will look like this:

You will notice that the two gray lines will look different because Adobe Acrobat XI uses some CMYK profile as the default profile to show the result (I assume!!) and therefore converts the rgb gray (parulagray01 from the preamble) different than the real gray (parulagray02 from the preamble) with some weighted conversion from R,G and B to C,M,Y and K. Actually you can have a look at the Adobe Acrobat Output Preview (or Ausgabevorschau in German) to have a close look at the CMYK composition. The result for the rgb gray (parulagray01 from the preamble) will yield this

while the result for the real gray (parulagray02 from the preamble) will yield this

at least for the color simulation profile U.S. Web Coated (WOP) v2, which Adobe Acrobat XI uses as the default (I assume again) and which is probably the reason why the colors appear as they look on the screen. You could also pick something like Adobe RGB here and then the two gray colors would look absolutly identical, which you can see here:

Anyway - if I get it right: The printer will use a lot of color for the parulagray01 (pseudo gray) color, as there is a lot of C, M, Y specified and I think it is called rich gray or rich black (a gray/black tone that will look gray/black in print but actually uses a lot of color).

Now the question: Is there a simple command to tell pdflatex (or maybe the komascript package or maybe the xcolor package - I don't know where to put it) to interprete all rgb colors that have three identical components (e.g. parulagray01 from the preamble, which uses r=0.33527,g=0.33527 and b=0.33527) as real gray scale colors and not to convert it to some rich gray or rich black color?

I realized that there are some options in Adobe Acrobat XI Pro to convert colors from one color space to another but I don't really understand it, yet. I played around a little bit and managed to get rid of rich gray in some vector graphics. But when I tried the inkov command of ghostscript (9.05 and higher) all pages (even those with text only) had C,M,Y and K components after the conversion by Acrobat, although the Output Preview showed in Adobe showed only K components. Is it even necessary to think about such color problems right now, when writing a PhD-Thesis, as the publisher will take care of the color management of the pdf? Does someone know how to convert all grey colors from rgb space to real gray colors in gray space in the whole document with Adobe Acrobat XI pro without affecting the real colors in the document? Does someone know, which things/aspects can typically go wrong about color specs in a PhD-Thesis, when working with LaTeX (tikz, pgfplots) but also having some *.eps vector graphics from other sources (such as Corel) embedded in the document, and therefore should be considered very early instead of having problems later?

• Since the colors are specified as RGB in the PDF file, the browser or printer driver would be responsible for conversion to CMYK. – John Kormylo Sep 19 '16 at 16:03

without the redefinition the test file below shows the two forms in the log:

$grep 33527 qq524.log ................\pdfliteral{0.33527 0.33527 0.33527 RG } ................\pdfliteral{0.33527 0.33527 0.33527 rg } ................\pdfliteral{0.33527 G } ................\pdfliteral{0.33527 g }  after the definition the log shows $ grep 33527 qq524.log
................\pdfliteral{0.33527 G }
................\pdfliteral{0.33527 g }
................\pdfliteral{0.33527 G }
................\pdfliteral{0.33527 g }


showing the same gray model is used for both inputs

\documentclass[12pt,a4paper,tikz]{standalone}
\showoutput
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{tikz,pgfplots,grffile,amsmath}

\makeatletter
\def\zzrgb{rgb}
\let\olddefinecolor\definecolor
\def\definecolor#1#2#3{%
\def\zz{#2}%
\ifx\zz\zzrgb
\zzrgbconv#3\relax{#1}%
\else
\olddefinecolor{#1}{#2}{#3}%
\fi}

\def\zzrgbconv#1,#2,#3\relax#4{%
\def\zza{#1}\def\zzb{#2}\def\zzc{#3}%
\ifx\zza\zzb\else\let\zzc\relax\fi
\ifx\zza\zzc
\olddefinecolor{#4}{gray}{#1}%
\else
\olddefinecolor{#4}{rgb}{#1,#2,#3}%
\fi
}
\makeatother

\definecolor{parula01}{rgb}{0.00600,0.39650,0.88330}%
\definecolor{parulagray01}{rgb}{0.33527,0.33527,0.33527}% same color as parula01, just converted to greyscale with a MATLAB algorithm - weighted sum: 0.2989 * R + 0.5870 * G + 0.1140 * B --> the result is about 33.527 % black
\definecolor{parulagray02}{gray}{0.33527}% probably the same color as parulagray01, just defined as a gray scale color with only one percentage argument for the grey level
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
]
\addplot [line width=0.8pt, color=parula01, forget plot]
table[row sep=crcr]{%
1  1\\
100    100\\
};
\addplot [line width=0.8pt, color=parulagray01, forget plot]
table[row sep=crcr]{%
1  5\\
100    105\\
};
\addplot [line width=0.8pt, color=parulagray02, forget plot]
table[row sep=crcr]{%
1  10\\
100    110\\
};
\end{axis}
\end{tikzpicture}%
\end{document}

• This works great David Carlisle, at least for self defined colors with \definecolor! One problem is left for me unfortunately (that's why I asked if there is a command, which can be applied to pdflatex, which will enforce a conversation for every rgb triple to gray if all three entries are the same): I also have some eps figures, which I have to include with pstool. These unfortunately also have some rich gray colors included and will be still converted to rich cmyk. Actually pdflatex does the whole conversation and interpretation of the code. There might be some command that does it? – phw Sep 19 '16 at 17:04
• I doubt it, pdftex doesn't really mess with the internal structure of the pdf files (it can't include eps ghostscript is used to conver eps to pdf before inclusion, so you could look to see if ghostscript has any options to convert the colour models) – David Carlisle Sep 19 '16 at 17:15
• Ok I see - and do you know how to include specific ghost script commandos in a latex document that is to be compiled with pdflatex? – phw Sep 19 '16 at 17:29
• @phw you can't I think but , but the built-in eps to pdf translation is only a minor convenience you can convert the eps to pdf using any tool in advance then it'll use that in preference. – David Carlisle Sep 19 '16 at 17:31
• I see. Maybe I'll have to ask about it in another question about pstool. I think your answer should be accepted :-). – phw Sep 20 '16 at 14:12