I have some "items" that I want to count and reference throughout the document. These items are usually equations. I also have different types of "items" that I want to differentiate via a prefix on the labels.
E.g. for "foo" items I can choose an "F" prefix on the corresponding label.
I want to count them in two ways:
in custom enumerate environments, where the counter is automatically increased by the
\item
command.in sections, or other similar places, where I add a reference to the item besides the section's text
In both use cases I want to have a label defined for cross-reference. Also, the labels should have a prefix to help understand which types of items are referenced.
Here is an MVE
\documentclass[en,12pt]{article}
\usepackage{ifthen}
\usepackage{enumitem}
\usepackage{hyperref}
\usepackage{prettyref}
% Define a new set of "things" to be counted
\newcommand{\DefEnumStuff}[3]{%
\newcounter{count#2}%
\setcounter{count#2}{0}%
% add a new enumerate command
\newenvironment{#1}%
{\let\olditem\item%
\begin{enumerate}[label={#3\arabic*}., ref={#3\arabic*}]%
\setcounter{enumi}{\value{count#2}}%
\renewcommand{\item}[1][]{%
\refstepcounter{count#2} \olditem%
\ifthenelse{ \equal{####1}{} }{}{\label{####1}}%
}%
}%
{\end{enumerate}}%
% add command to increase the counter outside the enumerate environment and define a label
\expandafter\newcommand\csname refstep#2\endcsname[1] {{\refstepcounter{count#2}\label{##1}}}%
}%
\newrefformat{foo}{F\ref{#1}}%
% define "foo" items to be counted.
% Have enumerate-like environment named "foo"
% and command "\refstepfoo" for use cases 1 and 2
\DefEnumStuff{foo}{foo}{F}
\begin{document}
\begin{foo}
\item[foo:A] foo A
\item[foo:B] foo B
\end{foo}
\begin{foo}
\item C
\end{foo}
As seen in \ref{foo:A}
\refstepfoo{foo:D}
\section*{Example (\ref{foo:D})} % expected Example F4
\end{document}
On my system I get the following result
It seems to me it works, except that I'd like the reference in the "Example" section to read as "Example (F4)" instead of "Example (4)".
Could you help me achieve this? Further suggestions on the overall idea are welcome!
TIA