# \newcommand vs \DeclareRobustCommand

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?

• 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. – Aurelius Sep 29 '12 at 0:09

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.

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.

Section 2.6 of LaTeX 2ε for class and package writers states:

Because LaTeX 2ε supports different encodings, definitions of commands for producing symbols, accents, composite glyphs, etc. must be defined using the commands provided for this purpose and described in LaTeX 2ε Font Selection. [...]

Also, \DeclareRobustCommand should be used for encoding-independent commands of this type.