2

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}
  @article{greenwade93,
    author  = "George D. Greenwade",
    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}
}

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

  @article{bluewade93,
    author  = "George D. Bluewade",
    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}

  \addbibresource{sample.bib}

\begin{document}

This document contains citations of \cite{greenwade93}, \cite{redwade93} and \cite{bluewade93}---but \cite{greenwade93} doesn't appear in the first bibliography.

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

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

\end{document}
2

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).

  • 1
    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
  • 1
    The fieldtarget overwrite bug is fixed in the current DEV version of biber (2.8). – PLK Feb 18 '17 at 15:57

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.