Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Folks - the various hints as how to get to an enumeration/description listing elsewhere (e.g. Enumerated description list, Automatically number a description list) work splendidly.

However - somehow I cannot get the references to work. A most trivial version is depicted below.

\documentclass[11pt]{amsart}

% Version 3.5.2 -- 2011-09-28
\usepackage{enumitem}

\newcounter{descriptcount}
\newcounter{descriptcount2}
\newlist{enumdescript}{description}{2}

\setlist[enumdescript,1]{%
  ref=\arabic{descriptcount},%
  before={%
    \setcounter{descriptcount}{0}%
    \renewcommand*\thedescriptcount{\arabic{descriptcount}}
  },%
  font=\bfseries\refstepcounter{descriptcount}\thedescriptcount~,%
}

\setlist[enumdescript,2]{%
  ref=\arabic{descriptcount}.\arabic{descriptcount2},%
  before={%
    \setcounter{descriptcount2}{0}%
    \renewcommand*\thedescriptcount{\arabic{descriptcount}.\arabic{descriptcount2}}
  },%
  font=\bfseries\refstepcounter{descriptcount2}\thedescriptcount~,%
}

\begin{document}

\begin{enumdescript}
\item[Tada] Foo \label{foo}
\item[Taba] Bar 
    \begin{enumdescript}
    \item[Dro] Boo
    \item[Dra] Zoo \label{zoo}
    \end{enumdescript}
\item Lets talk about \ref{zoo} and \ref{foo}.
\end{enumdescript}

\end{document}

The result of this is depicted below:

image with out the refs

and of specific note is that the refs are empty (i.e. not even ??). No info on the console. Would appreciate suggestions as where to look.

share|improve this question
1  
Welcome to TeX.sx! Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. –  Kurt Nov 5 '12 at 14:58
1  
Are you sure you want to use an environment based on description? From the example, enumerate seems the best choice. –  egreg Nov 5 '12 at 15:33

2 Answers 2

up vote 5 down vote accepted

The font=... trick steps the counter inside the group that surrounds the label, so using \refstepcounter instead of \stepcounter does not help.

The main problem is that the ref= key is ineffective in environments based on description where no number is assigned. Therefore one has to use an indirect method for setting the label at the right time:

\documentclass[11pt]{amsart}

% Version 3.5.2 -- 2011-09-28
\usepackage{enumitem}

\newcounter{descriptcounti}
\newcounter{descriptcountii}
\renewcommand*\thedescriptcountii{\thedescriptcounti.\arabic{descriptcountii}}

\newcommand*\refdescriptionlabel[1]{%
  \hspace\labelsep\stepcounter{descriptcount\edlevel}%
  \normalfont\bfseries\csname thedescriptcount\edlevel\endcsname~#1:%
  \aftergroup\setedref\aftergroup\edlevel}
\makeatletter
\newcommand{\setedref}[1]{\edef\@currentlabel{\csname thedescriptcount#1\endcsname}}

\newlist{enumdescript}{description}{2}

\setlist[enumdescript,1]{
  before={\setcounter{descriptcounti}{0}\let\makelabel\refdescriptionlabel\def\edlevel{i}},
}

\setlist[enumdescript,2]{
  before={\setcounter{descriptcountii}{0}\let\makelabel\refdescriptionlabel\def\edlevel{ii}},
}

\begin{document}

\begin{enumdescript}
\item[X] Foo \label{foo}
\item[Y] Bar 
    \begin{enumdescript}
    \item[A] Boo
    \item[B] Zoo \label{zoo}
    \end{enumdescript}
\item[Z] Lets talk about \ref{zoo} and \ref{foo}.
\end{enumdescript}

\end{document}

enter image description here

share|improve this answer
1  
Thank you - totally understood - and this pre-emptively also solves a whole wack of other puzzles I was having. Thank you very much! –  Dirk-Willem van Gulik Nov 5 '12 at 16:34

I give a slightly different work around from egreg's answer. This basically comes from this answer.

First you need to use \refstepcounter instead of \stepcounter.

Next you need to put the \label inside the optional argument for \item, basically for the reasons that egreg explained.

Code:

\documentclass[11pt]{amsart}

\usepackage{enumitem}

\newcounter{descriptcounti}
\newcounter{descriptcountii}

\renewcommand*\thedescriptcounti{\arabic{descriptcounti}}
\renewcommand*\thedescriptcountii{\arabic{descriptcounti}.\arabic{descriptcountii}}

\newlist{enumdescript}{description}{2}
\setlist[enumdescript,1]{%
  before={%
    \setcounter{descriptcounti}{0}},%
  font=\bfseries\refstepcounter{descriptcounti}\thedescriptcounti~,%
}

\setlist[enumdescript,2]{%
  before={%
    \setcounter{descriptcountii}{0}},%
  font=\bfseries\refstepcounter{descriptcountii}\thedescriptcountii~,%
}

\begin{document}

\begin{enumdescript}
\item[\label{foo}] Foo
\item Bar
    \begin{enumdescript}
    \item Boo
    \item[\label{zoo}] Zoo
    \end{enumdescript}
\item Lets talk about \ref{zoo} and \ref{foo}.
\end{enumdescript}

\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.