[Tex/LaTex] Outlined characters in Beamer

beamerformattingtext-decorations

Following Outlined characters, you can make selectable outlined text using the contour package. For example, the following writes "Text text text contour text", with "contour" in green with a red outline. It compiles and displays as expected (using pdflatex and lualatex):

\documentclass[12pt]{article}
\usepackage[outline]{contour}
\begin{document}
Text text text \contour{red}{\textcolor{green}{contour}} text.
\end{document}

However, when I try to do the same in a Beamer presentation—

\documentclass{beamer}
\usepackage[outline]{contour}
\begin{document}
\begin{frame}{Example}
Text text text \contour{red}{\textcolor{green}{contour}} text.
\end{frame}
\end{document}

—it fails to compile, with the error

! Use of \\@contour doesn't match its definition.
\beamer@ifnextcharospec #1#2->\def \reserved@a {
                                                #1}\def \reserved@b {#2}\fut...
l.14 \end{frame}

? 

How can I use the outline effect in a Beamer presentation?

Best Answer

Prolog

Apparently, beamer redefines \textcolor in a way that makes it fragile.

If you \usepackage{beamerarticle} in your article MWE, you experience the same problems as with beamer.

Long answer

What is the difference between Fragile and Robust commands?

Short answer

Use

  • \contour{<color>}{\protect\textcolor{<color>}{<text>}} or
  • \textcolor{<color>}{\contour{<color>}{<text>}}.

Code

\documentclass{beamer}
\usepackage[outline]{contour}
\begin{document}
\begin{frame}{Example}
Text text text \contour{red}{\protect\textcolor{green}{contour}} text. \\
Text text text \textcolor{green}{\contour{red}{contour}} text.
\end{frame}
\end{document}

Output

Output