I try to type \renewcommand{\mr}{\mathrm}, so that I can then use \mr in my text instead of \mathrm. I get the error \mr Undefined. what is going on?

  • 2
    That \mr is not defined and you should use \newcommand{\mr}{\mathrm} instead. – egreg Feb 26 '15 at 16:17
  • so is it right that renewcommand takes a predfined command in the second bracket and needs to have also a predefined command in the frist bracket, and that newcommand takes a predefined command in the second bracket and takes an anonymous, not predefined command in the first bracket? – user4437416 Feb 26 '15 at 16:23
  • No. It's not the way it works. The first argument to \newcommand or \renewcommand is the command to be (re)defined; in the second argument you specify what the command should be replaced with. – egreg Feb 26 '15 at 16:25
  • in \newcommand{\mr}{\mathrm}, i am taking the already predefined \mathrm and wanting it to be defined as the shorter \mr so that i can use \mr throughout the document. you now seem to be saying the opposite. \mr is not the command to be redefined; it is what the command \mathrm should be replaced with – user4437416 Feb 26 '15 at 16:29
  • 1
    @inquiries I think you are misunderstanding 'replaced' here. TeX is a macro expansion language, so with \newcommand{\mr}{\mathrm} when LaTeX finds \mr in your source it replaces it with \mathrm, then looks up the definition of \mathrm, etc. – Joseph Wright Feb 26 '15 at 16:36

TeX uses macro replacement as its fundamental concept. When you say


you're instructing the program to replace every occurrence of \foo with <whatever>. In order for that \newcommand to work, the command \foo must be undefined at the moment \newcommand is performed.

So with


you are basically creating an alias for \mathrm: upon finding \mr in the input stream, TeX will replace \mr with \mathrm and then \mathrm with its definition and so on until only “purely executable” commands remain, that TeX passes on for further processing in what is usually called the “stomach”.

If the command \foo already had a definition, you need to use \renewcommand (but be always afraid of using it).

The second argument to \newcommand needn't be just a single token: you may as well define

\newcommand{\independence}{When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.}

and upon finding \independence, TeX will replace it with that text.

You find much more in chapter 8 of “LaTeX for complete novices”

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.