5

Suppose I have a cats.bib and hats.bib which I want to use in an article on cats in hats. There already is an existing paper about that (well, sort of), which I have in both files.

Now, I do not want to merge these files (unlike in this question and this one). I am willing to allow whatever tool I use to ignore the possibility of differences between the entries and just pick whichever one it likes (not even consistently; I mean, I'm willing to guarantree they're really copies of the same entry). Under these conditions, what can I do to be able to use both bibliographies in my LaTeX document without getting any errors?

If you suggest doing something temporarily merging them just for the purpose of compiling the document, please sugget something which would integrate into, say, latexmk, so that I don't have to repeatedly do it manually, and hopefully also that whatever tool does this gets the bibliography names from the .tex file itself rather than apriori.

5
  • 2
    You can add several bib-files using \addbibresource if you are using recommended biblatex. If there are double defined keys you will only get warnings about this. Commented Feb 3, 2017 at 13:59
  • @Schweinebacke I guess I should have picked bibtex for my answer then.
    – Chris H
    Commented Feb 3, 2017 at 14:10
  • if your .bib files are in bibtex format, you might find some help in nelson beebe's "bibliographer's toolbox". the tools have been around for a long time and are quite well tested and robust. Commented Feb 3, 2017 at 14:40
  • @barbarabeeton: What other format would they be in? :-(
    – einpoklum
    Commented Feb 3, 2017 at 14:44
  • @einpoklum -- a fair question. i'm a user only of bibtex and amsrefs, but i've seen questions that implied that biber is sometimes involved, and i know nothing about that. Commented Feb 3, 2017 at 14:46

2 Answers 2

10

You can use as many .bib files as you want. Duplicate entries will result in a BibTeX error which has no consequence and keeps only the first found entry.

\begin{filecontents*}{\jobname-cats.bib}
@article{unique-cats,
  author={A. Uthor},
  title={Title},
  journal={Journal},
  year=2016,
}
@article{duplicate,
  author={W. Riter},
  title={Title},
  journal={Journal},
  year=2016,
}
\end{filecontents*}
\begin{filecontents*}{\jobname-hats.bib}
@article{unique-hats,
  author={P. Laywright},
  title={Title},
  journal={Journal},
  year=2016,
}
@article{duplicate,
  author={W. Riter},
  title={Title},
  journal={Journal},
  year=2016,
}
\end{filecontents*}

\documentclass{article}

\begin{document}

\title{Cats in hats}
\author{Einpoklum}
\maketitle

We want to cite \cite{unique-cats}, but also \cite{unique-hats}.

There is a duplicate \cite{duplicate}.

\bibliographystyle{plain}
\bibliography{\jobname-cats,\jobname-hats}

\end{document}

Here's the warning by BibTeX:

This is BibTeX, Version 0.99d (TeX Live 2016)
The top-level auxiliary file: einmulti.aux
The style file: plain.bst
Database file #1: einmulti-cats.bib
Database file #2: einmulti-hats.bib
Repeated entry---line 7 of file einmulti-hats.bib
 : @article{duplicate
 :                   ,
I'm skipping whatever remains of this entry
(There was 1 error message)

enter image description here

1
  • Re: "has no consequence and keeps only the first found entry": actually, for a refsection drawing only from the second bib file there are consequences: references that are also present in the first bib file won't be found in the refsection, since they've been skipped.
    – stafusa
    Commented Sep 28, 2021 at 8:45
1

Bib files are just plain text, and there's no equivalent to \end{document} so you can just concatenate them (as you accept the responsiility for duplicate entries).

On linux with --shell-escape you could do something like

\documentclass{article}
\immediate\write18 {cat nice_papers*.bib > \jobname.bib}
\addbibresource{\jobname.bib}
\begin{document}

On windows it would be similar: Instead of cat... you would use copy /y nice_papers*.bib \jobname.bib. This assumes biblatex, but the change for bibtex is trivial (\bibliography{\jobname}).

This is should be compatible with latexmk as it uses no external tools.

One thing to watch out for is that your source bib files should end with one or more newlines so you don't end up with a garbage line at the merge point (this is especially true if you have comments in your bibfile)

4
  • This was intended to be a comment originally, but the *nix and windows solutions (and bibtex/biblatex) ended up close enough that I made it a general answer
    – Chris H
    Commented Feb 3, 2017 at 14:11
  • (1) Where will the \write18 look for the files? Same place as an \addbibresource or a \bibliography command? (2) You are suggesting/assuming I'll use the biblatex package?
    – einpoklum
    Commented Feb 3, 2017 at 14:38
  • @einpoklum That wildcard-free copy command on windows would write cats.bib over the top of hats.bib redirecting the status to \jobname.bib. But the redirect in mine was wrong so I've corrected that
    – Chris H
    Commented Feb 3, 2017 at 16:16
  • If you want to use bibtex, the susbtitution is is just to call \bibliogrpahy{\jobname} (not.bib).
    – Chris H
    Commented Feb 3, 2017 at 16:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .