2

Based on this question and on the useful answers, for each theorem environment I create a dedicated enumerate list which I "crefalias" to the theorem. By doing so, when I cleve-refer to a list item, it prepends "Theorem < number >" to the item label (see the code and the picture below).

Everything works just fine, except that when I \Cref multiple items, it sorts them simply by the item counter without considering the theorem counter.

Here is a MWE

\documentclass{article}
\usepackage{amsthm}
\usepackage{enumitem}
\usepackage[colorlinks = true]{hyperref}
\usepackage{cleveref}

\newtheorem{thm}{Theorem}
    \Crefname{thm}{Theorem}{Theorems}
    % Crete a dedicated enumerate environment
    \newlist{enumthm}{enumerate}{1}
    \setlist[enumthm]{label=(\roman*),ref=\thethm(\roman*)}
    \crefalias{enumthmi}{thm} % alias 'enumthm' counter to thm

\begin{document}

\begin{thm}
This theorem has a list:
\begin{enumthm}
    \item First
    \item Second\label{Thm:Second}
\end{enumthm}
\end{thm}

\begin{thm}
Also this theorem has a list:
\begin{enumthm}
    \item Third\label{Thm:Third}
    \item Fourth
\end{enumthm}
\end{thm}

Sorted cleve-referencing: \Cref{{Thm:Second},{Thm:Third}}.
\end{document}

And here is the output:

enter image description here

As you see, Theorem 2(i) precedes Theorem 1(ii) because it considers only the enumerate counters, while I would like it to take the theorem counter into account as well. Is it doable?

Thanks

P.S. Probably a workaround is documented in this answer but in case I don't know to adapt it to my case, and I would prefer a cleaner tex solution rather than a hack.

1 Answer 1

1

I don't think it's a good idea to use \crefalias in the present context. Instead, I would (a) use \Crefname to define the singular and plural "labels" that cleveref should prefix to the enumthmi-level items and (b) load the cleveref package with the option compress (which disables automatic sorting).

\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{enumitem}
\usepackage[colorlinks = true]{hyperref}
\usepackage[compress]{cleveref}  % <-- "compress" is new

\newtheorem{thm}{Theorem}
\Crefname{thm}{Theorem}{Theorems}

% Create a dedicated enumerate environment
\newlist{enumthm}{enumerate}{1}
\setlist[enumthm]{label=\textup{(\roman*)},ref=\thethm(\roman*)}
\Crefname{enumthmi}{Theorem}{Theorems} % <-- use \Crefname

\begin{document}

\begin{thm}
This theorem has a list:
\begin{enumthm}
    \item First
    \item Second\label{Thm:Second}
\end{enumthm}
\end{thm}

\begin{thm}
This theorem has a list too:
\begin{enumthm}
    \item Third\label{Thm:Third}
    \item Fourth
\end{enumthm}
\end{thm}

Unsorted clever cross-references: \Cref{Thm:Second,Thm:Third}.
\end{document}
6
  • Thank you for the answer. But compress then would affect globally cleveref, and sorting wouldn't work anyway, right?. Isn't there really a way around?
    – AndreasT
    May 9, 2016 at 13:46
  • @AndreasT - I can't think of a way right now, but let me look into this matter a bit more later today.
    – Mico
    May 9, 2016 at 14:54
  • Thank you very much, take your time, I'm not in a hurry :)
    – AndreasT
    May 9, 2016 at 15:53
  • @AndreasT - I've tried to come up with a solution that doesn't require using the compress option, but no success. I have a feeling that the cross-referencing use case you've proposed falls into the "feature request" category. You may want to contact the author/maintainer of the cleveref package and ask him for a suggestion. He's very responsive to suggestions! For instance, he came up with the \crefstripprefix macro and added it to cleveref package in response to the posting Crossreference in Ref Range ((1a-1e) to (1a-e)).
    – Mico
    May 10, 2016 at 5:19
  • 1
    I contacted the author; this issue will be appended to the long list of feature requests, though unlikely to be addressed in a close future :)
    – AndreasT
    Aug 1, 2016 at 8:46

You must log in to answer this question.

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