# Name arrangement macro

I'm trying to write a c.v. macro. I've got a first, middle and last name and I would like to arrange these as either "first middle last" or as "first last" if middle is unknown

The code I have so far is as follows (which works) :

\def\@normalname{
\@ifundefined{@middlename}
{
\@firstname\ \@lastname
}{
\@firstname\ \@middlename\ \@lastname
}}


and a shorter version that doesn't

\def\@normalname{
\@firstname\
\@ifundefined{@middlename}{}{\@middlename\ }
\@lastname
}


Any reason why the code would fail in the second case ?

(using pdfLatex if it helps)

-
Both versions are working for me (with some superfluous blank spaces that must be elliminated) in some simple test document I created. Can you please elaborate a little more in your question? Perhaps add a minimal version of a document illustrating the problems you are experiencing. – Gonzalo Medina Jun 8 '12 at 1:53
I'm terribly sorry, I just saw that the error is in another macro that calls this one. Though I wouldn't have known about the gobble command if I hadn't asked. – Carel Jun 8 '12 at 8:57

As @Gonzalo said, if your problem is extra spaces then

\def\@normalname{%
\@firstname\ %(not strictly necessary)
\@ifundefined{@middlename}{}{\@middlename\ }%
\@lastname
}


is what you need (there are extra spaces in your other version as well). A shorter version is

\let\@middlename\@gobble
\def\@normalname{\@firstname\ \@middlename\  \@lastname}


as then if you don't define a middle name the default definition eats the extra space, but if you do define it to be a name the following \ will make a space.

-
Thanks, I didn't know about gobble, also just saw macros2e so I'll look into that. – Carel Jun 8 '12 at 9:33