0

Minimal Working Example

Consider the following code:

\documentclass{article}

% \usepackage{hyperref}  % Uncomment causes compile error
\usepackage{cleveref}
\usepackage{enumitem}

\newlist{main}{enumerate}{1}
\setlist[main,1]{label={$\cdot$}, ref={\arabic*}}
\creflabelformat{maini}{#2#1#3}
\crefname{maini}{Main}{Mains}

\newcounter{sub}[maini]
\crefname{sub}{Sub}{Subs}
\renewcommand{\thesub}{\themaini.\arabic{sub}}

\begin{document}

\begin{main}
\item\label{main:a} A
    \refstepcounter{sub}\label{main:a:1}
    \refstepcounter{sub}\label{main:a:2}

\item\label{main:b} B
    \refstepcounter{sub}\label{main:b:1}
    \refstepcounter{sub}\label{main:b:2}
\end{main}

\setlength{\parindent}{0pt}
\cref{main:a}\\             % Main 1
\cref{main:a:1}\\           % Sub 1.1
\cref{main:a:2}\\           % Sub 1.2

\cref{main:b}\\             % Main 2
\cref{main:b:1}\\           % Sub 1.1
\cref{main:b:2}\\           % Sub 1.2

\end{document}

Problem

The above code compiles fine without the hyperref. If it is loaded, however, the document no longer compiles and a cryptic error is produced:

! Missing \endcsname inserted.
<to be read again> 
                   \global 
l.20     \refstepcounter{sub}
                             \label{main:a:1}
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.

! Missing number, treated as zero.
<to be read again> 
                   \c@ 
l.20     \refstepcounter{sub}
                             \label{main:a:1}
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)
1
  • there is no error from the code after uncommenting hyperref in texlive 2024. You get the error shown in texlive 2023. Commented Aug 7 at 22:17

1 Answer 1

1

The posted code (with hyperref uncommented) works without error in current latex releases. For older releases (eg texlive 2023) you can re-order the package loading

\documentclass{article}

\usepackage{enumitem}

\newlist{main}{enumerate}{1}
\setlist[main,1]{label={$\cdot$}, ref={\arabic*}}


\usepackage{hyperref}  % Uncomment causes compile error
\usepackage{cleveref}

\creflabelformat{maini}{#2#1#3}
\crefname{maini}{Main}{Mains}

\newcounter{sub}[maini]
\renewcommand{\thesub}{\themaini.\arabic{sub}}
\crefname{sub}{Sub}{Subs}

\begin{document}

\begin{main}
\item\label{main:a} A
    \refstepcounter{sub}\label{main:a:1}
    \refstepcounter{sub}\label{main:a:2}

\item\label{main:b} B
    \refstepcounter{sub}\label{main:b:1}
    \refstepcounter{sub}\label{main:b:2}
\end{main}

\setlength{\parindent}{0pt}
\cref{main:a}\\             % Main 1
\cref{main:a:1}\\           % Sub 1.1
\cref{main:a:2}%\\           % Sub 1.2

\cref{main:b}\\             % Main 2
\cref{main:b:1}\\           % Sub 1.1
\cref{main:b:2}%\\           % Sub 1.2

\end{document}

(unrelated I commented out the two mis-placed \\ that generate underfull box warnings)

You must log in to answer this question.

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