TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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...?

share|improve this question
up vote 2 down vote accepted

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.}
share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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