0

I would like to be able to have a command, like \nameref, that given a label, retrieves an 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 most interested in more general approaches, similar to a linked answer. While cleverref provides functionality equivalent to this, for the purposes of this question, please presume that it cannot be used, and that hyperref must be used (though can be patched).

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


N.B. due to the intended general nature of this question, no MWE is provided. This question constitutes a new attempt at my prior equivalent question, which admittedly became convoluted. Thanks to Ulrike Fischer for their prior useful comments.

Coby Viner
  • 1,939

1 Answers1

1

If you want to process a list of labels you can do it like this.

\documentclass{article}
\usepackage{xparse,hyperref}
\ExplSyntaxOn
\NewDocumentCommand\multirefs{m}
{
  \seq_set_from_clist:Nn \l_tmpa_seq { #1 }
  \seq_set_map:NNn \l_tmpb_seq \l_tmpa_seq
    {
      \exp_not:N\ref{##1}
    }
  (\seq_use:Nn \l_tmpb_seq {,~})
}
\ExplSyntaxOff
\begin{document}
\section{a}\label{sec:a}
\section{b}\label{sec:b}
\multirefs{sec:a,sec:b}
\end{document}

enter image description here

Ulrike Fischer
  • 327,261