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

NEW: TikZ book now 40% off at Amazon.com for a short time.

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}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
or

Code: Select all

Code, edit and compile here:
\long\def\@caption#1[#2]#3{%
...}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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