LaTeX, of course, has a protective mechanism that prevents you from doing some stupid things:
\newcommand\a{a}
\newcommand\a{b} %% LaTeX Error: Command \a already defined.
Of course, if you know what you're doing, then you can circumvent it with \renewcommand. However, some commands have their own definition mechanisms:
\newcommand\a{a}
\DeclareMathOperator\a{a} %% LaTeX Error: Command \a already defined.
(and there is no \RedeclareMathOperator). I've been getting around this by doing something awkward like:
\newcommand\a{a}
\makeatletter
\DeclareMathOperator\@a{a}
\let\a=\@a %% \let (and \def) circumvents LaTeX's protection
\makeatother
(Of course, the best thing to do would be to delete that original definition, but, in practice, it's in another package that I must include but whose source I do not control.) However, it occurs to me that a hypothetical \undef command would do the job:
\newcommand\a{a}
\undef\a
\newcommand\a{b} %% No complaints
Does such a command exist? If not, is there an easy way to write it?
\let\a=\relaxwould do what I wanted.) – LSpice Dec 30 '14 at 18:13\let\a\imareallyundefinedcommandwould work too. – Ulrike Fischer Dec 30 '14 at 18:15etoolboxdefines exactly the\undefcommand for which I asked (taking a control sequence, rather than a name, as its argument). – LSpice Dec 30 '14 at 18:16\newcommandand\DeclareMathOperatorrely on\@ifdefinablewhich considers a command undefined in the following two cases: (1) it currently has no meaning; (2) it is equivalent to\relax; the same command rejects command names starting with\end...– egreg Dec 30 '14 at 18:25LaTeXimplements this check. (Indeed, I noticed that\renewcommandproceeds simply by\letting\@ifdefinableto\@rc@ifdefinable, and wondered if that might be appropriate; but that clobbers\@ifdefinablefor everyone, and so I think\letting the one relevant symbol to\relaxis probably better.) – LSpice Dec 30 '14 at 18:25\rc@ifdefinable. But\let\a\relaxis really what you're looking for. – egreg Dec 30 '14 at 19:06\def(i.e., Need a\undefcapability) – Werner Dec 30 '14 at 19:10\let\ato\relax", whereas that poster specifically mentions that\letting to\relaxdidn't work. – LSpice Dec 30 '14 at 20:19