3

Consider the following example class file

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myclass}
\RequirePackage{kvoptions}

\DeclareBoolOption{foo}

\ProcessKeyvalOptions*

\ifmyclass@foo
\def\@title{foo}
\else
\def\@title{bar}
\fi

\ProcessOptions\relax

\LoadClass{article}

And the document

\documentclass[foo]{myclass}

\begin{document}

\maketitle
\end{document}

It correctly produces a document with title "foo", so the class is actually using the option I gave. However, LaTeX says:

LaTeX Warning: Unused global option(s):
    [foo].

Apparently processing a given option is not enough. How can I mark an option as "used" in order to avoid that warning?

  • You can use \DeclareOption*{} before \ProcessOptions\relax. This will silence LaTeX about any unused or unknown key .... –  Aug 25 '16 at 08:53
  • Thank you. Would you make this an answer so I can accept it? And as a follow-up question: why is this? How does LaTeX judge whether an option is used or not, what is considered as use of an option? Only passing it to another package or class? – Philipp Imhof Aug 25 '16 at 09:20
  • I could make it answer but it's not really useful, is it? At the moment I can't answer your follow-up question (I would have to excavate the relevant code in latex.ltx) –  Aug 25 '16 at 09:32
  • It's useful in the sense that it solves my problem :) I might add another question about the terminology "used" and "unused" option. – Philipp Imhof Aug 25 '16 at 09:45

2 Answers2

1

Unused options are added to the \@unusedoptionlist macro, which will be printed to the console/log by \begin{document} using this code

  \ifx\@unusedoptionlist\@empty\else
    \@latex@warning@no@line{Unused global option(s):^^J%
            \@spaces[\@unusedoptionlist]}%
  \fi

if the list is not \@empty.

Using a handler for unused or undefined options named \DeclareOption*{} the warnings can be suppressed.

0

Do you need \ProcessOptions\relax in your class file at all? For example, here is a minimal class file (testkeyval.cls):

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{testkeyval}[2018/01/19 Test key-value options]
\RequirePackage{kvoptions}
\DeclareStringOption[?]{foo}
\DeclareDefaultOption{\PassOptionsToClass{\CurrentOptionKey}{article}}
\ProcessKeyvalOptions*
\newcommand\thefoo{`\testkeyval@foo'}
\LoadClass{article}

that can be used as follows:

\documentclass[foo=bar]{testkeyval}
%\documentclass[foo=bar,11pt]{testkeyval} % passes 11pt to article
%\documentclass[11pt]{testkeyval} % passes 11pt to article
%\documentclass{testkeyval} % default copyright and default fontsize for article
%\documentclass[foo]{testkeyval} % error

\begin{document}
% Number of 'x's on second line: 10pt 0, 11pt 3.
\noindent 
x x x x x x x x x x x x x x x x x x x x x x x x x x x x 
x x x x x x x x x x x x x x 

foo is \thefoo.
\end{document}

Note that in addition to handling key-value options it passes unused options (such as 11pt) onto the article class.

banbh
  • 1,055