29

I cant find a good way of adding a \cite to an equation. I'd like to give a reference to the equation's source, but I can't figure out how to typeset it nicely. If I include it in with the equation itself, it pushes the alignment leftwards and feel too much like it's invading the equation's space. I've tried putting an \hfill\cite{example} on the line after the equation, but there's too much vertical space between the equation and the reference.

I'd love to know if there's a commonly accepted way of doing this that I haven't managed to find. Failing that, if anyone has any not-too-inelegant compromises, that'd be great too.

4
  • 1
    Welcome to TeX.SE! It would be also great if you canadd a minimal working example (MWE) that illustrates your problem.
    – percusse
    Commented Nov 14, 2012 at 23:49
  • 2
    What would be wrong with something like \begin{equation}\label{1}...\end{equation}, and then Equation~\ref{1} can be found in \cite{} (or before the equation, maybe)?
    – T. Verron
    Commented Nov 14, 2012 at 23:56
  • 2
    @Tbbe: you can always use the marginnote package. Compare this question.
    – bodo
    Commented Jun 19, 2015 at 9:45
  • Thank you @ canaaerus it could be a solution! I'll dig deeper into marginnote and see what it can.
    – user2821
    Commented Jun 19, 2015 at 19:54

3 Answers 3

29

You shouldn't add the references inside the equation IMO, but outside as in this code:

% arara: pdflatex: {synctex: yes}
% arara: biber
% arara: pdflatex: {synctex: yes}
% arara: pdflatex: {synctex: yes}
%
\documentclass{article}
\usepackage{filecontents}
\usepackage[backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}
\begin{document}
From the famous inequality math relation~\cite{companion}
\begin{equation}
  y \neq x
\end{equation}
%
Or you can also say:
\begin{equation}
  y \neq x
\end{equation}
as proved by~\cite{companion} 
\printbibliography
\end{document}

enter image description here

Thus leaving equations to themselves. This reduces the confusion between the parameters and the citation number. (Equations are equations - Don't put something else inside :-))

3
  • 1
    Fair enough - I wasn't sure if there was a commonly-accepted way to incorporate the reference into the equation line, but if not, then that'll have to do. Thanks very much!
    – TroyHurts
    Commented Nov 18, 2012 at 19:17
  • 2
    Equations are equations - Don't put something else inside :-): except punctuation marks maybe. Touchy topic :D
    – anderstood
    Commented Jun 17, 2015 at 20:59
  • 1
    I would write the second reference as as proved in Ref.~\cite{companion}. or as proved by~\citeauthor{companion}.. Oh, and add punctuation to the equations.
    – Jost
    Commented Jun 20, 2015 at 9:35
9
+50

The following solution only works for the standard environment equation without package amsmath. It stores the cite command in macro \@eqcite, which is then set left to the equation number:

\documentclass{article}
\usepackage{filecontents}
\usepackage[backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}

\makeatletter
\newcommand*{\eqcite}[1]{%
  \def\@eqcite{\org@cite{#1}}%
}
\let\@eqcite\@empty
\def\@eqnnum{%
  {%
    \normalfont
    \normalcolor
    \ifx\@eqcite\@empty
    \else
      \@eqcite\space
    \fi
    (\theequation)%
  }%
}
\g@addto@macro\equation{%
  \let\org@cite\cite
  \let\cite\eqcite
}
\let\org@cite\cite
\makeatother

\begin{document}
The famous inequality math relation:
\begin{equation}
  y \neq x \cite{companion}
\end{equation}
\printbibliography
\end{document}

Result

The MWE is based on Harish Kumar's answer.

Different lines

As requested in the comment, a version with the equation number and citation on different lines. IMHO, also this does not look better. The implementation can be done via a tabular. The optional argument controls the vertical alignment of the two lines with respect to the base line of the equation.

\documentclass{article}
\usepackage{filecontents}
\usepackage[backend=biber, style=authoryear]{biblatex}
\addbibresource{biblatex-examples.bib}
\usepackage{lipsum}

\makeatletter
\newcommand*{\eqcite}[1]{%
  \def\@eqcite{\org@cite{#1}}%
}
\let\@eqcite\@empty
\def\@eqnnum{%
  {%
    \normalfont
    \normalcolor
    \ifx\@eqcite\@empty
      (\theequation)%
    \else
      \begin{tabular}[t]{@{}r@{}}(\theequation)\\\@eqcite\end{tabular}%
    \fi
  }%
}
\g@addto@macro\equation{%
  \let\org@cite\cite
  \let\cite\eqcite
}
\let\org@cite\cite
\makeatother

\begin{document}
The famous inequality math relation:
\begin{equation}
  y \neq x \cite{companion}
\end{equation}
\lipsum[2]
\printbibliography
\end{document}

Result different lines

Citation in line below with \vadjust

In the previous example, the equation moves to the left, because the available space is reduced by the longer citation in the author/year style.

\llap could be used for the citation, but the risk for overprinting the equation is much too large. The following example puts the citation below the equation via \vadjust. Again it only works for LaTeX without package amsmath:

\documentclass{article}
\usepackage{filecontents}
\usepackage[backend=biber, style=authoryear]{biblatex}
\addbibresource{biblatex-examples.bib}
\usepackage{lipsum}

\newcommand*{\eqcite}[1]{%
  \vadjust{%
    \smallskip
    \hbox to \linewidth{\hfill\cite{#1}}%
  }%
}

\begin{document}
The famous inequality math relation:
\begin{equation}
  y \neq x
  \eqcite{companion}
\end{equation}
\lipsum[2]
\printbibliography
\end{document}

Result with citation below equation using \vadjust

6
  • Yes, that is very neat and use of LaTeX script at a level I'd never find out myself!
    – user2821
    Commented Jun 24, 2015 at 20:13
  • Sorry to ask for more, but is there an easy way to update the macro and place equation number and citation on different lines?
    – user2821
    Commented Jun 24, 2015 at 21:27
  • 1
    @Tbbe See updated answer. Commented Jun 24, 2015 at 21:35
  • It's just perfect! It also inspires me to learn more.
    – user2821
    Commented Jun 24, 2015 at 21:50
  • Hello, I found there is a problem when a page break was located between the equation and the \eqcite. These two (\eqcite and the equation) should not be separated into two pages. Is there a way to resolve it?
    – Y. zeng
    Commented Jun 9, 2022 at 0:17
4

A Johnny-come-lately solution, using stackengine. This first approach only works in the standard equation environment.

\documentclass{article}
\usepackage{stackengine,filecontents}
\begin{filecontents*}{mybib.bib}
@ARTICLE{myref,
  AUTHOR = "last, first",
  TITLE = "This is the title",
  JOURNAL = "The Lancet",
  YEAR = "2014"
}
\end{filecontents*}
\bibliographystyle{unsrt}
\newcommand\citeequation[2]{%
  \stackengine{0pt}{$\displaystyle#1$}{\makebox[\linewidth]{\hfill \cite{#2}\kern20pt}}
    {O}{c}{F}{T}{L}
}
\begin{document}
\begin{equation}
\citeequation{E=mc^2}{myref}
\end{equation}
\bibliography{mybib}
\end{document}

enter image description here

Here's an alternate approach that works with align and aligned, where \aligncite must be called immediately after the alignment point, but requires, for the first in the set of aligncite calls, to have the optional argument tuned to the particular equation. When no optional argument is used, it uses the previous setting.

\alkerndefault is the default offset of the cite from the margin, for the case of a perfectly centered (baseline) alignment point (set to 20pt here). alkernbias is the bias to be applied for any given align set of equations. While set here to 0pt, it is globally redefined whenever the optional argument to \aligncite is employed.

\documentclass{article}
\usepackage{stackengine,filecontents,amsmath}
\begin{filecontents*}{mybib.bib}
@ARTICLE{myref,
  AUTHOR = "last, first",
  TITLE = "This is the title",
  JOURNAL = "The Lancet",
  YEAR = "2014"
}
@ARTICLE{myref2,
  AUTHOR = "last, first",
  TITLE = "Next title",
  JOURNAL = "JAP",
  YEAR = "2015"
}
\end{filecontents*}
\bibliographystyle{unsrt}
\newcommand\alkerndefault{20pt}% DETERMINES OFFSET OF BASELINE (CENTERED) CASE
\newcommand\alkernbias{0pt}% BIAS TO SHIFT WHEN ALIGNMENT POINT IS NOT CENTERED
\newcommand\aligncite[2][\relax]{%
  \ifx\relax#1\else\gdef\alkernbias{#1}\fi\def\alkern{\alkernbias}%
  \stackengine{0pt}{}{\makebox[\dimexpr\linewidth-2\dimexpr\alkerndefault]{%
    \hfill \protect\cite{#2}\kern-\dimexpr\alkern}}
    {O}{c}{F}{T}{L}
}
\begin{document}
\begin{align}
  Baseline/&\aligncite{myref}/Baseline
\end{align}
\begin{equation}
\begin{aligned}
 E &\aligncite[33.5pt]{myref}= mc^2\\
 y &\aligncite{myref2}= Ax^2 + Bx + C
\end{aligned}
\end{equation}
\begin{align}
 y &\aligncite{myref2}= mx + b\\
 E &\aligncite[18pt]{myref}= mc^2
\end{align}
\bibliography{mybib}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .