cleveref: Как ссылаться на несколько элементов в ненумерованной среде, похожей на теорему?

cleveref: Как ссылаться на несколько элементов в ненумерованной среде, похожей на теорему?

Мне нужен вывод команды

\cref{prob:third-problem,prob:fourth-problem}

в первой строке содержимого первой главы — той, вывод которой (с двумя ??s) отмечен на отображаемой странице ниже — станет «Упражнения 2.3 и 2.4» (без кавычек), как и любая другая команда формы \cref{first,second}.

(И аналогично для чего-то вроде \cref{first,fourth,fifth}списка из более чем двух проблемных ссылок.)

Как это можно сделать cleveref?

\documentclass{memoir}

% theorems    
\usepackage{amsthm}
\usepackage{thmtools}

\declaretheoremstyle[
  headformat=\NAME\NOTE,
  headfont= \sffamily\bfseries,
  headpunct={\vspace{\topsep}\newline},
  numbered=no,
  spaceabove=3\topsep,
  postheadspace=0pt    
]{probs}
\declaretheorem[
  name=EXERCISES,
  style=probs,
]{problemscontent}

\newenvironment{problems}
{\problemscontent}
{\endproblemscontent}

% lists
\usepackage{enumitem}

% For exercises
\newcounter{problemnumber} % number exercises within each chapter

\newlist{problemsenum}{enumerate}{3}
\setlist[problemsenum,1]{%...
    label=\bfseries\sffamily\arabic*.,
    ref={\arabic*}, % strips formatting!
    before=\leavevmode \vspace{-\dimexpr\baselineskip+\topsep\relax},
    after=\stepcounter{problemsenumi}\setcounter{problemnumber}{\value{problemsenumi}},
    start=\value{problemnumber}
}
\makeatletter
\renewcommand{\p@problemsenumi}{\maybe@thechapter{\thechapter}}
\protected\def\maybe@thechapter#1{%
  \ifnum#1=\value{chapter}%
  \else
    #1.%
  \fi
}
\makeatother

\newlist{problempartsenum}{enumerate}{2}
\setlist[problempartsenum,1]{%
    label=\bfseries\sffamily(\alph*),
    ref={(\alph*)},%, % strips formatting!
    before=\vspace{\dimexpr+6pt-\medskipamount\relax},
}

% links
\usepackage[pdftex]{hyperref} 
\hypersetup{%
  breaklinks=true,%
  colorlinks, citecolor=red,%
}

%% Allow ref to section n, not section m.n
%% From 'third installment' of  answer by Christian Hupfer 
%% https://tex.stackexchange.com/a/383608
\usepackage{xparse,xassoccnt}
\usepackage[user,hyperref]{zref}
\RegisterPostLabelHook{\zlabel}
% Replace \arabic{section} with \Roman{section} etc. as needed:
\makeatletter
\zref@newprop{section}{\arabic{section}} 
\zref@addprop{main}{section}
\newcommand{\secref}[1]{%
  \zref@ifrefundefined{#1}{%
    \ref{#1}}{%
    \hyperlink{\zref@extract{#1}{anchor}}%
       {\zref@extract{#1}{section}}}}
 \makeatother
%% End of code from Christian Hupfer's answer

\usepackage{aliascnt}
\usepackage[noabbrev,nameinlink]{cleveref}

\crefformat{problemsenumi}{#2Exercise~#1#3}
\Crefformat{problemsenumi}{#2Exercise~#1#3}
\crefformat{problemscontent}{#2\textnormal{#3}}
\Crefformat{problemscontent}{#2\textnormal{#3}}

\newcommand\crefprob[2]{\cref{#1}~\ref{#2}}
\newcommand\crefrangeprob[2]{Exercises~\textup{\ref{#1}}--\textup{\ref{#2}}}
\newcommand\crefrangeprobpart[2]{\textup{\ref{#1}}--\textup{\ref{#2}}}
\newcommand\crefprobandrangeprobpart[3]{\cref{#1}~\textup{\ref{#2}}--\textup{\ref{#3}}}

\begin{document}

\chapter{First}\label{chap:1}
\setcounter{problemnumber}{1}

See \cref{prob:first-problem} in a different chapter. And \cref{prob:third-problem,prob:fourth-problem}.

See also \cref{prob:chap1-number2}~\ref{prob-part:one-part-b}, that is, 
\crefprob{prob:chap1-number2}{prob-part:one-part-b}.

And consider \crefrangeprob{prob:chap1-number1}{prob:chap1-number2} in this chapter.

What about parts \crefrangeprobpart{prob-part:one-part-a}{prob-part:one-part-b} 
of \cref{prob:chap1-number2} in this chapter?
That is, \crefprobandrangeprobpart{prob:chap1-number2}{prob-part:one-part-a}{prob-part:one-part-b}.

Or \crefprobandrangeprobpart{prob:first-problem}{prob-part:first-problem-part-a}{prob-part:first-problem-part-b} 
in another chapter.

\begin{problems}
\begin{problemsenum}

\item\label{prob:chap1-number1}
A question.

\item\label{prob:chap1-number2}

\begin{problempartsenum}

\item\label{prob-part:one-part-a}
Why is $a = b$?

\item\label{prob-part:one-part-b}
Why is $d = c$?

\item\label{prob-part:one-part-c}
Is $x=y$?

\end{problempartsenum}

\end{problemsenum}

\end{problems}

%%%
\chapter{Second}\label{chap:2}
\setcounter{problemnumber}{1}

Refer to \cref{prob:first-problem} in this chapter---specifically, to 
\crefprob{prob:first-problem}{prob-part:first-problem-part-b}.


And see \crefrangeprob{prob:third-problem}{prob:fifth-problem}.

\section{First section}

\begin{problems}\label{probs:seconeprobs}
\begin{problemsenum}

\item \label{prob:first-problem}
First problem.

\begin{problempartsenum}

\item\label{prob-part:first-problem-part-a}
Why is $a = b$?

\item\label{prob-part:first-problem-part-b}
Why is $d = c$?

\item\label{prob-part:first-problem-part-c}
Is $x=y$?

\end{problempartsenum}

\item 
Second problem.

\end{problemsenum}
\end{problems}

\section{Second section}

\begin{problems}\label{probs:sectwoprobs}
\begin{problemsenum}

\item \label{prob:third-problem}
First problem.

\item \label{prob:fourth-problem}
Second problem.

\begin{problempartsenum}

\item\label{prob-part-fourth-problem-part-a}
Is it?

\item\label{prob-part-fourth-problem-part-b}
Why not?

\end{problempartsenum}

\item \label{prob:fifth-problem}
Fifth problem.

\end{problemsenum}
\end{problems}

\end{document}

Отсутствует слово Cleveref во множественном числе и «and».

Примечания:

  1. Окружение problemsбыло определено особым образом, чтобы разрешить cleverefссылки на перечисленные там элементы, без того, чтобы само окружение было пронумерованным окружением, подобным теореме. Это и связанные с ним команды и cleverefконструкции взяты из различных ответов в других сообщениях. Эти сообщения включаютСсылка, содержащая только часть номера раздела после десятичной точкии Как использовать CleverEf для получения имени, похожего на теорему, и номера элемента списка?.
  2. Мой фактический, гораздо более сложный документ, использует memoirкласс документа. Однако для этого MWE bookкласс, вероятно, также может быть использован, возможно, если дополнительные пакеты были явно загружены.

решение1

Это можно исправить, включив

\crefname{problemsenumi}{Exercise}{Exercises}

в преамбуле.

(Отсутствующую оксфордскую (серийную) запятую, которую я предпочитаю, можно вставить, как указано в ответеМожно ли заставить Cleveref использовать оксфордскую запятую для множественных цитат?, а именно, путем включения \newcommand{\creflastconjunction}{, and\nobreakspace}.

Связанный контент