7

A followup on enumitem: how to put a prime into certain parenthesized labels:

How do I put a prime superscript on ii in (ii) in the context of enumitem and cleveref? MWE:

\documentclass{article}
\usepackage{enumitem}
\usepackage{cleveref}
\begin{document}
\begin{enumerate}[label=(\roman*)]
\item\label{A} First
\item\label{B} Second
\item\label{C} Want to have (ii') here.
\item\label{D} Fourth
\end{enumerate}
Let's reference them: \ref{A}, \ref{B}, \ref{C} (want to have (ii') also here), and \ref{D} (want to have ``(iii)'' here).\\
Let's test cleveref: \cref{A}, \cref{B}, \cref{C} (want to have ``item (ii')'' here), \cref{D} (want to have ``item (iii)'' here),\\
\labelcref{A}, \labelcref{B}, \labelcref{C} (want to have ``(ii')'' here), and \labelcref{D} (want to have ``(iii)'' here), 
\end{document}

As opposed to that, I want to have

(i) First

(ii) Second

(ii') Another version of (ii).

(iii) Fourth

Let's reference them: (i), (ii), (ii'), (iii).

Let's test cleveref: item (i), item (ii), item (ii'), item (iii), (i), (ii), (ii'), and (iii).

How to do that in LaTeX without introducing global changes to standard macros? We are still allowed to introduce our own, fresh macros and local changes to standard macros. Moreover, I'd still like to reference all the items with \ref{A}, \ref{B}, \ref{C}, \ref{D}, not with (\ref{A}), (\ref{B}), (\ref{C}), (\ref{D}), respectively for the cleveref versions.

I tried

\documentclass{article}
\usepackage{textcomp}
\usepackage{enumitem}
\usepackage{cleveref}
\makeatletter
\newcommand\itemprime{%
  \item[(\roman{enumi}\textquotesingle)]%
  \def\@currentlabel{(\roman{enumi}\textquotesingle)}%
  \def\cref@currentlabel{(\roman{enumi}\textquotesingle)}%
}
\makeatother
\crefname{itemprime}{item}{item}
\begin{document}
\begin{enumerate}[label=(\roman*)]
\item\label{A} First
\item\label{B} Second
\itemprime\label{C} Want to have (ii') here.
\item\label{D} Fourth
\end{enumerate}
Let's reference them: \ref{A}, \ref{B}, \ref{C} (want to have (ii') also here), and \ref{D} (want to have ``(iii)'' here).\\
Let's test cleveref: \cref{A}, \cref{B}, \cref{C} (want to have ``item (ii')'' here), \cref{D} (want to have ``item (iii)'' here),\\
\labelcref{A}, \labelcref{B}, \labelcref{C} (want to have ``(ii')'' here), and \labelcref{D} (want to have ``(iii)'' here), 
\end{document}

but the results were not encouraging.

1 Answer 1

5

The format of \cref@currentlabel is quite different from \@currentlabel.

You have to define \itemprime in the following way to achieve what you want:

\newcommand\itemprime{%
  \item[(\roman{enumi}\textquotesingle)]%
  \def\@currentlabel{(\roman{enumi}\textquotesingle)}%
  \protected@edef\cref@currentlabel{%
    [\@tempa][\arabic{enumi}'][\cref@result](\roman{enumi}\textquotesingle)}%
}

Also note that the line

\crefname{itemprime}{item}{item}

does nothing since no itemprime counter is defined and anyway it is not needed since you are using enumi for your \itemprime.

MWE:

\documentclass{article}
\usepackage{textcomp}
\usepackage{enumitem}
\usepackage{cleveref}
\makeatletter
\newcommand\itemprime{%
  \item[(\roman{enumi}\textquotesingle)]%
  \def\@currentlabel{(\roman{enumi}\textquotesingle)}%
  \protected@edef\cref@currentlabel{%
    [\@tempa][\arabic{enumi}'][\cref@result](\roman{enumi}\textquotesingle)}%
}
\makeatother
%\crefname{itemprime}{item}{item}
\begin{document}
\begin{enumerate}[label=(\roman*)]
\item\label{A} First
\item\label{B} Second
\itemprime\label{C} Want to have (ii') here.
\item\label{D} Fourth
\end{enumerate}

Let's reference them: \ref{A}, \ref{B}, \ref{C} , and \ref{D}.

Let's test cleveref: \cref{A}, \cref{B}, \cref{C}, and \cref{D},

\labelcref{A}, \labelcref{B}, \labelcref{C}, and \labelcref{D}.
\end{document} 

Output:

enter image description here Just for completeness, this is the contents of the .aux file:

\relax
\newlabel{A}{{{{(i)}}}{1}}
\newlabel{A@cref}{{[enumi][1][]{{(i)}}}{1}}
\newlabel{B}{{{{(ii)}}}{1}}
\newlabel{B@cref}{{[enumi][2][]{{(ii)}}}{1}}
\newlabel{C}{{(ii\textquotesingle )}{1}}
\newlabel{C@cref}{{[enumi][2'][](ii\textquotesingle )}{1}}
\newlabel{D}{{{{(iii)}}}{1}}
\newlabel{D@cref}{{[enumi][3][]{{(iii)}}}{1}}

EDIT (in response to OP's comment)

Yes, it is possible with the help of \@ifpackageloaded macro. Substitute the code between \makeatletter and \makeatother with

\makeatletter
\newcommand{\setclevereflabel}{\relax}
\@ifpackageloaded{cleveref}{%
  \renewcommand{\setclevereflabel}{%
    \protected@edef\cref@currentlabel{%
      [\@tempa][\arabic{enumi}'][\cref@result](\roman{enumi}\textquotesingle)}%
  }%
}{}
\newcommand\itemprime{%
  \item[(\roman{enumi}\textquotesingle)]%
  \def\@currentlabel{(\roman{enumi}\textquotesingle)}%
  \setclevereflabel%
}
\makeatother

MWE (try it as is and uncommenting commented lines):

\documentclass{article}
\usepackage{textcomp}
\usepackage{enumitem}
%\usepackage{cleveref}

\makeatletter
\newcommand{\setclevereflabel}{\relax}
\@ifpackageloaded{cleveref}{%
  \renewcommand{\setclevereflabel}{%
    \protected@edef\cref@currentlabel{%
      [\@tempa][\arabic{enumi}'][\cref@result](\roman{enumi}\textquotesingle)}%
  }%
}{}
\newcommand\itemprime{%
  \item[(\roman{enumi}\textquotesingle)]%
  \def\@currentlabel{(\roman{enumi}\textquotesingle)}%
  \setclevereflabel%
}
\makeatother

\begin{document}
\begin{enumerate}[label=(\roman*)]
\item\label{A} First
\item\label{B} Second
\itemprime\label{C} Want to have (ii') here.
\item\label{D} Fourth
\end{enumerate}

Let's reference them: \ref{A}, \ref{B}, \ref{C} , and \ref{D}.

%Let's test cleveref: \cref{A}, \cref{B}, \cref{C}, and \cref{D},

%\labelcref{A}, \labelcref{B}, \labelcref{C}, and \labelcref{D}.
\end{document} 
1
  • 1
    @LeonMeier Yes, see the edit in the answer. Oct 30, 2016 at 12:05

You must log in to answer this question.