# Multiple Labels to a Single Definition or Theorem.

#### caffeinemachine

##### Well-known member
MHB Math Scholar
Suppose I define closed sets and open sets in a single definition environment. Now I want to put two labels in the environment. \label{Open Set} and \label{Closed Set}.

I have tried this and this doesn't cause any trouble and doesn't give any warning.

But are there any hidden pitfalls in doing this? Is there a better method?

#### Ackbach

##### Indicium Physicus
Staff member
I think you might have problems. You can't do this with the equation environment, for example. It throws away the first label. I would label like this:

\label{Open and Closed Sets}

How are you defining your definition environment?

#### caffeinemachine

##### Well-known member
MHB Math Scholar
I think you might have problems. You can't do this with the equation environment, for example. It throws away the first label. I would label like this:

\label{Open and Closed Sets}

How are you defining your definition environment?
I have used the amsthm package for the definition environment.

In the preamble I have written \newtheorem{definition}{Definition}[section]

Then wherever I need to define something I just write

\begin{definition}
stuff
\end{definition}
____

I think labeling it as \label{Open and closed sets} is not a viable option.
I have a definition environment where I have deifned injective, surjective, bijective functions. In the same environment I have defied image, preimage etc.

It is always a good idea to define closely related concepts in a single environment.

Multiple labels would make like so much better.

#### Ackbach

##### Indicium Physicus
Staff member
Hmm. Well, it seems to work. I tried a simple \newtheorem{theorem}{Theorem}, and slapped two labels on it. Then I used both labels later, and they both referenced correctly.

#### Ackbach

##### Indicium Physicus
Staff member
Another possibility is to create nested definition environments. You could create a subdefinition environment that takes its numbering within the standard definition environment. They would work similarly to sections and subsections. You'd have to experiment with the environment definition (I don't know the exact syntax to make it work off the top of my head).

#### caffeinemachine

##### Well-known member
MHB Math Scholar
Hmm. Well, it seems to work. I tried a simple \newtheorem{theorem}{Theorem}, and slapped two labels on it. Then I used both labels later, and they both referenced correctly.
Works on my system too. Hope it is not dangerous.

#### Evgeny.Makarov

##### Well-known member
MHB Math Scholar
I don't see any harm from multiple labels. The \label command writes to the .aux file a line of the following form.

\newlabel{eqythagoras}{{4}{1}}

Here the first number is the value of the counter that was incremented last using \refstepounter (in the case of the equation environment, the counter called "equation"), and the second number is the current page number. I don't see any difference between the lines in the .aux file from the two \label commands inside the equation environment. When the .aux file is read before processing the .tex file, the information about the labels is read and later used when a \ref command is encountered.

I would label like this:

\label{Open and Closed Sets}
The main drawback from this that I see is the need to change the labels if the author decides to split the definition into two.

I am not sure if the situation changes by packages that deal with references (such as hyperref).

#### caffeinemachine

##### Well-known member
MHB Math Scholar
I don't see any harm from multiple labels. The \label command writes to the .aux file a line of the following form.

\newlabel{eqythagoras}{{4}{1}}

Here the first number is the value of the counter that was incremented last using \refstepounter (in the case of the equation environment, the counter called "equation"), and the second number is the current page number. I don't see any difference between the lines in the .aux file from the two \label commands inside the equation environment. When the .aux file is read before processing the .tex file, the information about the labels is read and later used when a \ref command is encountered.
Danks. I feel much safer now.

#### Ackbach

##### Indicium Physicus
Staff member
The main drawback from this that I see is the need to change the labels if the author decides to split the definition into two.
True, although that's nothing a good text editor can't chew through fairly quickly.

#### dwsmith

##### Well-known member
Suppose I define closed sets and open sets in a single definition environment. Now I want to put two labels in the environment. \label{Open Set} and \label{Closed Set}.

I have tried this and this doesn't cause any trouble and doesn't give any warning.

But are there any hidden pitfalls in doing this? Is there a better method?

I dont understand what you want to achieve. Can you post some example code and describe the output you would like?

#### caffeinemachine

##### Well-known member
MHB Math Scholar
I dont understand what you want to achieve. Can you post some example code and describe the output you would like?
Okay.

Suppose on the first page of a document I write:

\begin{definition}
\label{Open And Closed Set}
An open set is blah blah. A closed set is the complement of an open set.
\end{definition}

Now suppose I am, say, on the 56th page and I need to invoke the concept of a closed set and want to tell the reader too see Definition ref{wait.. what was the label?}.
I know that I have defined it somewhere. May be in a same environment with some other concept also defined there. May be not. What could be the label I had used there? Going back and checking the label would be such a waste of time. So what I'd prefer doing is:

\begin{definition}
\label{Open Set}
\label{Closed Set}
An open set is blah blah. A closed set is the complement of an open set.
\end{definition}

Now I don't need to burden my head with what is the label I have used in the environment I have defined a closed set.
I know my habit is to label a definition environment once for each concept defined in it. So when I invoke the concept of a closed set, and want to make the reader's life easier, I simply write ref{Closed Set}.

Obviously the concept of a closed set is known to everybody and thus wouldn't need this kind of treatment. But some more involved and lesser known concepts demand this.

#### Evgeny.Makarov

##### Well-known member
MHB Math Scholar
What could be the label I had used there? Going back and checking the label would be such a waste of time.
Your approach may work for definitions, but it's hard to avoid giving hard-to-remember labels to other things, such as equations, theorems and items. A good text editor should facilitate recalling labels. I am using Ref mode in Emacs, which gives you a menu with recent labels, so you don't have to actually go to another part of the document.

#### dwsmith

##### Well-known member
Use AUCTeX with RefTeX and your problem will be solve. When you are using those two with whatever compiler you like, you simply hit control+c and then ). This bings up

Then I have the option of carriage return for ref, p for page ref, a autoref, and u autopageref. Now suppose I hit return then I get a list of all my references by section or chapter. This is a practice quiz that has only one reference so it isn't going to look too special.

n and p let me jump to the next or previous sections list of references. I can navigate through 1000s of references across many pages in seconds. Then I simply highlight the one I want and hit enter. I can even select multiple ones and hit enter to add them all.

To make life even easier, use cleveref when references. Then you don't have to do label{eq:name} or label{fig:name}, you just do label{name}, and when you reference, you will do \cref{name}. Cleveref can determine if it is a figure, equation, definition, theorem, lemma, or anything else.