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 set up references to list items in theorem environments. Using the thmtools and the cref-package I am able to reference theorem environments, such that the theorem type, e.g. theorem, lemma, corollary, is displayed in the reference (see Exam. 1).

Using the enumitem-package I refer to list items in theorem environments, such that the number of the theorem is displayed together with the item number in a reference (see Exam. 2).

Now to my question: Is there an elegant way to combine these two techniques, which would return the theorem type of the environment the list item is in as well as the combination of theorem and item number?
When I'm using the \autoref{•} command the label type item is displayed (see Exam. 3). Which makes sense since my list environment thmlist is derived form the enumerate environment. Using \cref{•} just produces two question marks (see Exam. 4).

At the moment I assign the type directly to the \label command as a optional parameter (see Exam. 5). But this solution requires me to hard code the theorem type plus TexMaker won't recognize the labels.

Since I like separating my theorems into parts an elegant solution for this problem would be very handy.

I shall be grateful for any hint or answer.

\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}

% 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}

\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}.
\item[5:] My current work around: \cref{thm:A2} and \cref{thm:B2}.
\end{description}
\end{document}

Result

share|improve this question
    
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  karlkoeller Feb 28 at 11:26

2 Answers 2

up vote 5 down vote accepted

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}

Result

share|improve this answer
    
+1 for accepting the challenge and for the nice solution ;-) –  karlkoeller Feb 28 at 15:59
    
I am pretty happy with your answer @T.Verron, but could one define the reference type of the thmlistiusing a command of the clverref-package as compared to the enumitem-package. Sometimes it would be useful that \ref{thm:A1}as in Example 2 returned «(i)»? –  tim6her Apr 2 at 8:07
    
@tim6her : I believe you should ask it as a follow-up question. Note that even without the \crefalias tweak, \ref and \autoref still include the theorem number in the label. That's because this number is included the moment the label is defined, from ref=\thethm.(\roman{thmlisti}). I cannot think of any simple way out of this. –  T. Verron Apr 2 at 8:23
    
Of course, if you always want the label to be (i), you can simply override this ref parameter, either globally or locally. But I understand you want to do this on a per-\ref basis, not per-\label. –  T. Verron Apr 2 at 8:24

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

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:

enter image description here

share|improve this answer
    
That's only a partial solution, since you still end up hard-coding the theorem type somehow. –  T. Verron Feb 28 at 11:27
    
@T.Verron Not a big problem, I think. Do you have any better solution? –  karlkoeller Feb 28 at 12:47
    
Challenge accepted. :) Your approach could probably be mixed with theorem hooks too, and that may be a more robust solution for the whole problem. –  T. Verron Feb 28 at 13:33

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.