0

In the following, is it possible to create a cross-reference that prints the contents of the "note-like" field of a \ditem optional argument?

That is, I would like to be able to print "something big" (without the quotes) when referencing the label ex:wow.

\documentclass{memoir}
\usepackage{amsthm,thmtools}
\usepackage{enumitem}

\declaretheoremstyle[
  headfont= \sffamily\bfseries, headpunct={\sffamily\bfseries.},
  postheadspace=0.5em,
  notefont=\sffamily\mdseries, bodyfont=\normalfont,
]{defstyle}

\declaretheorem[
  name=Examples, style=defstyle,
  numberwithin=chapter,
  qed=$\diamond$
  ]
{examples}
\counterwithin{examples}{chapter}

\newlist{pexenum}{enumerate}{1}
\setlist[pexenum,1]{%
  label= \sffamily\upshape(\arabic*),
  ref={\arabic*}, 
}
\makeatletter
\newcommand\gobblepar
  {\@ifnextchar\label{\gobblepar@label}{\@ifnextchar\par{\@gobble}{}}}
\newcommand\gobblepar@label[2]{\label{#2}\gobblepar}
\makeatother

% For examples with optional ``note-like'' field:
\newcommand\ditem[1][]{\item{\sffamily\MakeUppercase#1. }\gobblepar}

\usepackage[colorlinks,linkcolor=red]{hyperref}
\usepackage{cleveref}
\usepackage{crossreftools} % <--- does this help? 

\begin{document}
\chapter{The Main Thing}

\begin{examples}[some instances]\label{exs:mine}
    \begin{pexenum}
        \item A first example
        \ditem[something big]\label{ex:wow} A surprising example.\qedhere
    \end{pexenum}
\end{examples}

See \cref{ex:wow}.

\end{document}

Output as things stand now

Observe that \crtrefname{ex:wow} does not do what I want: it returns the note field "some instances" of the enclosing examples environment instead.

1 Answer 1

0

A fix is the method given by Ulrike Fischer in https://tex.stackexchange.com/a/303149/13492. Here is the whole document again, with that fix and checks that special cross-referencing commands still work.

\documentclass{memoir}
\usepackage{amsthm,thmtools}
\usepackage{enumitem}

\declaretheoremstyle[
  headfont= \sffamily\bfseries, headpunct={\sffamily\bfseries.},
  postheadspace=0.5em,
  notefont=\sffamily\mdseries, bodyfont=\normalfont,
  spacebelow=12pt
]{defstyle}

\declaretheorem[
  name=Examples, style=defstyle,
  numberwithin=chapter,
  qed=$\diamond$
  ]
{examples}
\counterwithin{examples}{chapter}

\newlist{pexenum}{enumerate}{1}
\setlist[pexenum,1]{%
  label= \sffamily\upshape(\arabic*),
  ref={\arabic*}, 
}
\makeatletter
\newcommand\gobblepar
  {\@ifnextchar\label{\gobblepar@label}{\@ifnextchar\par{\@gobble}{}}}
\newcommand\gobblepar@label[2]{\label{#2}\gobblepar}
\makeatother

% For examples with optional ``note-like'' field:
%   Original \ditem is method of Skillmon, https://tex.stackexchange.com/a/699243/13492
%   Fix: Ulrike Fischer's method, https://tex.stackexchange.com/a/303149/13492:
\makeatletter
\newcommand\ditem[1][]{\item{\sffamily\MakeUppercase#1. }%
  \protected@edef\@currentlabel{#1}\gobblepar}
\makeatother

\usepackage[colorlinks,linkcolor=red]{hyperref}
\usepackage{cleveref}
\usepackage{crossreftools} % <--- does this help? 

% Special cross-referencing commands to check still OK:    
\crefname{examples}{Examples}{Examples}
\crefname{pexenumi}{}{} % do not use ``Item''
\crefformat{pexenumi}{\textup{(}#2#1#3\textup{)}}
\newcommand{\crefex}[2]{\hyperref[#2]{\namecref{#1}~\labelcref*{#1}~(\crtcrefcountervalue{#2})}}        
\newcommand\crefexone[1]{\hyperref[#1]{\textup{Example}~\textup{(}\crtcrefcountervalue{#1}\textup{)}}}

\begin{document}
\chapter{The Main Thing}

\begin{examples}[some instances]\label{exs:mine}
    \begin{pexenum}
        \item\label{ex:first} A first example.
        \ditem[something big]\label{ex:wow} A surprising example. \qedhere
    \end{pexenum}
\end{examples}
  
OK: Grab the optional argument of item \cref{ex:wow} which is: \ref*{ex:wow}.  

OK: \crefex{exs:mine}{ex:wow}.

OK: \crefexone{ex:first} and \crefexone{ex:wow}.

\end{document}

Fixed \ditem

1
  • Is there some better way to do this?
    – murray
    Dec 11, 2023 at 21:16

You must log in to answer this question.

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