[Tex/LaTex] Custom Enumeration

#enumeratecross-referencinglists

I have a problem with enumerating a list of axioms in a custom style.

For instance, if I wanted to write down the axioms that a function will have to satisfy for it to be a homomorphism of rings, I'd prefer to call the axioms (HOM1) and (HOM2). I learnt that this is achievable by using this:

A map $f$ between two rings $R$ and $S$ is called a ring homomomorphism if
they respect the algebraic structure in both of them. More precisely, 
\begin{itemize}
\item[HOM1] $f(r_1+r_2)=f(r_1)+f(r_2)$
\item[HOM2] $f(r_1 \cdot r_2)=f(r_1) \cdot f(r_2)$
\end{itemize}

But the problem is, I have absolutely no way of referring to exactly one of these axioms, say in a proof, without having to "brutally" type in the (HOM1) to refer to the axiom.

This looks slightly like not knowing how to refer to an equation when there are several of them, say, in an align construct.

Any help in achieving this will be appreciated.

Best Answer

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:

enter image description here


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:

enter image description here


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}