[Tex/LaTex] Renewcommand not working

macros

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.

Best Answer

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".

Related Question