
答えはこの質問引用の「最終訪問」テキストを変更するためにどのよう\DefineBibliographyStrings
に使用できるかを説明します@online
。
ただし、このソリューションでは、このタイプのすべての参照のテキストが変更されます。特定の参照のテキストのみを変更できるようにしたいと思います。
現在の Web ページへの参照がいくつかあり、これを「最終アクセス」として保持したいのですが、archive.org へのリンクもいくつかあり、これを「アーカイブ日」として表示したいのです。
以下は MRE とその出力です。Stack Exchange 参照では日付の前に「archived on」を付けますが、Wikipedia 参照ではデフォルトの「visited at」のままにしておきたいと思います。
\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 は、 を含む参照に対しては「archived on」を書き込み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) に応じて、1 つまたは 2 つのオプションがあります。
a) bibtex を使用する場合、またはこの部分を自動化したくない場合は、.bib ファイルを編集し、options = {archived}
「archived on」を使用するすべての参照に以下を追加する必要があります。
@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}