
我想在第一次提到這些內容時添加我訪問線上參考資料的日期。我用的biblatex
風格authoryear-comp
。這是一個 MWE:
\documentclass{scrreprt}
\usepackage[style=authoryear-comp]{biblatex}
\addbibresource{\jobname.bib}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@online{key,
title = {Very nice online reference},
url = {https://www.example.com/},
urldate = {2019-11-25},
author = {Nobody},
}
\end{filecontents}
% Start of the document.
\begin{document}
% Your content.
I want to cite here with the urldate in the citation.
\parencite{key} should look like:
(Author 2001, visited on 25.11.2019) but just when I first reference it.
In every later cication it shall just look (Author 2001).
% End of the document.
\end{document}
有人能幫我解決這個問題嗎?
使用者備註https://tex.stackexchange.com/users/14649:這是一個後續問題如何取得文本中的urldate。
答案1
你可以嘗試這樣的事情。citetracker
測試需要該選項\ifciteseen
。的定義是來自以下兩行的cite
原始定義authoryear-comp.cbx
\setunit{\addcomma\space}%
\usebibmacro{cite:urlinfo}%
添加在最後。
可以對 執行相同的操作textcite
,但應該注意的是,\textcite
有一些特殊情況(壓縮引用、沒有名稱或年份的引用、簡寫),使用此配置可能會產生稍微意外的輸出。我想不出更好的通用解決方案,因此我建議仔細檢查輸出。
\documentclass{scrreprt}
\usepackage[style=authoryear-comp, citetracker]{biblatex}
\newbibmacro*{cite:urlinfo}{%
\ifciteseen
{}
{\DeclareFieldFormat{urldate}{\bibstring{urlseen}\space##1}%
\printurldate}}
\makeatletter
\renewbibmacro*{cite}{%
\iffieldundef{shorthand}
{\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
{\usebibmacro{cite:label}%
\setunit{\printdelim{nonameyeardelim}}%
\usebibmacro{cite:labeldate+extradate}%
\usebibmacro{cite:reinit}}
{\iffieldequals{namehash}{\cbx@lasthash}
{\ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
\(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
{\setunit{\addcomma}%
\usebibmacro{cite:extradate}}
{\setunit{\compcitedelim}%
\usebibmacro{cite:labeldate+extradate}%
\savefield{labelyear}{\cbx@lastyear}}}
{\printnames{labelname}%
\setunit{\printdelim{nameyeardelim}}%
\usebibmacro{cite:labeldate+extradate}%
\savefield{namehash}{\cbx@lasthash}%
\savefield{labelyear}{\cbx@lastyear}}}}
{\usebibmacro{cite:shorthand}%
\usebibmacro{cite:reinit}}%
\setunit{\addcomma\space}%
\usebibmacro{cite:urlinfo}%
\setunit{\multicitedelim}}
\renewbibmacro*{textcite}{%
\iffieldequals{namehash}{\cbx@lasthash}
{\iffieldundef{shorthand}
{\ifthenelse{\iffieldequals{labelyear}{\cbx@lastyear}\AND
\(\value{multicitecount}=0\OR\iffieldundef{postnote}\)}
{\setunit{\addcomma}%
\usebibmacro{cite:extradate}}
{\setunit{\compcitedelim}%
\usebibmacro{cite:labeldate+extradate}%
\savefield{labelyear}{\cbx@lastyear}}}
{\setunit{\compcitedelim}%
\usebibmacro{cite:shorthand}%
\global\undef\cbx@lastyear}}
{\ifnameundef{labelname}
{\iffieldundef{shorthand}
{\usebibmacro{cite:label}%
\setunit{%
\global\booltrue{cbx:parens}%
\printdelim{nonameyeardelim}\bibopenparen}%
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\usebibmacro{cite:labeldate+extradate}}
{\usebibmacro{cite:shorthand}}}
{\printnames{labelname}%
\setunit{%
\global\booltrue{cbx:parens}%
\printdelim{nameyeardelim}\bibopenparen}%
\ifnumequal{\value{citecount}}{1}
{\usebibmacro{prenote}}
{}%
\iffieldundef{shorthand}
{\iffieldundef{labelyear}
{\usebibmacro{cite:label}}
{\usebibmacro{cite:labeldate+extradate}}%
\savefield{labelyear}{\cbx@lastyear}}
{\usebibmacro{cite:shorthand}%
\global\undef\cbx@lastyear}}%
\stepcounter{textcitecount}%
\savefield{namehash}{\cbx@lasthash}}%
\setunit{\addcomma\space}%
\usebibmacro{cite:urlinfo}%
\setunit{%
\ifbool{cbx:parens}
{\bibcloseparen\global\boolfalse{cbx:parens}}
{}%
\textcitedelim}}
\makeatother
\begin{filecontents}{\jobname.bib}
@online{key,
title = {Very nice online reference},
url = {https://www.example.com/},
urldate = {2019-11-25},
author = {Nobody},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\parencite{key}
\parencite{key}
\end{document}