# \renewcommand for commands defined with \def

In the following MWE I've used \renewcommand to redefine a command defined through \def:

\documentclass{article}

\def\mymacro{Hello}
\renewcommand{\mymacro}{Hello world}

\begin{document}
\mymacro
\end{document}

and it works fine, as far as I can see.

What I would like to know is:

1. Are there cases in which it doesn't work?
2. Is it a good practice or I should I use \def to redefine commands defined through \def?

EDIT


-
The general rule (in LaTeX) is not to use \def unless you need to. Use \(re)newcommand where possible. – Ian Thompson Nov 16 '13 at 9:16
@percusse Thanks for the link. But see my edit. – Sterry Nov 16 '13 at 9:29
renewcommand is only a wrapper around \def. – Marco Daniel Nov 16 '13 at 10:17


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.

-
Thank you very much. – Sterry Nov 16 '13 at 19:13