2

How do I need modify this source so that:

  1. The first output line of Chapter 1, currently "See ?? 1, below", becomes instead "See Problem 2.1, below"
  2. 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}
2
  • No counter -- no label, unless explicitly setting \@currentlabel
    – user31729
    Commented Sep 1, 2016 at 19:57
  • So some other approach?
    – murray
    Commented Sep 1, 2016 at 20:56

1 Answer 1

1

You want to number your problems environment, but hiding the number.

\documentclass[oneside]{book}

\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{enumitem}

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

\declaretheoremstyle[
  headformat=\NAME\NOTE,
]{probs}
\declaretheorem[
  name=PROBLEMS,
  style=probs,
]{problemsinner}
\newenvironment{problems}
  {\problemsinner Solve these problems.}
  {\endproblemsinner}

\newlist{problemsenum}{enumerate}{1}
\setlist[problemsenum,1]{label=\arabic*}
\makeatletter
\renewcommand{\p@problemsenumi}{\maybe@thechapter{\thechapter}}
\protected\def\maybe@thechapter#1{%
  \ifnum#1=\value{chapter}%
  \else
    #1.%
  \fi
}
\makeatother

\crefformat{problemsenumi}{#2Problem~#1#3}
\Crefformat{problemsenumi}{#2Problem~#1#3}
\crefformat{problemsinner}{#2#3}
\Crefformat{problemsinner}{#2#3}

\begin{document}

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

See \cref{prob-part:first-problem} in a different chapter.

\chapter{Second}\label{chap:2}

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

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

enter image description here

Technical note: I used A6 paper format to produce the image.

13
  • Nice that this method does not require messing with preheadhook and postheadhook while retaining use of \newlist and \setlist. I had completely overlooked the possibility of using \crefformat.
    – murray
    Commented Sep 5, 2016 at 19:01
  • Seems to do everything I need, and it works nicely with hyperref, too. Let me just bang on this method within my complicated book-length (memoir) before accepting the answer.
    – murray
    Commented Sep 5, 2016 at 19:01
  • If in the example the item "Second problem" also has a label \label{prob-part:second-problem}, then neither \cref{prob-part:first-problem,prob-part:second-problem} nor \crefrange{prob-part:first-problem}{prob-part:second-problem}works here.
    – murray
    Commented Sep 5, 2016 at 20:22
  • I can live with the \crefrange issue by substituting \cref{...}--\creflabel{...}. Probably likewise for the \cref{..., ...} issue, but always a shame to have to do things ad hoc manually that cleveref was designed to do automatically.
    – murray
    Commented Sep 5, 2016 at 20:36
  • @murray You're asking for something the package is not designed for.
    – egreg
    Commented Sep 5, 2016 at 21:03

You must log in to answer this question.

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