TransWikia.com

Multiple DeclareSourcemap rules

TeX - LaTeX Asked by SU3 on December 14, 2020

I don’t think I understand how the DeclareSourcemap works in biblatex.

I’m trying to define 3 rules:

  1. Move issue to number;
  2. Remove number for journals that start with "Phys. Rev.";
  3. Remove volume for journals that are "JHEP".

Here’s what I have right now, but it seems to apply all transformations to all bibliography entries.

DeclareSourcemap{
  maps[datatype=bibtex]{
    map{
      step[fieldsource=issue]
      step[fieldset=number, origfieldval]
      step[fieldset=issue, null]
      %
      step[fieldsource=journal, fieldtarget=journaltitle]
      step[fieldsource=journaltitle, match=regexp{APhys.s+Rev.}]
      step[fieldset=number, null]
      %
      step[fieldsource=journal, fieldtarget=journaltitle]
      step[fieldsource=journaltitle, match=regexp{AJHEPZ}]
      step[fieldset=volume, null]
    }
  }
}

Ideally, I would also like for issue to be moved to number only if number is not defined.

One Answer

Biber processes all steps in a map sequentially unless one of the steps has the final option, which tells Biber to stop at this step if it does not apply.

Since there are no finals in the code shown in the question, all steps get executed, which means that in the end both volume and number get removed.

You need to separate the different things you want to do into separate maps and use final.

documentclass[british]{article}
usepackage[T1]{fontenc}
usepackage{babel}
usepackage{csquotes}

usepackage[backend=biber, style=authoryear]{biblatex}

DeclareSourcemap{
  maps[datatype=bibtex]{
    % remap fields for all entries, but nothing will be overwritten
    map{
      step[fieldsource=issue,   fieldtarget=number]
      step[fieldsource=journal, fieldtarget=journaltitle]
    }
    % delete number only for Phys. Rev.
    map{
      step[fieldsource=journaltitle, match=regexp{APhys.s+Rev.}, final]
      step[fieldset=number, null]
    }
    % delte volume only for JHEP
    map{
      step[fieldsource=journaltitle, match=regexp{AJHEPZ}, final]
      step[fieldset=volume, null]
    }
  }
}

begin{filecontents}{jobname.bib}
@article{elk,
  author    = {Anne Elk},
  title     = {A Theory on Brontosauruses},
  year      = {1972},
  journal   = {Phys. Rev.},
  volume    = {131},
  issue     = {5},
}
@article{belk,
  author    = {Anne Belk},
  title     = {A Theory on Brontosauruses},
  year      = {1971},
  journal   = {JHEP},
  volume    = {132},
  issue     = {6},
}
@article{celk,
  author    = {Anne Celk},
  title     = {A Theory on Brontosauruses},
  year      = {1974},
  journal   = {Lorem},
  volume    = {133},
  issue     = {7},
}
@article{delk,
  author    = {Anne Delk},
  title     = {A Theory on Brontosauruses},
  year      = {1975},
  journal   = {Lorem},
  volume    = {134},
  number    = {8},
}
@article{felk,
  author    = {Anne Felk},
  title     = {A Theory on Brontosauruses},
  year      = {1977},
  journal   = {Lorem},
  volume    = {135},
  number    = {9},
  issue     = {Michaelmas term},
}
end{filecontents}
addbibresource{jobname.bib}
addbibresource{biblatex-examples.bib}

begin{document}
Lorem autocite{sigfridsson,elk,belk,celk,delk,felk}

printbibliography
end{document}

Belk, Anne (1971). ‘A Theory on Brontosauruses’. In: JHEP 6.

Correct answer by moewe on December 14, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP