# How to get actual values of colour theme colours in beamer?

How would I go about finding the actual colour (like the RGB/HSV/etc) of a particular element in a given beamer colour theme (e.g., block title bg in orchid)?

I would like to use these colours in creating graphics with external programs. For example, I made a map in ArcGIS, and since it's quite a simple map, there's no reason not to choose colours which are consistent with the beamer theme I'm using.

From this question and this question I know that you can directly call the colours within a LaTeX document, but I'm asking about getting colour values for use outside of LaTeX.

EDIT Both answers below are great, thanks so much. I wasn't sure how to pick the accepted answer, so I just chose the one which seemed to accomplish the goal in fewer lines of code.

-
Why don't you just use a color picker software? You can find many of them for free on the internet. –  Thorsten Aug 9 '12 at 16:23

I don't know if I get exactly the point, but my answer tries to make a table in which automatically you have some color definition just inserting the name (based on Retrieve the color definition in HTML I defined).

With respect to Andrew's nice answer, mine just uses internal commands of xcolor to define macros able to extract the color value with a given format.

Code:

\documentclass{beamer}
\usetheme{CambridgeUS}
\usepackage{lmodern}
\usepackage{booktabs}

\newcommand{\extractHTML}[1]{\extractcolorspecs{#1}{\model}{\mycolor} \convertcolorspec{\model}{\mycolor}{HTML}\printcol \printcol}
\newcommand{\extractRGB}[1]{\extractcolorspecs{#1}{\model}{\mycolor} \convertcolorspec{\model}{\mycolor}{RGB}\printcol \printcol}
\newcommand{\extractCMYK}[1]{\extractcolorspecs{#1}{\model}{\mycolor} \convertcolorspec{\model}{\mycolor}{cmyk}\printcol \printcol}
\newcommand{\colrow}[1]{{\color{#1}#1} & \extractRGB{#1} & \extractCMYK{#1} & \extractHTML{#1}}

% Create Color definition From Template:
% #1 template name,
% #2 foreground color name
% #3 background color name
\newcommand{\ccft}[3]{
\usebeamercolor{#1}
\definecolor{#2}{named}{fg}
\definecolor{#3}{named}{bg}
}

\ccft{block title}{myblock title fg}{myblock title bg}
\ccft{block body}{myblock body fg}{myblock body bg}
\ccft{palette secondary}{palette secondary fg}{palette secondary bg}

\usebeamercolor{block body}

\begin{document}
\begin{frame}{Color definitions}
\begin{center}
\begin{tabular}{cccc}
\toprule
\multicolumn{1}{c|}{\textsc{Color}} &
\multicolumn{1}{c}{\textsc{RGB}} &
\multicolumn{1}{c}{\textsc{CMYK}} &
\multicolumn{1}{c}{\textsc{HTML}}\\
\midrule
\colrow{structure.fg}\\
\colrow{structure.bg}\\
\colrow{example text.fg}\\
\colrow{normal text.fg}\\
\colrow{myblock title fg}\\
\colrow{myblock title bg}\\
\colrow{myblock body fg}\\
\colrow{myblock body bg}\\
\colrow{palette secondary fg}\\
\colrow{palette secondary bg}\\
\bottomrule
\end{tabular}
\end{center}

\end{frame}

\end{document}


Result:

Some explanation

Some colors are immediately accessible, for example structure.fg, alerted text.fg, while for other like palettes or blocks is different. To cope with that, I referenced to Jake's answer in On using beamer's colors in a Tikz picture therefore a workaround is to declare first \usebeamercolor{palette primary}, for example, and later just use bg. That's the purpose of the command \ccft that defines two colors (color name provided by the second and third argument) starting from a template.

Here is an example that shows how to it's possible to retrieve the colors for all types of blocks assuming to adopt the Frankfurt theme and the crane color theme.

Blocks are characterized by a the color of the title (background bg and foreground fg) and the color of the body (again background bg and foreground fg).

The example could be seen as a sort of black box to detect blocks colors for any pair of Beamer theme and Beamer color theme: just copy the code in a new document blocks_colors.tex and change the apposite themes definition.

\documentclass{beamer}

\usepackage{lmodern}
\usepackage{booktabs}

%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Theme characteristics -
\usetheme{Frankfurt}
\usecolortheme{crane}

%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Commands -
\newcommand{\extractHTML}[1]{\extractcolorspecs{#1}{\model}{\mycolor} \convertcolorspec{\model}{\mycolor}{HTML}\printcol \printcol}
\newcommand{\extractRGB}[1]{\extractcolorspecs{#1}{\model}{\mycolor} \convertcolorspec{\model}{\mycolor}{RGB}\printcol \printcol}
\newcommand{\extractCMYK}[1]{\extractcolorspecs{#1}{\model}{\mycolor} \convertcolorspec{\model}{\mycolor}{cmyk}\printcol \printcol}
\newcommand{\colrow}[1]{{\color{#1}#1} & \extractRGB{#1} & \extractCMYK{#1} & \extractHTML{#1}}

% Create Color definition From Template (both background and foreground colors):
% #1 template name,
% #2 foreground color name
% #3 background color name
\newcommand{\ccft}[3]{
\usebeamercolor{#1}
\definecolor{#2}{named}{fg}
\definecolor{#3}{named}{bg}
}

% Blocks color definition (background and foreground)
\ccft{block title}{block title fg}{block title bg}
\ccft{block body}{block body fg}{block body bg}
\ccft{block title example}{block title example fg}{block title example bg}
\ccft{block body example}{block body example fg}{block body example bg}

\begin{document}
\begin{frame}{Block Color definitions - Crane color theme}
\scalebox{0.875}{
\begin{tabular}{cccc}
\toprule
\multicolumn{1}{c|}{\textsc{Color}} &
\multicolumn{1}{c}{\textsc{RGB}} &
\multicolumn{1}{c}{\textsc{CMYK}} &
\multicolumn{1}{c}{\textsc{HTML}}\\
\midrule
\colrow{block title fg}\\
\colrow{block title bg}\\
\colrow{block body fg}\\
\colrow{block body bg}\\
\colrow{block title example fg}\\
\colrow{block title example bg}\\
\colrow{block body example fg}\\
\colrow{block body example bg}\\
\bottomrule
\end{tabular}
}
\end{frame}

\begin{frame}
\begin{block}{Title}
text
\end{block}
\begin{exampleblock}{Title}
text
\end{exampleblock}
text
\end{frame}

\end{document}


Result:

-
I didn't know that xcolor had these commands! Otherwise I probably wouldn't have been hacking colorinfo. –  Andrew Stacey Aug 9 '12 at 15:45
Yes, in this case they are very useful. :) When I saw the question I immediately recall @percusse's answer that contained the major hint. –  Claudio Fiandrino Aug 9 '12 at 15:58

There's a package for that ...

It's called colorinfo. The idea is that one can define a colo[u]r using, say, xcolor (which is what beamer uses for its colour management, I think) and then use the colorinfo package to display the information about the colour. However, I found that it didn't quite work as it should - it's missing some options for some drivers (I think pdftex) - so I modified it a bit. The following code contains my modifications and an example.

\documentclass{beamer}
%\url{http://tex.stackexchange.com/q/66465/86}

\usepackage{colorinfo}

\makeatletter
\def\ModColorInfo#1{%
\begingroup
\gdef\colorModel{}\gdef\colorValue{}%
\@ifundefined{\string\color @#1}{}%
{%
\edef\@tempa{\csname\string\color @#1\endcsname}%
\expandafter\CI@color@info\@tempa{} \CI@STOP
}
\endgroup
}
\def\CI@gobble#1\CI@STOP{}%
\let\CI@STOP=\relax

\renewcommand\CI@DriverInit{%
\@ifundefined{Gin@driver}{}{%
\ifx\Gin@driver\@empty\else
\filename@parse{\Gin@driver}
\edef\colorDriver{\filename@base}
\@tempswatrue
\def\@tempa{dvips}
\ifx\@tempa\colorDriver
\else\def\@tempa{dvipdfm}
\ifx\@tempa\colorDriver
\else\def\@tempa{dvipsone}
\ifx\@tempa\colorDriver
\else\def\@tempa{pctex32}
\ifx\@tempa\colorDriver
\else\def\@tempa{xetex}
\ifx\@tempa\colorDriver
\else\@tempswafalse
\fi
\fi
\fi
\fi
\fi
\if@tempswa%                            --- dvips family ---
\def\CI@color@info##1 {%
\gdef\colorModel{##1}%
\csname CI@dvips@\colorModel\endcsname
}
\newcommand*\CI@dvips@rgb{}
\def\CI@dvips@rgb##1 ##2 ##3 {%
\gdef\colorValue{##1,##2,##3}%
}
\newcommand*\CI@dvips@gray{}
\def\CI@dvips@gray##1 {%
\gdef\colorValue{##1}%
}
\newcommand*\CI@dvips@cmyk{}
\def\CI@dvips@cmyk##1 ##2 ##3 ##4 {%
\gdef\colorValue{##1,##2,##3,##4}%
}
\else
\def\@tempa{pdftex}
\ifx\@tempa\colorDriver%              --- pdfTeX ---
\providecommand*\@gobblefive[5]{}
\providecommand*\@gobblesix[6]{}
\def\CI@color@info##1 ##2 ##3 ##4 {%
\def\@tempa{##4}%
\def\@tempb{rg}%
\ifx\@tempa\@tempb%   RGB
\gdef\colorModel{rgb}\gdef\colorValue{##1,##2,##3}%
\let\@tempb\CI@gobble
\else
\def\@tempb{G}%
\ifx\@tempa\@tempb% GRAY
\gdef\colorModel{gray}\gdef\colorValue{##1}%
\let\@tempb\relax
\else%              CMYK
\gdef\colorModel{cmyk}\gdef\colorValue{##1,##2,##3,##4}%
\let\@tempb\CI@gobble
\fi
\fi
\@tempb
}
\else
\def\@tempa{vtex}
\ifx\@tempa\colorDriver%            --- VTeX ---
\def\CI@color@info##1##2##3##4##5##6##7##8{%
\def\@tempa{##2}\def\@tempb{"}%
\ifx\@tempa\@tempb
\gdef\colorModel{rgb}%
\CI@normalize{\number"##3##4,\number"##5##6,\number"##7##8}%
{\colorValue}\let\@tempb\relax
\else
\gdef\colorModel{cmyk}%
\gdef\colorValue{\number"##3##4,\number"##5##6,\number"##7##8}%
\let\@tempb\CI@vtex@cmyk%
\fi
\@tempb
}
\newcommand*\CI@vtex@cmyk{}
\def\CI@vtex@cmyk##1##2{%
\CI@normalize{\colorValue,\number"##1##2}{\colorValue}
}
\newcommand*\CI@normalize[2]{%
\begingroup
\def\@tempb{}\@tempswafalse
\@for\@tempa:=##1\do{%
\if@tempswa\edef\@tempb{\@tempb,}\else\@tempswatrue\fi
\@tempdima=\@tempa\p@\divide\@tempdima by\@cclv\relax
\edef\@tempb{\@tempb\strip@pt\@tempdima}}
\xdef##2{\@tempb}
\endgroup
}
\else
\def\@tempa{textures}
\ifx\@tempa\colorDriver%          --- textures ---
\def\colorInfo##1{%
\def\colorModel{}\def\colorValue{}%
\@ifundefined{\string\color @##1}{}%
{%
\typeout{Not yet implemented...}
}
}
\else
\def\@tempa{tcidvi}
\ifx\@tempa\colorDriver%        --- tcidvi ---
\def\colorInfo##1{%
\def\colorModel{}\def\colorValue{}%
\@ifundefined{\string\color @##1}{}%
{%
\typeout{Not yet implemented...}
}
}
\else
\def\@tempa{truetex}
\ifx\@tempa\colorDriver% --- truetex ---
\def\colorInfo##1{%
\def\colorModel{}\def\colorValue{}%
\@ifundefined{\string\color @##1}{}%
{%
\typeout{Not yet implemented...}
}
}
\else
\def\@tempa{pctexps}
\ifx\@tempa\colorDriver%    --- pctexps ---
\def\colorInfo##1{%
\def\colorModel{}\def\colorValue{}%
\@ifundefined{\string\color @##1}{}%
{%
\typeout{Not yet implemented...}
}
}
\fi
\fi
\fi
\fi
\fi
\fi
\fi
\fi
}%  \@ifundefined{Gin@driver}
}%      \CI@DriverInit
\makeatother

\begin{document}
\begin{frame}{A Colour Test}

\begin{tabular}{l|l}
\structure{structure\ModColorInfo{.}} & \colorValue \\
normal\ModColorInfo{.} & \colorValue
\end{tabular}

\end{frame}
\end{document}


Result:

Things to note: the command \ModColorInfo{<colour>} doesn't display anything itself, it stores its information in various macros. This means you could write the information out to a file instead of the document which may be of more use. Also, more information is available (such as the colour model). Finally, the current colour in beamer is set to . so that's a simple way to find out what colour a particular element is.

-