# Finding the first appearance of citation

Is it possible to define a LaTeX command that takes as input a citation key and gives as output the section of the article, in which this key appeared the first time (inside \cite{}), i.e. where this given reference was first referred to? (not using bibtex or biblatex)

• Could you clarify what you mean by "not using bibtex or biblatex"? – Mico Feb 23 '16 at 20:10
• By using the built-in bibliography management of LaTeX. – Moppe Feb 26 '16 at 11:02
• The "built-in bibliography management [tools] of LaTeX" are rather rudimentary, I'm afraid. Are you talking about a hand-assembled thebibliography environment? – Mico Feb 26 '16 at 11:53
• Yes, I am. And I do know they are rudimentary, but the situation is what it is. I just want to know, what data is there available on the citations and how can it be accessed? – Moppe Feb 29 '16 at 10:48
• @Mico they're also required by journals in some situations (i.e. not obsolete), so the question is still interesting. – Chris H Feb 29 '16 at 11:12

I'm not sure about your use case, but here a starting point for you with package backref. At least, it prints the number of section(s) where each bib.-item was cited after the item itself.

\documentclass[a4paper]{article}

\usepackage[ref]{backref}
\renewcommand*{\backref}[1]{}
\renewcommand*\backrefalt[4]{%
\ifcase #1 %
No citations.%
\or
One citation in section #2.%
\else
#1 citations in sections #2.%
\fi
}

\begin{document}

\section{First Section}
\cite{Rei91}

\section{Second Section}
\cite{CA}, \cite{MSW00}, \cite{Rei91}

\section{Third Section}
\cite{MSW00}, \cite{Rei91}

\section{Fourth Section}
\cite{CA}, \cite{MSW00}, \cite{Rei91}

\begin{thebibliography}{99}
\bibitem{HB98} Huynen, M.~A. and Bork, P. 1998. Measuring genome
evolution. {\itshape Proceedings of the National Academy of Sciences
USA} 95:5849--5856.

\bibitem{CA} Caprara, A. 1997. Sorting by reversals is difficult. In:
{\itshape Proceedings of the First Annual International Conference
on Computational Molecular Biology (RECOMB 97),} New York: ACM.
pp. 75--83.

\bibitem{MSW00} McLysaght, A., Seoighe, C. and Wolfe, K.~H. 2000. High
frequency of inversions during eukaryote gene order evolution.  In
Sankoff, D. and Nadeau, J.~H., editors, {\itshape Comparative
Genomics}, Dordrecht, NL: Kluwer Academic Press. pp. 47--58.

\bibitem{Rei91} Reinelt, G. 1991. {\itshape The Traveling Salesman -
Computational Solutions for TSP Applications.} Berlin: Springer
Verlag.

\end{thebibliography}

\end{document}


• The case is, that a book contains a bibliography after each section. To avoid repeating printing references again, it would be useful to say that you can find the reference in the bibliography of this section. An example: You have a citation \cite{MSW00} in section 2. You cite it again in a later section, and you can then cite it as, let's say [2.3] (third reference in section 2). – Moppe Feb 26 '16 at 11:13

A colleague had a solution for the problem:

\documentclass[a4]{article}
\makeatletter
\renewcommand\@bibitem[1]{\item\if@filesw\immediate\write\@auxout
{\string\bibcite{#1}{\theenumiv}}\fi\ignorespaces}

\renewenvironment{thebibliography}[1]
{\section*{\refname}%  %% use \bibname instead of
%  %% \refname if using the
%  %% report or book document classes
\@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}%
\list{\@biblabel{\the\c@section.\@arabic\c@enumiv}}%
{\settowidth\labelwidth{\@biblabel{#1}}%
\leftmargin\labelwidth
\@openbib@code
\usecounter{enumiv}%
\let\p@enumiv\@empty
\renewcommand\theenumiv{\the\c@section.\@arabic\c@enumiv}}%
\sloppy
\clubpenalty4000
\@clubpenalty \clubpenalty
\widowpenalty4000%
\sfcode\.\@m}
{\def\@noitemerr
{\@latex@warning{Empty thebibliography' environment}}%
\endlist}
\makeatother

\begin{document}

\section{Foo}

Blah blah blah~\cite{cite1}, and see later~\cite{cite2}.

\begin{thebibliography}{99}
\bibitem{cite1} Foo bar.
\end{thebibliography}

\section{Bar}

Bleh bleh bleh~\cite{cite2}. And also~\cite{cite1}.

\begin{thebibliography}{99}
\bibitem{cite2} Baz bof.
\end{thebibliography}

\end{document}
`