1

As this might turn out to be an XY problem, I will try to give as much additional information as possible. But to start with, my question is:

  • Question (Y): How can I make biber (in tool mode) create a .bib file based on a .bcf file and using another .bib file as data source than the one specified in the .bcf file?

Question and Background (X):

Recently, I started to use JabRef for bibliography management. On the one hand, the fact that it uses .bib as database format is very handy, but on the other hand there are some drawbacks:

  • All meta information is contained in that .bib file, including file references, personal comments and database specific configuration. For some reasons (I think they don't matter here) I want to use a "clean" .bib file for my projects, containing only the relevant bibliographical data. As a consequence, I need to create a "reduced" version of the database .bib file which leads to the next point:
  • JabRef has no option to add custom BibTeX export filters. Of course, it is possible to export a subset of the bibliography in BibTeX format but this does not solve the issue of having configuration data and personal fields in the new file. I know that the latter issue could by solved with JabRef's "Set/clear/rename fields" feature but this is only a partial solution and very cumbersome when it needs to be done repeatedly.
  • I would prefer to have only references that are actually used in a project's .bib file. That means I need to create a .bib file containing only the cited references of a bigger .bib file.

The Goal

So what I want is:

  • Manage my bibliography in JabRef.
  • Write a LaTeX document using biblatex with biber.
  • Generate a .bib file containing only the references cited in the document as a subset of my JabRef database.
  • (Remove all fields containing superfluous information from that smaller .bib file. This is not part of the current question; I only mentioned it above as one of the reasons why I want to do all this.)

What I have so far

Basically, I found three different approaches to my problem:


Approach 3 almost did the trick. The following command takes all references cited in paper.tex and writes them to paper_biber.bib:

biber --output_format=bibtex --output_resolve paper.bcf

However, recall that I want to have two .bib files: A reduced file (paper_biber.bib) automatically created from the .bcf file and besides a master/database file master.bib containing all my references.

That means, in paper.tex I have a line like \addbibresource{paper_biber.bib}. Accordingly, biber writes the following into paper.bcf

<bcf:bibdata section="0">
    <bcf:datasource type="file" datatype="bibtex">paper_biber.bib</bcf:datasource>
  </bcf:bibdata>

and when I run biber --output_format=bibtex --output_resolve paper.bcf, biber looks for the data of the references from paper.bcf in paper_biber.bib. But this is the wrong file. I need biber to look for the data of the references from paper.bcf in master.bib.

When I manually edit paper.bfc and replace paper_biber.bib by master.bib

<bcf:bibdata section="0">
    <bcf:datasource type="file" datatype="bibtex">master.bib</bcf:datasource>
  </bcf:bibdata>

I get exactly the desired result, namely paper_biber.bib containing all the entries from master.bib that are referenced in paper.bcf.

Unfortunately, manually editing paper.bcf is not very convenient and difficult to automate. This brings me back to the original question:

How can I make biber (in tool mode) create a .bib file based on a .bcf file and using another .bib file as data source than the one specified in the .bcf file?

I tried to find an appropriate command line option in the biber manual and in biber --help but could not find anything useful.

I suppose that I could use a biber.conf file which, according to the manual, should overrule any settings in the .bcf file but I have no clue what I have to write in that file. I tried the following with no effect:

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <!-- SECTION 0 -->
  <bibdata section="0">
    <datasource type="file" datatype="bibtex">master.bib</datasource>
  </bibdata>
</config>
1

I found the solution myself and it is surprisingly trivial: The option --input-directory specifies the directory where biber looks for source files.

The only limitation is that the reduced .bib file and the full file need to have the same name. Then, the solution is:

biber --output_format=bibtex --input-directory "path/to/database/" --output_resolve paper.bcf

EDIT: The command above is not a complete solution. It produces the reduced file with a name like [name of input file]_biber.bib which implies that this could only work for very specific filename relations:

  • Master BIB file (database): somename_biber.bib
  • \addbibresource{somename_biber.bib}
  • Document: somename.tex

However, this is very restrictive. Therefore I decided to write a small batch file (I use Windows) to solve all problems at once:

cd %~dp0
cp relative/path/to/MasterDB.bib reduced.bib
biber --output_file=reduced.bib --output_format=bibtex --output_resolve --strip_comments ../paper
biber ../paper

@echo off
echo.
echo Done!

if "%1"=="--background" exit
Pause

This assumes the above script to be located in src/ and paper.tex with addbibresource{src/reduced.bib}.

The workflow is: Compile the paper.tex. Run the script. This updates/creates src/reduced.bib with the necessary data from MasterDB.bib and creates paper.bbl. Compile paper.tex again.

  • This is not a bad solution really. Just so it is clear - the .bcf is written by the first latex run and biber reads the .bcf. Everything biber knows comes only from the .bcf, any biber.conf file and command line options. – PLK Dec 5 '15 at 11:38
  • Thank you for your feedback. I agree -- if you explained where I imply something wrong about the .bcf file I'd happily clarify it. Or maybe you just want to edit the answer? At the moment I don't see which is the wrong part you're referring to. – CL. Dec 7 '15 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.