6

Up to now I always use slide numbers when invoking overlay commands such as \only<...>. But for me this is a bit cumbersome because I must count the slide position in my head. If I can use a string (like \label and \ref mechanism) instead of a slide number, it becomes more elegant, doesn't it?

Is it possible to use a string instead of a slide number when invoking overlay commands such as \only?

Minimal Working Example:

\documentclass{beamer}
\usepackage{pstricks-add}
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\PreviewEnvironment{pspicture}

\begin{document}

\begin{frame}
    \begin{pspicture}(6,6)
        \pnode(0,0){A}
        \pnode(6,0){B}
        \pnode(6,6){C}
        \pnode(0,6){D}
        \pnode(1,1){P}
        \pnode(5,1){Q}
        \pnode(3,5){R}
        \only<5>{\psclip{\pscircle[linestyle=none,dimen=middle](3,3){3}}}
        \only<1->{\pspolygon*[linecolor=red](A)(B)(Q)(P)}
        \only<2->{\pspolygon*[linecolor=green](B)(C)(R)(Q)}
        \only<3->{\pspolygon*[linecolor=blue](C)(D)(R)}
        \only<4->{\pspolygon*[linecolor=yellow](D)(A)(P)(R)}
       \only<5>{\endpsclip}
     \end{pspicture}
\end{frame}

\end{document}

Edit: Oh no. I just knew that the slide numbers in one frame can be reused for other frames. I thought when writing this question that the slide numbers continue from the first slide to the last slide in the beamer document. My question does not make sense now!

My imagination when writing this question is illustrated in the following minimal (NOT) working example:

\documentclass{beamer}
\usepackage{pstricks-add}
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\PreviewEnvironment{pspicture}

\begin{document}

\begin{frame}
    \begin{pspicture}(6,6)
        \pnode(0,0){A}
        \pnode(6,0){B}
        \pnode(6,6){C}
        \pnode(0,6){D}
        \pnode(1,1){P}
        \pnode(5,1){Q}
        \pnode(3,5){R}
        \only<5>{\psclip{\pscircle[linestyle=none,dimen=middle](3,3){3}}}
        \only<1->{\pspolygon*[linecolor=red](A)(B)(Q)(P)}
        \only<2->{\pspolygon*[linecolor=green](B)(C)(R)(Q)}
        \only<3->{\pspolygon*[linecolor=blue](C)(D)(R)}
        \only<4->{\pspolygon*[linecolor=yellow](D)(A)(P)(R)}
       \only<5>{\endpsclip}
     \end{pspicture}
\end{frame}


\begin{frame}
    \begin{pspicture}(6,6)
        \pnode(0,0){A}
        \pnode(6,0){B}
        \pnode(6,6){C}
        \pnode(0,6){D}
        \pnode(1,1){P}
        \pnode(5,1){Q}
        \pnode(3,5){R}
        \only<10>{\psclip{\pscircle[linestyle=none,dimen=middle](3,3){3}}}
        \only<6->{\pspolygon*[linecolor=red](A)(B)(Q)(P)}
        \only<7->{\pspolygon*[linecolor=green](B)(C)(R)(Q)}
        \only<8->{\pspolygon*[linecolor=blue](C)(D)(R)}
        \only<9->{\pspolygon*[linecolor=yellow](D)(A)(P)(R)}
       \only<10>{\endpsclip}
     \end{pspicture}
\end{frame}
\end{document}

I thought it will become cumbersome if the frame order change as I need to modify the slide numbers for each frame.

1 Answers1

7

Yes, you can as long as you use anything that is a number; in the case of \label, \ref you can't directly use \ref because the string associated is not a number; you can use the refcount package to convert the string to a number first. A simple example:

\documentclass{beamer}

\newcounter{refcount}

\begin{document}

\begin{frame}
\begin{enumerate}[<+->]
\item\label{a} Item on first slide.
\item\label{b} Item on second slide.
\item\label{c} Item on third slide.
\end{enumerate}
\only<\getrefnumber{b}>{Text on second slide}
\end{frame}

\end{document}

In your concrete example, you can do something like this:

\documentclass{beamer}
\usepackage{pstricks-add}
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\PreviewEnvironment{pspicture}

\newcounter{tmp}

\begin{document}

\begin{frame}
    \begin{pspicture}(6,6)
        \pnode(0,0){A}
        \pnode(6,0){B}
        \pnode(6,6){C}
        \pnode(0,6){D}
        \pnode(1,1){P}
        \pnode(5,1){Q}
        \pnode(3,5){R}
        \only<\thetmp>{\psclip{\pscircle[linestyle=none,dimen=middle](3,3){3}}}
        \only<+->{\pspolygon*[linecolor=red](A)(B)(Q)(P)}
        \only<+->{\pspolygon*[linecolor=green](B)(C)(R)(Q)}
        \only<+->{\pspolygon*[linecolor=blue](C)(D)(R)}
        \only<+->{\pspolygon*[linecolor=yellow](D)(A)(P)(R)}
        \setcounter{tmp}{\value{beamerpauses}}
       \only<\thetmp>{\endpsclip}
     \end{pspicture}
\end{frame}

\end{document}

Section 9.6.4 Incremental Specifications of the beamer manual contains some other useful details.

Gonzalo Medina
  • 505,128