6

This is a follow up question to Options in custom class. It seems that I still did not understand how global options work. Consider the following code:

\RequirePackage{filecontents}
\begin{filecontents}{sampleclass.cls}
    \NeedsTeXFormat{LaTeX2e}
    \ProvidesClass{sampleclass}

    %Providing key value syntax
    \RequirePackage{xkeyval}

    %Options
    \DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
    \DeclareOptionX{language}{\PassOptionsToPackage{#1}{babel}}
    \ExecuteOptionsX{language=latin}

    \ProcessOptions\relax
    \ProcessOptionsX\relax

    %Parent class
    \LoadClass[
    ]{article}

    %Language support
    \RequirePackage{babel}
\end{filecontents}

\documentclass[language=english]{sampleclass}
\usepackage{blindtext}

\begin{document}
    \blindtext
\end{document}

It prints the text in English - as it's supposed to - but gives the warning

Unused global option(s): [language=english].

If I comment out the line

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}

the warning disappears. What is the correct way to use a [language=english] option for my custom class to pass the option english to babel? After some playing around I did not come to find out which parts of the above code actually lead to the warning so I will leave this not-so-minimal working example.

6

You need \DeclareOptionsX* instead of \DeclareOption*, in order to process the user defined option (here with xkeyval)

\RequirePackage{filecontents}
\begin{filecontents}{sampleclass.cls}
    \NeedsTeXFormat{LaTeX2e}
    \ProvidesClass{sampleclass}

    %Providing key value syntax
    \RequirePackage{xkeyval}

    %Options
    \DeclareOptionX{language}{\PassOptionsToPackage{#1}{babel}}
    \DeclareOptionX*{\PassOptionsToClass{\CurrentOption}{article}}
    \ExecuteOptionsX{language=latin}

    \ProcessOptions\relax
    \ProcessOptionsX\relax

    %Parent class


    \LoadClass{article}

    %Language support
    \RequirePackage{babel}
\end{filecontents}

\documentclass[language=ngerman]{sampleclass}
\usepackage{blindtext}

\begin{document}
    \blindtext
\end{document}
  • 1
    I'm very fast to upvote.+1 :-) Hi, dear friend. – Sebastiano Mar 3 '18 at 11:28
  • Ah, and I guess if I want to include both xkeyvalue- and ordinary options in my document, I'll have to include both \DeclareOptionX*{\PassOptionsToClass{\CurrentOption}{article}} and \DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}} ? – John Dorian Mar 3 '18 at 11:31
  • @JohnDorian: No, \DeclareOptionX* should be sufficent, if I remember correctly. – user31729 Mar 3 '18 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.