LaTeX error · Commands, braces and arguments

Illegal parameter number in definition of \greet.

Quick answer

Inside a definition, #1, #2 and so on refer to the macro's arguments. If you use #2 in a \newcommand declared with only one argument (or none), TeX cannot substitute it and stops. Declare the right number of arguments in square brackets, \newcommand{\greet}[2]{...}, or, for a literal hash or a nested definition, write ##.

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.

! Illegal parameter number in definition of \greet.
<to be read again> 
                   2
l.3 \newcommand{\greet}[1]{Hello #1 and #2!}
                                            

Why it happens

  • The argument count in square brackets is too small: [1] with #2 in the body, or no [n] at all.
  • A definition nested inside another one, where the inner macro's parameters must be written ##1.
  • A literal # in the body, for example a colour like #ff0000 or a URL fragment, which must be \#.

How to fix it

Count the highest #n in the body and put that number in brackets after the command name. If the # belongs to an inner definition, double it; if it is meant to be printed, write \#.

Broken: reproduces the error

\documentclass{article}

\newcommand{\greet}[1]{Hello #1 and #2!}

\begin{document}

\greet{Ada}{Alan}

\end{document}

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

Fixed: compiles cleanly

\documentclass{article}

\newcommand{\greet}[2]{Hello #1 and #2!}

\begin{document}

\greet{Ada}{Alan}

\end{document}

Related errors

Frequently Asked Questions

How many arguments can a LaTeX command have?

Up to nine, #1 to #9. Declare the count with \newcommand{\name}[n]{...}. If you need more, group them with a key-value interface or split the macro.

When do I need ## instead of #?

When a definition contains another definition, such as a \newcommand inside \newenvironment, the inner macro's arguments are written ##1. The single #1 refers to the outer macro.

How do I print a # symbol inside a macro?

Write \#. A bare # is always read as a parameter marker, inside or outside a definition.

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 →