I am trying to add a field to biblatex entries in the tex
file. I am currently not able to apply a rule to one entry then apply it other rules to other entries.
I defined a command to add a field. Something is wrong with it but I don't know what it is:
\newcommand{\addnotetoentry}[2]{%
\DeclareSourcemap{%
\maps[datatype=bibtex]{%
\map[overwrite]{%
\step[fieldsource=entrykey,match=\regexp{^#1$},final]%
\step[fieldset=note,fieldvalue={#2}]%
}%
}%
}%
}
Which is used like this:
\addnotetoentry{a}{one note --- hello my friend}
\addnotetoentry{b}{another note}
MWE:
\documentclass[12pt,letterpaper]{article}
\usepackage[backend=biber,style=alphabetic-verb,doi=false,eprint=false]{biblatex}
\usepackage{filecontents}
\begin{filecontents}{jobname.bib}
@ARTICLE{a,
author = {Doe, J.},
title = {The Title},
journal = {The Journal},
}
@ARTICLE{b,
author = {Smith, J.},
title = {The New Title},
journal = {The Same Journal},
}
\end{filecontents}
\addbibresource{jobname.bib}
\newcommand{\addnotetoentry}[2]{%
\DeclareSourcemap{%
\maps[datatype=bibtex]{%
\map[overwrite]{%
\step[fieldsource=entrykey,match=\regexp{^#1$},final]%
\step[fieldset=note,fieldvalue={#2}]%
}%
}%
}%
}
\addnotetoentry{a}{one note}
\addnotetoentry{b}{another note}
\AtEveryBibitem{\printfield{note}\clearfield{note}\item}
\begin{document}
\nocite{*}
\printbibliography
\end{document}
I get in the ouput's references only one note (the last one that I defined):
\DeclareSourcemap
per document (only the last one will be executed), one can use an unlimited (I think) number of\maps
in a\DeclareSourcemap
though..bib
file.\DeclareSourcemap
in this form does not look like your best bet...map
into one source map works (just tried), so i'm searching for a way to add maps using a command (to make it easier) , I'll look into the implementation ofDeclareSourcemap