2

I'm trying to highlight some pseudocode lines, and I'm using this solution pseudocode block. However, I've not understood the following new command:

\newcommand{\fillcol}{green!20}
\newcommand<>{\boxto}[1]{
\only#2{
    \tikz[remember picture with id=#1]
    \draw[line width=1pt,fill=\fillcol,rectangle,rounded corners]
    (pic cs:#1) ++(8.2,-.1) rectangle (-3.4,-.1);
    }
}

What's mean the symbols <> in front of \newcommand?

Moreover, I'd like to pass the color to fill the rectangle as parameter for the \boxto command. In the posted solution, the color is defined as a command \fillcol How to do this change? Could someone help me?

Thanks!

tnas
  • 215

1 Answers1

4

Just for quickness: I did not copy over unnecessary code from the linked question, i.e. I disabled the pic coordinate system and the tikz remember picture with id=#1 style.

The beamer class adds a new version of \newcommand, making it possible to generate commands with overlay specification, with

\newcommand<>{\cmdname}[number of args]{%...

% rest of code
}

Important to know is that the overlay specification is inside and that the command in fact has one more argument than specified, i.e. in the example, there are 3 arguments. The third one is meant for the overlay, so the last argument is always 'hidden', but can be accessed.

Please note, that the pointed brackets <1> belong to the last argument, that's how \only#3 works then.

For more on this see section 9.6 of the current beamer documentation.

\documentclass{beamer}

\usepackage{tikz}


\newcommand{\fillcol}{green!20}
\newcommand<>{\boxto}[2]{
\only#3{%
  \tikz%[remember picture with id=#1]
  \draw[line width=1pt,fill=#2,rectangle,rounded corners] (1,1) rectangle (2,2);
  }%
}

\begin{document}


\begin{frame}{Foo frame}
\boxto<1>{1}{green}

\boxto<2>{1}{red}
\end{frame}

\end{document}
  • It works almost perfectly. There is just one problem: when I use \boxto<2>{1}{red} the second box is not displayed. So, I must to call \boxto<1>{1}{green} and \boxto<1>{1}{red}. In this case, the two boxes are displayed. Anyway, thank you so much! – tnas Jan 25 '17 at 18:58
  • 1
    @tnas a command with <2> will not be displayed originally, that is the meaning of the overlay, it will appear in the second layer if you advance the presentation. – David Carlisle Jan 25 '17 at 20:02
  • @tnas: My example was simplified because I did not want to copy the code from the linked question just in order to show how the <> syntax works for beamer's \newcommand –  Jan 25 '17 at 22:30