Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
This is what the relative slide syntax is for: is there a reason for not using it? –  Joseph Wright Jul 28 '12 at 16:11
    
Ah, your edit somewhat alters the situation: it would be very hard if every overlay had to be tracked separately! –  Joseph Wright Jul 28 '12 at 16:24
1  
Somewhat related: Reference overlay numbers with names –  diabonas Jul 29 '12 at 10:16
    
@diabonas: good +1 for your answer and comment each. (this comment will be deleted shortly) –  cyanide-based food Jul 29 '12 at 10:18

1 Answer 1

up vote 7 down vote accepted

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.

share|improve this answer
    
@HiggsBoson I updated my answer; it is something like that what you want? –  Gonzalo Medina Jul 28 '12 at 16:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.