# Efficient way of dealing with labels on large files

When dealing with a large tex file manually labeling definitions and equations can become quite a hassle: for sanity, I like to keep a single numbering system on my labels (so for example I star with \label{d1} for Definition 1 and \label{eq2} for the equation that would come right after and so on), that way I can just reference things as I go inside a chapter.

However this becomes a problem when I (inevitably) have to replace or remove some parts of the text, which would make me have to shift forward or backwards all of my previously defined labels. So my question is: is there a more efficient way of dealing with labels so that I don't have to change all my labels from a certain point if I alter some text in between?

• the whole point of \label is to avoid this problem. You do not need to relabel as you edit. Jun 14 at 21:35
• the printed equation number is not conected to the label which is an internal identifier it is good practice not to use numbers, although latex does not mind Jun 14 at 21:37
• I'm not talking about the printed number, I'm talking about the label name inside the file. I know I could give each equation and definition a unique name like "csineq" for the Cauchy-Schwarz Inequality, for example, but I wanted to know if there was a better way to do this, or simply shift label numbering once I change a certain number of labels before it. Jun 14 at 21:50
• But renumbering by hand as you edit defeats the whole purpose of \label Jun 14 at 21:55
• you only need \label if you reference, so leave it out and just make up a name as you add the reference, using the same in \labeland \ref Jun 14 at 21:59

The reason LaTeX has \label is to avoid this problem.

\documentclass{article}
\usepackage{amsmath}
\begin{document}

aaaaa
$$\label{dog} d=1$$
aaaaa
$$\label{cat} c=2$$
aaaaa
$$\label{rabbit} r=10$$

See  $c$ is defined in \eqref{cat}
\end{document}



can be edited to

\documentclass{article}
\usepackage{amsmath}
\begin{document}

aaaaa
$$\label{dog} d=1$$
aaaaa

aaaaa
$$\label{rabbit} r=10$$
aaa
$$\label{cat} c=2$$

See  $c$ is defined in \eqref{cat}
\end{document}


Moving the middle equation to the end, the \eqref (or \ref) will pick up the new number with no changes required other than moving the equation.

It sometimes helps when drafing to useshowkeysso the internal labels are visible

\documentclass{article}
\usepackage{amsmath}
\usepackage{showkeys}
\begin{document}

aaaaa
$$\label{dog} d=1$$
aaaaa

aaaaa
$$\label{rabbit} r=10$$
aaa
$$\label{cat} c=2$$

See  $c$ is defined in \eqref{cat}
\end{document}


produces

Avoid using numeric labels, they work exactly as shown here, but a human looking at the source may be misled thinking eq:2 is equation 2

• I really didn't want to use this kind of "string" name for labels as having several definitions, lemmas, theorems and equations would demand too much work to come up with names, but it is what it is (and numbering labels defeats the purpose of labels, that's true). I was only curious how people who write large files handle so many label names. Jun 15 at 2:28
• @園田海未 most documents that I see have many more equations than references to equations so do not need so many \label but if you do want to auto generate labels, look at other systems, eg your comment above has label comment1614445_647775 and can be referenced using #comment1614445_647775 . So you could use timestamps or even eq1, eq2, ... so long as you treat them as internal unchanging ids. No scheme that involves renaming cross references in the entire file collection every time you move an equation in the source should ever be used Jun 15 at 6:58

As David Carlisle pointed out in the comments, trying to manually handle numbers in labels defeats the purpose of labels. I'd go so far as to say that LaTeX is all about handling this for you.

Here's how I procede. I didn't invent this process, but I don't remember where I got it from.

• Each label starts with fig:, sec:, eq:, chap:, item:, and so on, depending on what sort of object I'm labeling. It isn't mandatory at all, it just helps me find my way.
• After : I just write a short but clear description of the object. Even if it's a bit long, any civilized editor will typeset it for me anyway.

Examples:

\chapter{My grand project}\label{chap:grand_project}
\begin{enumerate}
\item\label{item:intro} The introduction will be\dots
\item\label{item:goal} I'll be aiming at\dots
\end{enumerate}
Gauss Law is:
$$\label{eq:gauss_law} \phi=\frac{Q_{\text{int}}}{\varepsilon_0}$$

See equation~\eqref{eq:gauss_law} to enable my grand projet,
which goal is described in point~\ref{item:goal} on page~\pageref{chap:grand_project}.
`

Sorry for the silly example, you get the idea. ;-)