How do I need modify this source so that:
- The first output line of Chapter 1, currently "See ?? 1, below", becomes instead "See Problem 2.1, below"
- The first output line of Chapter 2, currently "Refer to ?? in these.", becomes instead "Refer to Problem 1 in these."?
Note that:
- the theorem-like environment
problems
is not itself numbered, but when referred to in a different chapter, should have the word "Problem" followed by that chapter's number, then the item number as the reference ; and - when an item in a
problemsenum
environment is referenced within the same chapter where that environment appears, the reference should include the word "Problem".
I'm failing to understand how to use appropriate aliases or counters here.
\documentclass[oneside]{book}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{aliascnt}
\usepackage[nameinlink]{cleveref}
\crefname{enumi}{}{}
\declaretheoremstyle[numbered=no]{probs}
\declaretheorem[name=PROBLEMS,style=probs]{problems}
\newenvironment{problemsenum}
{\begin{enumerate}%
Solve these problems.}%
{\end{enumerate}}
\crefname{problems}{Problem}{Problem}
\Crefname{problems}{Problem}{Problem}
\begin{document}
\chapter{}\label{chap:1}
See \cref{prob:my-problems} \cref{prob-part:first-problem}, below.
\chapter{}\label{chap:2}
Refer to \cref{prob-first-problem} in these.
\begin{problems}
\label{prob:my-problems}
\begin{problemsenum}
\item \label{prob-part:first-problem}
First problem.
\item
Second problem.
\end{problemsenum}
\end{problems}
\end{document}
Partial work-around
With the chapter labels added in the edited version above, in the preamble make definitions:
\newcommand{\probref}[1]{Problem~\cref{#1}}
\newcommand{\otherprobref}[1]{Problem~\thechapter.\cref{#1}}
And then create the cross-references in chapters 1 and 2, respectively, as follows:
See \otherprobref{prob-part:first-problem}
Refer to \probref{prob-part:first-problem} in these.
Why the partial work-around is unsatisfactory. Unfortunately, if I now also include in preamble...
\usepackage[colorlinks=true]{hyperref}
... then the links in chapters 1 and 2, respectively, will be only on the actual problem number (here, 1) rather than on the entire phrases "Problem 1.1" and "Problem 1". And that negates, for this type of cross-reference, the option nameinlink
I'm using for cleveref
.
Better partial work-around
In his answer to How suppress number of numbered theorem?, Christian Hupfer provides a clever new partial solution that:
- does create cross-references with numbers to enumerate items within an unnumbered theorem-like environment (which was one of my goals); but
- does not fulfill one of my requirements, namely, that when the reference is in the same chapter where that environment occurs, then the chapter number is suppressed in the reference.
Is there some way to modify Hupfer's answer so as to fulfill my requirement #2 at the top of the current post?
Here in essence is Hupfer's clever answer, modified slightly to fit my situation, with the unit divisions being chapters rather than sections (and added colored links, extra text to show readily where the links point, etc.):
\documentclass[oneside]{book}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{enumitem}
\usepackage[colorlinks, linkcolor=blue]{hyperref}
\declaretheoremstyle[numbered=yes,headpunct={}]{probs}
\declaretheorem[name=PROBLEMS,style=probs,numberwithin=chapter,preheadhook={\let\theproblems\relax},postheadhook={\newcommand{\theproblems}{\thechapter.\arabic{problems}}\leavevmode}]{problems}
\newlist{probenum}{enumerate}{1}
\setlist[probenum,1]{label=({\arabic*)},ref={Problem~\thechapter\,(\arabic*)}}
\usepackage{lipsum}
\begin{document}
\chapter{First chapter}
In \ref{fooother} you will prove that \dots .
\begin{problems}
\begin{probenum}
\item foo \label{foo} \lipsum[1]
\item bar \label{bar} \lipsum[2]
\end{probenum}
\end{problems}
In \ref{bar} and \ref{foo}, you already proved that \dots .
In \ref{fooother} you will prove that \dots .
\chapter{Second chapter}
\begin{problems}
\begin{probenum}
\item foo \label{fooother} \lipsum[3]
\item bar \label{barother} \lipsum[4]
\end{probenum}
\end{problems}
Earlier in \ref{bar}, you had already showed that \dots ; now in \ref{fooother} you just showed that \dots .
\end{document}
\@currentlabel