Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-refs to items in enumerate with reverse counting are wrong #27

Open
golivax opened this issue Sep 15, 2021 · 2 comments
Open

Cross-refs to items in enumerate with reverse counting are wrong #27

golivax opened this issue Sep 15, 2021 · 2 comments

Comments

@golivax
Copy link

golivax commented Sep 15, 2021

Hi. The package documentation contains an interesting example that uses \EnumitemId to implement reverse counting. I implemented the proposed solution and the labels are correctly produced. However, cross-refs are not working (produce wrong values). Am I doing anything wrong? Please see the MWE below.

\documentclass{article}

\usepackage{enumitem}
\usepackage{calc,cleveref,crossreftools}

\crtrefundefinedtext{0}

\newcounter{revcount}
\newcommand\revcounter[1]{%
  \setcounter{revcount}{1+\crtcrefnumber{enum-\EnumitemId}-\value{#1}}}
\AddEnumerateCounter\revcounter\revcounter{} % the 2nd is dummy

\SetEnumitemKey{revarabic}
  {label = \revcounter*(\arabic{revcount}),
   ref   = (\arabic{revcount}),
   after = \label{enum-\EnumitemId}}
   
\begin{document}

A reverse counting enumerate:

	\begin{enumerate}[revarabic]
    	\item \label{item4} A 
    	\item \label{item3} B
    	\item \label{item2} C 
    	\item \label{item1} D
	\end{enumerate}
	
	
The items \ref{item4} \ref{item3} \ref{item2} \ref{item1}

\end{document}

The output I'm getting is as follows:

Reverse counting enumerate:
(4) A
(3) B
(2) C
(1) D

The items (0) (4) (3) (2)

Any idea of what's going on? Thanks!

@muzimuzhi
Copy link

It seems in \item \label{...} the value of counter revcount, before being updated by \setcounter{revcount}{...}, is stored in label.

An ugly workaround:

ref   = (\protect\the\numexpr1+\crtcrefnumber{enum-\EnumitemId}-\arabic*),

@jbezos
Copy link
Owner

jbezos commented Nov 30, 2021

Thank you @muzimuzhi, and sorry for the late answer. Although I always test all examples, for some reason this one doesn’t work. Either I didn’t do the tests well, or I’ve changed something in enumitem. As I explain in the manual, the solution is not the best (an fancy way of saying it’s actually poor), and I’ll try to find an alternative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants