# Using beamer colors

To avoid having too many colors, I use beamer's colors to emphasize items of my text. It looks something like this:

\documentclass[xcolor=dvipsnames]{beamer}

\newcommand{\gn}[1]{\textcolor{block title example.bg}{{}#1{}}}

\begin{document}

\begin{frame}{Green text}
\gn{This isn't working.}

\begin{example}[boring example]

nothing to see here.
\end{example}

\gn{This is green.}

This is black.
\end{frame}
\end{document}


Now, if I try to use the color before beamer uses it for the first time (as in "This isn't working"), I get the error:

Package xcolor Error: Undefined color block title example.bg'.


Is there a way to resolve this?

\usebeamercolor[bg]{block title example} will use the color

\documentclass[xcolor=dvipsnames]{beamer}

\newcommand{\gn}[1]{{\usebeamercolor[bg]{block title example}#1}}

\begin{document}

\begin{frame}{Green text}
\gn{This isn't working.}

\begin{example}[boring example]

nothing to see here.
\end{example}

\gn{This is green.}

This is black.
\end{frame}
\end{document}
`
• Thanks for the fast reply! – Jan Aug 16 '19 at 10:56