2

I would like to use labels to assign overlay specifications. Below is the code I have so far. My main question is why does not the following terminate to compile.

\documentclass[11pt]{beamer}
\usepackage{pgfkeys}
\pgfkeys{/.unknown/.code=%
        {\PackageError{some name}{Label \pgfkeyscurrentname{} not defined}{}}%
}
\begin{document}
    \begin{frame}{Title}        
        \pgfkeys{/bar 1/.append={2}}
        \pgfkeys{/foo 2/.append={1}}
        \begin{itemize}
            \item<\pgfkeys{/bar 1}> Some bar
            \item<\pgfkeys{/foo 2}> and foo
        \end{itemize}
    \end{frame}
\end{document}

My solution so far:

The following code fixes the issue above. However, when I write one of the labels in the overlay specification wrong pdflatex does not terminate, as the key is unknown. That means, the .unknown handler is ignored, which is why I am not satisfied with my solution..

\documentclass[11pt]{beamer}
\usepackage{pgfkeys}
\pgfkeys{/.unknown/.code=%
    {\PackageError{some name}{Label \pgfkeyscurrentname{} not defined}{}}%
}
\begin{document}    
    \begin{frame}{Title}        
        \pgfkeys{/bar 1/.append={2}}
        \pgfkeys{/foo 2/.append={1}}
        \begin{itemize}
            \item<\pgfkeysvalueof{/bar 1}> Some bar
            \item<\pgfkeysvalueof{/foo 2}> and foo
        \end{itemize}
    \end{frame}
\end{document}

Related Questions:

Here it was suggested to just redefine \item. However, I am not sure how to redefine the overlay macros in a good and general way. With my current approach I can use the label approach with all overlay aware commands.

Here I asked about this the first time. I got it working without pgfkeys, storing the values in macros. But then I can only use letters in labels, which is inconvenient.

Here it was suggest to protect the pgfkeys command with \protect but that did not work. Thought it is related as the resulting problem is the same.

1 Answer 1

1

The first code with

\item<\pgfkeys{/bar 1}> Some bar
\item<\pgfkeys{/foo 2}> and foo

won't work because \pgfkeys is the command to process keys, it does not return the value of the keys given – what's beamer supposed to do with \pgfkeys{/bar 1, /foo 2, tikz/draw=green}?

If you need the value stored in a key, use \pgfkeysvalueof as you did in your second example. However, when a non-existing key is used \pgfkeysvalueof will expand to \relax which will break Beamer's <…> parser.

I don't see a way to insert an error message here (this will still mess with Beamer) but you can default to an overlay specification of 1- instead.

Code

\documentclass[11pt]{beamer}
\newcommand\pgfkeysValueof[1]{%
  \csname\ifcsname pgfk@#1\endcsname pgfk@#1\else pgfkeysValueofDefault\fi\endcsname}
\newcommand*\pgfkeysValueofDefault{1-}

\begin{document}
\begin{frame}{Title}        
\pgfkeys{/bar 1/.append={2}}
\pgfkeys{/foo 2/.append={1}}
\begin{itemize}
    \item<\pgfkeysValueof{/bar 1}> Some bar
    \item<\pgfkeysValueof{/foo 2}> and foo
    \item<\pgfkeysValueof{/foobar}> I'm wrong
\end{itemize}
\end{frame}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .