\nocite{*} for single bibdatasources with biblatex/biber

You can do this quite easily using reference sections with bound datasources:

\documentclass{article}
\usepackage[style=authoryear]{biblatex}
\addbibresource{resource1.bib}
\begin{document}
\begin{refsection}[resource2.bib]
\nocite{*}
\printbibliography
\end{refsection}
\nocite{*}
\printbibliography
\end{document}

Here, the first \nocite only adds the references from resource2.bib because it's local to the refsection. The second \nocite only picks up things from resource1.bib because both are in refsection "'0". \printbibliography is local to a refsection if it has no section argument.

Here's another way of thinking about this and why it's hard in general. biblatex works semantically with bibliographies and so the way to cite things is by semantic information that applies to bibliographies - citekeys, entry types, reference sections etc. biber knows how to map these to things to a semantically lower level like files, tags in an XML file (the .bcf) and the like. The problem is that what is wanted is a biblatex way of specifying cite keys at a semantic level below that of "bibliography" e.g. "file". biblatex has no concept of such things in its code and it's very hard to implement (and would be very messy). It can pass through such foreign concepts like file names to biber but that's not enough for this case as biblatex internal data structures would need to track citation and sorting lists at the "file" semantic level and that's impossible. Simply put, there would need to be a bibliographic semantic component between "one or more citation keys" and "all citation keys in a refsection" which is all \nocite currently understands. "File" is already ruled out for reasons mentioned above.


The following approach is not entirely satisfying because technically for biblatex all entries will have been \(no)cited, this leads to biblatex applying disambiguation techniques it would not have to use.

The main idea is to use a sourcemap restricted to \jobname-resource2.bib

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \perdatasource{\jobname-resource2.bib}
      \step[fieldset=keywords, fieldvalue={, nocitethis}, append]
    }
  }
}

to add a keyword nocitethis to all the entries in that file.

We also define \bibcheck

\defbibcheck{mynocite}{%
  \ifboolexpr{test {\ifciteseen} or test {\ifkeyword{nocitethis}}}
    {}
    {\skipentry}
}

This check will only print entries in the bibliography that either were cited before or have the specific keyword nocitethis that only entries from \jobname-resource2.bib have.

It remains to issue a \nocite{*} (so technically all entries are \nocited and processed by biber).

You will have to use the bibcheck in the bibliography

\printbibliography[check=mynocite]

We also will need to load biblatex with citetracker enabled in order for \ifciteseen to work

\usepackage[backend=biber,style=authoryear,citetracker=true]{biblatex}

MWE

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname-resource1.bib}
@article{A2014,
author={First Author},
journal={Journal A},
title={First Paper},
note = {should appear in bib, because it was cited},
year={2014}
}
@article{D2014,
author={First Author},
journal={Journal A},
title={First Paper},
note = {should not be seen in bib},
year={2014}
}
\end{filecontents*}
\begin{filecontents*}{\jobname-resource2.bib}
@article{B2014,
author={Another Author},
journal={Journal B},
title={Second Paper},
note = {should appear in bib, b/c it is in \jobname-resource2 and nocite was issued},
year={2014}
}
@article{C2014,
author={Next Author},
journal={Journal C},
title={Third Paper},
note = {should appear in bib, b/c it is in \jobname-resource2 and nocite was issued},
year={2014}
}
\end{filecontents*}

\documentclass{article}         

\usepackage[backend=biber,style=authoryear,citetracker=true]{biblatex}
\addbibresource{\jobname-resource1.bib}
\addbibresource{\jobname-resource2.bib}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \perdatasource{\jobname-resource2.bib}
      \step[fieldset=keywords, fieldvalue={, nocitethis}, append]
    }
  }
}

\defbibcheck{mynocite}{%
  \ifboolexpr{test {\ifciteseen} or test {\ifkeyword{nocitethis}}}
    {}
    {\skipentry}
}

\nocite{*}
\begin{document}
  This is a citation \cite{A2014}

  \printbibliography[check=mynocite]
\end{document}

enter image description here

You will notice that there is a "(2014a)" but no "(2014b)", for Biber "(2014b)" exists - it is D2014 - and has been cited (because of \nocite{*}), we just suppress it in the bibliography via our check.


I second the suggestion that being able to 'nocite' all entries in a specific .bib file would be useful, but until that happens, it is not tricky to quickly grab those citations all in one go.

Imagine we want to populate a single file with all entry keys from a .bib file, so we can simply add a

\input{nocites}

That means we need a file called nocites.tex that has something like

% nocites.tex
\nocite{%
 entrykey1, entrykey2, entrykey3, entrykey4, % ...
}

Using grep, sed, and tr, we can do this easily (and people better with regex will probably do it even more easily/efficiently):

# assuming a .bib file called `bibliography.bib`
grep @ bibliography.bib | grep -v '@string' | grep -v '\\\@' | sed 's/@.*{//g' | tr '\n' ' ' | sed 's/^/\\nocite{%\n/' | sed '$a}' > nocites.tex

What this does is:

  1. find each line that has an '@' in it;
  2. discard any line that has a '@string' in it (optional);
  3. discard any line that has a '\@' in it (optional; my .bib file would need this);
  4. remove from each matching line the @<entrytype>{ (e.g., turn @Book{entry1 into entry1);
  5. turn all new lines into a single line separated by spaces (optional);
  6. prepend to the file a \nocite{% while moving the entry keys to the next line;
  7. append a closing } to the end of the file;
  8. write all these transformations to a file called nocites.tex.