1

I'm using biblatex with biber under MiKTeX on Windows. I have many .bib files in a directory (say $localtexmf/bibtex/bib) which I would like to \addbibresource all at once. Is there a built-in option for biber to do that?

Related: Include all *.bib files in one directory to a bibliography

Bart Michels
  • 1,298
  • 2
  • 13
  • 24
  • 2
    Biblatex's documentation states it clearly, relative to \addbibresource: "Also note that the is a single resource." There is the legacy \bibliography which accepts as argument a comma separeted list of bib files. But it seems to me, there is no escape from listing the individual files, so not much is gained by this in the end. – gusbrs Nov 09 '18 at 22:53

3 Answers3

4

Please try biber 2.13 from the DEV folder on SourceForge. You can now use BSD style globbing with \addbibresource like:

\addbibresource{bibfile*.bib}
\addbibresource{bibfile?.bib}
\addbibresource(bibfile{1,2}.bib}
PLK
  • 22,776
3

TeX can not natively query the contents of a directory. So from within TeX you can't get a list of .bib files in a directory and loop over them unless you involve shell escape or LuaTeX.

With shell escape you can run ls or similar on the directory and then parse the returned list, with LuaTeX you can use Lua to access the file system, see How to iterate through the name of files in a folder. You could then loop over that list and apply \addbibresource for each item.

Biber could possibly query the contents of folders, but it has no user-facing interface to allow you to do that at the moment.

I would assume that the number of .bib files and their names are fairly stable, so you could compile a list of these files with \addbibresource around each and \input that list in all of your documents.

moewe
  • 175,683
  • 2
    Another thought in similar spirit: An external script that aggregates all the other bib files and whose result can be individually called by \addbibresource. – gusbrs Nov 10 '18 at 12:56
  • I am happy to take a biber feature request for this. – PLK Jan 19 '19 at 23:58
3

I use an external (PowerShell) script to merge all bib files in a folder to one.

$bibfile = "C:\localtexmf\bibtex\bib\_all.bib"
$bibtemp = "C:\localtexmf\bibtex\bib\_tmp.bib"
rm $bibfile -ErrorAction Ignore
cat "C:\localtexmf\bibtex\bib\*.bib" | sc $bibtemp
Get-Content $bibtemp | Out-File -Encoding UTF8 $bibfile
rm $bibtemp -ErrorAction Ignore

It is pretty convenient, you can even add this as the first task in your biber.bat, so you don't even have to think about it.

Bart Michels
  • 1,298
  • 2
  • 13
  • 24
  • 1
    As PLK indicates in his comment under my answer he might look into implementing something directly on the Biber side if you think it is worth itr and open a feature request https://github.com/plk/biber/issues. I guess the interface on the biblatex side would have to be considered, but even though I known nothing about Perl I guess the Biber side should be doable. – moewe Jan 20 '19 at 09:12
  • Thanks, I did that. https://github.com/plk/biber/issues/246 – Bart Michels Jan 20 '19 at 09:35