I'd like to move the definition of a color into a separate file for some reasons (cf forward in robust-externalize for details), but I don't know how to extract the definition of a color from its name. How could I do that?
I can think of two approaches:
- somehow (how?) get the rgb of the color. The main problem is that the color might be CMYK and I’m afraid to lose information on the color this way.
- somehow extract the parameters that were given to
\colorletand\definecolor
Importantly, I don't want to redefine \colorlet or \definecolor.
MWE:
\documentclass[]{article}
\usepackage{xcolor}
\definecolor{colorA}{rgb}{1,.5,0}
\definecolor{colorB}{HTML}{AABBCC}
\definecolor{colorC}{hsb:rgb/cmyk}{1,0,0/0,1,1,0}
\colorlet{colorD}{blue}
\colorlet{colorE}{red!50!blue}
% How to write this function
\NewDocumentCommand{\extractColorCommand}{m}{%
\texttt{\textbackslash definecolor{#1}{???}{???}}%
}
\begin{document}
\textcolor{colorA}{I am colorA}
\textcolor{colorB}{I am colorB}
\textcolor{colorC}{I am colorC}
\textcolor{colorD}{I am colorD}
\textcolor{colorE}{I am colorE}
You can define the above colors using:
\extractColorCommand{colorA}
\extractColorCommand{colorA}
\extractColorCommand{colorB}
\extractColorCommand{colorC}
\extractColorCommand{colorD}
\extractColorCommand{colorE}
\end{document}



\\. You shouldn't break lines that way outside special environments (e.g.tabular/array). – cfr Nov 07 '23 at 00:06\setlength{\parskip}{1cm}, \ looks very different from\par). HTML also defines p and br. – tobiasBora Nov 07 '23 at 00:39