# Access values within \newcommand

I am a LaTeX user with moderate experience. However, I am trying to create my own .cls file for the first time. I would like to produce a header in a similar fashion to how title is produced in article class. Something along the following lines.

\documentclass{MyResume}

\phone{281038901}
\email{xyz@example.com}

\begin{document}
\maketitlebox
\end{document}


I know the basics of how to use \newcommands to define these. But, I am not able to figure out how to access values of the fields like \name, \phone inside the definition of \headerbox.

• Welcome to TeX.SX! One usually says \newcommand\name[1]{\gdef\rajvi@name{#1}} and then uses \rajvi@name when the actual name is needed; rajvi stands for the prefix you'll be using for the macros in your class. – egreg Jun 23 '13 at 9:20
• See also here: tex.stackexchange.com/questions/10130/… – Marco Daniel Jun 23 '13 at 9:43

The trick generally used is to say in the class file

\newcommand{\name}[1]{\gdef\rajvi@name{#1}}


and then using \rajvi@name where needed.

You should supplement this with a default definition, such as

\def\rajvi@name{%
\ClassWarningNoLine{rajvi}{No \protect\name\space supplied}%
??%
}


so that the user will be warned about missing data and a pair of question marks will appear in the output. This might be made into an error, just choose the way you prefer.

With rajvi I mean the common prefix (often the class name) you use for avoiding macro conflicts.