# Make equation reference different to equation tag

I want the 'equation number' that appears in the text to be different to the 'equation number' that appears in the equation. For example, if I have

$$a=b \tag{1} \reftag{2} \label{eqn}$$
\eqref{eqn}


Then the equation should have (1), but the reference is to (2). Is this possible?

Edit: Background

I am trying to make it so I can have two sub equations side by side. My current solution is as follows:

\newlength{\sbsseLl}
\newlength{\sbsseLr}
\newlength{\sbsseLe}
\newlength{\sbsseLle}
\newlength{\sbsseLre}
\newlength{\sbsseLt}
\newcommand{\sidebysidesubequations}[6]{%
% #1    reference label
% #2    left subequation
% #3    left label
% #4    midtext
% #5    right subequation
% #6    right label
%
%Setup the equations to be typed
\def\sbsseEl{#2}
%Compute the width of the left and right side equations as inputted
\settowidth{\sbsseLl}{\begin{math}\displaystyle\sbsseEl\end{math}}
\settowidth{\sbsseLr}{\begin{math}\displaystyle\sbsseEr\end{math}}
\settowidth{\sbsseLt}{(\ref*{#1}a,b)}
%\setlength{\sbsseLt}{\sbsseLt+15mm}
%Compute the extra length to give to each
\setlength{\sbsseLe}{(\linewidth-\sbsseLl-\sbsseLr-\sbsseLt)/2}
\setlength{\sbsseLle}{\sbsseLl+\sbsseLe}
\setlength{\sbsseLre}{\sbsseLr+\sbsseLt+\sbsseLe}
%Construct table with these widths and place equations in cells

\noindent
\begin{subequations}\label{#1}
\begin{tabular}{@{}p{\sbsseLle}@{}p{\sbsseLre}@{}}%p{\sbsseLte}@{}}
$$\sbsseEl \vphantom{\sbsseEr} \label{#3} \tag*{}$$
\renewcommand\theequation{abc}\label{eqn:my}
&
$$\sbsseEr \vphantom{\sbsseEl} \label{#6} \tag*{(\ref*{#1}a,b)}$$
\end{tabular}
\end{subequations}
\newline
}


With this setup, I can write \sidebysidesubequations{eqn:all}{a=b}{eqn:left}{and}{c=d}{eqn:right} and get two equations formatted side by side with the equation number, e.g., (1a,b). However, \ref{eqn:left} gives an empty reference when it should be 1a, whilst \ref{eqn:right} gives the reference 1a,b when it should give 1b. What I would like to do is modify the referencing so that I can assign the correct label to each sub equation, and still have all the references together at the end of the line.

Edit 2: Minimal worked example

\documentclass{article}

\usepackage{amsmath}
\usepackage{cleveref}
\usepackage{calc,etoolbox}

\newlength{\sbsseLl}
\newlength{\sbsseLr}
\newlength{\sbsseLe}
\newlength{\sbsseLle}
\newlength{\sbsseLre}
\newlength{\sbsseLt}
\newcommand{\sidebysidesubequations}[6]{%
% #1    reference label
% #2    left subequation
% #3    left label
% #4    midtext
% #5    right subequation
% #6    right label
%
%Setup the equations to be typed
\def\sbsseEl{#2}
%Compute the width of the left and right side equations as inputted
\settowidth{\sbsseLl}{\begin{math}\displaystyle\sbsseEl\end{math}}
\settowidth{\sbsseLr}{\begin{math}\displaystyle\sbsseEr\end{math}}
\settowidth{\sbsseLt}{(\ref*{#1}a,b)}
%Compute the extra length to give to each
\setlength{\sbsseLe}{(\linewidth-\sbsseLl-\sbsseLr-\sbsseLt)/2}
\setlength{\sbsseLle}{\sbsseLl+\sbsseLe}
\setlength{\sbsseLre}{\sbsseLr+\sbsseLt+\sbsseLe}
%Construct table with these widths and place equations in cells

\noindent
\begin{subequations}\label{#1}
\begin{tabular}{@{}p{\sbsseLle}@{}p{\sbsseLre}@{}}%p{\sbsseLte}@{}}
$$\sbsseEl \vphantom{\sbsseEr} \label{#3} \tag*{}$$
&
$$\sbsseEr \vphantom{\sbsseEl} \label{#6} \tag{\ref*{#1}a,b}$$
\end{tabular}
\end{subequations}
\newline
}

\begin{document}

Here are my equations:
\sidebysidesubequations{eqn:all}{le=ft}{eqn:left}{and}{ri=ght}{eqn:right}
The overall system gets correctly referenced as \cref{eqn:all}'.
However, the left equation gets incorrectly referenced as \cref{eqn:left}', it should be eq. (1a)',
similarly the right gets referenced as \cref{eqn:right}', it should be eq. (1b)'.

\end{document}


Edit 3: Fixed example using solution by Werner

\documentclass{article}

\usepackage{amsmath}
\usepackage{cleveref}
\usepackage{calc,etoolbox}

\makeatletter
\newlength{\sbsseWl}    %Width of left equation
\newlength{\sbsseWm}    %Width of mid text
\newlength{\sbsseWr}    %Width of right equation
\newlength{\sbsseWt}    %Width of tag
\newlength{\sbsseWe}    %Remaining width on line
\newlength{\sbsseWd}    %Remaining width divided into pieces

\newcommand{\sidebysidesubequations}[6]{%
% #1    reference label
% #2    left subequation
% #3    left label
% #4    midtext
% #5    right subequation
% #6    right label

%Setup the equations to be typed
\def\sbsseEl{#2}
\def\sbsseEm{\textrm{#4}}
\def\sbsseEr{#5}
\def\sbsseEt{(\ref*{#1}a,b)}
%Compute the widths
\settowidth{\sbsseWl}{\begin{math}\displaystyle\sbsseEl\end{math}}
\settowidth{\sbsseWm}{\begin{math}\displaystyle\sbsseEm\end{math}}
\settowidth{\sbsseWr}{\begin{math}\displaystyle\sbsseEr\end{math}}
\settowidth{\sbsseWt}{\sbsseEt}
\setlength{\sbsseWe}{\linewidth-\sbsseWl-\sbsseWm-\sbsseWr-\sbsseWt}

%Beigin equation typesetting, with label for overall subequations
\begin{subequations}\ltx@label{{#1}}
\begin{displaymath}
%Left equation and label
\sbsseEl\refstepcounter{equation}\ltx@label{{#3}}
%Space, and midtext if any
\if\relax\detokenize{#4}\relax
\setlength{\sbsseWd}{\sbsseWe/3}
\hspace{\sbsseWd}
\else
\setlength{\sbsseWd}{\sbsseWe/4}
\hspace{\sbsseWd}\sbsseEm\hspace{\sbsseWd}
\fi
%Right equation and label
\sbsseEr\refstepcounter{equation}\ltx@label{{#6}}
%Tag
\tag*{\sbsseEt}
\end{displaymath}
\end{subequations}
}
\makeatother

\begin{document}

Here are my equations:
\sidebysidesubequations{eqn:all}{le=ft}{eqn:left}{and}{ri=ght}{eqn:right}
The overall system gets referenced as \cref{eqn:all}', the left equation gets referenced as \cref{eqn:left}', the right gets referenced as \cref{eqn:right}'.

\end{document}

• Background given. Feel free to either answer the original question as stated, or provide a better solution to the overall problem.
– Eddy
Nov 20, 2020 at 18:47
• @Eddy: Can you also make a minimal document that we can copy-and-paste-and-compile and see what your setup looks like? Something that uses \sidebysidesubequations.
– Werner
Nov 20, 2020 at 18:56
• @campa and Werner Thanks for your interest, a MWE has been added. Let me know if there are any problems with getting it working.
– Eddy
Nov 20, 2020 at 19:43
• Note that I'm fine mucking around with the layout to make it look nice, its just the referencing that I find difficult to work with.
– Eddy
Nov 20, 2020 at 19:46

Here is an implementation of \sidebysidesubequations that could work:

\documentclass{article}

\usepackage{amsmath}
\usepackage{hyperref}

\makeatletter
\newcommand{\sidebysidesubequations}[6]{%
% #1    reference label
% #2    left subequation
% #3    left label
% #4    midtext
% #5    right subequation
% #6    right label
%
\begin{subequations}
\ltx@label{#1}%
$#2\refstepcounter{equation}\ltx@label{#3} % https://tex.stackexchange.com/a/53091/5764 \if\relax\detokenize{#4}\relax \qquad \else \quad\text{#4}\quad \fi #5\refstepcounter{equation}\ltx@label{#6} \tag*{(\ref*{#1}a,b)}$
\end{subequations}
}
\makeatother

\begin{document}

See equations~\eqref{eqn:left} and~\eqref{eqn:right}.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam quam ligula,
venenatis ut mi non, feugiat imperdiet purus. Donec scelerisque suscipit
mauris euismod maximus. Nunc lacus diam, efficitur in justo ac, imperdiet
ultrices dolor. Nulla sed luctus massa. Vestibulum ornare venenatis justo
malesuada sagittis. Etiam tempus nec lorem quis commodo.
\sidebysidesubequations{eqn:all}{a=b}{eqn:left}{and}{c=d}{eqn:right}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam quam ligula,
venenatis ut mi non, feugiat imperdiet purus. Donec scelerisque suscipit
mauris euismod maximus. Nunc lacus diam, efficitur in justo ac, imperdiet
ultrices dolor. Nulla sed luctus massa. Vestibulum ornare venenatis justo
malesuada sagittis. Etiam tempus nec lorem quis commodo.

\clearpage

See equation~\eqref{eqn:other}.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam quam ligula,
venenatis ut mi non, feugiat imperdiet purus. Donec scelerisque suscipit
mauris euismod maximus. Nunc lacus diam, efficitur in justo ac, imperdiet
ultrices dolor. Nulla sed luctus massa. Vestibulum ornare venenatis justo
malesuada sagittis. Etiam tempus nec lorem quis commodo.
\begin{align}
a &= b & c &= d \label{eqn:other}
\end{align}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam quam ligula,
venenatis ut mi non, feugiat imperdiet purus. Donec scelerisque suscipit
mauris euismod maximus. Nunc lacus diam, efficitur in justo ac, imperdiet
ultrices dolor. Nulla sed luctus massa. Vestibulum ornare venenatis justo
malesuada sagittis. Etiam tempus nec lorem quis commodo.

\end{document}


The two-page output is just for comparison.

• Thanks for this. When I copied your definition of \sidebysidesubequations into my MWE the resultant PDF had a number of problems, but I managed to fix them by replacing \ltx@label{#1} with \ltx@label{{#1}}, and similarly for others. Do you know why I had to do this? Otherwise your solution works very well! I'll have a play with it tomorrow and probably accept as the answer.
– Eddy
Nov 20, 2020 at 20:54
• @Eddy: No, that's weird, but it works.
– Werner
Nov 20, 2020 at 22:02