1

I am trying to highlight one variable in an equation with annotation using Beamer (with help of automatic space adjustments following this suggestion Text below equation with hf-tikz). The slide contains an itemize environment with explanatory notes as well. Here a minimum working example for Beamer.

\documentclass{beamer}
\usefonttheme{professionalfonts}
\usefonttheme{serif}
\usefonttheme{structuresmallcapsserif}
\usepackage{amsmath, amssymb}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[beamer,markings]{hf-tikz}
\usepackage{mathtools,xparse} % texted arrows

\newcommand<>{\annotate}[2][]{
\onslide#3{
    \tikz[remember picture,overlay]\node[#1,use marker id] at (0,0){#2};
}
}

\newlength{\notewidth}
\newcommand{\setnotewidth}[1]{%
\settowidth{\notewidth}{$#1$}%
}

\newcommand{\mth}[2]{
\setnotewidth{#2}
\mathmakebox[0.100\notewidth]{#1}
}

\NewDocumentCommand{\tikzmarkaligned}{r<> o m m}{
\phantom{\mth{#3}{#4}}
\tikzmarkin<#1>[#2]{#3}#3\tikzmarkend{#3}
\phantom{\mth{#3}{#4}}
}

\def\savepointas#1#2{%
\expandafter\gdef\csname save@pt@#1\endcsname{#2}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    \newcommand\indentdisplays[1]{%
\everydisplay{\addtolength\displayindent{#1}%
    \addtolength\displaywidth{-#1}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setbeamertemplate{footline}[frame number]
\setbeamertemplate{navigation symbols}{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\begin{frame}
\transwipe
\begin{itemize}

\item<1->[]{ \indentdisplays{-3em}  \begin{equation} \mathbf{pb_{i,\,t}} = \underbrace{\gamma_{i}~\{~+\delta_{t}\}}_{\textrm{fixed effects}} + \alpha \cdot pb_{i,\,t-1} + 
\tikzmarkaligned<1->[mark at=0.825]{\beta_{0 (t)}}{\beta_{0\,(t)} \gg 0}
\annotate<1->[below,black,font=\scriptsize]{$\beta_{0\,(t)} \gg 0$}~\cdot~d_{i,\,t-1} \mathbf{\vartheta_{i,\,t}},   \end{equation} }

\begin{itemize}
\item<1->{$ pb_{i,\,t} = \tau_{i,\,t} - g_{i,\,t} - ir_{i,\,t}$}

\item<2->{}
\item<2->[]{ \setbeamercolor{postit}{fg=black,bg=gray!10} \begin{beamercolorbox}[\vskip -1.35em,\hskip 0.0em,wd=\linewidth,rounded=true,shadow=true]{postit} {\textbf{\emph{Sufficient}} but not necessary condition} \end{beamercolorbox}}

\end{itemize}
\end{itemize}
\end{frame}
\end{document}

It works with error message

Missing \endcsname inserted. \end{frame}.

If I use any greek letter and/or expression with \ such as \,, then another error message appears

Missing \endcsname inserted. \savepointas...

Then, the coloured box is not adjusted, a part of the equation is missing.

Since I am now to using tikz, I may be missing a definition of an object. Any suggestion is welcome.

  • First thing I noticed was that \newcommand is followed by <>. I have never seen that. I thought it had to be followed by the optional arguments (number of arguments of the new command and optional first argument's default value) or the mandatory argument. But maybe I'm about to discover something new :). Anyways there seem to be two problems: one comes from both the \annotate and the \tikzmarkaligned in the first item, the other one from the \hskip,\vskip given as options to beamercolorbox. If you take those out of the options, and remove the \tikzmarkaligned and (continues…) – MickG Mar 18 '16 at 15:15
  • (…continuing) \annotate lines (leaving \end{equation} } there), you get this as a second slide (or at least I do). If that is what you want, then take those spacing commands out of the beamercolorbox's options. – MickG Mar 18 '16 at 15:17
  • Another thing: it seems pgf does not know the shape marker unit vector-1 (which is what marker id seems to be auto-translated to for some reason). – MickG Mar 18 '16 at 15:23
  • Hi MickG, thanks for your suggestions. The code is copied from the link pasted in the introduction of my question (originaly posted by Claudio Fiandrino). Two spaces are for the box to be aligned in the itemize (I have not found other way yet). If ommitted, it does not change the result. I can only see in the background "\beta_{0\,(t)} rectangle 1.00.00.01.0-2..." However, if I use "beta" instead of "\beta", box is adjusted, annotate is below the highlighted variable, i.e. all as it should be... Any suggestion how to fix the pgf problem? – vendaval Mar 18 '16 at 15:47
  • No idea. But if this is what you want to achieve, then the problem is in Claudio's code if you ask me. Using #3 three times in \tikzmarkaligned, there is no way of getting the \beta in place. But if we give \tikzmarkin and \tikzmarkend argument #4 in \tikzmarkaligned, and then change that argument to foobarbaz (or anything roughly the same length as argument #3) we get the image. That of course is implicitly using the fix for the spaces problem stated above. – MickG Mar 18 '16 at 16:15
3

There are two problems here.

  • The first one is that beamercolorbox apparently doesn't like to have spacing instructions passed ad options. Those should be placed before the \begin.
  • The second one is in the definition of \tikzmarkaligned. I will address it out of this bullet list.

Let us recollect part of the preamble:

\newcommand{\mth}[2]{
\setnotewidth{#2}
\mathmakebox[0.100\notewidth]{#1}
}

\NewDocumentCommand{\tikzmarkaligned}{r<> o m m}{
\phantom{\mth{#3}{#4}}
\tikzmarkin<#1>[#2]{#3}#3\tikzmarkend{#3}
\phantom{\mth{#3}{#4}}
}

Now I don't know exactly what the \tikzmarkin and \tikzmarkend macros do. According to the hf-tikz documentation, they insert the delimiters for the colored region. However, they seem not to like greek letters inside them. So feeding #3 into both is looking for trouble, since #3 is what is supposed to be colored. The best thing, seen as it is #4 that is used to set the width for the coloring while #3 is typeset, would be to feed #4 to those two macros and then fill it with a random foobarbaz type string that causes no trouble and has roughly the correct width, i.e. the same width as #3.

So the code can be amended to:

\documentclass{beamer}
\usefonttheme{professionalfonts}
\usefonttheme{serif}
\usefonttheme{structuresmallcapsserif}
\usepackage{amsmath, amssymb}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[beamer,markings]{hf-tikz}
\usepackage{mathtools,xparse} % texted arrows

\NewDocumentCommand{\annotate}{r<>O{}m}{
\onslide#1{
    \tikz[remember picture,overlay]\node[#2,use marker id] at (0,0){#3};
}
}

\newlength{\notewidth}
\newcommand{\setnotewidth}[1]{%
\settowidth{\notewidth}{$#1$}%
}

\newcommand{\mth}[2]{
\setnotewidth{#2}
\mathmakebox[0.100\notewidth]{#1}
}

\NewDocumentCommand{\tikzmarkaligned}{r<> o m m}{
\phantom{\mth{#3}{#4}}
\tikzmarkin<#1>[#2]{#4}#3\tikzmarkend{#4}
\phantom{\mth{#3}{#4}}
}

\def\savepointas#1#2{%
\expandafter\gdef\csname save@pt@#1\endcsname{#2}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    \newcommand\indentdisplays[1]{%
\everydisplay{\addtolength\displayindent{#1}%
    \addtolength\displaywidth{-#1}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setbeamertemplate{footline}[frame number]
\setbeamertemplate{navigation symbols}{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\begin{frame}
\transwipe
\begin{itemize}

\item<1->[]{ \indentdisplays{-3em}  \begin{equation} \mathbf{pb_{i,\,t}} = \underbrace{\gamma_{i}~\{~+\delta_{t}\}}_{\textrm{fixed effects}} + \alpha \cdot pb_{i,\,t-1} + 
\tikzmarkaligned<1->[mark at=0.825]{\beta_{0 (t)}}{foobarbaz}
\annotate<1->[below,black,font=\scriptsize]{$\beta_{0\,(t)} \gg 0$}~\cdot~d_{i,\,t-1} \mathbf{\vartheta_{i,\,t}},   \end{equation} }

\begin{itemize}
\item<1->{$ pb_{i,\,t} = \tau_{i,\,t} - g_{i,\,t} - ir_{i,\,t}$}

\item<2->{}
\item<2->[]{ \setbeamercolor{postit}{fg=black,bg=gray!10} \vskip -1.35em \hskip 0.0em \begin{beamercolorbox}[wd=\linewidth,rounded=true,shadow=true]{postit} {\textbf{\emph{Sufficient}} but not necessary condition} \end{beamercolorbox}}

\end{itemize}
\end{itemize}
\end{frame}
\end{document}

This compiles fine, and gives:

enter image description here

Unfortunately I am no longer sure this is what was desired, since the comment I posted had a wrong url giving this image instead, which comes from Claudio Fiandrino's answer here, as the code in the OP's MWE.

Note that to adjust the box it is necessary to compile twice.

In a comment above, I stated I had gotten a:

Package pgf error: no marker shape "marker unit vector-1" is known

error. I have no idea where that came from or how to solve it. All I noticed was that eliminating marker id from the definition of \annotate the error vanished.

Update

I saw that something was wrong with the equation. I realized there was an extra 1-. Having changed the definition of \annotate from OP's code to:

\NewDocumentCommand{\annotate}{r<>O{}m}{
\onslide#1{
    \tikz[remember picture,overlay]\node[#2,use marker id] at (0,0){#3}
}
}

produced \onslide1-, which caused \onslide to do nothing, and the 1- to be typeset. My bad. Reverting to:

\newcommand<>{\annotate}[2][]{
\onslide#3{
    \tikz[remember picture,overlay]\node[#1,use marker id] at (0,0){#2};
}
}

fixes this. I don't know why though. I have never seen \newcommand<>. Apparently, this is a trick to define a command taking an argument wrapped in <> as #3 and then parsing what follows as a normal \newcommand would. So \annotate<1->[…]{……} has 1- as #3, as #1 and …… as #2.

Update on \savepointas

As I said in comments, I think it is plain useless, as it is never invoked in the code. Perhaps it is invoked by some package command used in one of the defined commands. Anyways I tried compiling with and without it. Here is the code:

\documentclass{beamer}
\usefonttheme{professionalfonts}
\usefonttheme{serif}
\usefonttheme{structuresmallcapsserif}
\usepackage{amsmath, amssymb}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[beamer,markings]{hf-tikz}
\usepackage{mathtools,xparse} % texted arrows

\newcommand<>{\annotate}[2][]{
\onslide#3{
    \tikz[remember picture,overlay]\node[#1,use marker id] at (0,0){#2};
}
}

\newlength{\notewidth}
\newcommand{\setnotewidth}[1]{%
\settowidth{\notewidth}{$#1$}%
}

\newcommand{\mth}[2]{
\setnotewidth{#2}
\mathmakebox[0.100\notewidth]{#1}
}

\NewDocumentCommand{\tikzmarkaligned}{r<> o m m}{
\phantom{\mth{#3}{#4}}
\tikzmarkin<#1>[#2]{#4}#3\tikzmarkend{#4}
\phantom{\mth{#3}{#4}}
}

\def\savepointas#1#2{%
\expandafter\gdef\csname save@pt@#1\endcsname{#2}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    \newcommand\indentdisplays[1]{%
\everydisplay{\addtolength\displayindent{#1}%
    \addtolength\displaywidth{-#1}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setbeamertemplate{footline}[frame number]
\setbeamertemplate{navigation symbols}{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\begin{frame}
\transwipe
\begin{itemize}

\item<1->[]{ \indentdisplays{-3em}  \begin{equation} \mathbf{pb_{i,\,t}} = \underbrace{\gamma_{i}~\{~+\delta_{t}\}}_{\textrm{fixed effects}} + \alpha \cdot pb_{i,\,t-1} + 
\tikzmarkaligned<1->[mark at=0.825]{\beta_{0 (t)}}{foobarbaz}
\annotate<1->[below,black,font=\scriptsize]{$\beta_{0\,(t)} \gg 0$}~\cdot~d_{i,\,t-1} \mathbf{\vartheta_{i,\,t}},   \end{equation} }

\begin{itemize}
\item<1->{$ pb_{i,\,t} = \tau_{i,\,t} - g_{i,\,t} - ir_{i,\,t}$}

\item<2->{}
\item<2->[]{ \setbeamercolor{postit}{fg=black,bg=gray!10} \vskip -1.35em \hskip 0.0em \begin{beamercolorbox}[wd=\linewidth,rounded=true,shadow=true]{postit} {\textbf{\emph{Sufficient}} but not necessary condition} \end{beamercolorbox}}

\end{itemize}
\end{itemize}
\end{frame}
\end{document}

Output with that \def line:

enter image description here

Output without it:

enter image description here

See any difference? I really don't… If you get a different result, you probably have an outdated version of one or more packages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.