7

What is the shortest and convenient way to Put reference above equal sign and refer to it in text, i.e. do something like this:

Sample code

It can be done manually, by using \stackrel{}{} command and manual numbering. My question is: can it be done in a smarter way?

  • Please clarify what (1) stands for. Is it supposed to be an automatically generated number (an equation number, maybe?), is it a cross-reference to some other result (a numbered theorem, maybe?), or is it something else? Please advise. – Mico Jul 8 '18 at 17:20
2

You haven't stated what you consider to be "shortest", "convenient", "smart", or "reference". However, I'll assume that a LaTeX macro (called \numeq in the example below) which takes one argument comes reasonably close to satisfying your objective.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\newcommand\numeq[1]%
  {\stackrel{\scriptscriptstyle(\mkern-1.5mu#1\mkern-1.5mu)}{=}}
\begin{document}
\begin{equation} \label{eq:xyz}
X \numeq{n} Y+Z
\end{equation}
A cross-reference to equation \eqref{eq:xyz}.
\end{document}
2

Below, I have defined a macro \labelrel that I believe should do what you want. It takes two arguments of which the first is the (relation) symbol you would like to label and the second is a label name. The labels are incremented automatically and you can refer to them using \eqref as if they were equations.

\documentclass{article}

\usepackage{amsmath}

\newcounter{relctr} %% <- counter for relations
\everydisplay\expandafter{\the\everydisplay\setcounter{relctr}{0}} %% <- reset every eq
\renewcommand*\therelctr{\alph{relctr}} %% <- label format

\newcommand\labelrel[2]{%
  \begingroup
    \refstepcounter{relctr}%
    \stackrel{\textnormal{(\alph{relctr})}}{\mathstrut{#1}}%
    \originallabel{#2}%
  \endgroup
}
\AtBeginDocument{\let\originallabel\label} %% <- store original definition

\begin{document}

  Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
  eirmod invidunt, and therefore
  \begin{equation}\label{myeq}
      X \labelrel={myeq:equality} Y + Z \labelrel\leq{myeq:inequality} \ldots.
  \end{equation}
  The equality~\eqref{myeq:equality} in equation~\eqref{myeq} was proven in Theorem~123,
  and the inequality~\eqref{myeq:inequality} is self-explanatory.
  Here is another equation,
  \[
      f(A \cap B) \labelrel\subseteq{somelabelname} f(A) \cap f(B)
  \]
  which contains an inclusion~\eqref{somelabelname} unrelated to equation~\eqref{myeq}.

\end{document}

enter image description here

A few remarks:

  • I'm using letters instead of numbers to avoid any clashes with equation numbers. To use numbers, replace (both instances of) \alph by \arabic above.

  • The labels start with (a) in every equation. If you don't want this you should remove the \everydisplay line. If you want the numbering to start over at the beginning of every section you should use \newcounter{relctr}[section].

  • It is also possible to refer to the relations in equation (1) as (1a), (1b), etc without changing their tags. This is accomplished by replacing the \therelctr line by \renewcommand*\therelctr{\theequation\alph{relctr}}. It does mean that every equation that has labelled relations must be numbered.

  • I'm storing the definition of \label in \originallabel because amsmath redefines the \label macro inside equations. I do this \AtBeginDocument in case any packages (like hyperref) loaded after this code change the definition.

  • I'm using \mathstrut (which is equivalent to \phantom() to ensure that every label is placed at the same height, independent of the height of the relation it is decorating. You can remove it if you don't like this.

  • \begingroup and \endgroup limit the scope of the effect of \refstepcounter. Without them it would no longer be possible to reference the equation itself.


2

Perhaps this is what you are looking for? I've assumed that you basically want the equation reference number (which would normally appear on the right hand side of the equation) changed to be positioned above the equal sign.

  • Label the equations as you normally would using \label{...}
  • Use \stackrel{(\ref{...})}{=} to get the reference number above the equal sign.
  • At the end of the equation use the custom command \nonumberthis which suppresses the reference number from appearing at the right hand side but keeps the counter going.

enter image description here

\documentclass{article}
\usepackage{mathtools}

\newcommand\nonumberthis{\nonumber\refstepcounter{equation}}

\begin{document}

\noindent \ldots We arrive to relationship
%
\begin{equation}\label{mylabel}
   X \stackrel{(\ref{mylabel})}{=} Y + Z = \ldots, \nonumberthis
\end{equation}
%
where in (\ref{mylabel}) we used Theorem 123. 
And another example
%
\begin{equation}\label{mylabel2}
   A \stackrel{(\ref{mylabel2})}{=} B + C = \ldots, \nonumberthis
\end{equation}
%
is given by the reference (\ref{mylabel2}).

\end{document}

The \nonumberthis command was based off this answer .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.