5

I have been using a custom class file for some time now, which requires several options with arguments; e.g. my documents often begin with something like \documentclass[name=John\ Smith]{mathwork}. This has worked without any compilation warnings for some time, but recently for whatever reason I'm getting an "Unused global options(s)" warning now, whenever I specify an option with an equals.

For instance, consider the MWE class file testwork.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{testwork}
\LoadClass{article}

\RequirePackage{xkeyval}
\DeclareOptionX{test}{\newcommand{\foo}{#1}}
\ProcessOptionsX\relax

\endinput

and the document file scratch.tex:

\documentclass[test=wtf]{testwork}

\begin{document}
test \foo
  
\end{document}

When I try to compile scratch.tex with the command latexmk scratch.tex, I get the warning

LaTeX Warning: Unused global option(s):
    [test=wtf].

But the document compiles fine otherwise, and \foo is indeed set to "wtf". On the other hand, if I replace the line \documentclass[test=wtf]{testwork} with \documentclass[test]{testwork}, the document now compiles without warning, but \foo is just empty. I'm struggling to understand why this happens; I just want to have class options with arguments without raising the "Unused global option(s)" warning. Any help would be much appreciated!

I'm using latexmk version 4.79, on Arch Linux with the texlive-most package.

2
  • Welcome to TeX.SE!
    – Zarko
    Commented Apr 10, 2023 at 22:25
  • The warning is harmless and not uncommon in parasitic classes. (My term - I don't know what the technical term is. I just invented this to describe the classes I've written which load other classes.)
    – cfr
    Commented Oct 14, 2023 at 4:51

1 Answer 1

0

I discovered a modification that resolves the problem. Alter the original code

\documentclass[test=wtf]{testwork}

to the revised version below:

\documentclass{testwork}
\setkeys{testwork.cls}{test=wtf}

This change suppresses the warning. Unfortunately, I'm currently unsure of the underlying reason this adjustment works. If anyone has insights into why this solution is effective, further clarification would be greatly appreciated.

3
  • 1
    It "works" because the option is no longer passed to article.cls. It will fail if testwork.cls does anything during loading with the option. Since classes very often do things with the options they're given before the rest of the preamble is read, this will fail in typical cases. I'd advise deleting this answer. An option not being processed correctly is a much more serious problem than a harmless warning.
    – cfr
    Commented Oct 14, 2023 at 4:49
  • I don't understand. After my change, the testwork.cls is still functional, and set \foo to wtf correctly. If it has the same output but no warning, why it isn't a valid answer?
    – KiringYJ
    Commented Oct 14, 2023 at 6:56
  • 1
    The problem is that usually a class does something with the value. In this case, it only executes the code in the declaration (\newcommand...). But that's a pretty unusual case. Suppose instead it set \footrue or foofalse and then later said \iffoo ... \else ... \fi. Then the default value of \iffoo would always be used, regardless of whether you set foo in the preamble, because the preamble wouldn't be read when iffoo was evaluated (unless you delayed it or whatever). So it works for the example, but it won't work for most cases.
    – cfr
    Commented Oct 14, 2023 at 11:45

You must log in to answer this question.

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