8

I want to use pgfopts (and therefore pgfkeys) when customizing a class with new options, keeping the old ones, and using some of them.

Here is a simplified example with a class "exa" which extends "article" with a new option, and also sets option "a5paper".

\begin{filecontents}{exa.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{exa}[2014/03/19 exa]
% As "article" with "a5paper" set, and an extra option "lastword".
\RequirePackage{pgfopts}
\pgfkeys{
  /exa/.cd,
  lastword/.code=\AtEndDocument{\par The last word is #1.}
}
\ProcessPgfOptions{/exa}
\PassOptionsToClass{a5paper}{article}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
\LoadClass{article}
\end{filecontents}

\documentclass[lastword=bar,twocolumn]{exa}

\usepackage{blindtext}
\begin{document}
\blindtext
\end{document}

The three options work as intended here; "a5paper" set by the class, "twocolumn" sent to "article", and the new option "lastword". But it gives a warning about unused global option ["lastword=bar]".

How can take away all options ProcessPgfOptions took care of, so that only the rest is sent on to "article"?

3
  • 1
    On my machine with updated TeXLive 2013 it is working nicely. Mar 19, 2014 at 14:18
  • Welcome to TeX.SX! If @ClaudioFiandrino is right about the issue, you might want to look at How do I update my TeX distribution?
    – Adam Liter
    Mar 19, 2014 at 14:33
  • Do you really mean you don't get that warning? (I also use TeXLive 2013.) That would surprise me, because I don't think it's strange I got that warning.
    – pst
    Mar 19, 2014 at 17:17

1 Answer 1

8
+50

You're mixing the two methods for setting options, which results in the warning.

\begin{filecontents}{exa.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{exa}[2014/03/19 exa]
% As "article" with "a5paper" set, and an extra option "lastword".
\RequirePackage{pgfopts}

%%% initialize the options
\def\exa@classoptions{a5paper}

\pgfkeys{
  /exa/.cd,
  lastword/.code=\AtEndDocument{\par The last word is #1.},
  %%% unknown keys are assumed to be options to be passed to the class
  .unknown/.code={\edef\exa@classoptions{\exa@classoptions,\pgfkeyscurrentname}}
}
\ProcessPgfOptions{/exa}
\LoadClass[\exa@classoptions]{article}

\end{filecontents}

\documentclass[lastword=bar,twocolumn]{exa}

\usepackage{lipsum}
\begin{document}
\lipsum[1-10]
\end{document}

You must log in to answer this question.

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