We have seen this excellent discussion on the differences between \def and \newcommand. From the answers the relatives merits of using \newcommand over \def are obvious.

Why are some LaTeX macros defined using \def?

Let us consider the cases one by one.

  • The highest level (kernel), in latex.ltx


The above is obvious. LaTeX is based on TeX, and \newcommand is a LaTeX overlay. \newcommand needs to be defined first using a TeX primitive. We can not move further without this bootstrapping.

But after this, there still so many \defs. (Afraid my examples have been picked up at random and hence are not representatives of some category.)


  • Now we move to the next level, the document classes.

In article.cls, one example of each kind.



In book.cls, again one random example of each kind.



In memoir.cls, \def inside \newcommand (I don't necessarily claim that such cases are not in the above ones.)

  \def\@memtempa{#1} \def\@memtempb{#2}
  \ifx \@memtempa\@memtempb

  • We move one step further, the packages. Picked fancyhdr.sty at random. We find both \def and \newcommand.


My question is, why does LaTeX use both \def and \newcommand?

Is it as simple as whatever the developer felt like using at that moment?

(Being originally a TeX human, I still use \def, may be more than \newcommand. There is no particular reason. I do this simply out of habit.)

Or are there deeper technical reasons?

  • 2
    I think it's the same for everyone else as for you :-) Note that when a user defines macros with \newcommand, he will get notified of duplications also with macros defined by \def, so for the kernel, it's mostly irrelevant. Also (a) some code was copied from TeX plain or packages and (b) sometimes you need delimited arguments. LaTeX3 will have a cleaner interface. Commented Dec 16, 2013 at 5:57
  • @StephanLehmke Never thought that it is that simple. Yes, I mentioned, whatever the developer felt like using. But I was afraid I will be rebuked for being so naive. Copying some code from TeX is another perspective which you pointed out. And about your last part about delimited arguments. This powerful feature of \def is something I particularly enjoy.
    – Masroor
    Commented Dec 16, 2013 at 6:03
  • 1
    at least some of those uses of \def were written before \newcommand had been written. so from the very start of its life, \newcommand and friends have been competing with \def and friends; add to that the many cases where \def can do things that \newcommand can’t, and you have a serious case. sure, it would be better if latex had been programmed to some standard, but in practice ... coding was done by a small group in their own time... Commented Dec 18, 2013 at 20:31

3 Answers 3


One prevailing reason for using \def is because it inherently defines something regardless of whether it already exists or not. For example, using TeX, you could define


and have no concern that \mymacro will exist after this call. In contrast, using pure LaTeX, one would have to (roughly)


While some of the LaTeX constructs (in latex.ltx) use the above check-before-defining, it's often just a convenient choice to \def (\edef, \gdef or \xdef).

Moreover, TeX's \def allows for specifying a parameter text which is very powerful, and cannot be replicated with ease using pure LaTeX (some discussion on this regard in Changing from \def to \newcommand*).

  • 14
    \providecommand{\mymacro}{}\renewcommand{\mymacro}{<stuff>} would be a bit easier IMHO :)
    – cgnieder
    Commented Dec 16, 2013 at 10:30
  • @cgnieder: Great addition!
    – Werner
    Commented Dec 16, 2013 at 18:12

Much of the style of the core latex format and classes such as article goes back to the initial latex 2.x and earlier. Note that it used to take minutes to load article.sty (as it was then) the whole business of removing comments (formalised these days as the dtx/doc system) was because it would be visibly quicker to load the uncommented file than the commented one. In such a situation, defining a high level command system with error checks for the user to use, but defining almost all the core functionality using lower level macros made absolute sense.

LaTeX2e changed it a bit but not much. One thing we did do at that time is to use the latex \setlength rather than a primitive length setting in all user accessible lengths (eg the width argument of minipage or p columns) so that they would be affected by the redefinition of \setlength if the calc package was loaded. But most defs stayed as def:-)

That said, given the facilities of latex2e, it does still make sense to use both forms in internal code. Taking your last example


This is the top level command, if this is already defined you may as well generate an error as something bad has happened, there is some other clashing code around.


But once you have decided you are going to load the package you may as well just define what needs defining without checking everything it's quicker (less important now, but this package is older than latex2e:-) but also you don't really want to generate an error on every internal definition, Ideally you want one error saying the package is clashing, or no errors if everything is good.

  • 2
    Nice account of the actual reasons for it all :-) Commented Dec 16, 2013 at 9:31
  • Good to know the historical side of the issue. Also, the last part is an eye-opener.
    – Masroor
    Commented Dec 16, 2013 at 9:33

Sadly it really is whatever the developer felt like. Sometimes its because it used to be a TEX, other times its because "That's what the developer was used it". LaTeX has gone through a few revisions and grown exponentially, far more than expected, so its natural for a codebase of that size to have a "few" quirks in it.

LaTeX3 is supposed to have a cleaner interface for defining commands, you can read about it here: LaTeX3

You must log in to answer this question.

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