1. Auto Generated Labels:
For the case where there is a simple pattern in the list names, one could use a normal enumerate
from the enumitem
package as follows:
\begin{enumerate}[label=HOM\arabic{*}, ref=(HOM\arabic{*}),leftmargin=5.0em]
\item $f(r_1+r_2)=f(r_1)+f(r_2)$ \label{item: FirstHom}
\item $f(r_1 \cdot r_2)=f(r_1) \cdot f(r_2)$
\end{enumerate}
and then the usual \ref{item: FirstHom}
yields the desired results:
2. Manually Specified Labels (Hack Alert) :
The more general case where the labels are manually specified in an arbitrary manner requires a minor change to the format in that the list content needs to be in a {}
:
\begin{MyDescription}[leftmargin=5.0em]
\item[GRP1]{$f(r_1+r_2)=f(r_1)+f(r_2)$ \label{item: FirstGrp}}
\item[RNG1]{$f(r_1 \cdot r_2)=f(r_1) \cdot f(r_2)$ \label{item: FirstRng}}
\end{MyDescription}
With this syntax, and some hackery, using \ref{item: FirstGrp}
, and \ref{item: FirstRng}
yields:
Notes:
- Requires two runs to resolve the reference. In the first run you will see ??, and in the second this will get replaced with the actual listing number.
It should be noted that in this answer to strange interaction between mdframed and item, egreg mentions that
Redefining \item
can be dangerous and have impredictable results
which is exactly what I have done for the Manually Specified Labels version, so perhaps an alternate solution might be needed if this fails under certain circumstances.
Code:
\documentclass{article}
\usepackage{enumitem}
\let\OldItem\item% remember the previous definition
\newcommand{\MyItem}[2][]{}%
\newenvironment{MyDescription}[1][]{%
\renewcommand{\item}[2][]{%
\begin{enumerate}[#1,label={##1},ref={(##1)}]%
\OldItem {##2}%
\end{enumerate}%
}%
}{%
}%
\begin{document}
\section{Auto Generated Labels}
\noindent
A map $f$ between two rings $R$ and $S$ is called a ring homomorphism if
they respect the algebraic structure in both of them. More precisely,
\begin{enumerate}[label=HOM\arabic{*}, ref=(HOM\arabic{*}),leftmargin=5.0em]
\item $f(r_1+r_2)=f(r_1)+f(r_2)$ \label{item: FirstHom}
\item $f(r_1 \cdot r_2)=f(r_1) \cdot f(r_2)$
\end{enumerate}
As can be seen in \ref{item: FirstHom} we conclude \ldots
\section{Manually Specified Labels}
A map $f$ between two rings $R$ and $S$ is called a ring homomorphism if
they respect the algebraic structure in both of them. More precisely,
\begin{MyDescription}[leftmargin=5.0em]
\item[GRP1]{$f(r_1+r_2)=f(r_1)+f(r_2)$ \label{item: FirstGrp}}
\item[RNG1]{$f(r_1 \cdot r_2)=f(r_1) \cdot f(r_2)$ \label{item: FirstRng}}
\end{MyDescription}
As can be seen in \ref{item: FirstGrp}, and \ref{item: FirstRng} we also conclude \ldots
\end{document}
I'd simplify the whole thing:
\documentclass{article}
\usepackage{enumitem}
\newenvironment{axioms}
{\enumerate[label=\textbf{A\arabic*.}, ref=A\arabic*]}
{\endenumerate}
\makeatletter
\newcommand\varitem[1]{\item[\textbf{A\arabic{enumi}\rlap{$#1$}.}]%
\edef\@currentlabel{A\arabic{enumi}{$#1$}}}
\makeatother
\begin{document}
\begin{axioms}
\item \label{item:A1} Axiom 1
\item \label{item:A2} Axiom 2
\varitem{'} \label{item:A2prime} Axiom 2$'$
\varitem{''} \label{item:A2dprime} Axiom 2$''$
\item Axiom 3
\varitem{'} Axiom 3$'$
\end{axioms}
\noindent References : \ref{item:A1}, \ref{item:A2} and \ref{item:A2prime}.
\end{document}
In my opinion, \rlap
is better (and primes are surely better than apostrophes), but you can simply get rid of it.
If you want different letters it's better to redefine \varitem
as part of the environment:
\providecommand{\varitem}{} % to keep LaTeX quiet
\makeatletter
\newenvironment{axioms}[1]
{\renewcommand\varitem[1]{\item[\textbf{#1\arabic{enumi}\rlap{$##1$}.}]%
\edef\@currentlabel{#1\arabic{enumi}{$##1$}}}%
\enumerate[label=\textbf{#1\arabic*.}, ref=#1\arabic*]}
{\endenumerate}
\makeatother
You'll have to pass the letter to the environment:
\begin{axioms}{A}
\item \label{item:A1} Axiom 1
\item \label{item:A2} Axiom 2
\varitem{'} \label{item:A2prime} Axiom 2$'$
\varitem{''} \label{item:A2dprime} Axiom 2$''$
\item Axiom 3
\varitem{'} Axiom 3$'$
\end{axioms}
Alternatively, you can define a "generic" environment and other environments based on it
\providecommand{\varitem}{} % to keep LaTeX quiet
\makeatletter
\newenvironment{statements}[1]
{\renewcommand\varitem[1]{\item[\textbf{#1\arabic{enumi}\rlap{$##1$}.}]%
\edef\@currentlabel{#1\arabic{enumi}{$##1$}}}%
\enumerate[label=\textbf{#1\arabic*.}, ref=#1\arabic*]}
{\endenumerate}
\makeatother
\newenvironment{axioms}{\statements{A}}{\endstatements}
\newenvironment{hypotheses}{\statements{H}}{\endstatements}
so that axioms
will be used as before.
Best Answer
A code with
enumitem
: I define asteps
environment:Alternatively, if you don't want to create a new environment, you can use the optional arguments of
enumerate
: