1

The answers to this question explain how \DefineBibliographyStrings can be used to change the "last visted" text for @online citations.

However, this solution changes the text for all references of this type. I would like to be able to change the text only for certain references.

I have some references to current webpages which I would like to keep as "last visited", however I also have some links to archive.org where I would like this to instead be displayed as "archived on".

Here is a MRE, and the output. I would like the stack exchange reference to prefix the date with "archived on", but the wikipedia reference to remain as the default "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}

references

1
1

This is a straightforward adaptation of moewe's answer to "Custom bib style for entries containing editor" (if this works for you, go upvote it too!).

First, add the following code to your preamble. This will make biblatex write "archived on" for references which include options = {archived}, and the default string otherwise.

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

Then you have one or two options, depending on what bibliography backend (bibtex or biber) you use:

a) If you use bibtex or don't want to automate this part, you'll need to edit your .bib file and add options = {archived} to all the references where you want to use "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) If you use biber, you don't need to edit the .bib file, as it can set the archived option automatically (this doesn't work with 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}] 
    }
  }
}

MWE for bibtex (requires editing your .bib file to add the archived option to archive.org references):

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

MWE for biber (automatic, no .bib edits needed):

\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}
2
  • Side note: thanks for asking this question, @JShorthouse! You've inspired me to use this in my own documents. Dec 10 '19 at 10:11
  • Works perfectly, thanks very much for taking the time to adapt the other answer into something I could easily copy and paste! Dec 13 '19 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.