I would like to use beamer defined colors into beamerarticle's version of my document. This way I can change beamer theme (or color theme) and colors change according it.
Here you have a MWE. A frame with a tikz figure using beamer colors fg and bg.
\documentclass[ignorenonframetext]{beamer}
%\documentclass{article}
%\usepackage{beamerarticle}
\usepackage{tikz}
\usecolortheme{beaver}
\begin{document}
This is some text outside any frame.
\begin{frame}{Frame}
\begin{alertblock}{Block}
\usebeamercolor[fg]{example text}
\begin{tikzpicture}
\filldraw[color=fg, fill=bg!50!white] (0,0) rectangle (5,3);
\draw[line width=5mm] (1,1)--(2,2);
\end{tikzpicture}
\end{alertblock}
\end{frame}
\end{document}
As soon as I try article with beamerarticle package, pdflatex complains with
! Package xcolor Error: Undefined color `fg'.
See the xcolor package documentation for explanation.
Type H <return> for immediate help.
...
l.16 ..., fill=bg!50!white] (0,0) rectangle (5,3);
The example contains a tikz figure but my question want to be more general, something like declaring sections (or any other text) with a beamer color and keeping this color in article mode.
Best Answer
Having just wanted to do this in answer to another question, I can tell you that this is Not Intended To Be Done! A lot of the theming and colour commands are simply set to "do nothing" when the
article
version of beamer is used. However, using a bit of trickery we can reload the commands and so make the colours available. This should be used with Extreme Caution as it might break something that I haven't tested (which is about everything).Here's a picture based on a slightly modified version of your example:
And here's the code:
The main part is the stuff between
\makeatletter
and\makeatother
. We need to load in the beamer colour management. Unfortunately, the file containing the commands checks themode
and skips most stuff inarticle
mode. So we need to temporarily change tobeamer
mode to persuade it that we really do want to define this stuff. But as the files have already been read in (via the\usepackage{beamerarticle}
) we can't\usepackage
them again but have to\input
them (this produces a couple of warnings in the log, but ignore them). We load in thethemes
set and thecolor
set. There are a couple of things that are defined inbeamer.cls
that these depend on so we have to set them up:\beamer@colorhook
and\beamer@lastskip
. Also, some things are defined by\newcommand
and were defined (to the wrong things) on the first read. So we need to set them all to\relax
to avoid errors. After that, it's plain sailing!