# How to expand keyval options immediately

I am trying to build up a macro that creates other macros depending on kvoptions' options. But then, the outcoming macros are dependent on the actual state of the options instead of their state at the runtime of the creation macro.

Here's a minimal example:

\documentclass[openany]{scrbook}
\usepackage{kvoptions}

\makeatletter
\SetupKeyvalOptions{family = fam, prefix = fam@}
\DeclareStringOption[]{prename}

\newcommand{\greetingsetup}[3]{%
\setkeys{fam}{#3}
\expandafter\newcommand\csname greeting#1\endcsname{Hallo \fam@prename, I am #2.}
}

\makeatother
\greetingsetup{john}{Johnny}{prename=Mike}
\greetingsetup{mark}{Mark}{prename=Michaela}

\begin{document}

\greetingjohn

\end{document}

What I want: Writing \greetingsetup{john}{Johnny}{prename=Mike} creates a macro \greetingjohn which writes "Hallo Mike, I am Johnny."

What it does: It creates a macro \greetingjohn which writes "Hallo xyz, I am Johnny." with xyz being replaced with the actual state of option prename. In the example LaTeX writes "Hallo Michaela, I am Johnny.".

Does anyone know how I can get just the bare string from the option \fam@prename written to the new macro \greeting...?

-

You can force the expansion using \edef or its safer LaTeX wrapper \protected@edef:

\expandafter\protected@edef\csname greeting#1\endcsname{Hallo \fam@prename, I am #2.}
-
Yes!! Brilliant! Thank you very much, David! :-) (Also thank you Svend Mortensen for polishing the format of my question) –  hepfi Mar 25 '13 at 10:36