2

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.

enter image description here

\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

  1. Error: Illegal Parameter number in definition of \iterate
  2. How to fix Illegal parameter number in definition of a new Tikz command?
  3. href: Illegal parameter number in definition of \test
  4. ! Illegal parameter number in definition of \NewValue
  5. Error: Illegal parameter number in definition of \reserved@a
  6. hyperref error using latex: "Illegal parameter number in definition of \Hy@temp"
  7. ! Illegal parameter number in definition of \abx@list@location
  8. LaTeX error: illegal parameter number in definition of \pgffor@b
  9. Why do I get the error "! Illegal parameter number in definition of \appendix."while redefining the \appendix command?
  10. Error "! Illegal parameter number in definition of \ tikz @ children @ list." with library mindmap and hyperref packages
  11. "! Illegal parameter number in definition of \reserved@a" working with fncychap

1 Answer 1

2

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}

enter image description here

2
  • 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
    Commented Oct 14, 2019 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.)
    – user194703
    Commented Oct 14, 2019 at 1:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .