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:


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

        \expandafter\newcommand\csname greeting#1\endcsname{Hallo \fam@prename, I am #2.}





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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.