Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.