Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
Quick answer: \newcommand defines a new LaTeX command (a macro) from a name and a replacement text, for example \newcommand{\R}{\mathbb{R}} makes \R typeset the blackboard-bold R. Put the definition in the preamble, before \begin{document}, and use the new command anywhere after it. The same page answers the variant search “latex new command”.
This guide is for researchers writing papers, theses and reports in LaTeX who want consistent notation and fewer repeated keystrokes. After reading it you should be able to define commands with zero, one or several arguments, give one argument a default value, redefine or conditionally define a command, and read the two errors LaTeX raises when a definition goes wrong.
What \newcommand is used for in research writing
Research documents repeat the same notation constantly: a number-set symbol, a vector, a unit with fixed spacing, a project name. Defining each once with \newcommand means a change of notation is made in one place instead of through the whole manuscript. The Overleaf documentation illustrates the pattern with \newcommand{\R}{\mathbb{R}}, after which \R produces the set of real numbers symbol in maths mode.
A practical workflow for a thesis or a multi-author paper is to keep all custom definitions together in the preamble (or in one separate file loaded from the preamble) so that every co-author uses the same macros. For notation that is a single accent or arrow, see also the related guides on vector notation in LaTeX and absolute value delimiters in LaTeX, which are common candidates for a shared macro.
Install or access
\newcommand is part of standard LaTeX, so there is nothing separate to install. You can use it in any LaTeX distribution you already compile with, or in the online editor Overleaf. The command is documented in the Overleaf “Commands” article and in the LaTeX2e reference at latexref.xyz (both listed under Sources). For where definitions sit in a file, see LaTeX document structure, classes and packages.
Step-by-step: define and use a command
1. A command with no arguments
- In the preamble, write the definition:
\newcommand{\R}{\mathbb{R}}(the Overleaf example). - In the body, use it in maths mode:
$f:\R \to \R$.
The first brace group is the new command name, which must begin with a backslash. The second is the definition that replaces it.
2. A command with arguments
- Put the number of arguments in square brackets after the name. Overleaf’s example is
\newcommand{\bb}[1]{\mathbb{#1}}: the[1]says the command takes one parameter, and#1marks where it is inserted. - Call it with the argument in braces:
\bb{Q}typesets the blackboard-bold Q.
According to the LaTeX2e user guide, a command can have up to nine arguments in total.
3. A command with an optional first argument (default value)
- Add a second bracket after the argument count holding the default for argument
#1:\newcommand{\plusbinomial}[3][2]{(#2 + #3)^#1}. - Call it without the optional argument to get the default:
\plusbinomial{x}{y}uses 2 as the exponent. - Override the default in square brackets:
\plusbinomial[4]{a}{b}.
When the bracketed argument is omitted in a call, #1 takes the default and the required arguments start at #2, as the LaTeX2e reference describes. Only one optional argument is allowed per command. Writing [] as the default makes the default an empty string.
4. Changing an existing command
\renewcommand uses the same syntax but requires that the command already exists. Overleaf’s example is \renewcommand{\S}{\mathbb{S}}, which replaces the meaning of \S. Check first whether a name is already in use, because redefining a built-in command changes it everywhere in the document.
Output and how to read it
A successful definition produces no output of its own. The effect appears wherever you call the command: \R prints the real-numbers symbol, \bb{Q} prints a blackboard-bold Q, and \plusbinomial{x}{y} prints (x + y) to the power 2. If the output is not what you expected, compare the call against the number of arguments declared in the definition: a command declared with [3] expects three braced arguments, or two if the first is optional with a default.
Variants compared: \newcommand, \renewcommand, \providecommand and starred forms
| Command | Requirement on the name | Behaviour |
|---|---|---|
\newcommand |
Must not already be defined | Defines the command; a name that already exists causes the error LaTeX Error: Command \fred already defined. (LaTeX2e reference) |
\renewcommand |
Must already be defined | Replaces the definition; otherwise the error is LaTeX Error: \hank undefined. (LaTeX2e reference) |
\providecommand |
Any name | Defines the command only if no command of that name exists; if one exists, the definition does nothing and no error is raised. The reference notes it is useful in a file that may be loaded more than once, such as a style file. |
Starred forms (\newcommand*, \renewcommand*, \providecommand*) |
Same as unstarred | Arguments to the command may not contain multiple paragraphs (LaTeX2e reference). |
All of these require the command name to begin with a backslash, and for \newcommand and \renewcommand the name must not begin with \end.
Troubleshooting
“LaTeX Error: Command \… already defined.”
You used \newcommand on a name that LaTeX, your class or a package already defines. Overleaf notes that defining an existing name with \newcommand fails compilation. Choose a different name, or use \renewcommand if you really intend to change the existing meaning.
“LaTeX Error: \… undefined.”
You used \renewcommand on a name that does not exist yet. Either correct the spelling of the name or switch to \newcommand.
The argument is not substituted as expected
Check that the number in the first square bracket matches the highest #n used in the definition, and that you have not declared more than one optional argument, since only one is permitted.
Free alternatives and related ways to define commands
All of these are built into LaTeX and cost nothing; the choice depends on whether you want an error on a clash.
| Goal | Use | Source |
|---|---|---|
| Define a new command and be told if the name is taken | \newcommand |
LaTeX2e reference |
| Deliberately change an existing command | \renewcommand |
Overleaf; LaTeX2e reference |
| Define only if absent, with no error when it exists | \providecommand |
LaTeX2e reference |
| Forbid multi-paragraph arguments | The starred form of any of the three | LaTeX2e reference |
For a related definition mechanism for numbered theorem-like environments, see LaTeX theorem environments with newtheorem, and for macro-style helpers around rounding symbols see LaTeX floor and ceiling symbols.
FAQ
What is the syntax of the new command in LaTeX?
\newcommand{\cmd}[nargs][optargdefault]{defn}, where nargs (0 to 9) and optargdefault are optional. The starred form \newcommand* disallows multi-paragraph arguments.
How do I define a new command in LaTeX with a default argument?
Give the argument count and then the default in a second bracket, for example \newcommand{\plusbinomial}[3][2]{(#2 + #3)^#1}. The first argument is then optional and defaults to 2.
Where should I put \newcommand?
In the preamble, so the command is defined before it is used in the document body.
How many arguments can a command take?
Up to nine in total, with at most one optional argument.
Can I redefine a command that already exists?
Yes, with \renewcommand, which uses the same syntax as \newcommand but requires the command to exist already. Using \newcommand on an existing name produces an error.
Sources
- Overleaf, “Commands” (Learn LaTeX): https://www.overleaf.com/learn/latex/Commands, read 2026-11-08.
- LaTeX2e: An unofficial reference manual, “\newcommand & \renewcommand”: latexref.xyz, read 2026-11-08.
- LaTeX2e: An unofficial reference manual, “\providecommand”: latexref.xyz, read 2026-11-08.
- LaTeX2e User Guide, argument limits for new commands: MIT SIPB mirror, read 2026-11-08.







