TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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) :

  \@firstname\ \@lastname
 \@firstname\ \@middlename\ \@lastname

and a shorter version that doesn't

 \@ifundefined{@middlename}{}{\@middlename\ }

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

(using pdfLatex if it helps)

share|improve this question
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
up vote 5 down vote accepted

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

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

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

\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

Your Answer


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.