# Is it possible to change the color of the text according to the background color?

I'd like to automatically change the color of the text according to the background color.

I've used tikz to create the background (the shape is only an example) but any other way to do it is welcome.

\documentclass{beamer}
\usepackage{tikz}
\usebackgroundtemplate{%
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (0,\paperheight);
\coordinate (C) at (\paperwidth,0);
\fill[blue] (A) -- (C) -- (B) -- cycle;
\end{tikzpicture}
}
\begin{document}
\begin{frame}
\frametitle{Example}
Could this text be automatically white on blue and blue on white?
\end{frame}
\end{document}


• Intuitively you'll have to do this manually using clipping. – Werner Mar 3 '17 at 22:02
• I don't know much about clipping in tikz. – Werner Mar 3 '17 at 22:25
• +1 nice question! I am sure that PowerPoint can't do this hehe lol – manooooh Sep 7 '18 at 6:01
• @manooooh Indeed, it can't. I asked just for that reason :):):) – CarLaTeX Sep 7 '18 at 6:02

The idea is simple: use some nontrivial blending mode.

You might want to

• tune the colors, so that "blue" minus "yellow" is "white"
• modify the background, so that the lower right corner looks right.

\documentclass{beamer}
\usepackage{tikz}
\usebackgroundtemplate{
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (0,\paperheight);
\coordinate (C) at (\paperwidth,0);;
\coordinate (D) at (\paperwidth,\paperheight);
\fill[blue] (A) -- (C) -- (B) -- cycle;
\fill[white](D) -- (C) -- (B) -- cycle;
\end{tikzpicture}
}
\begin{document}

\begin{frame}
\frametitle{Example}
\pgfsetblendmode{difference}
\color{yellow}Could this text be automatically white on blue and blue on white?
\end{frame}

\end{document}


Edit:

As @Werner suggested, if you do not know how to fix the footline, add this line:

\addtobeamertemplate{footline}{\pgfsetblendmode{normal}}{}


Change footline to anything else if you find them unexpected.

On the other hand, if you think it is awesome,

\addtobeamertemplate{navigation symbols}{\pgfsetblendmode{difference}}{}


• I knew that some tikz expert would have provided a gorgeous solution, thank you! – CarLaTeX Mar 4 '17 at 7:11
• The better fix for the navigation symbols is \setbeamertemplate{navigation symbols}{}. I've listened to (and given) lots of beamer talks in my life, but have never seen anyone use these links (except inadvertently). – gernot Mar 4 '17 at 13:22