So fügen Sie der ersten Zitierung in Online-Referenzen ein URL-Datum hinzu

So fügen Sie der ersten Zitierung in Online-Referenzen ein URL-Datum hinzu

Ich möchte das Datum hinzufügen, an dem ich meine Online-Referenzen bei der allerersten Erwähnung besucht habe. Ich verwende biblatexden authoryear-compStil. Hier ist ein 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}

Kann mir jemand bei diesem Problem helfen?

Anmerkung des Benutzershttps://tex.stackexchange.com/users/14649: Dies ist eine Folgefrage zuSo greifen Sie im Text auf das URL-Datum zu.

Antwort1

Sie können so etwas ausprobieren. Die Option citetrackerwird für den \ifciteseenTest benötigt. Die Definition von citeist die ursprüngliche Definition von authoryear-comp.cbxmit den folgenden zwei Zeilen

  \setunit{\addcomma\space}%
  \usebibmacro{cite:urlinfo}%

am Ende hinzugefügt.

Dasselbe kann für gemacht werden textcite, aber es sollte beachtet werden, dass \textcitees einige Sonderfälle gibt (komprimierte Zitate, Zitate ohne Namen oder Jahr, Abkürzungen), die mit dieser Konfiguration leicht unerwartete Ergebnisse liefern können. Mir ist keine bessere allgemeine Lösung eingefallen, daher empfehle ich, die Ergebnisse sorgfältig zu prüfen.

\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}

(Niemand 2019, besucht am 25.11.2019)//(Niemand 2019)

verwandte Informationen