# separating bibliography items based on resource file

I have several bib files, and I want to handle them slightly differently. I think the most obvious way would be to put them in different categories (\DeclareBibliographyCategory), and then handle the issue in \printbibliography.

My questions are the following:

• given 1.bib and 2.bib how can I automatically assign all entries in one file to a specific category? Based on the documentation \addtocategory only takes keys, and thus I would have to manually list all of them.
• given a third file, 3.bib, after assigning manually a few entries from 3.bib to a category, how could I assign all other entries in 3.bib to a another category?

Basically, I'm trying to automatize splitting the three files into 4 categories.

• With Biber, you can use the Sourcemapping feature, which can be specified by a perdatasource option, and create keywords for all entries in each .bib file. Then print by keywords. ... (Edit) Hmm, actually, this is a 'related' question already. – jon Apr 4 '17 at 16:24
• and for the second question I guess I could somehow add entries to the few specific elements and then filter out the ones without or something? – fbence Apr 4 '17 at 16:39
• – CarLaTeX Apr 4 '17 at 16:40
• You have access to regexp with Biber, so I assume you can do what you like with 3.bib, but it's hard to say what to do given the information provided so far. – jon Apr 4 '17 at 17:02
• You can assign databases locally to a refsegment or refsection and then print bibliographies for particular bits of the document. – cfr Apr 5 '17 at 0:35

99 per cent of what you want to do is answered in this question. Use the sourcemapping technique at the end of that answer to add suitable keywords to your files. Let's suppose you have then "cata" as one keyword (mapped to your files 1.bib and 2.bib, and "catb" as another keyword (mapped automatically to your file 3.bib

The only remaining problem you have then is the file where you want some assigned to one category, and some to another. With that file, assign manually to the keyword field to "cata, " and also allow biber to add its own extra keyword catb.

You now have three categories:

• Entries in two files with keywords set only to "cata".

• Entries in two files with keywords set to "catb".

• Some entries in one of those files with keywords set to BOTH "cata" (manually) and "catb" (automatically).

Now all you do is filter for keyword=cata in your first bibliography, and for keyword=catb, notkeyword=cata in your second. The first picks up both the automatically encoded file and the manually added one, the second picks up all the automatically encoded files but then excludes the one you manually assigned to the first category.

Only trick is you need to put a comma after the manually assigned keyword.

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{test1.bib}
@book{book1,
author = "Anonymous, Author",
title  = "First Bibliography: Category 1",
date   = {2000},
}
\end{filecontents}
\begin{filecontents}{test2.bib}
@book{book2,
author = "Writer, William",
title = "Second Bibliography: Category 2",
date = {2010},
}
\end{filecontents}
\begin{filecontents}{test3.bib}
@book{book3,
author = "Scribbler, Steven",
title  = "First Bibliography Again: Category A and B",
date = {1899},
keywords = {cata,},
}
@book{book4,
author = "Poetaster, Peter",
title = "Second Bibliography Again: Category B",
date = {1767},
}
\end{filecontents}
\usepackage{biblatex}

\DeclareSourcemap{
\maps[datatype=bibtex,overwrite] {
\map{
\perdatasource{test1.bib}
\step[fieldset=KEYWORDS, fieldvalue=cata, append]
}
\map{
\perdatasource{test2.bib}
\step[fieldset=KEYWORDS, fieldvalue=catb, append]
}
\map{
\perdatasource{test3.bib}
\step[fieldset=KEYWORDS, fieldvalue=catb, append]
}
}
}