在 biblatex 中 \DeclareSourcemap

在 biblatex 中 \DeclareSourcemap

我已经用\DeclareSourcemapbiblatex做了三件事,参见在 biblatex 2.7 中按括号年份对参考文献进行排序在 biblatex 中缩写解决作者名字的缩写, 和将参考书目 (biblatex) 中的美国邮政编码 (CA) 更改为 AP 样式手册缩写 (加利福尼亚州)

正如 moewe 在评论中指出的那样(https://tex.stackexchange.com/a/142665/9077),但\DeclareSourcemap不能使用多次。我尝试将我使用的三个命令组合\DeclareSourcemap成一个命令,如下面的 MWE 所示。但结果是,1 号与 2 号或 3 号组合不起作用。不过,2 号和 3 号组合起来可以正常工作。在下面的输出中,这三个命令组合在一起使用,只有 1 号有效。

我需要做什么才能充分利用这三者?

\documentclass{article}
\usepackage[style=authoryear]{biblatex}

\DeclareSourcemap{\maps[datatype = bibtex]{\map{
%% 1. Find year in brackets and sort them as if they were without brackets
    \step[fieldsource = year, 
        match = \regexp{\A\[(.+)\]\z}, final]
    \step[fieldset = sortyear, fieldvalue = {$1}]
%% 2. Abbreviate an entry such as Adam J[ohn] Smith to Smith, Adam J.
    \step[fieldsource = author,
        match = \regexp{\[[^]]+\]},
        replace = .]
%% 3. Change US postal codes such as 'MA' to 'StateMA'
    \step[fieldsource = location,
        match = \regexp{,\s*(MA|CA|NY)},
        replace = \regexp{,~\\State\{$1\}}]
    }}}
% then change 'StateMA' etc. to AP style abbreviations 'Mass.' etc.
\def\State#1{\csname State#1\endcsname}
\def\StateMA{Mass.}
\def\StateCA{Calif.}
\def\StateNY{N.Y.}

\begin{filecontents}{\jobname.bib}
@ARTICLE{western1889,
    AUTHOR = "Aug[ust] Western",
    TITLE = "Kurze darstellung des norwegischen lautsystems",
    JOURNALTITLE = "Phonetische Studien",
    YEAR = "1889",
    PAGES = "259--282",
    VOLUME = "2"}
@BOOK{lehiste1970,
    AUTHOR = "Ilse Lehiste",
    TITLE = "Suprasegmentals",
    YEAR = "1970",
    LOCATION = "Cambridge, MA",
    PUBLISHER = "The M.I.T. Press"}
@BOOK{hoff1946,
    AUTHOR = "Ingeborg Hoff",
    TITLE = "Skjetvem{\aa}let",
    YEAR = "1946",
    LOCATION = "Oslo",
    NUMBER = "1",
    PUBLISHER = "Jacob Dybwad",
    SERIES = "Skrifter utgitt av Det Norske Videnskaps-Akademi i Oslo. II. Historisk-filosofisk klasse. 1946"}
@INCOLLECTION{hoff1968,
    AUTHOR = "Ingeborg Hoff",
    BOOKTITLE = "Aurskog og Blaker",
    EDITOR = "[Eyvind Lillevold]",
    TITLE = "M{\aa}let i Aurskog og Blaker",
    YEAR = "[1968]",
    LOCATION = "[Aurskog og Blaker]",
    PAGES = "685--752",
    PUBLISHER = "Bygdeboknemnda for Aurskog og Blaker",
    VOLUME = "3"}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

在此处输入图片描述

答案1

Biber 源映射的最佳实践如下。

  • \DeclareSourcemap仅使用一次。从 3.11 版开始,biblatex您实际上可以使用\DeclareSourcemap多次而不会产生不良副作用。出于兼容性原因,您可能希望暂时坚持使用一个源图方法。我还认为仅使用一个源图可以帮助您在一个地方跟踪所有操作,所以我仍然推荐它,但在某些情况下,多个源图\DeclareSourcemap是更好的解决方案。
  • 仅将那些\step形成逻辑单元的 ,即那些“属于”一起的 - 那些做同样事情的 ,放入同一个\map。 (在此示例中,final其中一个映射命令中的 阻止了以下命令的进一步执行。)
  • \map表示相同的 s放入datatype相同的\maps环境中。

因此我们得到

\documentclass{article}
\usepackage[style=authoryear]{biblatex}

\DeclareSourcemap{
  \maps[datatype = bibtex]{
    \map{%% 1. Find year in brackets and sort them as if they were without brackets
      \step[fieldsource = year, 
          match = \regexp{\A\[(.+)\]\z}, final]
      \step[fieldset = sortyear, fieldvalue = {$1}]
    }
    \map{%% 2. Abbreviate an entry such as Adam J[ohn] Smith to Smith, Adam J.
      \step[fieldsource = author,
          match = \regexp{\[[^]]+\]},
          replace = .]
    }
    \map{%% 3. Change US postal codes such as 'MA' to 'StateMA'
      \step[fieldsource = location,
          match = \regexp{,\s*(MA|CA|NY)},
          replace = \regexp{,~\\State\{$1\}}]
    }
  }
}
% then change 'StateMA' etc. to AP style abbreviations 'Mass.' etc.
\newcommand{\State}[1]{\csname State#1\endcsname}
\newcommand{\StateMA}{Mass.}
\newcommand{\StateCA}{Calif.}
\newcommand{\StateNY}{N.Y.}

\begin{filecontents}{\jobname.bib}
@ARTICLE{western1889,
    AUTHOR = "Aug[ust] Western",
    TITLE = "Kurze darstellung des norwegischen lautsystems",
    JOURNALTITLE = "Phonetische Studien",
    YEAR = "1889",
    PAGES = "259--282",
    VOLUME = "2"}
@BOOK{lehiste1970,
    AUTHOR = "Ilse Lehiste",
    TITLE = "Suprasegmentals",
    YEAR = "1970",
    LOCATION = "Cambridge, MA",
    PUBLISHER = "The M.I.T. Press"}
@BOOK{hoff1946,
    AUTHOR = "Ingeborg Hoff",
    TITLE = "Skjetvem{\aa}let",
    YEAR = "1946",
    LOCATION = "Oslo",
    NUMBER = "1",
    PUBLISHER = "Jacob Dybwad",
    SERIES = "Skrifter utgitt av Det Norske Videnskaps-Akademi i Oslo. II. Historisk-filosofisk klasse. 1946"}
@INCOLLECTION{hoff1968,
    AUTHOR = "Ingeborg Hoff",
    BOOKTITLE = "Aurskog og Blaker",
    EDITOR = "[Eyvind Lillevold]",
    TITLE = "M{\aa}let i Aurskog og Blaker",
    YEAR = "[1968]",
    LOCATION = "[Aurskog og Blaker]",
    PAGES = "685--752",
    PUBLISHER = "Bygdeboknemnda for Aurskog og Blaker",
    VOLUME = "3"}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

得出 在此处输入图片描述

相关内容