I'm making a custom style for a presentation with beamer. I'm using \getbeamercolor to have the foreground and background colors of a given beamer color in fg and bg, respectively.
I realized I need to get those colors more than once, so I wrote a command to wrap the following code snippet up and call it every time I need it:
\newcommand{\getbeamercolors}[1]{%
\usebeamercolor{#1}%
\colorlet{fgColor}{fg}%
\colorlet{bgColor}{bg}%
}
Unfortunately, I also need to call that command twice, and get all those colors to use them at the same time. Then I thought I could simply modify the above command to append a suffix to each color, like this:
\newcommand{\getbeamercolors}[2]{%
\usebeamercolor{#1}%
\colorlet{fg#2}{fg}%
\colorlet{bg#2}{bg}%
}
But that didn't work. I even looked for an answer on this site, and I even read this, but to no avail.
Is there a way to append a text from a command argument inside the color name when defining it?
Simple MWE:
\documentclass{beamer}
\usetheme{Warsaw}
\usepackage{xcolor}
\newcommand{\getbeamercolors}[1]{%
\usebeamercolor{#1}%
\colorlet{fgColor}{fg}%
\colorlet{bgColor}{bg}%
}
% This didn't work!
%\newcommand{\getbeamercolors}[2]{%
% \usebeamercolor{#1}%
% \colorlet{fg#2}{fg}%
% \colorlet{bg#2}{bg}%
%}
\begin{document}
\begin{frame}
\frametitle{This is a test!}
\getbeamercolors{frametitle}{title}
Some text to color with \texttt{\textbackslash getbeamercolors}...
\textcolor{bgColor}{Text with frame title background color.}
\colorbox{black}{\textcolor{fgColor}{Text with frame title foreground color.}}
\end{frame}
\end{document}

\textcolor{bgtitle}and\textcolor{fgtitle}I get the same picture in your answer. – egreg Mar 20 '17 at 10:39