[Tex/LaTex] Using cleveref with enumitem’s newlists

cleverefcross-referencingenumitemlists

I'm trying to typeset a proof of a theorem, and I'd like to produce the following output:

Case 3: my text goes here and it can wrap to
        another line, wherein I have subcases:
        Case 3.a: some text
        Case 3.b: some more text

etc. I'd also like to be say \cref{case3a}, for a label defined just before "some text", and have it produce "Case 3.a".

Initially, I tried using a simple \newenvironment to wrap the enumerate environment, but that causes \cref{case3a} to produce "Item 3.a", and anyway I'd have to work on the numbering of items.

Here's a (nearly) minimal working example that shows the behavior I have, and questions inline what I'd like to achieve:

\documentclass{article}
\usepackage[pass,showframe]{geometry} % For showing the margins
\usepackage{cleveref} % For \cref
\usepackage{calc} % For \widthof
\usepackage{enumitem} % For defining {proofcases} environment
\newlist{proofcases}{enumerate}{3}
\setlist[proofcases,1]{%
  label=\textbf{Case~\arabic*:~},ref=\arabic*,%
  leftmargin=0pt,labelsep=0pt,align=left,%
  labelwidth=\widthof{\textbf{Case~8:~}},itemindent=\widthof{\textbf{Case~8:~}},listparindent=\parindent}
\setlist[proofcases,2]{%
  label=\textbf{Case~\theproofcasesi.\alph*:~},ref=\theproofcasesi.\alph*,%
  leftmargin=2em,labelsep=0pt,align=left,%
  labelwidth=\widthof{\textbf{Case~8.m:~}},itemindent=\widthof{\textbf{Case~8.m:~}},listparindent=\parindent}
\setlist[proofcases,3]{%
  label=\textbf{Case~\theproofcasesi.\theproofcasesii.\roman*:},ref=\theproofcasesi.\theproofcasesii.\roman*,%
  leftmargin=2em,labelsep=0pt,align=left,%
  labelwidth=\widthof{\textbf{Case~8.m.viii:~}},itemindent=\widthof{\textbf{Case~8.m.viii:~}},listparindent=\parindent}
% QUESTION: Is there a better way to integrate cref's capitalization
% with enumitem's case names?
\if@cref@capitalise
  \crefname{proofcases}{Case}{Cases}
\else
  \crefname{proofcases}{case}{cases}
\fi
% QUESTION: Is there a better way to hook up the three levels of
% counters to the main one?
\crefalias{proofcasesi}{proofcases}
\crefalias{proofcasesii}{proofcases}
\crefalias{proofcasesiii}{proofcases}
\begin{document}
This is the start of the document
\begin{proofcases}
\item This is case 1.
\item This is case 2.
\item Case 3 has a very long line of text that is certain to wrap
  around to at least the second line, probably the third line too if
  it feels like it, and then has some sub-cases: \begin{proofcases}
  \item\label{case3a} This is case 3.a.  It has a label, to be
    checked later.
  \item This is case 3.b.
  \item Case 3.c will have some subcases:
    \begin{proofcases}
    \item Case 3.c.i.
    \item Case 3.c.ii.
    \end{proofcases}
  \end{proofcases}
\item This is case 4.
\end{proofcases}
This is a reference to \cref{case3a}
\end{document}

It gives the results I want (the funny business with margins and label seps is to fine-tune the alignment of the labels, and is not 100% essential to the questions here), but it feels kludgy, because I'm using an @-internal macro of cleveref, and manually managing crefaliases. My question is, is there a way to get this behavior without the peeking under the hood of cleveref? The documentation for enumitem says that it automagically handles this kind of thing for theorem environments, but I didn't quite figure out enough of the implementation details to understand how it did that…

Best Answer

I don't think there's much you can do other than what you already do. In cleveref.sty we find something like

  \Crefname{enumi}{Item}{Items}%
  \Crefname{enumii}{Item}{Items}%
  \Crefname{enumiii}{Item}{Items}%
  \Crefname{enumiv}{Item}{Items}%
  \Crefname{enumv}{Item}{Items}%

and

  \if@cref@capitalise%
    ...
    \crefname{enumi}{Item}{Items}%
    \crefname{enumii}{Item}{Items}%
    \crefname{enumiii}{Item}{Items}%
    \crefname{enumiv}{Item}{Items}%
    \crefname{enumv}{Item}{Items}%
    ...
  \else
    ...
    \crefname{enumi}{item}{items}%
    \crefname{enumii}{item}{items}%
    \crefname{enumiii}{item}{items}%
    \crefname{enumiv}{item}{items}%
    \crefname{enumv}{item}{items}%
    ...
  \fi

(this is the code for English, it's replicated for all other known languages). So basically also cleveref solves the issue in a similar way as you do. The package has many predefined tags, so maybe enumitem's automagic relies on this.

As regards capitalization, probably the package author thought that in a document one already knows whether it's used or not. Thus he didn't provide a user interface, but only one for the package writer.

Probably a package command \Xcrefname to be used as

\Xcrefname{proofcases}{Case}{Cases}{case}{cases}

might help; it would be a matter of saying

\newcommand*{\Xcrefname}[5]{%
   \Crefname{#1}{#2}{#3}%
   \if@cref@capitalise
     \crefname{#1}{#2}{#3}%
   \else
     \crefname{#1}{#4}{#5}%
   \fi}

in cleveref.sty; this could also shorten the package itself. You could make a feature request to the author.

Related Question