多个 DeclareSourcemap 规则

多个 DeclareSourcemap 规则

我认为我不明白\DeclareSourcemap其中的工作原理biblatex

我正在尝试定义 3 条规则:

  1. 移至issue数字;
  2. 删除number以“Phys. Rev.”开头的期刊;
  3. 删除volume“JHEP”期刊。

这是我现在所拥有的,但它似乎将所有转换应用于所有参考书目条目。

\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{\AJHEP\Z}]
      \step[fieldset=volume, null]
    }
  }
}

理想情况下,我还希望能够issue转移到number 除非 number没有定义。

答案1

Biber 按顺序处理\stepa 中的所有 s,\map除非其中一个\steps 有final选项,该选项告诉 Biber 如果不适用则在此步骤停止。

final由于问题中显示的代码中没有s,因此所有\steps 都会被执行,这意味着最后volumenumber都会被删除。

您需要将想要做的不同的事情分成单独的\map部分并使用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{\AJHEP\Z}, 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)。《雷龙理论》。收录于:JHEP 6。

相关内容