Inspired by a question about \let and \def, I have some that essentially all boil down to asking

What are the differences between \def and \newcommand?

In particular, I wonder

  1. Is it possible to have parameters passed to \defed commands, both optional and required?
  2. Is there a \redef command equivalent to \renewcommand?
  3. I have only ever used \newcommand -- is there any reason I should change that habit?

but I welcome comments on anything else I may not have thought of in this list!


5 Answers 5


\def is a TeX primitive, \newcommand is a LaTeX overlay on top of \def. The most obvious benefits of \newcommand over \def are:

  1. \newcommand checks whether or not the command already exists
  2. \newcommand allows you to define an optional argument

In general, anything that \newcommand does can be done by \def, but it usually involves a little trickery and unless you want something that \newcommand can't do, there's no point in reinventing the wheel.

In answer to your particular points:

  1. Yes and No. A command defined using \def has to know exactly what its options are, and how they will be presented to it. However, a TeX command can be a bit clever and examine things other than its arguments. The way that optional commands are handled is to look at the next character in the stream and if it is [ then one version of the command is called, whereas if it isn't then another is called. So if you're prepared to do some hackery, then optional arguments are possible via \def, but it isn't half so easy as \newcommand.
  2. No. Since \def doesn't check for a command already being defined, you can redefine stuff simply using \def again. To get the checking, you need to use the \@ifundefined command (note the ampersat (@) sign!).
  3. No!

There's probably lots more to be said on the differences, but that's enough from me.

  • 12
    I'd add that \newcommand can't make anything starting \end.... This is because LaTeX uses these names for the end of environments, and wants to 'discourage' you from breaking things.
    – Joseph Wright
    Commented Jul 30, 2010 at 18:18
  • 2
    @SamB: looking at the man page, probably. Although in connection with "brains", the word "upgrade" makes me think of Cybermen. As I live in the same country as Bad Wolf Bay, I like to steer clear of such things as much as possible. Commented Dec 2, 2010 at 8:18

Adding to Andrew's already good response, the one thing that \def can do that \newcommand cannot is define commands that take delimiters other than braces. For example, if you want to be able to write \foo<hello> and have the ‘hello’ interpreted as an argument, you can write

\def\foo<#1>{...something with #1...}

You can also have commands that read input up to the next brace, such as

\foobar 47pt {hello}

For a combination of the extensibility of \def with the ease-of-use of \newcommand, check out David Kastrup's suffix package. Very handy when you want to define custom markup for your document.

Also look at the LaTeX3 package xparse which takes a more structured and generalised look at how \newcommand should work.


Here is a summary of the main points made by the other answers. In each case, click on the ▶ symbols for more details.

  • \newcommand is part of LaTeX; \def is part of TeX. []

  • \newcommand fails if the command is already defined; \def doesn't. []

  • \newcommand provides a convenient syntax for specifying the number of arguments, and specifying a (single) optional argument; \def enables pattern-matching on the form of its arguments, which makes it more general but also less readable. []

  • \newcommand can't define a command whose name starts with "end"; \def can. []

  • \newcommand defines "long" commands; \def (unless \long\def is used) defines short ones. (The arguments of a "long" command can include paragraph breaks.) []

  • 11
    I thought I would add this summary because there is no single "definitive" answer here; there are instead several good points raised in different answers. Commented May 25, 2013 at 8:08

One quite important difference, not mentioned in the discussion so far, is:

  • \newcommand\foo{...} corresponds to \long\def\foo{...}
  • \newcommand*\foo{...} corresponds to \def\foo{...}

What does \long mean? Well, if \myCommand is defined using \long, then its arguments can contain paragraph breaks, like this:

\myCommand{Lorem ipsum

dolor sit 


If \myCommand were defined without \long, then the code above would generate an error. The idea is, that if you know that your command won't ever need to take arguments containing paragraph breaks, then defining it without \long helps you to catch some situations where you've forgotten a closing brace.

For more in-depth discussion: What's the difference between \newcommand and \newcommand*?

Slight digression. Here is a little example that highlights this particular difference between \newcommand and \def.

The following code prints Not empty ...

\ifx\foo\empty Empty\else Not empty\fi

... but if you swap \newcommand for \def, it would print Empty! This phenomenon has been explained in a comment by Qrrbrbirlbel. The \empty command is created using \def\empty{}. Then, the \foo command is created (via \newcommand) using \long\def\foo{}. The presence of the \long stops these definitions being equal, and thus makes the test in the conditional fail.

  • 1
    Hi John. A tip: if you directly paste the url of a question/answer, the title will automatically appear. Commented May 24, 2013 at 13:12

One subtle difference is that you cannot define commands starting with end:




results in

! LaTeX Error: Command \endtest already defined.
               Or name \end... illegal, see p.192 of the manual.

You can always use \newenvironment to achieve this. But the above code doesn't work even when using \providecommand instead of \newcommand.

Why is there no \provideenvironment? According to Frank Mittelbach, it's performance considerations -- saving memory, 20 years ago. But now there's \ProvideDocumentEnvironment from the xparse package. Plus,

Unlike LaTeX 2ε’s \newcommand and relatives, the \DeclareDocumentCommand function do not prevent creation of functions with names starting \end.

  • 6
    Interesting that LaTeX reports \endtest already defined when using \newcommand, but with renewcommand the message is \endtest undefined. I didn't know that LaTeX suffers from schizophrenia. :-) Commented Jul 5, 2012 at 17:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .