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
  • One thing: when you insert code in a comment or post, please wrap it in backticks `. It makes it easier to identify and thus makes the post easier to read. And nicer to the eye if you ask me :). (And "omitted" has only one m :) ) – MickG Mar 18 '16 at 16:16
  • If I see right, the vertical space places the box on the item's line, and the horizontal one makes it align properly. In fact, I think the horizontal one is just plain useless, as it is, after all, 0em, preceded by something that already places the box to the right of the bullet. – MickG Mar 18 '16 at 16:28
  • OK scratch that. Probably the horizontal space enters horizontal mode to start the bullet's line before the box environment causes vertical mode to start again. But I might be wrong there. – MickG Mar 18 '16 at 16:29
  • I cannot quite see the purpose of the outer itemize, since its only item is a display which anyway deletes the bullet, and the point of the empty \item in the second itemize. – MickG Mar 18 '16 at 16:31
  • Sorry for the typo and the visualisation. I have tried to do my best :)

    Yes, it should be that the highlighting goes first, then the annotation appears. I will check your suggestions. The empty \item and the \hspace are only to make it fit in better (I have spent some time playing with it.)

    – vendaval Mar 18 '16 at 17:47
  • Having changed the argument to \#4 as you suggested results in me seeing now the equation written correctly, not adjusted box around the variable and one empty slide with >> 0pgfid2 >>0pgfid7. (The error message is now: Missing \endcsname inserted...t \kern +..1667em\relax (t)} \gg 0}{pgfid2}). I will try to adjust the length following your advice.

    Many thanks for your help!

    – vendaval Mar 18 '16 at 18:00
  • There was a problem with the manually inserted space \,, so I fixed that. I can see the equation completely, but the box is still not adjusted - I am trying to update the defintion of \savepointas from #1#2 to a more general. – vendaval Mar 18 '16 at 18:38
  • Try recompiling. The box should adjust by itself. – MickG Mar 18 '16 at 18:39
  • If I do it with \def\savepointas#1#2{% \expandafter\gdef\csname save@pt@#1\endcsname{#2}% }, then the "oval" is misplaced and there are some numbers written over the equation. With #3#4 I get not-adjusted "oval" and an error Parameters must be numbered consecutively. \def\savepointas#3. A bit clueless now... – vendaval Mar 18 '16 at 18:46
  • I have the impression you are never using \savepointas in your code, so what is it for? Anyway of course you can't have #3#4 without #1#2! – MickG Mar 18 '16 at 18:53
  • If it is deleted, I can see some numbers written over the equation and the message Missing \endcsname inserted. \savepointas {\beta_{0\,(t)} \gg 0}{pgfid2}..., i.e. repeating the content of {...} being highlighted. – vendaval Mar 18 '16 at 19:12
  • I just compiled both with and without the definitoin of \savepointas. No difference in the warnings/errors and I find it really hard to tell the difference between the two outputs. Consider updating your TeX distribution: it's probably out of date. I have TL2014 which is, AFAIK, the latest. – MickG Mar 18 '16 at 20:38

1 Answers1

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.

MickG
  • 5,426