# BibLaTeX: Remapping groups field as keywords field doesn't work

I want to use the groups from my literature management tool as keywords for BibLaTeX to create specific bibliographies for certain chapters. I managed to remap the groups field as a keywords field if an entry contains both fields, however, this seems not to work. How do I have to adjust the \DeclareSourcemap command to make this work? Thanks in advance!

MWE:

\documentclass[a4paper,12pt]{scrartcl}

\usepackage{filecontents}
\usepackage[
backend=biber,
style=authoryear-comp,
]{biblatex}

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=groups, fieldtarget=keywords]
}
}
}

\begin{filecontents}{sample.bib}
title   = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
year    = "1993",
journal = "TUGBoat",
volume  = "14",
number  = "3",
pages   = "342--351",
keywords  = {bar},
groups  = {foo}
}

title   = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
year    = "1993",
journal = "TUGBoat",
volume  = "14",
number  = "3",
pages   = "342--351",
groups  = {foo}
}

title   = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
year    = "1993",
journal = "TUGBoat",
volume  = "14",
number  = "3",
pages   = "342--351",
keywords  = {bar}
}
\end{filecontents}

\begin{document}

\printbibliography[keyword=foo,title={Bibliography One}]

\printbibliography[keyword=bar,title={Bibliography Two}]

\end{document}


By default, biblatex is very reluctant to change or overwrite existing fields. You will have to encourage it with overwrite=true.

Up to and including version 2.7 of Biber the fieldtarget approach seems to have trouble with existing fields even if overwrite=true us enabled, however. You could use

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite=true]{
\step[fieldsource=groups]
\step[fieldset=keywords, origfieldval]
}
}
}


This will simply overwrite keywords with the content of groups.

This problem is fixed in version 2.8 (DEV version, not yet released), so we can then use

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite=true]{
\step[fieldsource=groups, fieldtarget=keywords]
}
}
}


If you want to collect both fields into keywords use

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite=true]{
\step[fieldsource=keywords, final]
\step[fieldsource=groups]
\step[fieldset=keywords, fieldvalue={,}, append]
\step[fieldset=keywords, origfieldval, append]
}
\map{
\step[fieldsource=groups]
\step[fieldset=keywords, origfieldval]
}
}
}


With this groups is copied to keywords if the latter does not exist; the contents of groups is appended to keywords if there already are some keywords present (note that we need to insert a comma, so we can't do both steps in one go).

• Because I didn't understand why fieldtarget would not work with overwrite=true, I asked on the biblatex bugtracker: github.com/plk/biblatex/issues/535 – moewe Feb 13 '17 at 23:12
• The fieldtarget overwrite bug is fixed in the current DEV version of biber (2.8). – PLK Feb 18 '17 at 15:57