Does there exists a version of \newcommand, something like \extranewcommand{\foo}{bar} which does defines \foo to stand for bar regardless of whether \foo has been previously defined? Of course, if \foo is undefined, one can use \newcommand{\foo}{bar}, and if it is defined, one can use \renewcommand{\foo}{bar}. However, in either case, one has to know which version to use: if one chooses wrong, the document won't compile. What I am interested in is if there exists a similar command (or perhaps a combination of commands, etc.) which will work in either situation.
As a rationalisation for the question, below are two situations in which I would find this command useful. Of course, the change is very minor, but it adds up over time, I think.
- One doesn't always know what commands are already defined. Sometimes, it happens that a newly defined command happens to also be something defined in some standard package. For instance, one wants to use
\operatorname{Im}for the image of a linear operator, so it is convenient to declare\newcommand{\Im}{\operatorname{Im}}. However,\Imis already a fancy symbol for the imaginary part, so arenewcommandis needed instead. I never use the mentioned imaginary part symbol, so it would be nice if I could just forget that it exists (but I can't). (Of course, this issue can be solved by compiling, noticing the error and adding "re" in front of "newcommand"; but, there are a lot of other such clashes that happen.) - I use a lot of commands used only "locally" (I'm not sure if it's a good coding practice, but I find it useful). For example, if I have a set S which occurs in many places in the text, I would often declare
\newcommand{\Set}{S}or even\newcommand{\S}{S}, so that I can easily change the symbol S to another one if I feel like it. This potentially leads to renewing commands quite frequently, which is not that much of a problem. However, if a block of text with a\newcommandmoves, then also a prefixrehas to move. (Again, it is not much of a problem, but I find it a nuisance).
\ito be a math function, failing to notice that one of the items in the bibliography was by a russian author whose transliterated name required\i(for use with a breve). it took a ridiculously long time for the production team to figure out (1) why there was a message that math mode was required, and (2) change all the other instances of\ito something else (and hoping that no mistakes were made in the process).{\renewcommand\sum{s_{um}} $\sum$} $\sum$would have the same result as typing$s_{um}$ $\sum$because the renewed command only remains defined within the brackets.