Counting items in itemize or enumerate environments
itemize
does not use a counter (with \refstepcounter)
) -- The \label
is useless then (and if it should be used, it must after the last
item, not before the first one.
I've patched the itemize
environment a little bit and added a new counter, that is reset and stepped each time \item
is used.
Use \getrefnumber{...}
from the refcount
package to get an expandable number.
\documentclass{article}
\usepackage{xpatch}
\usepackage{refcount}
\newcommand{\numitems}[1]{\getrefnumber{#1}}
\newcounter{itemcntr}
\AtBeginEnvironment{itemize}{%
\setcounter{itemcntr}{0}%
\xapptocmd{\item}{\refstepcounter{itemcntr}}{}{}%
}
\begin{document}
Here are the \numitems{mylist} points I wanted to address:
\begin{itemize}
\item important issue;
\item another important issue;
\item oh, and yet another critical thing. \label{mylist}
\end{itemize}
Here are the \numitems{otherlist} points I wanted to address:
\begin{itemize}
\item important issue;
\item another important issue;
\item almost forgotten stuff;
\item oh, and yet another critical thing. \label{otherlist}
\end{itemize}
\end{document}