# How to create a colour option in custom beamer theme?

I have used this answer from the question about how to design a beamer theme from scratch to design a Beamer theme to look like a university presentation (Powerpoint) template. There are 3 colour options for the Powerpoint template (blue,green,slate). I know one option for a solution would be to create 3 separate colour themes and to just call them with;

\usecolortheme{mythemeblue}
\usecolortheme{mythemegreen}
\usecolortheme{mythemeslate}


What I would like to do though is to define all the different colours in one colortheme file and then be able to use an option to call them as follows

\usetheme[blue]{mytheme}  %or green or slate


I have seen questions on the site that seem to use \DeclareOption (at this question, but couldn't get to work) or \DeclareOptionBeamer (This question & This question - didn't really understand these solutions)

Ideally what I would like is a solution where I can define differently in the beamercolorthememytheme.sty the same colour names depending on what option was chosen. For example if option blue was chosen Beamer would know that \definecolor{col1}{RGB}{104,7,90} but if option green was chosen it would know that \definecolor{col1}{RGB}{81,139,36} etc

Hopefully this is enough info but if not let me know in the comments

This is what I have in my beamercolorthememytheme.sty

\mode<presentation>

% define colours from NUIG stylesheet
\definecolor{col1}{RGB}{104,7,90}
\definecolor{col2}{RGB}{27,65,99}
\definecolor{col3}{RGB}{138,167,147}
\definecolor{col4}{RGB}{143,183,195}
\definecolor{col5}{RGB}{194,230,242}
% set colours for different elements
\setbeamercolor{structure}{fg=col3!100!col4}
\setbeamercolor{frametitle}{bg=col4,fg=col2}
\setbeamercolor*{subtitle}{fg=col5}
\setbeamercolor*{author}{fg=col5}
\setbeamercolor*{date}{fg=col5}
\setbeamercolor*{item}{fg=col5}
\setbeamercolor{block title}{bg=col1,fg=col5}
\mode
<all>


The following example shows how to change the colour of the frame title conditionally. blue will be used as the default colour, in case no option is specified.

Consider the following MWE:

\documentclass{beamer}

\usetheme[style=blue]{mytheme}

\begin{document}

\begin{frame}
\frametitle{test}
abc
\end{frame}

\end{document}


with the corresponding beamerthememytheme.sty, which does little more than just pass the colour option to the colour theme.

\mode<presentation>

\DeclareOptionBeamer{style}{
\PassOptionsToPackage{style=#1}{beamercolorthememytheme}
}
\ExecuteOptionsBeamer{style=blue}
\ProcessOptionsBeamer

\usecolortheme{mytheme}

\mode
<all>


and the colour theme beamercolorthememytheme.sty:

\mode<presentation>

\DeclareOptionBeamer{style}{\def\beamer@mytheme@style{#1}}
\ExecuteOptionsBeamer{style=blue} % blue will be default if nothing is given
\ProcessOptionsBeamer

\def\beamer@mytheme@stylegreen{green}%
\def\beamer@mytheme@styleblue{blue}%
\def\beamer@mytheme@stylered{red}%

\ifx\beamer@mytheme@style\beamer@mytheme@stylegreen%
\definecolor{col1}{RGB}{0,255,0} % green
\else%
\ifx\beamer@mytheme@style\beamer@mytheme@stylered%
\definecolor{col1}{RGB}{255,0,0} % red
\else%
\definecolor{col1}{RGB}{0,0,255} % blue
\fi%
\fi%

\setbeamercolor{frametitle}{bg=white,fg=col1}

\mode
<all>


• This works great but when I try to define a third option I can't get the 3 options to work. Does the code have to be different for a third option to apply?
– gman
Feb 19, 2016 at 19:31
• @gman see the edit Feb 19, 2016 at 20:01
• Perfect; I was missing the extra \else% and \fi% when trying to add a third option. All working fine now.
– gman
Feb 19, 2016 at 20:13