How to add label to equation for reference in LaTeX?

This tutorial will teach you how to add labels to equations and use them as references later.

There are many methods for display math mode in LaTeX, among them you have to choose the methods that return equation number. Because without number equation, how can you add labels and use them as references?

Use label with ref command in latex

First, you need to know how to use label and ref commands, which together will complete this task.

Process is very simple as first adding label to equation and then calling this label by ref command.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
Now, let's write down a simple trigonometric identity:
 \begin{equation}
    \sin^2 \theta + \cos^2 \theta = 1 \label{eq:trig}
 \end{equation}
Equation~\ref{eq:trig} represents the Pythagorean identity for sine and cosine.
\end{document}

Output :

This figure shows the use of label and ref commands. How they depend on each other.

In most cases the reference number is enclosed in parenthesis. You can do that if you want. Add parenthesis to both sides of the ref command.

\documentclass{article}
\begin{document}
Another important equation is the quadratic formula:
 \begin{equation}
    x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \label{eq:quadratic}
 \end{equation}
This is Equation(\ref{eq:quadratic}), commonly used to find the roots of a quadratic equation~\ref{eq:quadratic}.
\end{document}

Output :

The ref command is passed into the parenthesis.

Use label with eqref command in latex

By default, eqref command is not stored in LaTeX. For this, amsmath package needs to be added to preamble.

eqref command usage is similar to ref. But, there is a difference in output. Because the eqref command returns parenthesis with reference, note in the above output that the ref command does not, extra should be added.

\documentclass{article}
\usepackage{amsmath}  % Required for the eqref
\begin{document}
\section*{Differential Equation System}
Consider the following system of ordinary differential equations (ODEs):
\begin{equation}
  \frac{dx}{dt} = a x^2 - b \label{ode1}  
\end{equation}
\begin{equation}
      \frac{dy}{dt} = c x - d y^2 \label{ode2}   
 \end{equation}
We can refer to these ODEs as \eqref{ode1} and \eqref{ode2}, which will include parenthesis around the equation numbers.
\end{document}

Output :

Use of eqref command is shown, although similar in functionality, but different in terms of output.

Multi Equation Reference in latex

Suppose there are many equations at once, some of which want to be identified by reference. Then add the multi label. For example

\documentclass{article}
\usepackage{amsmath}  % Required for the align environment
\begin{document}
 \begin{align}
    F &= ma \label{eq:newton} \\
    E &= mc^2 \label{eq:einstein} \\
    \sin^2 \theta + \cos^2 \theta &= 1 \label{eq:trig}
 \end{align}
\noindent We can refer to these equations as \eqref{eq:newton}, \eqref{eq:einstein}, and \eqref{eq:trig}, each with parenthesis around the equation numbers.
\end{document}

Output :

You can add multi-number equations as references at the same time.

Change number style for reference

You can change the reference number style. Like bold, color etc.

\documentclass{article}
\usepackage{amsmath, xcolor}  % Required for the align environment and color package
% Define custom styles for references
\newcommand{\boldref}[1]{\textbf{\ref{#1}}}
\newcommand{\italref}[1]{\textit{\ref{#1}}}
\newcommand{\colorref}[2]{\textcolor{#1}{\ref{#2}}}
\begin{document}
Consider the following set of equations:
 \begin{align}
    F &= ma \label{eq:newton} \\
    F &= m\frac{dv}{dt} \label{eq:einstein} \\
    \sin^2 \theta + \cos^2 \theta &= 1 \label{eq:trig}
 \end{align}

We can refer to these equations with custom styles:
 \begin{itemize}
    \item Bold reference: Equation~\boldref{eq:newton}
    \item Italics reference: Equation~\italref{eq:einstein}
    \item Colored reference: Equation~\colorref{red}{eq:trig}
 \end{itemize}
\noindent In this document, we explored multiple mathematical equations and referenced them using custom styles.
\end{document}

Output :

In this output, number style of the reference is changed to different formats.

Label equation with symbol or custom text

Not always that number to use. You can use symbols or custom text if you want. For this I will take the help of tag command. See the code example below.

\documentclass{article}
\usepackage{amsmath}  % Required for the align environment
\begin{document}
\noindent In this document, we explored equations with custom tag using the \texttt{\textbackslash tag} command.
 \begin{align}
    a^2 + b^2 &= c^2 \tag{$\star$} \label{eq:pythagorean} \\
    \int_{0}^{1} x^2 \,dx &= \frac{1}{3} \tag{Integral} \label{eq:integral} \\
    \alpha^2 + \beta^2 &= \gamma^2 \tag{Custom Text} \label{eq:customtext}
 \end{align}
\vspace{.5cm}
\noindent We can refer to these equations as \eqref{eq:pythagorean}, \eqref{eq:integral}, and \eqref{eq:customtext}.
\end{document}

Output :

Symbols and custom text are used instead of numbers in equations.

Share tutorial

Don't forget to share if I have added any value to your education life. See you again in another tutorial. thank you!

Facebook iconTwitter iconWhatsapp iconPinterest icon

Md Jidan Mondal

LaTeX expert with over 10 years of experience in document preparation and typesetting. Specializes in creating professional documents, reports, and presentations using LaTeX.

Leave a Comment

Your email address will not be published. Required fields are marked *