# How do I prevent the beamer class from removing my global options

I'm currently writing a latex package (or actually a beamer theme, but apparently that makes no difference) and I want to be able to specify a few things using key-value pairs in the global options. However when using the beamer class, this fails.

As a minimal example, take the following:

document:

\documentclass[key=bla]{beamer}
\usepackage{needsoption}
\begin{document}
\MOPstore
\end{document}


package:

\ProvidesPackage{needsoption}
\RequirePackage{pgfopts}
\pgfkeys{
/MOP/.cd,
key/.store in=\MOPstore
}
\ProcessPgfOptions{/MOP}


Even though the option is clearly specified, it is never handled by \ProcessPgfOptions. If I specify the option locally (i.e. \usepackage[key=bla]{needsoption}) everything works fine, if I remove the value (i.e. \documentclass[key]{beamer}) everything works fine, if I switch to a different document class (e.g. \documentclass[key=bla]{article}) again everything works fine. I also tried using kvoptions instead of pgfopts but ran into the same problem.

So what I deduce from that is that apparently something in the beamer class removes key-value options from the list of global options, while leaving other options intact. So I guess I have two questions: Firstly I would really like to know why the hell this happens and secondly how do I prevent the beamer class from behaving that way? I will also accept answers telling me how to hack around the problem if solving it is not an option.

I'm not sure about it but you need to pass the option to your package because your package is not actively looking for options. It might also be the case that beamer does not try each package for the options.

The following works if the option is specifically passed to the package. I've changed key to mykey since it's asking for trouble to be confused by internal options.

\begin{filecontents*}{needsoption.sty}
\ProvidesPackage{needsoption}
\RequirePackage{pgfopts}
\pgfkeys{
/MOP/.cd,
mykey/.store in=\MOPstore
}
\ProcessPgfOptions{/MOP}
\end{filecontents*}

\PassOptionsToPackage{mykey=bla}{needsoption}

\documentclass{beamer}
\usepackage{filecontents}
\usepackage{needsoption}

\begin{document}
\begin{frame}
\MOPstore
\end{frame}
\end{document}

• Hm, I'm still a little bit confused. As I said, options that are specified without a value DO reach the package. So I'm not sure how the "not actively looking for options"part can be the problem. Other than that, your solution seems to work, but it's not really better than simply passing the options when calling \usepackage. But thank you anyway. – Maeher Apr 26 '13 at 11:05
• @Maeher Are you sure that's the case? beamerbaseoptions.sty doesn't look like passing options. article and other classes might but beamer has extra processing in between via keyval – percusse Apr 26 '13 at 11:23
• I'm 100% certain that the option without a value reaches the package, yes. – Maeher Apr 26 '13 at 11:26
• @Maeher Then, I'm confused too. Something should be eating the value. When I use /.try or /.retry on your key it's always empty. – percusse Apr 26 '13 at 11:34
• My confusion is only growing right now. If I specify both initial and default values for my key, then the key always has the initial value, even when the key is specified without value. (Which is the behaviour you described.) However, the macro \MOPstore holds the default value in that case. I have no idea how or why this happens. – Maeher Apr 26 '13 at 12:10