Your own commands with \newcommand
Write \newcommand{\name}{replacement} in the preamble, with [n] for arguments #1 to #n; from then on \name is replaced by its definition, in text and in math.
A command without arguments
A command saves typing and keeps notation consistent. Define it once in the preamble and use it anywhere.
Shortcuts for sets and a product name
\documentclass{article}
\usepackage{amssymb}
\newcommand{\R}{\mathbb{R}}
\newcommand{\product}{Scissor LaTeX}
\begin{document}
Every $x \in \R$ has a square $x^2 \ge 0$.
This page was typeset by \product.
\end{document}Arguments and a default
[n] after the name says how many arguments the command takes; inside the definition they are #1, #2 and so on. A second bracket gives the first argument a default, which makes it optional.
Arguments and an optional first argument
\documentclass{article}
\newcommand{\vect}[1]{\mathbf{#1}}
\newcommand{\norm}[1]{\left\lVert #1 \right\rVert}
\newcommand{\greet}[2][Hello]{#1, #2!}
\begin{document}
The length of $\vect{v}$ is $\norm{\vect{v}}$.
\greet{Erika} \greet[Good morning]{John}
\end{document}Changing an existing command
\renewcommand replaces a command that already exists, and \providecommand defines one only if it does not exist yet. \newcommand for a name that is taken is an error in a TeX installation; use \renewcommand then.
\renewcommand and \providecommand
\documentclass{article}
\renewcommand{\emph}[1]{\textbf{#1}}
\providecommand{\R}{\mathbb{R}}
\begin{document}
This is \emph{emphasised} in bold now, and $\R$ is defined.
\end{document}Operator names
Function names such as sin and log are set upright with the right spacing. \DeclareMathOperator (amsmath) makes your own; the starred form puts limits underneath in displays, like \max.
\DeclareMathOperator and its starred form
\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\Var}{Var}
\DeclareMathOperator*{\argmax}{arg\,max}
\begin{document}
\[
\Var(X) = \mathbb{E}\left[(X - \mu)^2\right],
\qquad
\hat{\theta} = \argmax_{\theta} L(\theta)
\]
\end{document}Your own environments
\newenvironment{name}[n]{before}{after} defines an environment: the "before" code runs at \begin{name} and the "after" code at \end{name}. Arguments can be used in the "before" part.
An environment with an argument
\documentclass{article}
\newenvironment{task}[1]
{\par\noindent\textbf{Task #1.}\ }
{\par}
\begin{document}
\begin{task}{44}
Measure the rainfall every morning.
\end{task}
\end{document}What works
| Command | In Scissor LaTeX | Notes |
|---|---|---|
\newcommand, \renewcommand, \providecommand | Works | Up to 9 arguments, an optional first argument with a default. Starred forms too. |
\DeclareRobustCommand | Works | As \newcommand. |
\newenvironment, \renewenvironment | Works | With arguments and a default. |
\DeclareMathOperator, \DeclareMathOperator* | Works | |
\def\name{...}, \gdef, \edef, \xdef | Partly | Simple definitions and #1 style arguments work; delimited parameters such as \def\pt(#1,#2){...} are not matched and give garbled output. |
\let\new\old | Works | |
\NewDocumentCommand, \RenewDocumentCommand (xparse) | Not supported | The definition is dropped and the command is reported as unknown where it is used. |
\DeclarePairedDelimiter (mathtools) | Works | |
\makeatletter, \makeatother | Accepted | Commands with @ in their names are not run. |
Definitions are expanded before typesetting, so a command can be used in text, in math, in captions and in section titles. To protect against loops, expansion stops at a safety limit, with a message in the Problems tab.
xparse commands
\NewDocumentCommand from xparse is not read. The definition is dropped, and where the command is used, its name is skipped with a message while its arguments stay in the text.
\NewDocumentCommand is not supported
\documentclass{article}
\usepackage{xparse}
\NewDocumentCommand{\pair}{m m}{(#1, #2)}
\begin{document}
The pair \pair{a}{b} loses its parentheses and comma.
\end{document}Problems tab: Skipped 1 unknown command: \pair
To fix it, write the same command with \newcommand{\pair}[2]{(#1, #2)}. For optional arguments, \newcommand with a default covers the common case.
What differs from a TeX installation
The xparse and mathtools manuals are on CTAN: xparse, mathtools. For operators and function names, see also Sums, integrals and function names.
Questions and answers
How do I define a new command in LaTeX?
Write \newcommand{\name}{text} in the preamble. Add [2] after the name for two arguments and use #1 and #2 in the text.
What is the difference between \newcommand and \def?
\newcommand checks that the name is free and supports an optional argument. \def is the low-level TeX command; it overwrites without asking. Prefer \newcommand and \renewcommand.
Does \NewDocumentCommand work in Scissor LaTeX?
No. Rewrite such commands with \newcommand, which covers mandatory arguments and one optional argument.
Every example on this page is typeset by Scissor LaTeX when the site is built. Last updated 2026-11-07.