2

I have three mdframed environments in my document.

\begin{mdframed}[backgroundcolor=blue!20]   

\begin{mdframed}[backgroundcolor=purple!20] 

\begin{mdframed}[backgroundcolor=brown!20]

Using the xcolor package. I am wondering how (if possible) I can recover the CMKY codes for the colours from this information?

5

You can use the \extractcolorspecs macro from xcolor package and extract its model first to \modelcmd and the spec to \colorcmd and then use \convertcolorspecs to transform it to another specification, say cmyk.

\documentclass{article}

\usepackage{xcolor}

\begin{document}

\extractcolorspecs{brown!20}{\modelcmd}{\colorcmd}
\convertcolorspec{\modelcmd}{\colorcmd}{cmyk}{\colorcmdcmyk}

\colorcmd

\colorcmdcmyk


\end{document}

Update

Direct conversion:

\documentclass{article}

\usepackage{xcolor}

\newcommand{\convertdirectly}[3][cmyk]{%
  \extractcolorspecs{#2}{\modelcmd}{\colorcmd}%
  \convertcolorspec{\modelcmd}{\colorcmd}{#1}{#3}%
}

\begin{document}
\convertdirectly{brown!20}{\cmykbrown}
\convertdirectly[hsb]{brown!20}{\hsbbrown}
\convertdirectly[RGB]{brown!20}{\RGBbrown}

cmyk: \cmykbrown

hsb: \hsbbrown

RGB: \RGBbrown

\end{document}

enter image description here

  • @AngusTheMan: Glad I could help. Happy Texing – user31729 Dec 17 '15 at 18:08

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.