# beamer - overlays and incrementing a counter in a macro

I have a macro incrementing a custom counters in it. When this macro is used with overlays (class beamer), the counter is incremented for every overlay (as the macro appears to be called for every overlay)

Macro:

\def\test{\stepcounter{mycounter}}


Main code:

\begin{frame}
\test\\
\onslide<1->{One}
\onslide<2->{Two}
\end{frame}


Here the counter is not supposed to increase on every overlay command, just when calling the test macro. How can it be prevented that the counter increments?

• Why do you want to change the section counter even inside the same section? To change the section (and its counter), use \section{} outside a frame. Oct 10 '19 at 13:23
• It is just an example. Using a custom counter results in the same problem. Oct 10 '19 at 14:04
• I cannot add an answer to the question, because it is flagged as lacking details (which IMHO, does not). The solution to this problem is to use \resetcounteronoverlays{mycounter} in the preamble. Nov 18 '20 at 8:30