Illegal parameter number in definition of \<name>.

A # in a definition does not refer to a declared argument: #1 without [1], #1 in an environment's end code, or a # in a URL. Fix the count or escape it.

Help centre › LaTeX errors › Commands and packages · Error: the build stops or the output is wrong

What the log says

! Illegal parameter number in definition of \vect.
<to be read again>
                   1
l.2 \newcommand{\vect}{\mathbf{#1}}

What it means

Inside a definition, #1, #2 … stand for the arguments of the command being defined, and # followed by anything else is not allowed. TeX found a # that does not match an argument the definition declared. The name in the message is the command being defined, which may be an internal one (\endnote for the end code of an environment note).

Causes and fixes

Most common first. Each example is a complete document; the first fails with this message, the second is the same document fixed.

1. #1 used without declaring the argument

\newcommand{\vect}{\mathbf{#1}} declares no arguments. Add the count in square brackets: \newcommand{\vect}[1]{\mathbf{#1}}. A #2 needs [2], and so on.

Fails
\documentclass{article}
\newcommand{\vect}{\mathbf{#1}}
\begin{document}
$\vect{v}$
\end{document}
Fixed
\documentclass{article}
\newcommand{\vect}[1]{\mathbf{#1}}
\begin{document}
$\vect{v}$
\end{document}

2. An environment's argument used in its end code

In \newenvironment{name}[1]{begin code}{end code}, #1 is available only in the begin code. Save it in a macro there (\newcommand{\notetitle}{#1} … then \notetitle in the end code).

Fails
\documentclass{article}
\newenvironment{note}[1]{\textbf{#1:}}{(end of #1)}
\begin{document}
\begin{note}{Remark} Text. \end{note}
\end{document}
Fixed
\documentclass{article}
\newenvironment{note}[1]{\def\notetitle{#1}\textbf{#1:}}{(end of \notetitle)}
\begin{document}
\begin{note}{Remark} Text. \end{note}
\end{document}

3. A # in a URL or text inside a definition

A link such as https://example.org/#results inside a \newcommand (or inside another command's argument) puts a bare # in a definition. Write \# instead: \url and \href print it as # in the link.

Fails
\documentclass{article}
\usepackage{url}
\newcommand{\site}{\url{https://example.org/#results}}
\begin{document}
See \site.
\end{document}
Fixed
\documentclass{article}
\usepackage{url}
\newcommand{\site}{\url{https://example.org/\#results}}
\begin{document}
See \site.
\end{document}

4. A definition inside a definition

The inner definition's parameters must be written ##1 so that they are not taken as the outer command's arguments.

In Manulyx

The editor shows the error beside the line with an explanation, and the compile log is parsed into a list of problems.

Write in Manulyx for free · Journal templates

More in commands and packages

Every example on this page was compiled with pdfLaTeX to check that it fails and is fixed as described. All LaTeX errors