[Tex/LaTex] How to pass parameters in a class file to different packages

babeldocumentclass-writingpackagesparameters

I'm writing a new class file that is based on book, and thought of making it available both in an English and in a Dutch version. Easiest to do seemed passing the arguments, so I constructed following class file :

...
\ProvidesClass{UGentCourse}[2011/07/28 v1.0 UGentCourse]

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}
\ProcessOptions \relax
\LoadClass[12pt,a4paper,twoside]{book}

\RequirePackage{babel} %francais, polish, spanish, ...
...

Which I believed would allow me to do :

\documentclass[dutch]{UGentCourse}

Strange thing, it doesn't work completely. If I switch it from dutch to English (or back), I get an error :

Package babel Error: You haven't loaded the option english (dutch) yet.

If I rerun the file, the error is gone. I have a faint idea about what is going on, but not really a clue of how I can prevent this from happening. All help appreciated.

Best Answer

You can avoid this error by modifying your class definition as follows:

\ProvidesClass{UGentCourse}[2011/07/28 v1.0 UGentCourse]

\DeclareOption{english}{\AtEndOfClass{\main@language{english}}}
\DeclareOption{dutch}{\AtEndOfClass{\main@language{dutch}}}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}}

\ProcessOptions\relax

\LoadClass[12pt,a4paper,twoside]{book}

\RequirePackage[dutch, english]{babel}

The last language in the option list passed to the babel package (i.e. english here) is the default language. It is active at the beginning of the document if no language has been specified in the optional argument of \documentclass.