Imagine I have a macro \createcontact that accepts three parameters. Now, instead of using these during the expansion, I would like to save them separately for later use and retrieval. The above macro is used in the following context:
\newcommand{\myfirstauthor}{\createcontact{Alice}{Munich}{Germany}}
\newcommand{\mysecondauthor}{\createcontact{Bob}{London}{United Kingdom}}
% and so forth
How do I implement \createcontact so that I can extract the individual parameters that have been passed to it from \myfirstauthor, \mysecondauthor etc.? How would then the code for the extraction look like? In other words, how do I need to define \createcontact and, say, a macro \extractsecond so that \extractsecond\myfirstauthor expands to Munich?
EDIT: Note that only the definition of \createcontact can be adapted, not that of \myfirstauthor, \mysecondauthor etc.. That is, the usage pattern above must remain "as is".
The reason of this exercise is that the above pattern is used in users' documents all over the place. I would like to do more complex processing of the \createcontact parameters than simply using them once in a macro. (For example, I want to use Munich in one context, and Germany in another.)
As per Peter's request, here comes a "compilable" example that has placeholders instead of the commands I'm interested in:
\documentclass{article}
% HOW TO IMPLEMENT THIS?
\newcommand{\createcontact}[3]{...}
\newcommand{\extractfirst}[1]{...}
\newcommand{\extractsecond}[1]{...}
\newcommand{\extractthird}[1]{...}
% HOW TO IMPLEMENT THIS?
% DO NOT CHANGE OR MOVE THIS
\newcommand{\myfirstauthor}{\createcontact{Alice}{Munich}{Germany}}
\newcommand{\mysecondauthor}{\createcontact{Bob}{London}{United Kingdom}}
% DO NOT CHANGE OR MOVE THIS
\begin{document}
\extractfirst{\myfirstauthor} lives in \extractsecond{\myfirstauthor}
which is located in \extractthird{\myfirstauthor};
this may or may not be true for \extractfirst{\mysecondauthor}.
\end{document}




\createcontactdepending on the context. This aim might be achievable by doing\renewcommand{\createcontact}[3]{#2}for instance to have\myfirstauthortypesetMunich, and replacing#2by#3would make\myfirstauthor typesetGermany`. Please clarify when you want each behaviour, and what should trigger the change in behaviour. – Bruno Le Floch Mar 22 '12 at 2:38\newcommand{\myfirstauthor}be moved to the preamble? – Peter Grill Mar 22 '12 at 2:38\create...and\extract.... – krlmlr Mar 22 '12 at 2:41\createcontactonly in the\extract...macros. Do you want to convert this to an answer? – krlmlr Mar 22 '12 at 2:47% DO NOT CHANGE THIScoming from a separate file? It would be easier to add code after the definitions of\myfirstauthorand before\begin{document}, but can work around this if really needed. Also, is it ok to change\extractfirst{\myfirstauthor}to\extractfirst{myfirstauthor}(slash removed)? – Peter Grill Mar 22 '12 at 2:49