# Cite references in the order that they appear in another file

Suppose I have file A.tex that is the main document and has a list of references, say

[1] Reference 1
[2] Reference 2
[3] Reference 3
[4] Reference 4


There is also B.tex which is like a letter and I want to be able to cite some references from A in B, keeping the order as in A. For example, I would like to cite [2] and [4] in B and also have the reference list

[2] Reference 2
[4] Reference 4


at the end of B. Is this possible and how?

• Can you please provide a minimal example? You have tagged this both Biblatex and BibTeX. Are you using Biblatex with backend=bibtex? That's the only way I can make sense of the tagging. – cfr Oct 17 '15 at 22:27
• That sounds like a complicated issue. See also the distantly related and not yet answered Excluding items cited in another .tex file from biblatex bibliography? – moewe Oct 18 '15 at 5:20
• @cfr, I am interested in solution based on both Biblatex and BibTex. Providing a minimal example is difficult besides what I wrote above since I don't know how to do it! – passerby51 Oct 18 '15 at 19:01
• So Biber isn't an option at all? That's a shame. For help creating an example, see here. – cfr Oct 18 '15 at 19:11
• @cfr, it could be, I am all ears! Biber is a bit more inconvenient since I have to run it separately on the .bcf file every time (?), while runing pdflatex on a document containing ...[backend=bibtex]{biblatex} once seems to work. I wonder if there is an easy solution to my problem using Biber? Can I, for example, pass the .bcf file from A through Biber to achieve what I am after? – passerby51 Oct 18 '15 at 20:31

Here is a solution using the docmute package.

The idea is to import the other document in a savebox but not actually typeset it. In order to be able to print only those entries cited in our actual main document we will have to use a refsegment. To ensure that all defernumbers features work as expected we also always print the bibliography from the the other document to make sure the numbering is fine.

\makeatletter
\defbibenvironment{plainimport}{}{}{}
\newsavebox{\importbox}
\newcommand{\importcites}[1]{%
\sbox\importbox{\vbox{%
\citetrackerfalse
\begin{refsegment}
\input{#1}
\let\blx@anchor\@empty
\printbibliography[env=plainimport,segment=\therefsegment]
\end{refsegment}}}}
\makeatother


We then have a command \importcites which takes the file name of the .tex document we want to import the citations from. Use it directly after \begin{document} of your main file.

In the example setup \jobname.tex corresponds to your file B, and \jobname-ext.tex is file A. The technical machinery needs to reside in file B, file A is only ever mentioned in \importcites. You will have to call \printbibliography in file B with segment=\therefsegment (or segment=0) to work properly. If you omit the segment argument you will get to see the references of file A as well.

MWE

\documentclass[british]{scrartcl}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=numeric,backend=biber,sorting=none,backref=true,defernumbers=true]{biblatex}
\usepackage{docmute}

\usepackage{filecontents}
\begin{filecontents*}{\jobname-ext.tex}
\documentclass[british]{scrartcl}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=numeric,backend=biber,sorting=none]{biblatex}

\begin{document}
\cite{sigfridsson} and \cite{geer} and \cite{worman} and \cite{cicero}
\end{document}
\end{filecontents*}

\makeatletter
\defbibenvironment{plainimport}{}{}{}
\newsavebox{\importbox}
\newcommand{\importcites}[1]{%
\sbox\importbox{\vbox{%
\citetrackerfalse
\begin{refsegment}
\input{#1}
\let\blx@anchor\@empty
\printbibliography[env=plainimport,segment=\therefsegment]
\end{refsegment}}}}
\makeatother

\begin{document}
\importcites{\jobname-ext}
\cite{geer} and \cite{cicero}
\printbibliography[segment=\therefsegment]
\end{document}


• Thanks. It mostly worked with some caveats: (1) I had to comment out float environments in the A document, otherwise I would get errors, (2) docmute apparently drops the preamble of A, so I had to move those definitions to the preamble of B, (3) I use hyprref package to make the citations hyperlink so that they jump to the reference list once clicked. This didn't work in B, and I assume it is because they point to ref. list in A somehow? It would be really nice if (3) can be fixed. – passerby51 Oct 18 '15 at 20:17
• Oh... and another wired problem: Since A ends in some appendices, now all sections in B are appendices... – passerby51 Oct 18 '15 at 20:23
• @passerby51 This solution would be much better if there was a way to essentially disable all commands in A save for the macros biblatex provides (especially floats and \appendix, just write \let\appendix\@empty, but one will have to make sure to gobble enough arguments). We can get correct hyperlinking with the fix I edited in just a few seconds ago. – moewe Oct 19 '15 at 5:47
• sorry for the long delay. I have tried your fix for hyperlinking (seems to be \let\blx@anchor\@empty), but it doesn't seem to help. Any ideas? – passerby51 Dec 22 '15 at 18:05
• @passerby51 Mhhh, could you possible come up with an example that makes troubles. At the moment I cannot say why I thought that this was the right way to go then, but I will happily investigate with something more to go on. – moewe Dec 22 '15 at 18:18