Emulate a "tuple" data structure when the syntax for creating a tuple is predefined and cannot be altered
Basic Solution:
Without more details it is difficult to know if something as simple as this will work for you: You call \myfirstauthor{Kenobi}{General}{1138}
, and then to access each member you simply refer to \myfirstauthorName
, \myfirstauthorRank
, and \myfirstauthorSerialNum
:
\documentclass{article}
\newcommand{\myfirstauthor}[3]{%
\newcommand{\myfirstauthorName}{#1}%
\newcommand{\myfirstauthorRank}{#2}%
\newcommand{\myfirstauthorSerialNum}{#3}%
}
\begin{document}
\myfirstauthor{Kenobi}{General}{1138}
The details of the first author are:
\medskip
\begin{tabular}{rl}
Name: & \myfirstauthorName\\
Rank: & \myfirstauthorRank\\
Serial Number: & \myfirstauthorSerialNum
\end{tabular}
\end{document}
Alternate Solution:
Instead of creating a list of separate macors \myfirstauthor
, \mysecondauthor
, etc you could specify the differentiation between them as the first parameter to the \myauthor
macro. This yields a more flexible solution as you can create the macros on the fly. So with this solution yo can use \myauthor[first]{Kenobi}{General}{1138}
(or leave out the first
as that is the default), but others can simply be defined by \myauthor[second]{Dooku}{Count}{66}
, and accessed as in the above case to yield:
To create another one you just use \myauthor[third]{}{}{}
, etc...
\documentclass{article}
\newcommand{\myauthor}[4][first]{%
\expandafter\newcommand\csname my#1authorName\endcsname{#2}%
\expandafter\newcommand\csname my#1authorRank\endcsname{#3}%
\expandafter\newcommand\csname my#1authorSerialNum\endcsname{#4}%
}
\begin{document}
\myauthor{Kenobi}{General}{1138}
\myauthor[second]{Dooku}{Count}{66}
The details of the first two authors are:
\medskip
\begin{tabular}{rll}
Name: & \myfirstauthorName & \mysecondauthorName\\
Rank: & \myfirstauthorRank & \mysecondauthorRank\\
Serial Number: & \myfirstauthorSerialNum & \mysecondauthorSerialNum
\end{tabular}
\end{document}
Solution Based on given MWE:
With the revised restrictions, you can use \AtBeginDocument
to change the definition of
\createcontact
based on if \myfirstauthor
or \mysecondauthor
is called:
\documentclass{article}
% HOW TO IMPLEMENT THIS?
\newcommand{\createcontact}[3]{}
\newcommand{\extractfirst}[1]{\csname #1Name\endcsname}
\newcommand{\extractsecond}[1]{\csname #1City\endcsname}
\newcommand{\extractthird}[1]{\csname #1Country\endcsname}
\newcommand{\myfirstauthorName}{}%
\newcommand{\myfirstauthorCity}{}%
\newcommand{\myfirstauthorCountry}{}%
\newcommand{\CreateFirstContact}[3]{%
\renewcommand{\myfirstauthorName}{#1}%
\renewcommand{\myfirstauthorCity}{#2}%
\renewcommand{\myfirstauthorCountry}{#3}%
}
\newcommand{\mysecondauthorName}{}%
\newcommand{\mysecondauthorCity}{}%
\newcommand{\mysecondauthorCountry}{}%
\newcommand{\CreateSecondContact}[3]{%
\renewcommand{\mysecondauthorName}{#1}%
\renewcommand{\mysecondauthorCity}{#2}%
\renewcommand{\mysecondauthorCountry}{#3}%
}
\AtBeginDocument{%
\let\OldFirstAuthor\myfirstauthor
\let\OldSecondAuthor\mysecondauthor
\renewcommand{\myfirstauthor}{\let\createcontact\CreateFirstContact\OldFirstAuthor}
\renewcommand{\mysecondauthor}{\let\createcontact\CreateSecondContact\OldSecondAuthor}
\myfirstauthor
\mysecondauthor
}
% HOW TO IMPLEMENT THIS?
% DO NOT CHANGE THIS
\newcommand{\myfirstauthor}{\createcontact{Alice}{Munich}{Germany}}
\newcommand{\mysecondauthor}{\createcontact{Bob}{London}{United Kingdom}}
\begin{document}
\noindent
\extractfirst{myfirstauthor} lives in \extractsecond{myfirstauthor}
which is located in \extractthird{myfirstauthor};
this may or may not be true for \extractfirst{mysecondauthor}.
\end{document}
With credit to Bruno Le Floch for the idea, here is what I would consider "working for me":
\documentclass{standalone}
% ONE POSSIBLE SOLUTION
\newcommand{\createcontact}[3]{}
\newcommand{\extractfirst}[1]{\renewcommand{\createcontact}[3]{##1}#1}
\newcommand{\extractsecond}[1]{\renewcommand{\createcontact}[3]{##2}#1}
\newcommand{\extractthird}[1]{\renewcommand{\createcontact}[3]{##3}#1}
% ONE POSSIBLE SOLUTION
% DO NOT CHANGE THIS
\newcommand{\myfirstauthor}{\createcontact{Alice}{Munich}{Germany}}
\newcommand{\mysecondauthor}{\createcontact{Bob}{London}{United Kingdom}}
% DO NOT CHANGE THIS
\begin{document}
\extractfirst{\myfirstauthor} lives in \extractsecond{\myfirstauthor}
which is located in \extractthird{\myfirstauthor};
this may or may not true for \extractfirst{\mysecondauthor}.
\end{document}
Using lambda lists:
\documentclass{minimal}
\usepackage{lambda} % http://www.ctan.org/pkg/lambda-lists
%
\def\createcontact#1#2#3{\Listize[#1,#2,#3]}
\let\extractfirst\Head
\def\extractsecond#1{\extractfirst{\Tail{#1}}}
\def\extractthird#1{\extractsecond{\Tail{#1}}}
%
\newcommand{\myfirstauthor}{\createcontact{Alice}{Munich}{Germany}}
\newcommand{\mysecondauthor}{\createcontact{Bob}{London}{United Kingdom}}
%
\begin{document}
\extractfirst{\myfirstauthor} lives in \extractsecond{\myfirstauthor}
which is located in \extractthird{\myfirstauthor};
(or \Head{\Tail{\Tail{\myfirstauthor}}},
or \Head{\Reverse{\myfirstauthor}})
this may or may not be true for \extractfirst{\mysecondauthor}.
\end{document}