# Custom Enumeration

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.

• In here, yes, there is some kind of pattern--numbers follow the letters HOM. However, in general, a Mathematician's way of numbering is mnemonic but no pattern. For instance, there are papers where, one writes E0, then E0^{op}, then E1 and then, E1^{op} and so on... Even here, one might argue of a pattern. This is another kind of numbering I can see, I might be interested in is: Grp1, Rng1, Fld1. So, clearly, I am interested in a very general solution. Anyway, I would like to thank you for the suggestion. I'd be happy if you wote up an example code. – kan Mar 9 '12 at 0:22
• For this specific example and many others, the gather environment can be used, with \tag{HOM1} to customize the labels. – T. Verron Jun 22 '12 at 22:02

## 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}

• For reference, if the ref is the same as label, you only need label. – Werner Mar 9 '12 at 0:20
• @Werner: I tried \ref{HOM1} and \ref{item: HOM1} in the updated MWE but they did not work, so probably misunderstanding what you mean. – Peter Grill Mar 9 '12 at 0:24
• I am glad for the quick response. I'd appreciate if you can extend this answer to a case like I have given in the comment below my question. As I see, this answer exploits the symmetry in my labels, but in general that is not the case. Thank you, – kan Mar 9 '12 at 0:25
• +1 how about mentioning newlist to make a custom list so that the changes could be made globally? – cmhughes Mar 9 '12 at 0:54
• @cmhughes: Was going to do that once I found a general solution. If you have one you should post it. – Peter Grill Mar 9 '12 at 1:00

This is a possible solution for the last numbering schema mentioned in the comment to the original question (it is too long to be a comment); the idea is to use the series, resume* approach provided by the enumitem package:

\documentclass{article}
\usepackage{enumitem}

\begin{document}

\begin{enumerate}[leftmargin=1.3cm,label=Grp\arabic*,ref=(Grp\arabic*),series=group]
\item $a + (b + c) = (a + b) + c$. \label{ite:gras}
\end{enumerate}
\begin{enumerate}[leftmargin=1.3cm,label=Rng\arabic*,ref=(Rng\arabic*),series=ring]
\item $a + (b + c) = (a + b) + c$. \label{ite:rnas}
\end{enumerate}
\begin{enumerate}[leftmargin=1.3cm,label=Fld\arabic*,ref=(Fld\arabic*),series=field]
\item $a + (b + c) = (a + b) + c$. \label{ite:flas}
\end{enumerate}
And now some text...
\begin{enumerate}[resume*=group]
\item $a + e = e + a = a$. \label{ite:grne}
\end{enumerate}
\begin{enumerate}[resume*=ring]
\item $a + e = e + a = a$. \label{ite:rnne}
\end{enumerate}
\begin{enumerate}[resume*=field]
\item $a + e = e + a = a$. \label{ite:flne}
\end{enumerate}
And once again some text...
\begin{enumerate}[resume*=group]
\item $a + b = b + a = e$. \label{ite:grin}
\end{enumerate}
\begin{enumerate}[resume*=ring]
\item $a + b = b + a = e$. \label{ite:rnin}
\end{enumerate}
\begin{enumerate}[resume*=field]
\item $a + b = b + a = e$. \label{ite:flin}
\end{enumerate}
And some references: \ref{ite:rnas}, \ref{ite:flne}, and \ref{ite:grin}...

\end{document}


• Nice Answer. This is another perspective of a solution. Thank You. (I am sadly unable accept two answers, but, yes, I have upvoted this answer.) Thank You so much. : ) – kan Mar 9 '12 at 2:47

I'm an engineer, not a mathematician, but I think the following has a cleaner syntax, and could be modified with enumitem to handle consistent indentation of group, field, and homomorphism content:

\documentclass{article}
\usepackage[thref]{ntheorem}
\let\hom\relax % since hom defined in amsmath (http://tex.stackexchange.com/a/34927/3345)
\makeatletter
\newtheoremstyle{homstyle}% (http://tex.stackexchange.com/a/36563/3345)
\newtheoremstyle{grpstyle}%
\newtheoremstyle{fldstyle}%
\makeatother
\theoremstyle{homstyle} \newtheorem{hom}{HOM}
\theoremstyle{grpstyle} \newtheorem{grp}{GRP}
\theoremstyle{fldstyle} \newtheorem{fld}{FLD}

\begin{document}
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{hom}
$f(r_1+r_2)=f(r_1)+f(r_2)$ \label{hom:first}
\end{hom}
\begin{hom}
$f(r_1 \cdot r_2)=f(r_1) \cdot f(r_2)$ \label{hom:second}
\end{hom}
As seen in \thref{hom:first} and \thref{hom:second}, \ldots{}
Futhermore, we can define groups and fields, subjects unfamiliar to most engineers as
\begin{grp}
$1+e^{i \pi}=0$
\end{grp}
\begin{grp}
$\sin^2\theta + \cos^2 \theta = 1$
\end{grp}
\begin{fld}
$3 \approx \pi$
\end{fld}
\end{document}


One thing I haven't figured out is how to eliminate the space between the label and number in the \thref commands. Removing it in the label is no problem, however.

The enumitem manual suggested me the following solution. It is still hack-ish, and requires the user to provide all the labels for the enumeration, so I guess it still needs some tweaking.

\documentclass{article}

\usepackage{enumitem}

\makeatletter
\def\myEnumCounter#1{\expandafter\@myEnumCounter\csname c@#1\endcsname}
\def\@myEnumCounter#1{\ifcase#1\or Grp1\or Rng1\or Fld1\fi}
\makeatother

% In the next line, Grp1 has to be replaced by the widest label in the enumeration.
% An alternative syntax is :
% which means the widest label is the 1st one.

\begin{document}
\begin{enumerate}[label=\textbf{\myEnumCounter*.},ref=\myEnumCounter*]
\item \label{item:1} Group equation
\item \label{item:2} Ring equation
\item \label{item:3} Field equation
\end{enumerate}

\noindent References : \ref{item:1}, \ref{item:2} and \ref{item:3}.
\end{document}


In case the counter is somewhat natural, even though there's no scheme, it does the trick. However, here and in many other examples it may not be the case, and the solutions proposed above should prove more convenient for a one-time-use environment.