# conflict between hyperref and enumitem packages (and \refstepcounter)

The solution outlined for each of the following two posts appears to conflict with the hyperref package.

Here is a MWE. The desired output for the example is

1. Outer
2.1. This is line 2.1, in block 2.
2.2. Inner again
3. Outer again
4. Let’s end here


This output is indeed produced by the LaTeX source below, but if I uncomment the \usepackage{hyperref} line in the header, LaTeX gives me an error just after the \skipitem command, as described in the inline comment below:

\documentclass{article}

% \usepackage{hyperref}
% if we uncomment the above line, we get an error as described below

\usepackage{enumitem}

\newlist{steps}{enumerate}{9}
\setlist[steps]{itemindent=0pt}
\setlist[steps,1]{label=\arabic*.,ref=\arabic*}
\setlist[steps,2]{label=\arabic{stepsi}.\arabic*.,ref=\arabic{stepsi}.\arabic*}

\makeatletter
\newcommand{\skipitem}{\refstepcounter{\@enumctr}}
\makeatother

\begin{document}
\begin{steps}
\item Outer
\skipitem
% If we uncomment the \usepackage{hyperref} line in the header,
% we get the following error after the \skipitem above
%
% ./tmp.tex:20: Missing number, treated as zero.
%   \c@0.0ptxcii
% l.20   \skipitem
% \item[] \label{blockA}
\label{blockA}\item[]
\begin{steps}
\item\label{lineB} This is line~\ref{lineB}, in block~\ref{blockA}.
\item Inner again
\end{steps}
\item Outer again
\item Let's end here
\end{steps}

\end{document}


Can someone help me work around this conflict, so I can use hyperref with this use of enumitems and refstepcounter? Thanks.

(Note: smaller working examples are possible, but they give different error messages. I'm hoping to get the current example working.)

• Load hyperref last. NOT before enumitem. – cfr Jan 9 '18 at 4:25

Just load hyperref last. It should be last except for advertised exceptions, such as cleveref.

\documentclass{article}
\usepackage{enumitem}
\newlist{steps}{enumerate}{9}
\setlist[steps]{itemindent=0pt}
\setlist[steps,1]{label=\arabic*.,ref=\arabic*}
\setlist[steps,2]{label=\arabic{stepsi}.\arabic*.,ref=\arabic{stepsi}.\arabic*}
\makeatletter
\newcommand{\skipitem}{\refstepcounter{\@enumctr}}
\makeatother
\usepackage{hyperref}
\begin{document}
\begin{steps}
\item Outer
\skipitem
\label{blockA}\item[]
\begin{steps}
\item\label{lineB} This is line~\ref{lineB}, in block~\ref{blockA}.
\item Inner again
\end{steps}
\item Outer again
\item Let's end here
\end{steps}
\end{document}


Note that you will probably need to delete generated files and compile cleanly to avoid getting errors on the initial runs after correcting your code.

• And not just last, but after the declarations of the new list types. Wow, never would have figured that out. Thanks. – Neal Young Jan 9 '18 at 13:59
• @NealYoung Actually, I don't know if that's necessary or not. I just put it after everything list-related to be on the safe side. – cfr Jan 9 '18 at 17:11
• FWIW I tried putting it immediately after the other \usepackage commands, and that did not work. – Neal Young Jan 10 '18 at 0:37
• @NealYoung Thanks for the info. I had only checked that putting it after the lot worked, so I wasn't sure. – cfr Jan 10 '18 at 0:40