Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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)

share|improve this question
4  
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
add comment

1 Answer

up vote 5 down vote accepted

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.

share|improve this answer
    
Thanks, I didn't know about gobble, also just saw macros2e so I'll look into that. –  Carel Jun 8 '12 at 9:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.