7

I am struggling to understand how option processing works in classes. As a MWE

foo.tex:

\documentclass[draft,figures]{foo}
\begin{document}
  \includegraphics{example-image}
\end{document}

foo.cls:

\ProvidesClass{foo}
\RequirePackage{foo}
\LoadClassWithOptions{article}
\RequirePackage{graphicx}

foo.sty

\ProvidesPackage{foo}
\RequirePackage{etoolbox}
\newbool{foo@figures}
\DeclareOption{figures}{\booltrue{foo@figures}}
\ProcessOptions\relax
\ifbool{foo@figures}{\PassOptionsToPackage{final}{graphicx}}{}

When I process foo.tex with pdflatex the log shows

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

but I also see the graphic, which means that I am passing the final option to the graphicx package. Why does LaTeX think the figures option is unused?

Moving \LoadClassWithOptions to before the package is loaded gets rid of the warning. In my real use case, the class that is being loaded, loads the graphicx package and therefore I need to load the package before loading the class.

StrongBad
  • 20,495
  • I think \LoadClassWithOptions overrules the foo.sty options. Try \LoadClassWithOptions first –  Nov 13 '15 at 22:55
  • by coincidence in chat this morning: http://chat.stackexchange.com/transcript/message/25378324#25378324 – David Carlisle Nov 13 '15 at 23:02
  • @ChristianHupfer that removes the warning, but I need to pass the final option to graphicx first (see edit). – StrongBad Nov 13 '15 at 23:02

1 Answers1

5

Some aspects of the global option handling are less intuitive than perhaps they could have been, but basically the unused option list is set up at the end of the class, with the intention of catching misuse of packages within the document.

Packages loaded within the class are more or less part of the class processing and the global option check was not really designed with them in mind, as the options handled by packages included by the class are statically determined by the class, they do not depend on the end users use in the controlling document.

That said, the nested use of package processing makes it hard to completely isolate the use of packages within a class (especially given the memory requirements at the time) so you get what you get, and as Christian noted you get different results depending on whether the nested RequirePackage is before of after the class option processor.

David Carlisle
  • 757,742
  • I did not check, but I could imagine that \LoadOptionsWithClass resets the option list such that it's is basically undefined again, i.e the already set up options (by the package(s)) are forgotten? Somehow it's namespace pollution, in my point of view –  Nov 13 '15 at 23:24