6

I am typesetting a document with the memoir class and the cleveref package. Often I have a numbered theorem and enumerated parts. I would like to be able to refer to a part of a theorem as simply as possible.

Here is a MWE:

\documentclass{memoir}
\usepackage{amsthm}
\usepackage{cleveref}

\newtheorem{theorem}{Theorem}

\begin{document}
\begin{theorem}\label{thm}
My big theorem
\begin{enumerate}[(a)]
\item\label{thm!simple} Simple case
\item\label{thm!complex} Complex case
\end{enumerate}
\end{theorem}

\Cref{thm}\cref{thm!simple} % Theorem1item a

\Cref{thm}\ref{thm!simple}  % Theorem 1a
\Cref{thm}(\ref{thm!simple})% Theorem 1(a), but redundant coding

\end{document}

None of these is optimal. If I change the label format, I have to change every reference, which goes against the DRY mantra.

My best workaround so far is to redefine the reference format, as in:

\begin{theorem}\label{thm2}
My second big theorem
\begin{enumerate}[(a)]
\crefformat{enumi}{#2(#1)#3}
\item\label{thm2!simple} Simple case
\item\label{thm2!complex} Complex case
\end{enumerate}
\end{theorem}

\Cref{thm2}\cref{thm2!simple} % Theorem2(a)

Then if I want to change the label format I still have to change it in two places, but at least they are next to each other.

I guess the next level hack would be to look into how memoir extends enumerate and have it update \crefformat at the same time. But before I got my hands dirty I thought I would ask the hive.

  • 2
    You could use enumitem. With \begin{enumerate}[label=(\alph*)] both \ref{thm!simple} and (after saying \crefformat{enumi}{#2#1#3} in the preamble) \cref{thm!simple} will give (a). – cgnieder Jul 26 '13 at 14:21
  • I normally use enumitem, but since memoir duplicates the enumerate package I thought I was not able to use it here. Might work. – Matthew Leingang Jul 26 '13 at 14:32
  • As fas as I know enumitem does work with memoir. I'm not a memoir user, though... – cgnieder Jul 26 '13 at 14:41
  • Do you always want the theorem number in front of the item letter? – egreg Jul 26 '13 at 15:13
  • @egreg: No, not always. – Matthew Leingang Jul 26 '13 at 17:07
5

Define your own command for splitting the label.

\documentclass{memoir}
\usepackage{amsthm}
\usepackage{enumitem}
\usepackage{cleveref}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}

\newenvironment{tenumerate}[1][]
  {\enumerate[label=\textup(\alph*\textup),ref=(\alph*),#1]}
  {\endenumerate}

\newcommand{\dref}[1]{\dodref\cref#1\relax}
\newcommand{\Dref}[1]{\dodref\Cref#1\relax}
\def\dodref#1#2!#3\relax{#1{#2}\ref{#2!#3}}

\begin{document}
First of all a lemma.
\begin{lemma}\label{lem}
Here it is:
\begin{tenumerate}
\item\label{lem!a} A
\item\label{lem!b} B
\end{tenumerate}
\end{lemma}

And a wonderful theorem follows.

\begin{theorem}\label{thm}
My big theorem:
\begin{tenumerate}
\item\label{thm!simple} Simple case
\item\label{thm!complex} Complex case
\end{tenumerate}
\end{theorem}

\Dref{thm!simple} and \dref{thm!complex}; we
can also use \ref{thm!simple} or \cref{thm!complex}.

The proof follows immediately from \Dref{lem!b}.

\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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