2

I have to print the date when I visited a website in the main text of my thesis. Can I automatically do this with biblatex?

moewe
  • 175,683
mathse
  • 101

1 Answers1

4

There is no predefined command to do that, but it is simple to define a command \citeurldate analogous to \citedate (see biblatex.def, ll. 2183-2189). Note the redefinition of the urldate format (\DeclareFieldFormat{urldate}{####1}) in the precode argument of \DeclareCiteCommand{\citeurldate} to avoid the additional "visited on" string and parentheses (the # character had to be doubled twice because this is a nested macro definition, see What is the meaning of double pound symbol (number sign, hash character) ##1 in an argument?).

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=authoryear, backend=biber]{biblatex}


\DeclareCiteCommand{\citeurldate}
  {\DeclareFieldFormat{urldate}{####1}%
   \boolfalse{citetracker}%
   \boolfalse{pagetracker}%
   \usebibmacro{prenote}}
  {\printurldate}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\addbibresource{biblatex-examples.bib}

\begin{document}
\cite{markey} from \citeurldate{markey}

\printbibliography
\end{document}

Markey 2005 from 01/10/2006

moewe
  • 175,683
  • +1: Good as always, could you point out "Note the redefinition of the urldate format in the precode argument" as a comment in the code? – Dr. Manuel Kuehner Dec 20 '19 at 16:05
  • @Dr.ManuelKuehner I usually try to avoid excessive code comments and I think that in this case it is quite clear where the redefinition happens, so I'd rather not add a comment. Is there any specific reason why you ask about that? Maybe I can make the text of the answer more clear so the comment isn't needed. – moewe Dec 20 '19 at 16:14
  • Thanks for the great answer! One additional question: Can one redefine the \parentice command just for @online sources, that it adds the urldate in a postnote? – mathse Dec 20 '19 at 18:18
  • @mathse In general yes, but how will depend on the style you use. Please open a new question and post a short example document (an MWE: https://tex.meta.stackexchange.com/q/228/35864) that shows which style you use. – moewe Dec 20 '19 at 19:35
  • @moewe thanks, I posted a new question here: https://tex.stackexchange.com/questions/521238/how-to-add-urldate-to-first-citation-in-online-references Thanks again for the answer here! – mathse Dec 20 '19 at 20:53
  • Thanks for your reply. I did not see where/what the precode is. But maybe I should consult the biblatex manual (RTFM) :). – Dr. Manuel Kuehner Dec 21 '19 at 03:34
  • 1
    @Dr.ManuelKuehner I see, I tried to add a few more pointers to the text. – moewe Dec 21 '19 at 05:59
  • Thanks a lot for considering my comment :). I upvote anyway :). – Dr. Manuel Kuehner Dec 21 '19 at 07:41