Citing the source of an equation?
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}
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 :-)
)
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}
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}
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}
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}
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}