Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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...

share|improve this question
    
Sorry to see the question only now; a minimal example is necessary to understand what's really going on. –  egreg Sep 3 '11 at 23:32
    
Your example doesn't compile. –  lockstep Sep 4 '11 at 20:58
    
@lockstep, Fixed. That's a new warning from enumitem, I think, telling me that my new environment was too deeply nested. D'oh! I was trying to point out an error case anyway, but apparently the package was smarter than I was... –  Ben Lerner Sep 4 '11 at 21:03
    
@egreg, my focus in this question (the "kldugy" bit) was having to specify all three levels of proofcasesi, proofcasesii, proofcasesiii as aliases to proofcases --- it seemed to me at the time that defining \newlist{X} ought to link Xi, Xii, etc and the aliases seemed like I was missing something important in the documentation. It's entirely possible that the answer here is, "that's the best you can do, it's not a kludge", in which case feel free to vote the question closed... –  Ben Lerner Sep 4 '11 at 21:15
add comment

1 Answer

up vote 9 down vote accepted

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.

share|improve this answer
    
Thanks :) I was hoping there was some such macro already defined that I'd missed (I was focusing on writing my thesis, at least mostly ;-p), but I'm semi-glad to see I didn't miss a trick here. I'll ping the package author to suggest your \Xcrefname approach. I'm going to wait a day before accepting this answer, just in case someone else found something we both missed; otherwise this works for me. –  Ben Lerner Sep 5 '11 at 1:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.