# \crefname for several layers of an enumerate: problem with enumitem

I want to use the \crefname macro from the cleveref package to set the label names on several layers of an enumerate environment. The following code works very well:

\documentclass{article}
\usepackage{forloop}
\usepackage{cleveref}

\newcounter{ct}\forloop{ct}{1}%
{\value{ct}<10}
{\crefname{enum\roman{ct}}{case}{cases}}

\begin{document}
\begin{enumerate}
\item \label{l} test
\begin{enumerate}
\item test
\item \label{k} test
\end{enumerate}
\end{enumerate}

\cref{l,k}

\end{document}


However, it stops working when I use the enumitem package:

\documentclass{article}
\usepackage{forloop}
\usepackage{enumitem}
\usepackage{cleveref}

\newlist{test}{enumerate}{10}
\setlist[test]{label=\arabic*}

\newcounter{ct}\forloop{ct}{1}%
{\value{ct}<10}
{\crefname{test\roman{ct}}{case}{cases}}

\begin{document}
\begin{test}
\item \label{l} test
\begin{test}
\item test
\item \label{k} test
\end{test}
\end{test}

\cref{l,k}

\end{document}


You can check that adding \crefname{testi}{case}{cases} will indeed make the first reference label correctly, so I have no idea why this is not working. It'd be great if someone could tell me what is going wrong and how to fix it.

-

I really don't know why the thing works for enumi and so on, but it's decidedly a bad idea to give them a \crefname globally.

You're looking for "aliasing" the testii, testiii, … counter reference to testi, I believe:

\documentclass{article}
\usepackage{enumitem}
\usepackage{cleveref}

\newlist{test}{enumerate}{10}
\setlist[test]{label*=.\arabic*}
\setlist[test,1]{label=\arabic*}
\crefname{testi}{case}{cases}

% alias testii, testiii, ... to testi
\count255=1
\loop\ifnum\count255<10
\crefalias{test\romannumeral\count255}{testi}
\repeat

\begin{document}
\begin{test}
\item \label{l} test
\begin{test}
\item test
\item \label{k} test
\end{test}
\end{test}

\cref{l,k}

\end{document}


Feel free to use a different loop macro, I'm not familiar with forloop.

I've modified the list counters, as it would be unclear which level you're referring to.

-
Perfect! Thanks a bunch, this finally settles an ancient LaTeX battle for me. –  Jesko Hüttenhain Mar 7 '13 at 18:56