[Tex/LaTex] Highlight some portion of an equation

beamertikz-arrowstikz-pgf

Following the instructions of some posts here on stackexchange, I have used the following codes to generate the attached image of an equation. However, I would also like to have the terms inside the square brackets highlighted in blue. In addition, I would like to annotate the first term on the right side of the equation i.e. (1-delta) with highlighting. It's my first time using the tikz package and I am struggling with this terribly. I have already checked out the example from http://www.texample.net/tikz/examples/beamer-arrows. But since I am very new, I could not make much of it.

I will be immensely grateful if someone could help me here with codes and their explanations.

\documentclass[xcolor=dvipsnames]{beamer}
\usetheme{Madrid}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{tikzmark, positioning, arrows,shapes}

\begin{document}

\begin{frame}{Household}
with the law of motion of capital,
\begin{equation}
\label{capmot}
K_{t+1}^p= (1-\delta)K_t^P + I_t^P\tikzmark{pdt}{\left[1 - \dfrac{\chi}{2}\left(\dfrac{I_t^P}{I_{t-1}^P} -1 \right)^2 \right]}
\end{equation}
\begin{tikzpicture}[
  remember picture,
  overlay,
  expl/.style={draw=orange,fill=orange!30,rounded corners,text width=3cm},
  arrow/.style={red!80!black,ultra thick,->,>=latex}
]
\node<2->[fill=blue!20,anchor=base,expl] 
  (pdtex) 
  at (6,3.5cm)
  {Investment Adjustment Cost};
\draw<2->[arrow]
  (pdtex.west) to[out=180,in=180] ([yshift=0.5ex]{pic cs:pdt});  
\end{tikzpicture}
\end{frame}
\end{document}

P.S. I require the annotations to appear one by one on click.

Best Answer

Here is a proposal. To change the color to blue, you can use \alert after telling beamer to use blue for \alert. I also change the way you add the box by using a callout and \tikznode for more precise highlighting.

\documentclass[xcolor=dvipsnames]{beamer}
\usetheme{Madrid}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{tikzmark, positioning, arrows,shapes}
\usetikzlibrary{shapes.callouts,shadows.blur,positioning}
\usetikzlibrary{overlay-beamer-styles}
\setbeamercolor{alerted text}{fg=blue}
\newcommand{\tikznode}[2]{\relax
\ifmmode%
  \tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {$#2$};
\else
  \tikz[remember picture,baseline=(#1.base),inner sep=0pt] \node (#1) {#2};%
\fi}

\begin{document}

\begin{frame}{Household}
with the law of motion of capital,
\begin{equation}
\label{capmot}
K_{t+1}^p= \alert<2>{\tikznode{del}{(1-\delta)}}K_t^P + 
I_t^P\alert<3>{\tikznode{pdt}{\left[1 -
\dfrac{\chi}{2}\left(\dfrac{I_t^P}{I_{t-1}^P} -1 \right)^2 \right]}}
\end{equation}
\begin{tikzpicture}[
  remember picture,
  overlay,
  expl/.style={draw=orange,fill=orange!30,rounded corners,text width=3cm},
  arrow/.style={red!80!black,ultra thick,->,>=latex}
]
\node[alt={<2>{drop shadow,opacity=0.8,text opacity=1}{invisible}},
visible on=<2>, 
align=center, fill=blue!20, align=center, 
rounded corners,draw,rectangle callout,
anchor=pointer,callout relative pointer={(-300:1cm)}]
at (del) {Depreciation};
\node[alt={<3>{drop shadow,opacity=0.8,text opacity=1}{invisible}},
visible on=<3>, 
align=center, fill=blue!20, align=center, 
rounded corners,draw,rectangle callout,
anchor=pointer,callout relative pointer={(230:1cm)}]
at (pdt.north) {Investment Adjustment Cost};
\end{tikzpicture}
\end{frame}

\end{document}

enter image description here