I would like to write a class that loads the package babel
with a default language but that this language could be overridden by a language specified in the class options. MWE:
\RequirePackage{filecontents}
\begin{filecontents}{test.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{test}[2015/09/22 v0 testclass]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass{article}
\RequirePackage{babel}
%% or
%% \RequirePackage[english]{babel}
\end{filecontents}
\documentclass[a4paper, english]{test}
%% or
%% \documentclass{test}
\begin{document}
\Huge We are typing in \languagename.
\end{document}
As written, babel
is loaded (as expected) with english. But if I omit english
in the option, I have an error (logically) from babel.
The problem is that if I use \RequirePackage[english]{babel}
in the class I can't override it --- for example:
\RequirePackage{filecontents}
\begin{filecontents}{test.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{test}[2015/09/22 v0 testclass]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass{article}
\RequirePackage[english]{babel}
\end{filecontents}
\documentclass[a4paper, spanish]{test}
\begin{document}
\Huge We are typing in \languagename.
\end{document}
...is still printing out "english".
Is there a general way to solve this generically, or I have the only option to use \DeclareOption
each language that I am interested in and create a big \if
loading babel
in different ways?
To explain better --- I know how to provide with \DeclareOption
a way to explicitily set babel defaults, like in jon's answer. But suppose I want that the class' users could do:
\documentclass[a4paper, whatever]{test} %% babel default to english
or
\documentclass[a4paper, whatever, turkish, serbian, italian]{test}
%% ...and now babel is called with [turkish, serbian, italian] options
The way I have it now is requiring the package babel
with no option and letting it fail if the user do not specify at least a language on the class options... and documenting it. But it would be nice to have a default...