使用 Biblatex 将数据附加到参考书目

使用 Biblatex 将数据附加到参考书目

我正在尝试向我的 bibtex 数据添加自定义“字段”,然后调用它。但是,我遇到了一个非常奇怪的情况:当我调用该字段时mr,它会起作用;当我调用它时mrnumber,它不起作用。下面是 MWE。

\documentclass[]{article}

\usepackage{filecontents}
\begin{filecontents*}{ext-eprint.dbx}
\ProvidesFile{ext-eprint.dbx}[2016/09/11 extended stand-alone eprint fields]
\DeclareDatamodelFields[type=field,datatype=verbatim]{arxiv,mr}
\DeclareDatamodelEntryfields{arxiv,mr}
\end{filecontents*}

\begin{filecontents*}{\jobname.bib}
@article{AGHH:dynamic-cm,
    archivePrefix = {arXiv},
    eprinttype = {arxiv},
    eprint = {1606.07639},
    title = {Mixing Times of Random Walks on Dynamic Configuration Models},
    date = {2016-06-24},
    author = {Avena, Luca and G{\"u}lda{\c s}, Hakan and van der Hofstad, Remco and den Hollander, Frank},
    options = {useprefix=true}
}
@article{FR:giant-mixing,
    title = {The Evolution of the Mixing Rate of a Simple Random Walk on the Giant Component of a Random Graph},
    volume = {33},
    number = {1},
    journaltitle = {Random Structures \& Algorithms},
    urldate = {2018-03-22},
    date = {2008-05-12},
    pages = {68-86},
    author = {Fountoulakis, Nikolaos and Reed, Bruce A.},
    mr = {12}
}
@book{LPW:markov-mixing,
    location = {{Providence, RI, USA}},
    title = {Markov {{Chains}} and {{Mixing Times}}},
    isbn = {978-1-4704-2962-1},
    pagetotal = {xvi+447},
    publisher = {{American Mathematical Society}},
    date = {2017},
    author = {Levin, David A. and Peres, Yuval and Wilmer, Elizabeth L.},
    mr = {3726904},
}
\end{filecontents*}

\usepackage{csquotes}
\usepackage[doi=false,isbn=false,url=false,
    backend=biber,
    style=numeric,
    datamodel=ext-eprint]{biblatex}
\usepackage{hyperref}
\addbibresource{\jobname.bib}

\makeatletter
\DeclareFieldFormat{arxiv}{%
    ---HOW DO I CUSTOMISE THIS??---}%\href{https://arxiv.org/abs/#1}}
\makeatother
\DeclareFieldFormat{mr}{%
    {\href{http://www.ams.org/mathscinet-getitem?mr=MR#1}{MR#1}}}

\renewbibmacro*{eprint}{%
  \printfield{arxiv}%
  \newunit\newblock
  \printfield{mr}%
  \newunit\newblock
  \iffieldundef{eprinttype}
    {\printfield{eprint}}
    {thisdoesappear\printfield[eprint:\strfield{eprinttype}]{eprint}}
}


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

这将打印出以下内容。 输出

mr但是,如果我用替换所有五个引用mrnumber,那么我会得到相同的输出,只是没有附加。我从的回答MR3726904中获得了大部分结构moeweDOI、MR、Zbl 和 arxiv 的 BibTeX 字段?

您可能已经在 MWE 中注意到,我确实使用了\DeclareFieldFormat{arxiv}{...,但无论我在这里输入什么都不会影响输出,只有thisdoesappear会出现,而且这是在\iffieldundef声明中。我确实想只使用eprintarXivMR因为每个项目都恰好有其中一个。我希望能够自定义 arxiv 部分的外观,就像我对 MR 部分所做的那样。

评论。我知道其他一些格式不是很好,但不要担心:我已经单独看过了,并且只是尝试在这里的例子中放入最少的内容。

答案1

这里有几个事情要做。最重要的是将biblatex明确定义的字段arxivmrnumber字段区分开来eprinteprint字段是特殊的,其内容会得到特殊处理。

  1. 下面的 MWEmrnumber对我有用。代码只是将mr代码中的所有 s替换为 的结果mrnumber
  2. 如果要更改 arXiv- eprints 的输出,则无需修改字段格式arxiv,而需要修改。通过检查 的 false 分支,eprint:arxiv您可以看到 被使用:。这调用字段格式,因此在我们的例子中。 仅当您直接使用 字段时才有效。eprint:arxiviffieldundef{eprinttype}\printfield[eprint:\strfield{eprinttype}]{eprint}eprint:<eprinttype>eprint:arxiv\DeclareFieldFormat{arxiv}arxiv
  3. 您也可以eprint同时使用 arXiv 和mrnumber,但这样就必须将其转换mrnumbereprints。这可以使用源映射自动完成。这种方法的优点是您不需要新.dbx文件。缺点是mrnumber占用了eprint插槽。

下面的代码展示了处理 MR 数字和 arXiv 链接的三种方法

  1. 将标识符写入eprint字段并将类型(arxiv, mrnumbereprinttype手动写入。请参阅条目AGHH:dynamic-cmFR:giant-mixing
  2. 在源代码中使用专用的arxivand字段。这就是and 的作用。这里可以通过两种方式 在侧面实现。mrnumberbaez/onlineLPW:markov-mixingbiblatex
    1. 在内部重新映射arxiv = {foo}eprint = {foo}和。这是通过eprinttype = {arxiv}下面的外部源映射完成的,在这种情况下不需要数据模型。这会导致字段被视为,这意味着和是负责的格式,字段使用 打印。这种方法的优点是您不需要数据模型,缺点是您拥有的一个插槽已被占用。在侧面(即用于编写样式)这相当于第一种方法。mrnumber = {bar}eprint = {bar}eprinttype = {mrnumber}\iffalseeprintDeclareFieldFormat{eprint:arxiv}DeclareFieldFormat{eprint:mrnumber}\printfield[eprint:\strfield{eprinttype}]{eprint}eprintbiblatexbiblatex
    2. arxivmrnumber字段声明为特殊数据模型中的本机字段并加载数据模型。这些字段可以独立使用,并使用 和 进行控制,DeclareFieldFormat{arxiv}并使用和DeclareFieldFormat{mrnumber}进行打印。\printfield{arxiv}\printfield{mrnumber}

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{ext-eprint.dbx}
\ProvidesFile{ext-eprint.dbx}[2018/05/09 extended stand-alone eprint fields]
\DeclareDatamodelFields[type=field,datatype=verbatim]{arxiv,mrnumber}
\DeclareDatamodelEntryfields{arxiv,mrnumber}
\end{filecontents*}

\begin{filecontents*}{\jobname.bib}
@online{AGHH:dynamic-cm,
  eprinttype    = {arxiv},
  eprint        = {1606.07639},
  title         = {Mixing Times of Random Walks on Dynamic Configuration Models},
  date          = {2016-06-24},
  author        = {Avena, Luca and G{\"u}lda{\c s}, Hakan and van der Hofstad, Remco and den Hollander, Frank},
  options       = {useprefix=true}
}
@online{baez/online,
  author  = {Baez, John C. and Lauda, Aaron D.},
  title   = {Higher-Dimensional Algebra {V}: 2-Groups},
  date    = {2004-10-27},
  version = 3,
  arxiv   = {math/0307200v3},
}
@article{FR:giant-mixing,
  title        = {The Evolution of the Mixing Rate of a Simple Random Walk on the Giant Component of a Random Graph},
  volume       = {33},
  number       = {1},
  journaltitle = {Random Structures \& Algorithms},
  urldate      = {2018-03-22},
  date         = {2008-05-12},
  pages        = {68-86},
  author       = {Fountoulakis, Nikolaos and Reed, Bruce A.},
  eprinttype   = {mrnumber},
  eprint       = {12},
}
@book{LPW:markov-mixing,
  location  = {Providence, RI, USA},
  title     = {Markov Chains and Mixing Times},
  isbn      = {978-1-4704-2962-1},
  pagetotal = {xvi+447},
  publisher = {American Mathematical Societ},
  date      = {2017},
  author    = {Levin, David A. and Peres, Yuval and Wilmer, Elizabeth L.},
  mrnumber  = {3726904},
}
\end{filecontents*}

\usepackage{csquotes}
\usepackage[doi=false,isbn=false,url=false,
  backend=biber,
  style=numeric,
  datamodel=ext-eprint, % comment this out to see what the data model does
]{biblatex}
\usepackage{hyperref}
\addbibresource{\jobname.bib}

\DeclareFieldFormat{arxiv}{%
  arXiv\addcolon\space
    \ifhyperref
      {\href{https://arxiv.org/abs/#1}{\nolinkurl{#1}}}
      {\nolinkurl{#1}}%
  \addspace
  as field}
\DeclareFieldFormat{eprint:arxiv}{%
  arXiv\addcolon\space
    \ifhyperref
      {\href{https://arxiv.org/abs/#1}{\nolinkurl{#1}}}
      {\nolinkurl{#1}}%
  \addspace
  via eprint}

\DeclareFieldFormat{mrnumber}{%
  \ifhyperref
    {\href{http://www.ams.org/mathscinet-getitem?mr=MR#1}{MR#1}}
    {MR#1}%
  \addspace
  real field}
\DeclareFieldFormat{eprint:mrnumber}{%
  \ifhyperref
    {\href{http://www.ams.org/mathscinet-getitem?mr=MR#1}{MR#1}}
    {MR#1}%
  \addspace
  eprint}

% This map maps all mrnumber fields to eprints with eprinttype mrnumber
% and all arxiv fields to eprint with eprinttype arxiv
% If you remove the \iffalse and \fi, this becomes active,
% in that case the datamodel is not needed any more.
\iffalse
\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=mrnumber, fieldtarget=eprint, final]
      \step[fieldset=eprinttype, fieldvalue=mrnumber]
    }
    \map{
      \step[fieldsource=arxiv, fieldtarget=eprint, final]
      \step[fieldset=eprinttype, fieldvalue=arxiv]
    }
  }
}
\fi

\renewbibmacro*{eprint}{%
  \printfield{arxiv}%
  \newunit\newblock
  \printfield{mrnumber}%
  \newunit\newblock
  \iffieldundef{eprinttype}
    {\printfield{eprint}}
    {\printfield[eprint:\strfield{eprinttype}]{eprint}}}

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

在此处输入图片描述

答案2

建议您使用biblatexmoewe 的易于扩展的 eprint 功能第三个建议)。

为此,您必须按照 biblatex 期望的格式为所需的新电子版创建字段格式。对于您的情况eprint:mr

\DeclareFieldFormat{eprint:mr}{% based on eprint:jstor
  \autocap{a}vailable\space at\space MR\addcolon\space
  \ifhyperref
    {\href{http://www.ams.org/mathscinet-getitem?mr=MR#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}}

您可以保留mrnumber它并将其重新映射到eprint

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=mrnumber, fieldtarget=eprint, final]
      \step[fieldset=eprinttype, fieldvalue=mr]
    }
  }
}

这也将所有包含 的条目设置eprinttype为。mrmrnumber

至于定制arXiv,您应该使用\DeclareFieldFormat{eprint:arxiv},正如moewe所解释的那样。

总结一下:

\documentclass[]{article}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{AGHH:dynamic-cm,
    eprinttype = {arxiv},
    eprint = {1606.07639},
    title = {Mixing Times of Random Walks on Dynamic Configuration Models},
    date = {2016-06-24},
    author = {Avena, Luca and G{\"u}lda{\c s}, Hakan and van der Hofstad, Remco and den Hollander, Frank},
    options = {useprefix=true}
}
@article{FR:giant-mixing,
    title = {The Evolution of the Mixing Rate of a Simple Random Walk on the Giant Component of a Random Graph},
    volume = {33},
    number = {1},
    journaltitle = {Random Structures \& Algorithms},
    urldate = {2018-03-22},
    date = {2008-05-12},
    pages = {68-86},
    author = {Fountoulakis, Nikolaos and Reed, Bruce A.},
    mrnumber = {12}
}
@book{LPW:markov-mixing,
    location = {{Providence, RI, USA}},
    title = {Markov {{Chains}} and {{Mixing Times}}},
    isbn = {978-1-4704-2962-1},
    pagetotal = {xvi+447},
    publisher = {{American Mathematical Society}},
    date = {2017},
    author = {Levin, David A. and Peres, Yuval and Wilmer, Elizabeth L.},
    mrnumber = {3726904},
}
\end{filecontents*}

\usepackage{csquotes}
\usepackage[doi=false,isbn=false,url=false,
    backend=biber,
    style=numeric]{biblatex}
\usepackage{hyperref}
\addbibresource{\jobname.bib}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=mrnumber, fieldtarget=eprint, final]
      \step[fieldset=eprinttype, fieldvalue=mr]
    }
  }
}

\makeatletter
\DeclareFieldFormat{eprint:arxiv}{%
  \autocap{a}vailable\space at\space arXiv\addcolon\space% <- changed here, relative to the default definition
  \ifhyperref
    {\href{https://arxiv.org/\abx@arxivpath/#1}{%
       \nolinkurl{#1}%
       \iffieldundef{eprintclass}
         {}
         {\addspace\texttt{\mkbibbrackets{\thefield{eprintclass}}}}}}
    {\nolinkurl{#1}%
     \iffieldundef{eprintclass}
       {}
       {\addspace\texttt{\mkbibbrackets{\thefield{eprintclass}}}}}}
\makeatother

\DeclareFieldFormat{eprint:mr}{% based on eprint:jstor
  \autocap{a}vailable\space at\space MR\addcolon\space
  \ifhyperref
    {\href{http://www.ams.org/mathscinet-getitem?mr=MR#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}}


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

在此处输入图片描述

相关内容