# Defining a new list with enumitem that uses ref from surrounding environment

Consider the following MWE

\documentclass{article}

\usepackage{amsmath,amsthm}
\usepackage{enumitem}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}

\begin{document}

\begin{theorem}[Great result]
\label{th:great}
Let 1 be the number one.
Then:
\begin{enumerate}[label=\alph*), ref={\ref{th:great}.\alph*}]
\item if $x=1$ and $y=x$, then $y=1$;
\label{th:x-eq-y}
\item if $x<1$ and $y=x$, then $y<1$.
\end{enumerate}
\end{theorem}

\begin{theorem}[Lesser result]
\label{th:lesser}
Let 0 be the number zero.
Then:
\begin{enumerate}[label=\alph*), ref={\ref{th:lesser}.\alph*}]
\item if $x=0$ and $y=x$, then $y=0$;
\label{th:other}
\item if $x<0$ and $y=x$, then $y<0$.
\end{enumerate}
\end{theorem}

Wow, that Theorem~\ref{th:great} was great.
Proving Theorem~\ref{th:x-eq-y} was particularly challenging, much more than Theorem~\ref{th:other}.
\end{document}


It works as expected.

How can I define a new list with \newlist/\setlist so that the ref is set appropriately depending on the ref of the surrounding theorem environment?

Ideally I would like to be able to write just

\begin{theorem}[Great result]
\label{th:great}
Let 1 be the number one.
Then:
\begin{thenumerate}
\item if $x=1$ and $y=x$, then $y=1$;
\label{th:x-eq-y}
\item if $x<1$ and $y=x$, then $y<1$.
\end{thenumerate}
\end{theorem}


And get \ref{th:x-eq-y} produce "1.a".

• \thecountername? [Not literally - substitute the name of the counter, of course.]
– cfr
Commented Dec 7, 2014 at 23:51
• And if somebody answers the 'bonus', will you accept their answer, rejecting egreg's? Or will you stick with egreg's, rejecting theirs? Your question should be of a kind such that you can select a single answer on a reasonable basis. This looks like a follow-up question to me. Remember: one question per question.
– cfr
Commented Dec 8, 2014 at 0:33
• In fact I think @egreg answered the bonus in the comments. I'll remove the edit. Commented Dec 8, 2014 at 0:47

Use \thetheorem:

\documentclass{article}

\usepackage{amsmath,amsthm}
\usepackage{enumitem}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}

\newenvironment{thenumerate}[1][]
{\enumerate[label=\alph*\textup{)},ref=\thetheorem.\alph*),#1]}
{\endenumerate}

\begin{document}

\begin{theorem}[Great result]
\label{th:great}
Let $1$ be the number one. Then:
\begin{thenumerate}
\item\label{th:x-eq-y} if $x=1$ and $y=x$, then $y=1$;
\item if $x<1$ and $y=x$, then $y<1$.
\end{thenumerate}
\end{theorem}

\begin{theorem}[Lesser result]
\label{th:lesser}
Let $0$ be the number zero. Then:
\begin{thenumerate}
\item\label{th:other} if $x=0$ and $y=x$, then $y=0$;
\item if $x<0$ and $y=x$, then $y<0$.
\end{thenumerate}
\end{theorem}

Wow, that Theorem~\ref{th:great} was great. Proving Theorem~\ref{th:x-eq-y} was
particularly challenging, much more than Theorem~\ref{th:other}.

\end{document}


So long as you number theorem-like environments based on the theorem environment, say with

\newtheorem{lemma}[theorem]{Lemma}


there will be no problem in inheriting the correct number.

The following variation also copes with different counters for the different environments. It will go wrong if there's an explicit \refstepcounter at the same level (which shouldn't generally happen).

\documentclass{article}

\usepackage{amsmath,amsthm}
\usepackage{enumitem}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}

\makeatletter
\newenvironment{thenumerate}[1][]
{\edef\thistheorem{\@currentlabel}%
\enumerate[label=\alph*\textup{)},ref=\thistheorem.\alph*),#1]}
{\endenumerate}
\makeatother

\begin{document}

\begin{theorem}[Great result]
\label{th:great}
Let $1$ be the number one. Then:
\begin{thenumerate}
\item\label{th:x-eq-y} if $x=1$ and $y=x$, then $y=1$;
\item if $x<1$ and $y=x$, then $y<1$.
\end{thenumerate}
\end{theorem}

\begin{lemma}[Lesser result]
\label{th:lesser}
Let $0$ be the number zero. Then:
\begin{thenumerate}
\item\label{th:other} if $x=0$ and $y=x$, then $y=0$;
\item if $x<0$ and $y=x$, then $y<0$.
\end{thenumerate}
\end{lemma}

Wow, that Theorem~\ref{th:great} was great. Proving Theorem~\ref{th:x-eq-y} was
particularly challenging, much more than Lemma~\ref{th:other}.

\end{document}

• Two questions: 1) would you use the parenthesis in the ref too? 2) Is there a simple way to adapt this to be usable with other kinds of theorems without needing to define a new list for each kind? Commented Dec 7, 2014 at 23:58
• @Bordaigorl (1) Definitely not. (2) Since you won't be numbering the other theorems separately, there is no problem. Commented Dec 8, 2014 at 0:00
• but would \thetheorem hold the right counter even inside a, say, lemma? Commented Dec 8, 2014 at 0:03
• @Bordaigorl If you have \newtheorem{lemma}[theorem]{Lemma} that's what happens. If you use separate numbering for theorems, lemmas, corollaries and propositions, you're not thinking to your readers who won't have clues for finding them. Commented Dec 8, 2014 at 0:04
• Ah! Now I understand what you meant. I agree with your comment on numbering but sometimes you do not have control on that. Commented Dec 8, 2014 at 0:08

This is just an addition to egregs answer. There is no reason to use an extra env for this. Just add the extra configuration whenever we are inside a theorem env. Downside: this has to be added to every thm like env.

I use this to control that enumerates are formatted consistently in teaching materials etc.

\documentclass{article}

\usepackage{amsmath,amsthm}
\usepackage{enumitem,etoolbox}
\SetEnumitemKey{:thmrefs}{
label=\alph*\textup{)},
ref=\thetheorem.\alph*)
}
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\AtBeginEnvironment{theorem}{
\setlist*[enumerate]{:thmrefs}
}

\begin{document}

\begin{theorem}[Great result]
\label{th:great}
Let $1$ be the number one. Then:
\begin{enumerate}
\item\label{th:x-eq-y} if $x=1$ and $y=x$, then $y=1$;
\item if $x<1$ and $y=x$, then $y<1$.
\end{enumerate}
\end{theorem}

\begin{theorem}[Lesser result]
\label{th:lesser}
Let $0$ be the number zero. Then:
\begin{enumerate}
\item\label{th:other} if $x=0$ and $y=x$, then $y=0$;
\item if $x<0$ and $y=x$, then $y<0$.
\end{enumerate}
\end{theorem}

Wow, that Theorem~\ref{th:great} was great. Proving Theorem~\ref{th:x-eq-y} was
particularly challenging, much more than Theorem~\ref{th:other}.

\end{document}

• Very nice trick! Great for consistency. Thanks! Commented Dec 8, 2014 at 14:53