2

I provide this pre-amble of my main desired output, having been told that my below approach is inherently misguided (due to \nameref not being designed or able to obtain only a numeral, instead of a descriptive label).

I would nonetheless like to be able to have a command, like \nameref, that given a label retrieves the enumerate counter associated with its respective item.

My goal is to be able to refer to enumerate items in both a single (as currently accomplished with \ref) and multiple-label contexts. For example, I would like to be able to continue to do \ref{<label1>}, but also to do something like \multirefs{<label1>, <label2>} and have this result in the following outputs:

\ref{<label1>} : (A_{1}) ← this currently works

\multirefs{<label1>, <label2>} : (A_{1}, A_{2}) ← this is what I would like

I am, however, most interested in more general approaches, similar to the linked answer.


I am trying to get \nameref to work properly with enumitem. To do so, I am using the preamble code provided in the existing answer on this topic.

I am then wrapping the document code from that answer, within a custom command, as shown below (and partly adapted from another answer):

\newcommand{\labelleditem}[1]{%
                                 \stepcounter{enumi}%
                                 \item[{\theenumi{}}\label{#1}]%
                             }

I want to make use of the description environment, with the optional arguments of an enumerate environment, as follows:

\begin{description}[label={($\text{A}_{\arabic*}$)}, series=name, resume=name]
    \labelleditem{Broken} XXX
    \item XXX
\end{description}

This does not work, presumably in part due to the description environment not fully-implementing or making accessible the enumitem optional arguments.

To clarify, I only wish to use the enumerate list, as shown in the below MWE. I do not, however, know how to properly adapt the existing answer on this topic, which uses a description list, to an enumerate list.

How might I be able to get this to work, similar to the existing answer on this topic, but with my additional specifications, shown above?

Alternatively, how can I get \nameref to work via a more general or direct patch to enumitem?


MWE:

\documentclass{article}

\usepackage{enumitem}

\makeatletter
\newcommand\enit@descriptionlabel@hook[1]{}
\def\enit@description@i#1#2#3#4{%
  \ifnum#1>#3\relax
    \enit@toodeep
  \else
    \enit@list{}%
      {\let\enit@type\tw@
       \advance#1\@ne
       \labelwidth\z@
       \enit@align@left
       \let\makelabel\descriptionlabel
       \enit@style@standard
       \enit@preset{#2}{#1}{#4}%
       \enit@calcleft
       \let\enit@svlabel\makelabel
       \def\makelabel##1{%
         \NR@gettitle{##1}%
         \labelsep\z@
         \ifenit@boxdesc
           \enit@svlabel{\enit@align{\enit@format{\enit@descriptionlabel@hook{##1}}}}%
         \else
           \nobreak
           \enit@svlabel{\enit@format{\enit@descriptionlabel@hook{##1}}}%
           \aftergroup\enit@postlabel
         \fi}%
       \enit@before
       \enit@negwidth%
       }%
     \enit@keyfirst
  \fi}

\usepackage{hyperref}

\AtBeginDocument{\let\descriptionlabel\NRorg@descriptionlabel}
\renewcommand\enit@descriptionlabel@hook[1]{\NR@gettitle{#1}#1}

\newcommand{\labelleditem}[1]{%
                             %\label{#1}%
                             \stepcounter{enumi}%
                             \item[{\theenumi{}}\label{#1}]%
                             %
                             }
% -------------------------------------

\begin{document}


\begin{description}
  \item [{Test}\label{Test}] Some text
\end{description}

\begin{description}[label={($\text{A}_{\arabic*}$)}, series=name, resume=name]
    \labelleditem{Broken} XXX
    \item XXX
\end{description}

\nameref{Test}

\nameref{Broken}

\end{document}

The above produces:

Compiled output of the above MWE

It also outputs the following error:

Missing control sequence inserted.
<inserted text> 
                \inaccessible 
l.57 ...}_{\arabic*}$)}, series=name, resume=name]

I also provide this MWE on Overleaf.

7
  • 1
    Your goal is quite unclear. You seem to mix a description list with an enumerate list, but add the numbers only for some items. Why are you doing this? Oct 10, 2019 at 7:21
  • @UlrikeFischer Yes, that's not my intention. I just don't know how to properly adapt the linked solution to an enumerate-based list. I only want an enumerate list, but I'd like it to work with \nameref, as implemented in the description modifications from the linked answer. I must just be misunderstanding how that was done, and I'm not sure how to adapt it.
    – Coby Viner
    Oct 10, 2019 at 17:13
  • Enumerate lists don't have "names" only numbers so what do you expect to get back? Oct 10, 2019 at 19:50
  • @UlrikeFischer The numbers themselves, e.g. (A_{1}) vs., say, (A_{10}) , in this example.
    – Coby Viner
    Oct 10, 2019 at 19:58
  • That is, I'd like to be able to do, e.g., \hyperref[\nameref{<label>}]{<label>}, obtaining, say, (A_{1}), that properly links to that item.
    – Coby Viner
    Oct 10, 2019 at 20:06

2 Answers 2

0

From the comments I guess that you don't want description or nameref but simply an enumerate list with a special label:

\documentclass{article}

\usepackage{enumitem}
\usepackage{hyperref}

\begin{document}

\begin{enumerate}[label={(A\textsubscript{\arabic*})}, series=name, resume=name]
    \item\label{test} XXX
    \item XXX
\end{enumerate}

\ref{test}


\end{document}

enter image description here

12
  • Thanks, but I really need \nameref to function, as poorly attempted in my question. This simple approach is what I am already using, but I need \nameref to work for my custom command \labelleditem, as shown in my (admittedly broken) MWE.
    – Coby Viner
    Oct 11, 2019 at 18:18
  • I don't see what nameref has to do with your command. It simply increases a counter and doesn't set a name. Oct 11, 2019 at 20:39
  • Well, that's fair enough, but I nonetheless wish to use \nameref to manually construct more complex references. I thought I could elide those details, but my eventual goal is to have the option to construct, e.g., (\hyperref[\nameref{<label1>}]{<label1>}, \hyperref[\nameref{<label2>}]{<label2>}), to produce, say, (A_{1}, A_{2}), where each properly links to their items.
    – Coby Viner
    Oct 11, 2019 at 21:28
  • You are misunderstanding nameref. Oct 11, 2019 at 21:42
  • 2
    For a section ref gives the number and nameref gives the title. There is nothing similar in an enumerate. It only has a number, there is no text that nameref can retrieve. Stop to cling on the nameref idea and better describe what you really want, so that someone can tell you how to implement it. Oct 11, 2019 at 21:56
0

The answer provided on a more recent iteration of this question has proven sufficient.

You must log in to answer this question.

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