仅更改特定参考文献的参考书目字符串

仅更改特定参考文献的参考书目字符串

答案这个问题解释如何\DefineBibliographyStrings使用来更改引用的“最后访问”文本@online

但是,此解决方案会更改此类型所有引用的文本。我希望能够仅更改某些引用的文本。

我有一些当前网页的引用,我想将其保留为“上次访问”,但我也有一些指向 archive.org 的链接,我想将其显示为“存档于”。

这是 MRE 和输出。我希望 Stack Exchange 引用在日期前加上“存档日期”,但维基百科引用保留默认的“访问日期”。

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{citations.bib}
@online{wikipedia,
    author       = {{Wikimedia Foundation}},
    title        = {Wikipedia},
    url          = {https://en.wikipedia.org},
    year         = {2019},
    urldate      = {2019-12-09}
}
@online{stack,
    author       = {{Stack Exchange Inc}},
    title        = {Stack Overflow},
    url          = {https://web.archive.org/web/20100813082822/http://www.stackoverflow.com/},
    year         = {2010},
    urldate      = {2010-08-13}
}
\end{filecontents}
\usepackage[style=authoryear,backend=bibtex,urldate=long]{biblatex}
\addbibresource{citations.bib}

\DefineBibliographyStrings{english}{
  urlseen = {archived on} 
}

\begin{document}
Lorem ipsum dolor sit amet \autocite{wikipedia}, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua \autocite{stack}. 
\printbibliography
\end{document}

参考

答案1

这是一个直接改编的moewe 对“包含编辑器的条目的自定义 bib 样式”的回答(如果这对您有用,请也投票赞成!)。

首先,将以下代码添加到您的序言中。这将使 biblatex 为包含的参考文献写入“存档于” options = {archived},否则写入默认字符串。

% define a new "archivedon" string as an alternative to "urlseen"
\NewBibliographyString{archivedon}
\DefineBibliographyStrings{english}{ 
    archivedon = {archived on}
}

% for each reference, detect if the "archived" option is used and set the urldate string accordingly
\newtoggle{bib:archived}
\DeclareEntryOption{archived}[true]{%
  \settoggle{bib:archived}{#1}}
\DeclareFieldFormat{urldate}{% 
  \mkbibparens{%
    \iftoggle{bib:archived}
      {\bibstring{archivedon}} % "archived" option is on - write "archived on"
      {\bibstring{urlseen}} % "archived" option is off - write "visited on"
    \addcolon\space#1}}

然后,您有一个或两个选项,取决于您使用什么参考书目后端(bibtex 或 biber):

a) 如果您使用 bibtex 或不想自动执行此部分,则需要编辑 .bib 文件并将options = {archived}您想要使用“存档于”的所有参考文献添加到:

@online{stack,
    author  = {{Stack Exchange Inc}},
    title   = {Stack Overflow},
    url     = {https://web.archive.org/web/20100813082822/http://www.stackoverflow.com/},
    year    = {2010},
    urldate = {2010-08-13},
    options = {archived}
}

b) 如果您使用 biber,则不需要编辑 .bib 文件,因为它可以archived自动设置选项(这不适用于 bibtex):

% automatically add the "archived" option when reference url contains "archive.org"
\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \step[fieldsource=url, match=\regexp{archive\.org},final] 
      \step[fieldset=options, append, fieldvalue={archived=true}] 
    }
  }
}

bibtex 的 MWE(需要编辑您的 .bib 文件以将archived选项添加到 archive.org 引用):

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{citations.bib}
@online{wikipedia,
    author       = {{Wikimedia Foundation}},
    title        = {Wikipedia},
    url          = {https://en.wikipedia.org},
    year         = {2019},
    urldate      = {2019-12-09}
}
@online{stack,
    author       = {{Stack Exchange Inc}},
    title        = {Stack Overflow},
    url          = {https://web.archive.org/web/20100813082822/http://www.stackoverflow.com/},
    year         = {2010},
    urldate      = {2010-08-13},
    options      = {archived}
}

\end{filecontents}
\usepackage[style=authoryear,backend=bibtex,urldate=long]{biblatex}
\addbibresource{citations.bib}


% use "archived on" instead of "visited on" when bib entry includes "options = {archived}"
%   (inspired by https://tex.stackexchange.com/a/265929)
\NewBibliographyString{archivedon}
\DefineBibliographyStrings{english}{ 
    archivedon = {archived on} 
}
\newtoggle{bib:archived}
\DeclareEntryOption{archived}[true]{%
  \settoggle{bib:archived}{#1}}
\DeclareFieldFormat{urldate}{%
  \mkbibparens{%
    \iftoggle{bib:archived}
      {\bibstring{archivedon}}
      {\bibstring{urlseen}}%
    \addcolon\space#1}}
%-----


\begin{document}
Lorem ipsum dolor sit amet \autocite{wikipedia}, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua \autocite{stack}. 

\printbibliography
\end{document}

biber 的 MWE(自动,不需要编辑 .bib):

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{citations.bib}
@online{wikipedia,
    author       = {{Wikimedia Foundation}},
    title        = {Wikipedia},
    url          = {https://en.wikipedia.org},
    year         = {2019},
    urldate      = {2019-12-09}
}
@online{stack,
    author       = {{Stack Exchange Inc}},
    title        = {Stack Overflow},
    url          = {https://web.archive.org/web/20100813082822/http://www.stackoverflow.com/},
    year         = {2010},
    urldate      = {2010-08-13}
}

\end{filecontents}
\usepackage[style=authoryear,backend=biber,urldate=long]{biblatex} % changed to biber
\addbibresource{citations.bib}


% use "archived on" instead of "visited on" when bib entry includes "options = {archived}"
%   (inspired by https://tex.stackexchange.com/a/265929)
\NewBibliographyString{archivedon}
\DefineBibliographyStrings{english}{ 
    archivedon = {archived on} 
}
\newtoggle{bib:archived}
\DeclareEntryOption{archived}[true]{%
  \settoggle{bib:archived}{#1}}
\DeclareFieldFormat{urldate}{%
  \mkbibparens{%
    \iftoggle{bib:archived}
      {\bibstring{archivedon}}
      {\bibstring{urlseen}}%
    \addcolon\space#1}}
%----------

% for biber only - add the "archived" option automatically when url contains "archive.org"
\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map[overwrite]{
      \step[fieldsource=url, match=\regexp{archive\.org},final]
      \step[fieldset=options, append, fieldvalue={archived=true}]
    }
  }
}
%-----


\begin{document}
Lorem ipsum dolor sit amet \autocite{wikipedia}, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua \autocite{stack}. 

\printbibliography
\end{document}

相关内容