# [Tex/LaTex] usage of \only with counter, pdfcomment and beamer class

beamercounterspdfcomment

I cannot manage to get the following command to work. I have a beamer presentation with several slides on a frame. Then I want to use the pdfcomment package to show some comments on the slides. Usually this works fine, but on frames with multiple steps, it's annoying, because the comments appear on each slide (and they are visible on each slide, even if the respective text has not appeared yet!). So my solution is the following:

I calculate the slide number on the frame and the use the \only command to show the comment only of the last slide of the frame. In my example, this is the fifth slide on the frame. The command works like this:

\only<5>{\pdfcomment[style=note,author=name]{comment...}}


However, as it is quite annoying to find the last slide on the frame by hand, I tried to define a command, which reads:

\newcommand{\pdfnote}[2]{%
\setcounter{slidenum}{\insertpagenumber}
\only<\value{slidenum}>{\pdfcomment[style=note,author=#1]{#2}}%
}


Basically it uses the counter slidenum, which contains the last slide on the frame, e.g. 2. The routine works, except that the pdfcomment is visible on all slides! It's kind of weird, because when I simply replace \value{slidenum} with 2, it works. And I just added the line \arabic{slidenum} just before the \only command so check if the counter is correct. Furthermore I replaced the \pdfcomment by a simple text. That's working as well.

By the way: \only does work, \onslide does not work at all for pdfcomment. I really don't understand. Do you have any ideas? Below you find a complete example.

\documentclass{beamer}

\definestyle{note}{icon=Comment,color=white,open=true}
\definestyle{warning}{icon=Comment,color=red,open=true}

\newcounter{slidenum}

\newcommand{\pdfnote}[2]{%
\setcounter{slidenum}{\insertpagenumber}
%\arabic{slidenum}
\only<\value{slidenum}>{\pdfcomment[style=note,author=#1]{#2}}%
}

\begin{document}

\begin{frame}

test\\ \pause
next line
\pdfnote{me}{my comment}

\end{frame}

\end{document}


I didn't test exactly the reason why it doesn't work but it is apparent that the calculations fall short and it is being shown on every slide, although the number shown is correct.

However, you can use the internal counter of beamer which is the beamerpauses counter. As the name implies it is incremented whenever there is an overlay specification is given.

\documentclass{beamer}
\definestyle{note}{icon=Comment,color=white,open=true}
\definestyle{warning}{icon=Comment,color=red,open=true}
\newcommand{\pdfnote}[2]{%
\onslide*<\value{beamerpauses}>{\pdfcomment[style=note,author=#1]{#2}}%
}
\begin{document}
\begin{frame}
test\\ \pause
next line
\pdfnote{me}{comment 1}
\\ \pause

I have changed \only to \onslide* to show yet another possibility which is effectively the same thing as stated in the manual.