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].
  • 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 Feb 12 '24 at 15:51
  • @cabohah Thanks. Do you know of good examples? I find the clsguide.pdf still a bit cryptic – Tom de Geus Feb 12 '24 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 https://tex.stackexchange.com/a/648001/277964 and if you have a new question about using it, please ask it. – cabohah Feb 12 '24 at 16:57

2 Answers2

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)

David Carlisle
  • 757,742
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}

Skillmon
  • 60,462
  • Thanks! Do I understand well that LaTeX decided to officially support features from expkv-opt / kvoptions? – Tom de Geus Feb 15 '24 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 Feb 16 '24 at 07:08