6

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

PerroNoob
  • 641
  • 9
  • 23
  • 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
  • 1
    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
  • @cfr -- Surely, the (or 'a') point of BibTeX is to make it so you don't have 'to copy and paste the refs manually' from one file to the next? – jon Feb 20 '17 at 23:50
  • 1
    @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
  • @cfr -- That may be a fairly minor problem that is easily sorted out depending on a number of factors (such as the bibliography style) that are still unclear (bibitems and biblatex?). Of course, I did not mean to suggest that one need only 'just use BibTeX' and all problems are instantly solved. But I still suspect a BibTeX/Biber solution is possible. (Or, maybe, just use grep and figure out what number to put in the optional argument of \bibitem --- if in fact \bibitems are being used.) – jon Feb 21 '17 at 00:12
  • @jon I wasn't disagreeing. I only meant what I said. I didn't mean anything more. – cfr Feb 21 '17 at 00:16
  • What method do you use for your bibliography? Your question body mentions bibitem, yet your question is tagged biblatex. The bibitems makes me think of a manual approach with which biblatex is not compatible. Can you please clarify your question? (By help of an MWE, if you like.) – moewe Feb 21 '17 at 06:52
  • @moewe Thanks or the help, I added a mwe. Basically, I want to use the citations from tex1 so they appear in tex2 with the same numbering as tex1 references. I'm not sure if using biblatex in tex2 – PerroNoob Feb 23 '17 at 11:33
  • Is it possible to use biblatex in tex1? Will both files use the article class or something more specific? – Dai Bowen Feb 23 '17 at 11:46
  • I'm actually using revtex4-1, I'm not sure if that makes any difference – PerroNoob Feb 23 '17 at 11:51
  • @DavidWinchester Use of revtex4-1 does make a difference as it means tex1 cannot have a bibliography generated by biblatex (revtex4-1 also loads natbib and I think redefines thebibliography environment though that's less likely to limit possible solutions). – Dai Bowen Feb 23 '17 at 12:23

1 Answers1

10

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}

enter image description here

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}

enter image description here

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}

enter image description here

Dai Bowen
  • 6,117
  • 1
    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
  • 1
    @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
  • Thank you so much for this answer (the last part)! I have been looking for ages until I finally found this. However, on overleaf I get an error TeX capacity exceeded, sorry [grouping levels=255] every other time I compile. Any ideas why, or how I can get rid of it? – Nayunis May 12 '21 at 12:47
  • And a second question: Let's say in tex2 I cite the references [5], [2], and [7] from tex1 (in that order). In the "References" of tex2, they are then listed in the order 5>2>7. I there a way to sort the references in tex2, such that they appear as [2], [5], [7] in the bibliography of tex2? – Nayunis May 12 '21 at 12:50
  • @Nayunis No idea on the error, may be Overleaf-specific, but as said this solution is likely to break quickly with other bibliography styles and packages. That said it's not an error to ignore. If you can reproduce with an MWE locally (not on overleaf) I can only suggest asking a new question. As far as the ordering of the bibliography, \nocite at the start of tex2.tex is probably the easiest idea unless tex1 has a sorted bibliography in which case something to match it like abbrv may work for tex2. – Dai Bowen May 12 '21 at 17:20