# Renewcommand not working

I have a tex file compiling with no errors or warnings.

But when I add this line:

\newcommand{\mag}{randomstr}


I get this error:

LaTeX Error: Command \mag already defined. [\newcommand{\mag}{randomstr}]


So, I try to change it to this:

\renewcommand{\mag}{randomstr}


but get all of these errors too:

report.tex:32: Missing number, treated as zero. [\begin{document}]
report.tex:32: Missing = inserted for \ifnum. [\begin{document}]
report.tex:32: Missing number, treated as zero. [\begin{document}]
report.tex:32: Missing $inserted. [\begin{document}] report.tex:32: Missing number, treated as zero. [\begin{document}] report.tex:32: Missing = inserted for \ifnum. [\begin{document}] report.tex:32: Missing number, treated as zero. [\begin{document}] report.tex:32: You can't use the letter r' after \the. [\begin{document}] report.tex:33: Missing$ inserted. []


I have also tried the \def directive, but with no result. Any idea how to fix this? Thanks.

-
This is because \mag is a TeX primitive used in setting magnification levels of fonts. You should use an alternative macro for your definition of randomstr. –  Werner Mar 13 at 18:43
So, you're basically saying I can't redefine the \mag command in any way right? –  nunos Mar 13 at 18:46
Yes, that is what I'm saying. Perhaps you can elude more to why you're trying to use \mag and not something else? Would \Mag work? –  Werner Mar 13 at 18:54
It makes sense to use \mag, because of the context of what I am writing, but \Mag or \MAG work just as well. Just finding out latex commands are case sensitive, no idea before. –  nunos Mar 13 at 18:59

This is because \mag is a TeX primitive used in setting magnification levels of fonts. While you are able to change it, it has disastrous consequences, since it's used in its original setting, which you've adjusted. Translated into more colloquial terms, this would be like deciding to change the fuel used in your car, since it suits your wallet better. So, instead of using petrol, you opt for diesel (say). The car still requires petrol to run without further modification, regardless of your preference, causing major problems (either immediately, or down the road).*

The solution: Do not redefine a TeX primitive (via \renewcommand, \def, or the like). You should use an alternative macro for your definition of randomstr. For example,

\newcommand{\Mag}{randomstr}


should work, since control sequences (macros) are case-sensitive.

* In the above discussion, the car/engine is (La)TeX, petrol is \mag and diesel is the "redefinition of \mag".

-
Follow-up question: How do you know it's a TeX primitive? Don't seem to be able to figure that from the error log. –  nunos Mar 13 at 19:00
And in the same line: I guess \cal would be the same case, a TeX primitive, since I am getting the same error, correct? –  nunos Mar 13 at 19:01
@nunos Try \show\mag: you get \mag=\mag. Primitives 'are themselves'. –  Joseph Wright Mar 13 at 19:19
@nunos no \cal isn't a primitive but it doesn't matter really, if \newcommand tells you a command is defined you shouldn't redefine it unless you know what the original definition is used for. \begin` isn't a primitive but if you redefine it most of latex will break. –  David Carlisle Mar 13 at 19:51
@nunos The golden rule is: don't redefine a command unless you know precisely what it does. –  egreg Mar 13 at 21:26