# Illegal parameter number in definition of \enit@before. You meant to type ## instead of #, right?

I am trying to renew the \item command, inside the \setlist command for How to create a enumerate list adding a custom prefix before each item number?, but latex keeps telling me:

test1.tex:22: Illegal parameter number in definition of \enit@before
You meant to type ## instead of #, right?
Or maybe a } was forgotten somewhere earlier, and things
are all screwed up? I'm going to assume that you meant ##.


But I am already typing ##. I also tried typing ###, #### and #####, but the error still the same. If I replace the ## by a single one #, then, latex stops creating the PDF correctly. As it is now, the PDF is generated correctly, even with that error popping up.

\documentclass{scrbook}
\usepackage{enumitem}
\usepackage{xspace}

\newcounter{descriptcount}
\newlist{enumdescript}{description}{1}

\setlist[enumdescript,1]{%
before={%
\setcounter{descriptcount}{0}%
\renewcommand*\thedescriptcount{\arabic{descriptcount}}%
\let\olditem\item%
\renewcommand{\item}[1][]{%
\olditem##1\space\stepcounter{descriptcount}\thedescriptcount)\xspace}%
},
after={\let\item\olditem},
align=left
}

\begin{document}
\begin{enumdescript}
\item one
\item two
\item[Some Text] three
\item four
\item five
\end{enumdescript}
\end{document}


# Related questions

With these keys it is sometimes hard to guess at which level one is, so I suggest to use

\documentclass{scrbook}
\usepackage{enumitem}
\usepackage{xspace}

\newcounter{descriptcount}
\newlist{enumdescript}{description}{1}

\def\renewitem{%
\setcounter{descriptcount}{0}%
\renewcommand*\thedescriptcount{\arabic{descriptcount}}%
\let\olditem\item%
\renewcommand{\item}[1][]{%
\olditem##1\space\stepcounter{descriptcount}\thedescriptcount)\xspace%
}%
}
\setlist[enumdescript,1]{%
before={\renewitem},
after={\let\item\olditem},
align=left,
}

\begin{document}
\begin{enumdescript}
\item one
\item two
\item[Some Text] three
\item four
\item five
\end{enumdescript}
\end{document}


• Thanks! I did not know I had to keep trying adding more #. After trying up, I figured out it works after adding 6 # as in ######1 – user Oct 14 '19 at 1:00
• @user Yes. The problem, though, is that the number may change if you, say, put this in a foreach loop. This is why I usually do things as indicated in the answer. This has the additional benefit that you could locally redefine the macro. (Of course you may want to put \let\olditem=\item only once in the preamble.) – Schrödinger's cat Oct 14 '19 at 1:24