# Defining (optional) data in a class

I'm trying to learn how to write latex classes and am using my resume as a toy example. I am trying to separate style from content as much as possible so I am trying to define data fields such as \name \address \university, similar to those that I have seen in \maketitle. Some of the fields of each of these are to be optional. I have a working example but since this is my first attempt at writing a latex class, I wanted to ask how I should be defining the class's metadata.

My attempt so far is like so (optional second line for the address):

\RequirePackage{xkeyval} % for keyval

}
}
}
}
}

\newcommand{\makeCV}{%
\fi
}


This works okay for me, I can type

\address
{
%second_line=my county,
town=my city,
postcode=my post code
}
\makeCV


but it the class seems a little verbose? In particular, having to define all those \newcommand{...}{} and all the various \newif 's seems a little verbose.

My question is how should I be doing this task properly?

-
In what sense are these meta data? –  Seamus Mar 9 '11 at 18:35
@Seamus Thats what I thought data in a class was called... (have taken the meta out of the title) –  Tom Mar 9 '11 at 18:35
as it stands, I'm not sure it's clear what you're asking. "How should I do this properly?" is a little unclear. Could you try and sharpen up what you want from answers here? –  Seamus Mar 9 '11 at 19:01
@Seamus You are right, I want to know what is usually done when someone defines \name \address etc in a package. I couldn't find a guide that told me so I had a go, but I feel that I have almost certainly done it badly. –  Tom Mar 9 '11 at 19:11

You can cut out a lot of the verbosity of the coding part using the keycommand package.

But I wouldn't worry too much about the verbosity of coding, but rather about the author interface you are presenting to your potential users, which is verbose. From my experience with users they prefer (environments) and simple commands. I would reserve the key-val pairs for mostly switches such as including a photo or not. Certainly the address lines do not belong in the key-val portion of the command. An interface as shown below,

\usepackage[foto=none]{sCV}
\begin{CV}
\end{CV}


would be easier to code and use. Using an environment would also make it easier for coding something that is going to span potentially over many pages.

-
"program to an interface, not an implementation." –  Matthew Leingang Mar 9 '11 at 21:01

I write this directly without a try so be careful: NPK for new package better is to use for example letters of the name for your package. mcv makeCV. With \define@boolkey you don't need \newif. \ifNPK@mcv@LineTwois automatically created. \presetkeys is to give default values and \setkeys[NPK]{mcv}{#1} is to apply the options inside your macro. Without a try, perhaps i make some typos :(

Now I prefer to use pgfkeysif you want the same things it's possible but perhaps it's more verbose

\define@boolkey [NPK] {mcv} {LineTwo}[true]{}
\define@cmdkey  [NPK] {mcv} {firstline}{}
\define@cmdkey  [NPK] {mcv} {secondline}{}
\define@cmdkey  [NPK] {mcv} {town}{}
\define@cmdkey  [NPK] {mcv} {postcode}{}
\presetkeys     [NPK] {mcv} {LineTwo      = false,
firstline    = {},
secondline   = {},
town         = {},% Paris
postcode     = {}}{} % 75005
\newcommand{\makeCV}[1][]{%
\setkeys[NPK]{mcv}{#1}
\cmdNPK@mcv@firstline\\%
\ifNPK@mcv@LineTwo
\cmdNPK@mcv@secondline\\%
\fi
\cmdNPK@mcv@town\\%
\cmdNPK@mcv@postcode%
}

-
I fixed a ' that should have been a ` Hope you don't mind. –  Seamus Mar 9 '11 at 19:05