0

This excellent answer explains how to create a new list definition to allow cleverref to refer to the items in an enumerate inside a definition as definition def# (item#).

Specifically, it describes how to create a list defineenum so that the following code (where defin is created with newtheorem)

\begin{defin}\label{defin_1}
\leavevmode % more elegant than '$ $'
   \begin{definenum}
      \item\label{item_1} Part 1 \dots
      \item\label{item_2} Part 2 \dots
   \end{definenum}
\end{defin}

\cref{defin_1} consists of the \cref{item_1,item_2}.

Produces something like

...

Definition 1.1 consists of the definitions 1.1(i) and 1.1(ii)

However, this half defeats the purpose of cleverref. The point is that one can freely change the type of the referenced object (e.g. lemma to proposition) without having to muck around changing a bunch of other stuff to get the references to be correct.

I'd like to create a single environment thmparts so that for some finite number of theorem environments (e.g. theorem, definition, lemma etc..) they all allow code like the following to work one says definition/definitions and the other says theorem/theorems (and so on)

\begin{definition}\label{defin_1}
\leavevmode % more elegant than '$ $'
   \begin{thmparts}
      \item\label{item_1} Part 1 \dots
      \item\label{item_2} Part 2 \dots
   \end{thmparts}
\end{definition}

\cref{defin_1} consists of the \cref{item_1,item_2}.

\begin{theorem}\label{thm_1}
\leavevmode % more elegant than '$ $'
   \begin{thmparts}
      \item\label{titem_1} Part 1 \dots
      \item\label{titem_2} Part 2 \dots
   \end{thmparts}
\end{theorem}

\cref{thm_1} consists of the \cref{titem_1,titem_2}.

If I was happy just creating new environments that wrapped theorem, lemma etc.. this would be tedious if straightforward (just let thmparts to the appropriate type of list in each wrapper) but I'd really like this to work with the restateable environment from thm-tools so I'm hoping there is some way I can define a thmparts environment in a way that lets it suss out what kind of theorem environment it was expanded inside of (and use whatever kind of list is appropriate to that environment?) Or an even more elegant way to do this?

1 Answer 1

2

You can locally override the label type with \label[<type>]{<key>}, so at the start of each theorem you can define \thmtype to be the environment name and define \plabel{<key>} as \label[\thmtype]{<key>}. I first tried to overwrite the definition of \label so you wouldn't have to use a different command, but for reasons I don't understand something like \NewCommandCopy{\origlabel}{\label} doesn't copy the definition of \label in the way I'd expect.

\documentclass{book}
\usepackage{amsthm}
\usepackage[shortlabels]{enumitem}
\usepackage[colorlinks]{hyperref}
\usepackage[capitalize,nameinlink]{cleveref}

\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{lemma}[theorem]{Lemma}
\theoremstyle{definition}
\newtheorem{defin}[theorem]{Definition}
\crefname{defin}{Definition}{Definitions} % needed since cleveref only predefines for fixed set of theorem names

\newlist{thmparts}{enumerate}{1}
\setlist[thmparts]{
  label=(\roman*),
  ref=\thetheorem\,(\roman*),
  }

\newcommand{\plabel}[1]{\label[\thmtype]{#1}}
 
\makeatletter
\apptocmd{\@begintheorem}{\let\thmtype\@currenvir}{}{\ERROR}
\makeatother

\begin{document}
    
\begin{defin}\label{defin_1}
\leavevmode
   \begin{thmparts}
      \item\plabel{item_1} Part 1 \dots
      \item\plabel{item_2} Part 2 \dots
   \end{thmparts}
 \thmtype
\end{defin}

\begin{theorem}\label{thm_1}
\leavevmode
   \begin{thmparts}
      \item\plabel{thmitem_1} Part 1 \dots
      \item\plabel{thmitem_2} Part 2 \dots
   \end{thmparts}
 \thmtype
\end{theorem}

\begin{lemma}\label{lem_1}
\leavevmode
   \begin{thmparts}
      \item\plabel{lemitem_1} Part 1 \dots
      \item\plabel{lemitem_2} Part 2 \dots
   \end{thmparts}
 \thmtype
\end{lemma}

\cref{defin_1} consists of the \cref{item_1,item_2}.

\cref{thm_1} consists of the \cref{thmitem_1,thmitem_2}.

\cref{lem_1} consists of the \cref{lemitem_1,lemitem_2}.

\end{document}

thms

2
  • Thanks so much. But I thought I needed to load etoolbox for the apptocmd macro? Is that now part of the core? Not really an issue, it's a dependency of one of the standard packages I use, but I was a bit surprised not to see it required here. Is it pulled in by enumitem or something? Commented Apr 17 at 21:09
  • 1
    @PeterGerdes etoolbox is loaded by hyperref
    – mbert
    Commented Apr 17 at 21:16

You must log in to answer this question.

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