LaTeX error · Commands, braces and arguments

LaTeX Error: Command \R already defined.

Quick answer

\newcommand refuses to overwrite a command that already exists, so you do not silently break LaTeX or a package. Pick a different name, or use \renewcommand if you really want to replace the existing command. \providecommand defines the command only if it does not exist yet, which is handy in shared preambles.

The error in the log

This is how the message appears in the .log file (and in the compile output). The line starting with l. is the line number where TeX noticed the problem; the real mistake is there or just before it.

! LaTeX Error: Command \R already defined.
               Or name \end... illegal, see p.192 of the manual.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.4 \newcommand{\R}{\mathbb{R}}

Why it happens

  • A name that a package already uses, for example \R, \C or \G from some packages, or \vec, \comment and \proof.
  • The same \newcommand twice, often because two included files or a template and your preamble both define it.
  • A name starting with \end, which \newcommand rejects (Or name \end... illegal).

How to fix it

Rename your macro to something unused (for example \Real or \reals), or, when you deliberately want your own version, use \renewcommand. Check what the old command did before replacing it: overwriting something like \vec or \c can break other parts of the document.

Broken: reproduces the error

\documentclass{article}
\usepackage{amssymb}
\newcommand{\R}{\mathbb{R}}
\newcommand{\R}{\mathbb{R}}

\begin{document}

Let $x \in \R$.

\end{document}

Try this in Octree — free LaTeX editor with AI, compiles in your browser

Fixed: compiles cleanly

\documentclass{article}
\usepackage{amssymb}
\providecommand{\R}{}
\renewcommand{\R}{\mathbb{R}}

\begin{document}

Let $x \in \R$.

\end{document}

Related errors

Frequently Asked Questions

What is the difference between \newcommand and \renewcommand?

\newcommand only defines commands that do not exist and errors otherwise. \renewcommand only redefines commands that do exist and errors if the name is unknown. \providecommand defines it only when it is missing.

How do I check whether a command is already defined?

Put \show\R (with your command name) in the preamble and compile. The log shows undefined if the name is free, or its current definition otherwise.

Why does a template give Command already defined?

The template and a package you added define the same name, or the class already provides it. Remove your duplicate definition or switch it to \renewcommand.

Paste your document into Octree — compile errors get a Fix with AI button

When a compile fails, Octree shows the error next to the line that caused it and offers a one-click fix that you can review before applying. Free, nothing to install.

Fix it in Octree →