# Citing and printing references from another tex file

I have two tex files, tex1.tex and tex2.tex. I have defined multiple bibitems on tex1.tex and printed the bibliography there. Is it possible to reference some of the biblatex items from tex1 in tex2, and print the corresponding referenced items in tex2?

MWE:

tex1.tex:

\documentclass{article}

\begin{document}

I'm citing~\cite{cite2} first and then~\cite{cite1}

% I could also manually write the bibitems here
\bibliographystyle{unsrt}
\bibliography{tex1_biblio}

\end{document}


tex1_biblio.bib:

@article{cite1,
author =       "Author1",
title =        "Title1",
journal =      "Journal1",
volume =       "8",
number =       "20",
pages =        "888",
year =         "2000",
DOI =          ""
}

@article{cite2,
author =       "Author2",
title =        "Title2",
journal =      "Journal2",
volume =       "3",
number =       "10",
pages =        "77",
year =         "2010",
DOI =          ""
}


tex2.tex:

\documentclass{article}
\usepackage{biblatex}

\begin{document}

\section{Sec1}
I'm citing~\cite{cite1} from mwe1 (shoud be [2])

\printbibliography % (?)

\section{Sec2}
I'm citing~\cite{cite1} from mwe1 (shoud be [2])

\printbibliography % (?)

\end{document}


So, if I cite [2] (from tex1) in tex2, I have a bibliography as

[2] ref 2 from tex 1 ...


If this is possible, would it be also possible to print these references in tex2 multiple times? (for example, for different sections)

I'm aware of the xcite package but I can't figure out how to make it work and I think it doesn't allow me to print the bibliography on a different tex file

• I'm not aware of any such method, though your account is pretty sketchy so I'm not completely sure. What is the motivation for this, though? It may be that there are other possibilities to achieve (more or less) what you are looking for. – jon Feb 20 '17 at 20:58
• Sketchy? I'm asking because I was writing a paper and I need to use some of its references (using the same citation numbers) in a letter about that paper, and I didn't want to copy and paste the refs manually from the PDF file :o – PerroNoob Feb 20 '17 at 21:49
• Well, I wondered if there was a real TeX-related reason as opposed to just an ad hoc one. The 'problem' you face is why BibTeX (et cetera) was invented, after all. Failing that, I'd be inclined to harness the power of grep to make the cutting and pasting even more painless. However, it is possible someone else has an answer. – jon Feb 20 '17 at 22:43
• @jon I don't think BibTeX would especially help, would it? Not directly. I mean, if you were using BibTeX, you could, I think, solve the problem quite elegantly, but I wouldn't say it is part of its purpose to solve it. – cfr Feb 20 '17 at 23:37
• @jon Yes. But that is not really the problem here. The problem is to get the numerical labels to match those assigned to sources in the paper, given that only a subset will be referenced in the letter and not necessarily in the same order. If you just use BibTeX with the same style and .bib, you won't get e.g. 4 and 6 but, say, 2 and 1 or whatever. – cfr Feb 20 '17 at 23:57

tex1.tex being the paper, upon which bibtex is run should look like a normal document.

\documentclass{article}

\begin{document}

I'm citing~\cite{cite2} first and then~\cite{cite1}

% I could also manually write the bibitems here
\bibliographystyle{unsrt}
\bibliography{tex1_biblio}

\end{document}


tex2.tex can then make use of the xcite package to use the same reference labels without generating a bibliography.

\documentclass{article}
\usepackage{xcite}
\externalcitedocument{tex1}

\begin{document}
\section{Sec1}
I'm citing~\cite{cite1} from mwe1 (shoud be [2])

\section{Sec2}
I'm citing~\cite{cite1} from mwe1 (shoud be [2])

\end{document}


Or if the bibliography should be replicated in its entirity then \input{tex1.bbl} can be used.

\documentclass{article}

\begin{document}
\section{Sec1}
I'm citing~\cite{cite1} from mwe1 (shoud be [2])

\section{Sec2}
I'm citing~\cite{cite1} from mwe1 (shoud be [2])

\input{tex1.bbl}

\end{document}


To generate references with the same labels as tex1 but only print those used in tex2 then xcite should be used to determine the labels and then a separate bibliography needs to be generated. To use the same labels we can do the below (this is not a very robust solution and may well break with use of any other bibliography-related packages or different bibliography styles) where the bibliography label for every entry is generated from a \cite command which extracts the relevant number from tex1.

\documentclass{article}
\usepackage{xcite}
\externalcitedocument{tex1}

\let\oldbibitem\bibitem
\renewcommand{\bibitem}[1]{\oldbibitem[\cite{#1}]{#1}}
\makeatletter
\renewcommand\@biblabel[1]{#1}
\makeatother

\begin{document}
\section{Sec1}
I'm citing~\cite{cite1} from mwe1 (shoud be [2])

\section{Sec2}
I'm citing~\cite{cite1} from mwe1 (shoud be [2])

\bibliographystyle{unsrt}
\bibliography{tex1_biblio}

\end{document}


• Brilliant. Using the tex1.bbl file prints all the references. Is it possible to only print the ones used on tex2.tex? – PerroNoob Feb 23 '17 at 13:08
• @DavidWinchester see my edit for one (hacky) method, I've also updated the answer generally as it was somewhat erroneous beforehand with what xcite and \input{tex1.bbl} were actually needed for. – Dai Bowen Feb 23 '17 at 14:27