2

I am trying to adjust the rendering of a reference to a nested enum. Here is my MWE:

\documentclass[a4paper,14pt,openany]{memoir}

\usepackage{cleveref}

\renewcommand{\theenumi}{\arabic{enumi}}
\renewcommand{\theenumii}{\arabic{enumii}}
\renewcommand{\theenumiii}{\arabic{enumiii}}

\renewcommand{\labelenumi}{\arabic{enumi}}
\renewcommand{\labelenumii}{\arabic{enumii}}
\renewcommand{\labelenumiii}{\arabic{enumiii}}

\crefformat{enumi}{#2#1#3}
\crefformat{enumii}{#2#1#3}
\crefformat{enumiii}{#2#1#3}

\labelcrefformat{enumi}{#2#1#3}
\labelcrefformat{enumii}{#2#1#3}
\labelcrefformat{enumiii}{#2#1#3}

\begin{document}

\begin{enumerate}
 \item\label{first} First level
 \begin{enumerate}
  \item\label{second} Second level
  \begin{enumerate}
   \item\label{third} Third level
  \end{enumerate}  
 \end{enumerate}
\end{enumerate}

First level ref: \cref{first}.

% Expected result: 1
Second level ref: \cref{second}.

% Expected result: 1
Third level ref: \cref{third}.

\end{document}

As you can see, I did everything I could, but I still couldn't reach whatever place in which cleveref "cooks" the label:

Result

0

1 Answer 1

3

The issue you describe is not related to the cleveref package. It would occur every bit as much if you used \ref instead of \cref. Being able to "reach whatever place in which cleveref 'cooks' the label" would be of absolutely no use here.

What's going on, then? For each counter variable (say, mycounter) defined via a \newcounter instruction, LaTeX automatically creates an associated macro (called \p@mycounter) that's used to create a "prefix" when creating a cross-references to that counter; the full cross-reference number is a combination of the outputs of \p@mycounter and \themycounter macros.

What exactly these prefix macros are supposed to do is a choice that's left to the document class designer; by default, these prefix macros usually do nothing. However, the prefix macros \p@enumii and \p@enumiii (as well as \p@enumiv) are not empty when one uses the memoir document class: they execute \theenumi and \theenumi(\theenumii), respectively. That's what you have (re-)discovered.

If you want to reset these two prefix macros so that they "do nothing", you should provide the following code in the preamble:

\makeatletter
\renewcommand\p@enumii{}
\renewcommand\p@enumiii{}
\makeatother

(The \makeatletter directive changes the category code of the @ character to "letter"; without it, macros whose names contain one or more @ characters could not be modified via \renewcommand. The \makeatother directive restores the default category code of @, viz., "other".)

1
  • 1
    Domo arigato OTL
    – ScumCoder
    Commented Jan 16, 2020 at 18:02

You must log in to answer this question.

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