Thursday, April 25, 2013

Convincing BibLatex to handle collaborations properly

In HEP, I end up with a lot of citations that look like:

@article{Banner:1983jy,
	Author = {Banner, M. and others},
	Collaboration = {UA2 Collaboration},
	Date-Added = {2013-04-10 19:41:58 +0000},
	Date-Modified = {2013-04-10 19:42:58 +0000},
	Doi = {10.1016/0370-2693(83)91605-2},
	Journal = {Phys.Lett.},
	Pages = {476-485},
	Reportnumber = {CERN-EP-83-25},
	Slaccitation = {%%CITATION = PHLTA,B122,476;%%},
	Title = {{Observation of Single Isolated Electrons of High Transverse Momentum in Events with Missing Transverse Energy at the CERN anti-p p Collider}},
	Volume = {B122},
	Year = {1983},
	Bdsk-Url-1 = {http://dx.doi.org/10.1016/0370-2693(83)91605-2}}

(These come from the excellent inSPIRE)

I'd like to have the author listed as the collaboration if the collaboration field is present. Otherwise, it should fall back to the usual author field.

Here's what I came up with.
\usepackage[backend=biber]{biblatex}
\DeclareSourcemap{
 \maps[datatype=bibtex,overwrite=true]{
  \map{
    \step[fieldsource=Collaboration, final=true]
    \step[fieldset=usera, origfieldval, final=true]
  }
 }
}

\renewbibmacro*{author}{%
  \iffieldundef{usera}{
    \printnames{author}
  }{
    \printfield{usera}
  }
}

Basically, we're loading up biblatex with the biber backend. Then, we use a hack to copy the collaboration field, which biblatex doesn't recognize into the usera field, which it does. Finally, we update the author macro to print the usera field if it exists. Otherwise, it prints the usual author.

No comments:

Post a Comment