[Tex/LaTex] How to get actual values of colour theme colours in beamer

beamercolorthemes

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 In beamer use colors that are already defined in a given color scheme and Getting the color from a beamer theme?, 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.

Best Answer

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}}

\setbeamercolor{block title alerted}{fg=yellow}

% 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{block title alerted}{myblock title alerted fg}{myblock title alerted 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{alerted text.fg}\\
\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{myblock title alerted fg}\\
\colrow{myblock title alerted bg}\\
\colrow{palette secondary fg}\\
\colrow{palette secondary bg}\\
\bottomrule
\end{tabular}
\end{center}

\end{frame}    

\end{document}

Result:

enter image description here

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 alerted}{block title alerted fg}{block title alerted bg}
\ccft{block body alerted}{block body alerted fg}{block body alerted 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 alerted fg}\\
\colrow{block title alerted bg}\\
\colrow{block body alerted fg}\\
\colrow{block body alerted 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}
\begin{alertblock}{Title}
text
\end{alertblock}
\end{frame}

\end{document}

Result:

enter image description here