2

I am trying to define a block with customizable colors. I want to put this in a file of common definitions (say common_defs.tex) and include it in each presentation and set its title and text background and foreground colors based on the theme of that presentation. Using the suggestion here I define the following in the common_defs.tex file

\newenvironment{varblock}[3]{%
  \setbeamercolor{block title}{#2}
  \setbeamercolor{block body}{#3}
  \begin{block}{#1}}{\end{block}}

Now in the main beamer presentation I have the following:

\documentclass{beamer}

\setbeamercolor{varblock text}{bg=red!20, fg=black} \setbeamercolor{varblock title}{bg=red, fg=white}

\begin{document}

\begin{frame} \frametitle{Test}

\begin{varblock}{Block Title} Some block text \end{varblock}

\end{frame} \end{document}

This, understandably gives an error since it expects three arguments to \begin{varblock}. How can I change the definition to make this work?

ozsu
  • 2,385

1 Answers1

5

Will this work?

main.tex

\documentclass{beamer}
\input{common}    
\newcommand{\prevarblock}{%
  \setbeamercolor{block title}{bg=red!20, fg=black}%
  \setbeamercolor{block body}{bg=red, fg=white}%
}
\begin{document}
  \begin{frame}\frametitle{Test}
    \begin{varblock}{Block Title}
      Some block text
    \end{varblock}
  \end{frame}
\end{document}

common.tex

\newenvironment{varblock}[1]{%
  \prevarblock
  \begin{block}{#1}}{\end{block}}
jessexknight
  • 2,732