0

I would like my custom class to forward unknown keys to the base class, or in this case, a package.

The following works (to make the example smaller, this forwards only one key; expanding it to a list would clutter the code):

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mwe}[2020/02/17 MWE]

\LoadClass{beamer}

\RequirePackage{pgfopts}
\def\@unknownkeys{}

\pgfkeys{
    /mwe/.cd,
    .unknown/.code={
        \message{mwe found unknown key: \pgfkeyscurrentname}
        \edef\@unknownkeys{\pgfkeyscurrentname}
    }
}

\ProcessPgfPackageOptions{/mwe}
\relax

\PassOptionsToPackage{\@unknownkeys}{geometry}
\RequirePackage{geometry}

Now the following document:

\documentclass[showframe]{mwe}
\begin{document}
foo
\end{document}

displays a frame, as expected.

But if I modify my code by replacing

\edef\@unknownkeys{\pgfkeyscurrentname}

by

\edef\@unknownkeys{\pgfkeyscurrentname=\pgfkeyscurrentvalue}

then it does not work anymore:

\documentclass[paper=a0paper]{mwe}
\begin{document}
foo
\end{document}

gives me a DIN-A4 document. What's more, the custom message does not appear in the log, showing that the .unknown/.code was never executed at all.

Why is this? Am I doing something wrong?

PS: I originally had code similar to that provided in this answer, but that does not work, as you can see above.

Edit: forgot a line in my MWE.

  • Welcome! On my machine not even your working example works. It does say mwe found unknown key: showframe, as you describe, but then terminates with the error ! Package geometry Error: \paperwidth (0.0pt) too short.. What am I doing wrong? – Schrödinger's cat Feb 17 at 18:03
  • @Schrödinger'scat: Thank you, of course. In my rush to minimize the MWE I deleted the \LoadClass line. The edited version works for me as described. – Betta George Feb 17 at 19:12
0

I figured out that it is the class beamer which kills it. Moving the \LoadClass statement to after the option processing makes it work as expected.

My best guess is that beamer uses some .unknown handler internally itself. I would still be glad for a more qualified explanation though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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