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)

  • 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

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.

  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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