[Tex/LaTex] Beamer: highlighting text with colored background through which surrounding text can be seen

beamerhighlightingtcolorbox

On some slides I'd like to highlight some text by using a colored background, like so:
text with some words highlighted

I've exaggerated the width of the border around the text in this example to indicate the effect I want.

I produced this example manually. I'd like to have a macro \highlighton so that I can produce the effect by writing \highlighton<1>{`to protrude out'}. The wonderful package tcolorbox provides macros that almost do the trick. Here's an example.

\documentclass{beamer}
\usepackage{etex}
\setbeamertemplate{navigation symbols}{}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usepackage{times}
\def\highlighton<#1>#2{%
  \alt<#1>{\tcbox[enhanced,boxrule=0pt,colback=red!50,interior style=
  {opacity=0.7},frame style={opacity=0.5},nobeforeafter,tcbox raise base,shrink
  tight,extrude by=5mm]{#2}}{#2}%
}

\begin{document}
\begin{frame}

\textbf{Extrude}, \textit{v}.\ trans. \textbf{1}.\ To thrust (a person) out or forth;
to urge or force out; to expel.  \textbf{a}.\ with obj.\ a person.  \textbf{b}.\ with
obj.\ a material thing; in mod.\ use esp.\ to exclude (an embryo, ova, etc.). Also 
occas.\ with sense \highlighton<1>{`to protrude out'}.  \textbf{c}. with an immaterial 
thing as obj. \textbf{d}.\ To shape (metals, plastics, etc.)\ by forcing them through 
dies. \textbf{2}.\ intr.\ for refl. To protrude out. rare.

\pause

\end{frame}
\end{document}

This code (in which extrude by 5mm generates the border) produces the following output. Text before the highlighted text is "dimmed", but text after the highlighted text isn't. Is there a way to produce exactly the effect I want?

enter image description here

Best Answer

My answer is using the same idea as Claudio Fiandrino did. But it uses tcolorbox (v2.61) and you may use as many highlights as you want on a page.

\documentclass{beamer}
\usepackage{etex}
\setbeamertemplate{navigation symbols}{}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usepackage{times}
\def\remember#1#2{%
  \tcbox[enhanced,remember as={#1},frame hidden,interior hidden,boxrule=0pt,nobeforeafter,
    tcbox raise base,shrink tight]{#2}%
  \pgfkeyssetvalue{/myremember/#1}{#2}%
}
\def\highlighton<#1>#2{%
  \alt<#1>{\tikz[overlay,remember picture]\node at (#2){%
  \tcbox[enhanced,boxrule=0pt,colback=red!50,interior style={opacity=0.7},
         frame style={opacity=0.5},nobeforeafter,tcbox raise base,shrink tight,
         extrude by=5mm]{\pgfkeysvalueof{/myremember/#2}}};}{}%
}

\begin{document}
\begin{frame}

\textbf{Extrude}, \textit{v}.\ trans. \textbf{1}.\ To thrust (a person) out or forth;
to urge or force out; to expel.  \textbf{a}.\ with obj.\ a person.  \textbf{b}.\ with
obj.\ a material thing; in mod.\ use esp.\ to exclude (an embryo, ova, etc.). Also
occas.\ with sense \remember{protrude}{`to protrude out'}.  \textbf{c}. with an immaterial
thing as obj. \textbf{d}.\ To shape \remember{etc}{(metals, plastics, etc.)}\ by forcing them through
dies. \textbf{2}.\ intr.\ for refl. To protrude out. rare.%
\highlighton<2>{protrude}
\highlighton<3>{etc}

\pause
\end{frame}
\end{document}

enter image description here