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 sort of understand the difference between the two. But that's not what I'm interested in—I just want to know, which one should I use? In general, when I'm creating commands in a package or class, which one should I use all the time?

share|improve this question
8  
If you are in a position to require the e-TeX extension (and most people are), I would consider loading etoolbox and using \newrobustcmd for any document command which does not explicitly need to be expandable. \newrobustcmd creates engine-protected commands, which will never expand unexpectedly. –  Joseph Wright Jun 28 '12 at 7:38
    
@JosephWright If I copy only the definition of \newrobustcmd and \renewrobustcmd from etoolbox.sty like this? www11.zippyshare.com/v/57630671/file.html are there problem? And what do you mean with: "for any document command which does not explicitly need to be expandable" ? Thanks. –  FormlessCloud Sep 29 '12 at 0:09
add comment

2 Answers

up vote 15 down vote accepted

In my opinion, it is better to use \newcommand if there are no obvious expansion issues. There are two drawbacks of \DeclareRobustCommand:

  1. \DeclareRobustCommand does not check if the macro is predefined.

  2. Macros defined by \DeclareRobustCommand are less efficient.

share|improve this answer
add comment

A simple rule of thumb is that if you're creating commands that contain data that LaTeX will reread later, you should be using a robust command that is defined using \DeclareRobustCommand.

Such data is contained in arguments that typically go into table of contents, list of figures, list of tables etc.; namely, data that are written to an auxiliary file and read in later. Other places are those data that might appear in headers or footers.

share|improve this answer
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.