I'm trying to have separately numbered "Resource" sections in a memoir
document, but have produced cleveref
erences that refer to the "current" Resource counter value instead of the referenced Resource's counter value.
I don't think this is due to the incompatibilities between memoir
and titlesec
(see the edit, below).
I'm open to non-titlesec
solutions, but I do require memoir
for the document as a whole. Here's a MWE.
\documentclass[11pt]{memoir}
\usepackage{titlesec}
\newcounter{resourcecounter}
\setcounter{resourcecounter}{0}
\newcommand{\resource}[2]{
\stepcounter{resourcecounter}
\titleformat{\section}{\Large\sffamily\bfseries}{Resource \arabic{resourcecounter}}{1ex}{}
\section[Resource \arabic{resourcecounter}: #1]{#2}
\renewcommand*\thesubsection{\arabic{resourcecounter}.\arabic{subsection}}
\titleformat{\subsection}{\sffamily}{Resource \thesubsection}{1ex}{}
}
\usepackage[noabbrev,capitalise,nameinlink]{cleveref}
\crefname{resource}{Resource}{Resources}
\creflabelformat{resource}{#2\arabic{resourcecounter}#3}
\crefname{resource:sub}{Resource}{Resources}
\begin{document}
\section{Baz}
Foo \cref{res:bar}.
\resource{Bar}{Bar}
\label[resource]{res:bar}
Bar \cref{res:bar}.
\end{document}
Note that I have found several related issues, none of which has been exactly the same, AFAICT.
Edit
I've confirmed that the same numbering issue remains when titlesec
and \titleformat
are removed. It seems to have something to do with cleveref
and declaring a \section
with a custom label inside the \resource
macro.
\refstepcounter{resourcecounter}
instead of `\stepcounter{resourcecounter}?