2

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} 
\usetheme{Madrid}

\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?

4

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

\documentclass[xcolor=dvipsnames]{beamer} 
\usetheme{Madrid}

\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}
| improve this answer | |
  • Thanks for the fast reply! – Jan Aug 16 '19 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.