Biblatex:仅当没有 URL 时才使用 doi

Biblatex:仅当没有 URL 时才使用 doi

有没有办法doi仅在缺少URL字段的情况下插入条目的?doiURL基本上相同,插入它们会产生冗余。我正在biblatex使用biber

附言:如果您认为这个目标没有意义,请分享您的想法!

答案1

您可以重新定义 bibmacro doi+eprint+url,以便仅当未定义doi该字段时才打印该字段,即在序言中添加以下几行:url

\renewbibmacro*{doi+eprint+url}{%
  \iftoggle{bbx:doi}
    {\iffieldundef{url}{\printfield{doi}}{}}
    {}%
  \newunit\newblock
  \iftoggle{bbx:eprint}
    {\usebibmacro{eprint}}
    {}%
  \newunit\newblock
  \iftoggle{bbx:url}
    {\usebibmacro{url+urldate}}
    {}}

平均能量损失

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[backend=biber]{biblatex}

\addbibresource{\jobname.bib}

\renewbibmacro*{doi+eprint+url}{%
  \iftoggle{bbx:doi}
    {\iffieldundef{url}{\printfield{doi}}{}}
    {}%
  \newunit\newblock
  \iftoggle{bbx:eprint}
    {\usebibmacro{eprint}}
    {}%
  \newunit\newblock
  \iftoggle{bbx:url}
    {\usebibmacro{url+urldate}}
    {}}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@article{kastenholz1,
  hyphenation = {american},
  author = {Kastenholz, M. A. and H{\"u}nenberger, Philippe H.},
  indextitle = {Computation of ionic solvation free energies},
  title = {Computation of methodology\hyphen independent ionic solvation free
    energies from molecular simulations},
  subtitle = {I. The electrostatic potential in molecular liquids},
  journaltitle = jchph,
  volume = {124},
  eid = {124106},
  date = {2006},
  url = {http://dx.doi.org/10.1063/1.2172593},
  urldate = {2006-10-01},
  doi = {10.1063/1.2172593},
}
@article{kastenholz2,
  hyphenation = {american},
  author = {Kastenholz, M. A. and H{\"u}nenberger, Philippe H.},
  indextitle = {Computation of ionic solvation free energies},
  title = {Computation of methodology\hyphen independent ionic solvation free
    energies from molecular simulations},
  subtitle = {I. The electrostatic potential in molecular liquids},
  journaltitle = jchph,
  volume = {124},
  eid = {124106},
  date = {2006},
  doi = {10.1063/1.2172593},
}
\end{filecontents}


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

输出:

在此处输入图片描述

如您所见,除字段外,这两个条目完全相同url,如果定义了该字段,doi则不会打印该字段。

答案2

您可以通过数据源映射来实现这一点。\DeclareSourcemap命令

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=url,final]
      \step[fieldset=doi,null]
    }  
  }
}

处理任何bibtex输入数据,并对 bibliograhpy 文件中的每个项目执行如下命令\step

  • 第一步fieldsource检查url字段

    • 该指令final表示如果该字段为空或不存在,则终止当前条目的处理
  • fieldset=doi,null否则执行下一步;这将清除该字段,实际上它使它看起来好像输入中doi从来没有字段。doi

这样做的结果是,所有人biber/biblatex看到的都是一个带有一个url字段或一个doi字段的条目,但不是同时带有这两个字段。

这样做的好处是您不需要知道特定biblatex样式如何选择处理这些字段。

示例输出

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[backend=biber]{biblatex}

\addbibresource{\jobname.bib}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=url,final]
      \step[fieldset=doi,null]
    }  
  }
}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@Article{Akbulut-S:deformations-G2,
  author =   {Akbulut, Selman and Salur, Sema},
  title =    {Deformations in {$G_2$} manifolds},
  journal =  {Adv. Math.},
  volume =   217,
  year =     2008,
  number =   5,
  pages =    {2130--2140},
  issn =     {0001-8708},
  doi =      {10.1016/j.aim.2007.09.009},
  url =      {http://dx.doi.org/10.1016/j.aim.2007.09.009}
}
@Article{Akbulut-S:deformations-G22,
  author =   {Akbulut, Selman and Salur, Sema},
  title =    {Deformations in {$G_2$} manifolds},
  journal =  {Adv. Math.},
  volume =   217,
  year =     2008,
  number =   5,
  pages =    {2130--2140},
  issn =     {0001-8708},
  url =      {http://dx.doi.org/10.1016/j.aim.2007.09.009}
}
@Article{Akbulut-S:deformations-G23,
  author =   {Akbulut, Selman and Salur, Sema},
  title =    {Deformations in {$G_2$} manifolds},
  journal =  {Adv. Math.},
  volume =   217,
  year =     2008,
  number =   5,
  pages =    {2130--2140},
  issn =     {0001-8708},
  doi =      {10.1016/j.aim.2007.09.009},
}

\end{filecontents}

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

相关内容