6

I am trying to define a variant of \ref that picks out only the item number of an in-theorem list item without the preceding theorem number. For example:

Theorem 1.1.

(i) Something important.

(ii) Something important that refers to (i).

However, I can only manage the following:

Theorem 1.1.

(i) Something important.

(ii) Something important that refers to 1.1(i).

Note that I do still want to be able to print the counter 1.1(i), since I may wish to use it later on in the document. That is, in addition to being able to print 1.1(i) and Theorem 1.1(i) using the commands \ref{theoremlabel} and \Cref{theoremlabel} respectively, I'd like a new command \itemref{itemlabel} that prints just (i). I would like all three to be clickable too (using the hyperref package).

Note that this is very similar to the question ref to subsection number only and I've tried to adapt the solution givien there by Marco Daniel but alas my TeX coding skills are lacking.

Here's my MWE:

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}

\usepackage{enumitem}
\newlist{thmlist}{enumerate}{1}
\setlist[thmlist]{label=(\roman{thmlisti}), ref=\thethm(\roman{thmlisti})}

\usepackage{hyperref}
\usepackage[nameinlink]{cleveref}
\theoremstyle{plain}
\newtheorem{thm}{Theorem}[section]
\Crefname{thm}{Theorem}{Theorems}

\addtotheorempostheadhook[thm]{\crefalias{thmlisti}{thm}}

\begin{document}

\section{A theorem}

\begin{thm}\label{theoremlabel}~
\begin{thmlist}

\item\label{itemlabel} Something important.

\item Something important about \ref{itemlabel}. [Here's where I'd like to use my proposed \verb+\itemref{itemlabel}+ command.]

\end{thmlist}
\end{thm}

Later on in my document... Isn't \Cref{theoremlabel} interesting? I particularly like its clickable counter \ref{theoremlabel}.

\end{document}

Notet: The clever trick using the \addtotheorempostheadhook command is due to T. Verron in the question Reference to List Items in Theorem Environment with Label Type “Theorem”.

Many thanks in advance!

3

You can use the \p@<counter> feature: when the counter's representation, it's preceded by the expansion of \p@<counter> (usually empty), which we can use for our purposes, that is inserting in it \thethm, but as the argument to another command that we can redefine at point of use.

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}

\usepackage{enumitem}
\newlist{thmlist}{enumerate}{1}
\setlist[thmlist]{label=(\roman{thmlisti})}
\makeatletter
\renewcommand{\p@thmlisti}{\perh@ps{\thethm}}
% the same \DeclareRobustCommand{\perh@ps}[1]{#1}, but more efficient
\protected\def\perh@ps#1{#1}

\newcommand{\itemref}[1]{%
  \begingroup % locally disable \perh@ps
  \let\perh@ps\@gobble\ref{#1}%
  \endgroup
}
\makeatother

\usepackage{hyperref}
\usepackage[nameinlink]{cleveref}
\theoremstyle{plain}
\newtheorem{thm}{Theorem}[section]
\Crefname{thm}{Theorem}{Theorems}

\addtotheorempostheadhook[thm]{\crefalias{thmlisti}{thm}}

\begin{document}

\section{A theorem}

\begin{thm}\label{theoremlabel}\mbox{}
\begin{thmlist}

\item\label{itemlabel} Something important.

\item Something important about \itemref{itemlabel}.

\end{thmlist}
\end{thm}

Later on in my document... Isn't \Cref{theoremlabel} interesting? 
I particularly like its clickable counter \ref{theoremlabel}
and \ref{itemlabel}.

\end{document}

enter image description here

Alternative solution, that satisfies Barbara Beeton's and my tastes, with upright item markers:

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}

\usepackage{enumitem}
\newlist{thmlist}{enumerate}{1}
\setlist[thmlist]{label=\textup{(\roman{thmlisti})},ref={(\roman{thmlisti})}}
\makeatletter
\renewcommand{\p@thmlisti}{\perh@ps{\thethm}}
\protected\def\perh@ps#1#2{\textup{#1#2}}
\newcommand{\itemrefperh@ps}[2]{\textup{#2}}
\newcommand{\itemref}[1]{\begingroup\let\perh@ps\itemrefperh@ps\ref{#1}\endgroup}
\makeatother

\usepackage{hyperref}
\usepackage[nameinlink]{cleveref}
\theoremstyle{plain}
\newtheorem{thm}{Theorem}[section]
\Crefname{thm}{Theorem}{Theorems}

\addtotheorempostheadhook[thm]{\crefalias{thmlisti}{thm}}

\begin{document}

\section{A theorem}

\begin{thm}\label{theoremlabel}\mbox{}
\begin{thmlist}

\item\label{itemlabel} Something important.

\item Something important about \itemref{itemlabel}.

\end{thmlist}
\end{thm}

Later on in my document... Isn't \Cref{theoremlabel} interesting? 
I particularly like its clickable counter \ref{theoremlabel}
and \ref{itemlabel}.

\end{document}

enter image description here

2

Redefined some stuff, hyperlinks works, basically I reinvented the way John Kormylo did it (Please upvotes his answer there too!): How to change the appearance of \ref depending on where it's called relative to the \label

I've defined the requested \itemref, using the \getrefnumber from refcount package. With \StrBetween it's possible to search the item label between the parentheses: (i), for example.

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}

\usepackage{xstring}
\usepackage{refcount}
\usepackage{enumitem}

\usepackage{hyperref}
\usepackage[nameinlink]{cleveref}
\theoremstyle{plain}
\newtheorem{thm}{Theorem}[section]
\Crefname{thm}{Theorem}{Theorems}

\newlist{thmlist}{enumerate}{1}
\setlist[thmlist]{label={\textup{(\roman{thmlisti})}}, ref={\textup{\thethm(\roman{thmlisti})}}}


\providecommand{\itemreffont}[1]{\textup{#1}}

\addtotheorempostheadhook[thm]{\crefalias{thmlisti}{thm}}
\makeatletter
\newcommand{\itemref}[1]{%
  \begingroup
  \@ifundefined{r@#1}{\refused{#1}}{%
  \edef\tempx{\detokenize\getrefnumber{#1}}%  Fetch the literal reference 1.1(i) (here)
  \StrBetween{\tempx}{(}{)}[\@itemref]%  Get what's between the parantheses
  \edef\restore@@@@link{\getrefbykeydefault{#1}{anchor}{}}%
  \hyperlink{\restore@@@@link}{\itemreffont{(\@itemref)}}% Display the reference
  }%
\endgroup
}
\makeatother


\usepackage{blindtext}
\begin{document}

\blindtext[10]

\section{A theorem}

\begin{thm}\label{theoremlabel}~
\begin{thmlist}

\item\label{itemlabel} Something important.

\item Something important about \itemref{itemlabel}. [Here's where I'd like to use my proposed \verb+\itemref{itemlabel}+ command.]

\end{thmlist}
\end{thm}

Later on in my document... Isn't \Cref{theoremlabel} interesting? I particularly like its clickable counter \ref{theoremlabel}.

\newpage
Test for the hyperlink: \itemref{itemlabel}

\end{document}

enter image description here

  • please make the item labels upright. it looks so much nicer. – barbara beeton Sep 9 '15 at 18:34
  • @barbarabeeton: Agreed, it looks nicer -- I've done so, however, it looks strange in conjunction that the list labels are italic nevertheless -- compare (ii) and (i)... but, in the end, this is somewhat a matter of taste – user31729 Sep 9 '15 at 19:38
  • i really meant the list labels too (which is what i usually mean by "item labels). they definitely should have the same style, and the style i'm used to (and preferred by ams) is always upright. – barbara beeton Sep 9 '15 at 19:56
  • @barbarabeeton: Yes, but that's the style of the O.P. – user31729 Sep 9 '15 at 19:57
  • ah -- i didn't actually process the example. – barbara beeton Sep 9 '15 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.