# Pass keyval string option to babel

How to pass a keyval string option given to my package to babel?

\usepackage[languages={ngerman,english}]{mylang}


In package mylang I want to handle this optional languages parameter and hand it over to babel. If the option is missing I want to define a default value.

My attempt:

\usepackage{kvoptions}
\DeclareStringOption{languages}[english,ngerman]


But how to go on from there? I think the default value is set correctly but how to hand it over to babel now? Do I need to run the default process option routine?

For a non keyval value I would use

\DeclareOption{languages}{\PassOptionsToPackage{\CurrentOption}{babel}}
\DeclareOption*{\OptionNotUsed}

-
kvoptions allow to use DeclareOption. –  Marco Daniel Sep 30 '11 at 11:08
But how to use kvoptions' DeclareOption then to pass the languages keyval options to babel? –  Sebastian Sep 30 '11 at 11:17

It is not really an answer but I want to show a minimal working example in relation to mhp answer.

DeclareStringOption (important is the order)

\RequirePackage{filecontents}
\begin{filecontents}{mylang.sty}
\ProvidesPackage{mylang}
\RequirePackage{kvoptions}
\SetupKeyvalOptions{%
family=ML,
prefix=ML@,
}

\DeclareStringOption[english,ngerman]{languages}
\ProcessKeyvalOptions*
\PassOptionsToPackage{\ML@languages}{babel}
\RequirePackage{babel}

\end{filecontents}
\documentclass{article}
\usepackage[languages=frenchb]{mylang}
\usepackage{blindtext}
\begin{document}
\blindtext
\end{document}

-
Works like a charm. Hint: my package name contained numbers and therefore I had to set the prefix myself since the macro \L10n@langiages didn't work with numbers. –  Sebastian Oct 3 '11 at 13:02

The value of an option declared with \DeclareStringOption is stored in the macro \<package>@<option>. Hence, try

\ProvidesPackage{mylang}

...

\usepackage{kvoptions}

\DeclareStringOption{languages}[english,ngerman]

\ProcessKeyvalOptions*

\PassOptionsToPackage{\mylang@languages}{babel}


If you prefer a shorter prefix than mylang@ use \SetupKeyvalOptions before declaring options, e.g.:

\SetupKeyvalOptions{family=ML, prefix=ML@}

-
I get errors: "missing \endscname inserted \ProcessOptions*" –  Sebastian Oct 1 '11 at 10:31
@Sebastian: Look at the answer of Marco, he's built a minimal working example around my code. It should definitely work. –  mhp Oct 1 '11 at 19:54
@mhp: please compare the \DeclareStringOption in the mwe and in your code. –  Marco Daniel Oct 1 '11 at 21:23
@Marco: OK, I see. In contrast to Sebastian, you don't specify a default value, but an initial value for the languages option. In fact, this is a better approach since it allows the babel package to be loaded without options at all. But I don't think the error reported by Sebastian is related thereto. –  mhp Oct 2 '11 at 17:39
@mhp: You are right. –  Marco Daniel Oct 2 '11 at 18:59