僅更改某些參考文獻的參考書目字串

僅更改某些參考文獻的參考書目字串

的答案這個問題解釋如何\DefineBibliographyStrings用於更改引用的「最後訪問」文字@online

但是,此解決方案更改了該類型的所有引用的文本。我希望能夠僅更改某些參考文獻的文本。

我有一些對當前網頁的引用,我希望將其保留為“上次訪問”,但是我也有一些指向 archive.org 的鏈接,我希望將其顯示為“存檔於”。

這是 MRE 和輸出。我希望堆疊交換引用在日期前加上「歸檔於」前綴,但維基百科引用保留為預設的「存取於」。

\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 對「包含編輯器的條目的自訂圍兜樣式」的回答(如果這對您有用,也請投票!)。

首先,將以下程式碼加入序言中。這將使 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}

相關內容