if a command created with \def
is "context sensitive" (or "delimited"), it can't be redefined with \renewcommand
. but for a simple definition like the one you show, \renewcommand
works just fine, and is considered preferable in LaTeX.
the following pattern is used internally in amsmath
to check the presence or class of symbols in order to "do the right thing" when defining symbol commands that are more flexible than similar ones provided by plain tex:
\def\@tempa#1#2\@nil{<...>}
the string \@nil
looks like a command, but it really isn't. instead, it is used as a "sentinel" to delimit the scope of what is being tested.
use of a sentinel in this matter avoids the need for braces when using the defined command. the "LaTeX way" is to use braces, but in some contexts, the proliferation of braces makes input more difficult to read (and debug when errors occur), and the sentinel method can be used to advantage.
edit: as noted by @Dan, this doesn't mean that a command can't be redefined using \renewcommand
, but that it's impossible to replicate the usage syntax of the original when doing so.
I'd change the approach:
\newcommand{\makename}[3][s]{%
\expandafter\newcommand\csname #2\endcsname{#3\xspace}%
\expandafter\newcommand\csname #2s\endcsname{#3#1\xspace}%
}
\makename{individual}{name}
\makename[es]{veggie}{potato}
In the document you can do
The \individual eats \veggie, while \individuals eat \veggies.
that will print
The name eats potato, while names eat potatoes.
Note. In general I recommend against using \xspace
; I do also in this case.
Best Answer
If you really want to do this, in
amsmath.sty
,\eqref
is defined asso you could say
Notice the inconsistencies that the redefinition introduces; you are cross-referencing section
(1)
, but your document has section1
; a similar problem will appear for floats, and other objects in your document.Adendum
Perhaps, if you are interested in redefining the cross-reference format for a particular type of object, the
cleveref
package could be a better option; a little example in which I changed the formatting for cross-referencing figures, leaving all other cross.references unalatered: