GeneralWhen can \newcommand not replace \def ?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
deniss
Posts: 11
Joined: Tue Aug 04, 2009 9:06 pm

When can \newcommand not replace \def ?

Post by deniss »

I am wondering about the general equivalence of \newcommand and the TeX primitive \def. The authors of main LaTeX books advise against using \def and for using \newcommand instead. But I distinctly remember reading that in certain instances, \def must be used instead of \newcommand... Could anyone please give some examples of such instances and some general guidelines?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

When can \newcommand not replace \def ?

Post by sommerfee »

deniss wrote:Could anyone please give some examples of such instances and some general guidelines?
\newcommand and \renewcommand are limited in parsing arguments. For example things like

Code: Select all

\def\@tempb#1=#2\@nil{#1}
or

Code: Select all

\long\def\@caption#1[#2]#3{%
  ...}
are not possible using \newcommand.

As a generic guideline I would say use \newcommand preferred to \def, if possible, so one would not accidently overwrite an already-defined command.
Post Reply