# How can I pass babel options through class options?

I built a class upon the article class. This class load a package where the \maketitle command is define. If I do not load babel inside the class, the title of the document is always in english (the date). Thus, I would like to pass the language in the class options, but I also would like to keep the possibility to load article class options. How can I do ?

I would like to do something like:

\documentclass[language, opt1, opt2]{myclass}


where in myclass, I send language to babel and opt1, opt2 to the article class. This is the beginnig of my class :

% default options
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax



Giving the option globally can be a handy thing. The class file passes the options further to packages. You mentioned the language, let's have a look at it.

Internally, siunitx loads package translator (part of the beamer bundle). translator can see the global option for the language and react by using the right dictionary.

Another famous instance where a global option is passed to a package is draft.

\begin{filecontents}{\jobname.cls}
\ProvidesClass{\jobname}[2014/10/15 test class TeX.SX]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax

\renewcommand{\maketitle}{
\begin{center}
\Huge \@date
\end{center}
}
\endinput
\end{filecontents}
\documentclass[
draft,
%draft=true,
%ngerman
french
]{\jobname}
\usepackage{babel}
\usepackage{siunitx}
\begin{document}
\maketitle
Let the pizza dough leaven for \SIrange{18}{24}{\hour}. Is the
draft option working here? hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

\includegraphics{example-image}
\end{document}


An alternative to babel is polyglossia. Both do the same thing, but polyglossia has another syntax. So giving ngerman (or french) as a global option isn't known by polyglossia and hence ignored. Using the polyglossia syntax, translator won't know the option and hence ignore it.
I once saw a custom class taking options via a key-value-syntax. Please replace draft by draft=true in the above example and take a look at the output. Package graphicx doesn't know the syntax and thus ignores it.
• If amsmath gets the option french or ngerman, it will just ignore it. siunitx will pick it up as well. Some new features of babel won't work with global options and need to be given as a package option directly. – Johannes_B Oct 15 '14 at 14:17