When I tried to integrate the answer for my question How to recognize the enumerate shortlabels in my custom environment? on my thesis document, latex throwed this error:
main.tex:26: Missing number, treated as zero
main.tex:26: Missing \endcsname inserted
main.tex:26: Missing number, treated as zero
After two hours, I managed to create a minimal example reproducing this error:
\documentclass[12pt]{article}
\errorcontextlines 10000
\usepackage[shortlabels]{enumitem}
\usepackage{hyperref}
\def\renewenumerateoptionalitem{%
\let\itemenumerateoptional\item
\renewcommand{\item}[1][]{%
\refstepcounter{enumerateoptionali}% increment the counter
\itemenumerateoptional[\bfseries##1~\theenumerateoptionali]%
}%
}
\newlist{enumerateoptional}{enumerate}{1}
\setlist[enumerateoptional]{
before=\renewenumerateoptionalitem,
label=\arabic*,
nosep,
labelindent=20mm,
leftmargin=*,
after=\let\item\itemenumerateoptional,
}
\begin{document}
\begin{enumerateoptional}[1.]
\item[Some first] item one
\item[Some second] item two
\end{enumerateoptional}
\end{document}
If you run this, you will get the error main.tex:26: Missing number, treated as zero. The line 26 is the first \item[Some first] item one on the enumerateoptional list.
If you comment the line \usepackage{hyperref}, everything works fine. You can also comment the line before=\renewenumerateoptionalitem, and keep enabled the hyperref package and everything will also work fine too.
After looking into the hyperref package code I found this:
\let\H@item\item
\newcounter{Item}
\def\theHItem{\arabic{Item}}
\def\item{%
\@hyper@itemfalse
\if@nmbrlist\@hyper@itemtrue\fi
\H@item
}
It seems hyperref is also redefining \item to something. How can I integrate the How to recognize the enumerate shortlabels in my custom environment? answer with the hyperref package?
Related questions
- How to fix error Missing number, treated as zero
- Missing number, treated as zero using BibTeX in IOP template
- conflict between hyperref and enumitem packages (and \refstepcounter)
- Footnote in input file - missing number treated as zero
- Enumeration error after renew
- Missing number, treated as zero <to be read again> \c@list \item f or \item o
\usepackage{hyperref}to the end of the preamble (just before the\begin{document}). This is really a duplicate of conflict between hyperref and enumitem packages (and \refstepcounter), so I will vote to close. – Oct 17 '19 at 03:58