Reference to List Items in Theorem Environment with Label Type “Theorem”
This is an attempt based on your example. I used the theorem hooks defined by thmtools
to override the format for thmlisti
in the current environment:
\addtotheorempostheadhook[thm]{\crefalias{thmlisti}{thm}}
\addtotheorempostheadhook[lem]{\crefalias{thmlisti}{lem}}
I cannot promise that it won't break anything, for example if you use a thmlist
without any surrounding theorem.
\documentclass[10pt,a4paper]{article}
% Input Type and AMS-Packages
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
% Typography
\usepackage{enumitem}
\usepackage{letltxmacro}
\newlist{thmlist}{enumerate}{1}
\setlist[thmlist]{label=(\roman{thmlisti}), ref=\thethm.(\roman{thmlisti}),noitemsep}
% Math, Operators and Theorems
\usepackage{thmtools}
\declaretheorem[
name=Theorem,
%refname={theorem,theorems}, %Lower Case Versions of Theorem Type
Refname={Theorem,Theorems},
numberwithin=section]{thm}
\declaretheorem[
name=Lemma,
%refname={lemma,lemmas},
Refname={Lemma,Lemmas},
sibling=thm]{lem}
% References
\usepackage{nameref,hyperref}
\usepackage[capitalize]{cleveref}
\Crefname{thm}{Theorem}{Theorems}
\Crefname{lem}{Lemma}{Lemmas}
%%% NEW
\addtotheorempostheadhook[thm]{\crefalias{thmlisti}{thm}}
\addtotheorempostheadhook[lem]{\crefalias{thmlisti}{lem}}
\begin{document}
\begin{thm}\label{thm:A}
\begin{thmlist}
\item Statment 1\label{thm:A1}
\item Statment 2\label[thm]{thm:A2}
\end{thmlist}
\end{thm}
\begin{lem}\label{thm:B}
\begin{thmlist}
\item Statment 1\label{thm:B1}
\item Statment 2\label[lem]{thm:B2}
\end{thmlist}
\end{lem}
\begin{description}
\item[1:] That's how I refer to theorems and their like: \cref{thm:A} and \cref{thm:B}.
\item[2:] That's how I refer to parts of theorems but without the label type: \ref{thm:A1} and \ref{thm:B1}.
\item[3:] This happens when using \verb+\autoref{•}:+ \autoref{thm:A1} and \autoref{thm:B1}.
\item[4:] This happens when using \verb+\cref{•}:+ \cref{thm:A1} and \cref{thm:B1} (now working)
\item[5:] My current work around: \cref{thm:A2} and \cref{thm:B2}.
\end{description}
\end{document}
Here's a solution.
Define a new list lemlist
\newlist{lemlist}{enumerate}{1}
\setlist[lemlist]{label=(\roman{lemlisti}), ref=\thethm.(\roman{lemlisti}),noitemsep}
and use this one inside lem
.
Then, declare
\Crefname{thmlisti}{Theorem}{Theorems}
\Crefname{lemlisti}{Lemma}{Lemmas}
and you will be able to avoid the optional argument for \label
s.
MWE:
\documentclass[10pt,a4paper]{article}
% Input Type and AMS-Packages
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
% Typography
\usepackage{enumitem}
\newlist{thmlist}{enumerate}{1}
\setlist[thmlist]{label=(\roman{thmlisti}), ref=\thethm.(\roman{thmlisti}),noitemsep}
\newlist{lemlist}{enumerate}{1}
\setlist[lemlist]{label=(\roman{lemlisti}), ref=\thethm.(\roman{lemlisti}),noitemsep}
% Math, Operators and Theorems
\usepackage{thmtools}
\declaretheorem[
name=Theorem,
%refname={theorem,theorems}, %Lower Case Versions of Theorem Type
Refname={Theorem,Theorems},
numberwithin=section]{thm}
\declaretheorem[
name=Lemma,
%refname={lemma,lemmas},
Refname={Lemma,Lemmas},
sibling=thm]{lem}
% References
\usepackage{nameref,hyperref}
\usepackage[capitalize]{cleveref}
\Crefname{thm}{Theorem}{Theorems}
\Crefname{lem}{Lemma}{Lemmas}
\Crefname{thmlisti}{Theorem}{Theorems}
\Crefname{lemlisti}{Lemma}{Lemmas}
\begin{document}
\begin{thm}\label{thm:A}
\begin{thmlist}
\item Statment 1\label{thm:A1}
\item Statment 2\label{thm:A2}
\end{thmlist}
\end{thm}
\begin{lem}\label{thm:B}
\begin{lemlist}
\item Statment 1\label{thm:B1}
\item Statment 2\label{thm:B2}
\end{lemlist}
\end{lem}
\begin{description}
\item[1:] That's how I refer to theorems and their like: \cref{thm:A} and \cref{thm:B}.
\item[2:] That's how I refer to parts of theorems but without the label type: \ref{thm:A1} and \ref{thm:B1}.
\item[3:] This happens when using \verb+\autoref{•}:+ \autoref{thm:A1} and \autoref{thm:B1}.
\item[4:] This happens when using \verb+\cref{•}:+ \cref{thm:A1} and \cref{thm:B1}.
\item[5:] My current work around: \cref{thm:A2} and \cref{thm:B2}.
\end{description}
\end{document}
Output:
I was able to improve the great answer by @T.Verron such that \ref
will return the plain counter of the list-environments while \cref
will return the complete label compromising type, number of theorem and counter of the list (see my comment on @T.Verron's answer).
To do so I set up two new counters
\newcounter{listthm}
\newcounter{listlem}
whose names correspond to the theorem environment I want to use them in
\Crefname{thm}{Theorem}{Theorems}
\Crefname{lem}{Lemma}{Lemmas}
\Crefname{listthm}{Theorem}{Theorems}
\Crefname{listlem}{Lemma}{Lemmas}
In the theorem's headposthook the style of thmlisti
is now set to listthm
or listlem
respectively.
\addtotheorempostheadhook[thm]{\crefalias{thmlisti}{listthm}}
\addtotheorempostheadhook[lem]{\crefalias{thmlisti}{listlem}}
The critical step is that I am now able to tinker with the label format of listthm
and listlem
without affecting the format of thm
and lem
solely making use of commands provided by the cref
-package
\creflabelformat{listthm}{#2\thethm.#1#3}
\creflabelformat{listlem}{#2\thethm.#1#3}
Now I can avoid setting the ref
-style of thmlisti
using the enumitem
-package which caused the \ref
-command to return the counter of the theorem as well.
For full details see my example below.
\documentclass[10pt,a4paper]{article}
% Input Type and AMS-Packages
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
% Typography
\usepackage{enumitem}
\newlist{thmlist}{enumerate}{1}
\setlist[thmlist]{label=(\roman{thmlisti}),noitemsep}
% Math, Operators and Theorems
\usepackage{thmtools}
\declaretheorem[
name=Theorem,
numberwithin=section]{thm}
\declaretheorem[
name=Lemma,
sibling=thm]{lem}
% References
\usepackage{hyperref}
\usepackage[capitalize]{cleveref}
\newcounter{listthm}
\newcounter{listlem}
\Crefname{thm}{Theorem}{Theorems}
\Crefname{lem}{Lemma}{Lemmas}
\Crefname{listthm}{Theorem}{Theorems}
\Crefname{listlem}{Lemma}{Lemmas}
\addtotheorempostheadhook[thm]{\crefalias{thmlisti}{listthm}}
\addtotheorempostheadhook[lem]{\crefalias{thmlisti}{listlem}}
\creflabelformat{listthm}{#2\thethm.#1#3}
\creflabelformat{listlem}{#2\thethm.#1#3}
\begin{document}
\begin{thm}\label{thm:A}
\begin{thmlist}
\item Statment 1\label{thm:A1}
\item Statment 2\label{thm:A2}
\end{thmlist}
\end{thm}
\begin{lem}\label{thm:B}
\begin{thmlist}
\item Statment 1\label{thm:B1}
\item Statment 2\label{thm:B2}
\end{thmlist}
\end{lem}
\begin{enumerate}
\item That's how I refer to theorems and their like: \cref{thm:A} and \cref{thm:B}.
\item Referring to parts of theorems works like a charm with \verb+\cref{•}:+ \cref{thm:A1} and \cref{thm:B1}.
\item If I use \verb+\ref{•}+ to refer to a part of a theorem \LaTeX{} returns \ref{thm:A1} and \ref{thm:B2}.
\end{enumerate}
\end{document}