10

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

1
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Feb 28, 2014 at 11:26

5 Answers 5

11

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

4
  • +1 for accepting the challenge and for the nice solution ;-) Feb 28, 2014 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, 2014 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, 2014 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, 2014 at 8:24
4

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

3
  • That's only a partial solution, since you still end up hard-coding the theorem type somehow.
    – T. Verron
    Feb 28, 2014 at 11:27
  • @T.Verron Not a big problem, I think. Do you have any better solution? Feb 28, 2014 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, 2014 at 13:33
2

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 thmlistiis now set to listthmor listlemrespectively.

\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 listthmand listlemwithout affecting the format of thmand 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 thmlistiusing 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}

enter image description here

1
  • The theorem number when doing \creflabelformat{listthm}{#2\thethm.#1#3} and \creflabelformat{listlem}{#2\thethm.#1#3} is not correct (see item 2 of your screenshot), because it corresponds to the current value of the thm counter when \cref is called, as opposed to the value this counter had when the label was created. See my answer for a possible fix.
    – frougon
    Jul 13, 2019 at 20:37
0

This is a fixed version of tim6her's answer . The problem in that answer is that \creflabelformat{listthm}{#2\thethm.#1#3} 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 fix proposed below consists in setting ref=\thethm.(\roman{thmlisti}) in the \setlist[thmlist]{...} command used for theorem “subitems.”

\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{enumitem}
\usepackage{thmtools}

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

\declaretheorem[
    name=Theorem,
    numberwithin=section]{thm}
\declaretheorem[
    name=Lemma,
    sibling=thm]{lem}

% References
\usepackage{hyperref}
\usepackage[capitalize]{cleveref}

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

\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{lem}\label{thm:C}
\begin{thmlist}
\item Statment 1\label{thm:C1}
\item Statment 2\label{thm:C2}
\item Statment 3\label{thm:C3}
\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\ prints
      \ref{thm:A1} and \ref{thm:B2}.
\end{enumerate}
\end{document}

Screenshot

0

(Dependency graph: this answer improves on @frougon's, which improves on @tim6her's, which improves on @T.Verron's.)

As suggested here, it is possible to design a slightly more general solution:

  • that does not rely on the hooks of thmtools and enables you to choose another theorem package,
  • that does not need defining specific lists inside theorem, by customizing enumerate inside the theorem environments only.

See the linked post for details.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .