1
\begin{filecontents}{foo.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{foo}

\RequirePackage{kvoptions}
\SetupKeyvalOptions{family=myoptions,prefix=myoptions@}

\DeclareStringOption[scriptsize]{bibsize}

\ProcessKeyvalOptions{myoptions}\relax
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax

\LoadClass[a4paper, twoside]{article}

\def\bibfont{\csname \myoptions@bibsize\endcsname}
\end{filecontents}

\documentclass[bibsize=footnotesize]{foo}

\begin{document}
Foo bar
\end{document}

Works fine, but raises the warning:

LaTeX Warning: Unused global option(s):
    [bibsize].
3
  • 1
    Off-topic: For new classes or package I would suggest to use \DeclareKeys or l3's \keys_define:nnand \ProcessKeyOptions. See clsguide.pdf (current version) section 4.4 and interface3.pdf.
    – cabohah
    Commented Feb 12 at 15:51
  • @cabohah Thanks. Do you know of good examples? I find the clsguide.pdf still a bit cryptic Commented Feb 12 at 16:48
  • 1
    Just search for \ProcessKeyOptions in the sty and cls files of your TeX distribution. I'm sure, there are several. Or see here on TeX.SX. Maybe start with tex.stackexchange.com/a/648001/277964 and if you have a new question about using it, please ask it.
    – cabohah
    Commented Feb 12 at 16:57

2 Answers 2

2

The unused option list warning really wasn't designed for keyval options, just 10pt etc as used by the standard classes. It's probably possible to improve kvoptions handling here but the warning doesn't always make sense. if you have foo=false is the option foo used or not?

It's better not to warn than make spurious warning so I would simply silence it and arrange the class using kv parsing simply empties the unused list:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{foo}

\RequirePackage{kvoptions}
\SetupKeyvalOptions{family=myoptions,prefix=myoptions@}

\DeclareStringOption[scriptsize]{bibsize}

\ProcessKeyvalOptions{myoptions}\relax
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax

\LoadClass[a4paper, twoside]{article}

\let\@unusedoptionlist\@empty%<<<<<<<<<<<<<<<<<<<<<<<<

\def\bibfont{\csname \myoptions@bibsize\endcsname}

For any new code use the built in key/value option handling in LaTeX, not the older package based versions. (A similar issue with the unused option list was just raised there)

1
  • Or you use the vastly superior expkv-opt package :P
    – Skillmon
    Commented Feb 15 at 9:48
1

The following would port your option to LaTeX's built in key=val option handler.

\begin{filecontents}{foo.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{foo}

\DeclareKeys[myoptions]
  {
    bibsize .store = \myoptions@bibsize,
    unknown .code  = \PassOptionsToClass{\CurrentOption}{article}
  }
\SetKeys[myoptions]{bibsize=scriptsize}

\ProcessKeyOptions[myoptions]

\LoadClass[a4paper, twoside]{article}

\def\bibfont{\csname \myoptions@bibsize\endcsname}
\end{filecontents}

\documentclass[bibsize=footnotesize]{foo}

\begin{document}
Foo bar {\bibfont bibfont}
\end{document}

Alternative solution, just to show stuff using expkv-opt (disclaimer: I'm the author of expkv-opt).

\begin{filecontents}{foo.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{foo}

\RequirePackage{expkv-opt, expkv-def}
\ekvdefinekeys{myoptions}
  {
    store   bibsize = \myoptions@bibsize,
    initial bibsize = scriptsize,
    unknown code    = \PassOptionsToClass{\CurrentOption}{article},
    unknown noval   = \PassOptionsToClass{\CurrentOption}{article}
  }
\ekvoUseUnknownHandlers* % for the next ekvoProcess use set's unknown handlers
\ekvoProcessLocalOptions{myoptions} % these are forwarded to article
\ekvoProcessFutureOptions{myoptions} % these aren't, article doesn't support it

\LoadClass[a4paper, twoside]{article}

\def\bibfont{\csname \myoptions@bibsize\endcsname}
\end{filecontents}

\documentclass[bibsize=footnotesize]{foo}

\begin{document}
Foo bar {\bibfont bibfont}.
\end{document}
2
  • Thanks! Do I understand well that LaTeX decided to officially support features from expkv-opt / kvoptions? Commented Feb 15 at 14:27
  • @TomdeGeus LaTeX has key=value option handling built in nowadays, yes. You don't need any package anymore, but you can still use them. But as you saw some of them didn't yet adapt to the new mechanisms and yield false positives. expkv-opt is very correct in this regard (and was for some time in fact more correct than the kernel...), while expkv-opt allows fine grained control over which options are parsed with which set and which unknown-key handlers (which is why in above's example the option parsing needs three macro calls instead of just one to be as correct as possible).
    – Skillmon
    Commented Feb 16 at 7:08

You must log in to answer this question.

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