Reference to List Items in Theorem Environment

I'm trying to implement and customize the solution that admits cross-referencing in the theorem environment.

The following attempt is extracted from my thesis template (so some packages might not be used, but they are necessary for me).

\documentclass[11pt,a4paper,twoside,final]{book}

\usepackage[utf8]{inputenc}
\usepackage[IL2]{fontenc}
\usepackage[czech]{babel}
\usepackage{lmodern}
\usepackage{longtable}

\usepackage{amsmath,amssymb,amsthm}
\usepackage{thmtools}
\usepackage{mathtools}
\usepackage{hyperref}

\declaretheoremstyle[bodyfont=\slshape]{slshape}
\declaretheorem[style=slshape,name=Theorem,numberwithin=chapter]{thm}
\declaretheorem[style=slshape,name=Lemma,numberlike=thm]{lem}

\usepackage{enumitem}

\newlist{thmlist}{enumerate}{1}
\setlist[thmlist]{label=(\roman{thmlisti}),noitemsep}

\usepackage[capitalize]{cleveref}

\newcounter{listthm}
\newcounter{listlem}

\Crefname{thm}{Theorem}{Theorems}
\Crefname{lem}{Lemma}{Lemmas}
\Crefname{listthm}{Theorem}{Theorems}
\Crefname{listlem}{Lemma}{Lemmas}

\creflabelformat{listthm}{#2\thethm.#1#3}
\creflabelformat{listlem}{#2\thethm.#1#3}

\begin{document}
\chapter{Peek-a-boo}

\begin{thm}\label{thm:A}
Assumptions
\begin{thmlist}
\item Statment 1\label{thm:A1}
\item Statment 2\label{thm:A2}
\end{thmlist}
\end{thm}
\begin{lem}\label{thm:B}
Assumptions
\begin{thmlist}
\item Statment 1\label{thm:B1}
\item Statment 2\label{thm:B2}
\end{thmlist}
\end{lem}
\begin{thm}\label{thm:C}
Assumptions
\begin{thmlist}
\item Statment 1\label{thm:C1}
\item Statment 2\label{thm:C2}
\end{thmlist}
\end{thm}
\begin{thm}\label{thm:D}
Assumptions
\begin{thmlist}
\item Statment 1\label{thm:D1}
\item Statment 2\label{thm:D2}
\end{thmlist}
\end{thm}

\begin{enumerate}
\item That's how I refer to theorems and their like: \cref{thm:A}, \cref{thm:B} and \cref{thm:C}.
\item Referring to parts of theorems works like a charm with \verb+\cref{•}:+
\begin{itemize}
\item \cref{thm:A1}
\item \cref{thm:B1}
\item \cref{thm:C}
\item \cref{thm:C1}
\item \cref{thm:C2}
\end{itemize}
\item If I use \verb+\ref{•}+ to refer to a part of a theorem \LaTeX{} returns \ref{thm:A1} and \ref{thm:B2} and \ref{thm:A}.
\end{enumerate}

\newpage

aaa

\end{document}


The output is almost perfect.

All links refer to parts that they are meant to refer, but there is a problem with counters (I guess?). That is, all the following crefs

\cref{thm:A1}
\cref{thm:B1}
\cref{thm:C1}
\cref{thm:C2}


print number of the very last theorem. So the natural question, how/what to fix there, please?

• Welcome to tex.sx. – barbara beeton Jul 13 '19 at 19:54
• \creflabelformat{listthm}{#2\thethm.#1#3} is simply wrong. \thethm doesn't refer to a labeled value, it will print the current value of the thm-counter. – Ulrike Fischer Jul 13 '19 at 20:03

You can use the following (I came to the same conclusion as Ulrike Fischer: the original code doesn't take the thm counter from the label, instead it uses the value of the thm counter that is current when \cref is called). The theorem number to use in references can be set with ref=\thethm.(\roman{thmlisti}) in the \setlist[thmlist]{...} command related to theorem subitems.

\documentclass{book}
\usepackage{amsmath,amsthm}
\usepackage{thmtools}
\usepackage{enumitem}
\usepackage{hyperref}
\usepackage[capitalize]{cleveref}

\declaretheoremstyle[bodyfont=\slshape]{slshape}
\declaretheorem[style=slshape,name=Theorem,numberwithin=chapter]{thm}
\declaretheorem[style=slshape,name=Lemma,numberlike=thm]{lem}

\newlist{thmlist}{enumerate}{1}
\setlist[thmlist]{label=(\roman{thmlisti}),
ref=\thethm.(\roman{thmlisti}),
noitemsep}

\Crefname{thm}{Theorem}{Theorems}
\Crefname{lem}{Lemma}{Lemmas}
\Crefname{listthm}{Theorem}{Theorems}
\Crefname{listlem}{Lemma}{Lemmas}

\begin{document}

\chapter{Peek-a-boo}

\begin{thm}\label{thm:A}
Assumptions
\begin{thmlist}
\item Statment 1\label{thm:A1}
\item Statment 2\label{thm:A2}
\end{thmlist}
\end{thm}
\begin{lem}\label{thm:B}
Assumptions
\begin{thmlist}
\item Statment 1\label{thm:B1}
\item Statment 2\label{thm:B2}
\end{thmlist}
\end{lem}
\begin{thm}\label{thm:C}
Assumptions
\begin{thmlist}
\item Statment 1\label{thm:C1}
\item Statment 2\label{thm:C2}
\end{thmlist}
\end{thm}
\begin{thm}\label{thm:D}
Assumptions
\begin{thmlist}
\item Statment 1\label{thm:D1}
\item Statment 2\label{thm:D2}
\end{thmlist}
\end{thm}

\begin{enumerate}
\item That's how I refer to theorems and their like: \cref{thm:A},
\cref{thm:B} and \cref{thm:C}.
\item Referring to parts of theorems works like a charm with \verb|\cref|:
\begin{itemize}
\item \cref{thm:A1}
\item \cref{thm:B1}
\item \cref{thm:C}
\item \cref{thm:C1}
\item \cref{thm:C2}
\end{itemize}
\item If I use \verb|\ref| to refer to a part of a theorem, \LaTeX\ prints
\ref{thm:A1}, \ref{thm:B2} and \ref{thm:A}.
\end{enumerate}

\end{document}