1

Problem

Related to the question I asked here Lyx - change URL appearance in bibtex bibliography, I would like to include something like "Accessed at: Date (dd.mm.yyyy)" in my bibliography. I am not 100 % sure "accessed at" is the right wording in english but this question is more focussed on how to implement this.

I am using Lyx with the Natbib setting and the else-harv biblipgraphy style. I only want the accessed at date for all URLs that are displayed in the bibliography. I have no clue how to start about it, apart from that probably something has to be changed in the .bst file ? Or is there some easiere solution to this.

What it should look like:

URL: www.whatever.com (Accessed at: Date)

I am not sure about the style whether this is common with or without brackets around the accessed at, but I guess either will do.

Code

documentclass[11pt,twoside,english,openright, bibliography=totoc]{scrreprt}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=2.75cm,rmargin=2.5cm,headheight=18pt,headsep=8pt,footskip=26pt}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setlength{\parskip}{\smallskipamount}
\setlength{\parindent}{0pt}
\usepackage{verbatim}
\usepackage{textcomp}
\usepackage{amstext}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage[authoryear]{natbib}
\usepackage{nomencl}
% the following is useful when we have the old nomencl.sty package
\providecommand{\printnomenclature}{\printglossary}
\providecommand{\makenomenclature}{\makeglossary}
\makenomenclature
\onehalfspacing

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{lscape} 
{scrpage2} &oldpackage
\usepackage[automark, headsepline, footsepline, plainfootsepline]{scrlayer-scrpage}
\pagestyle{scrheadings}
\clearpairofpagestyles
\ohead{\headmark}
\ifoot[Test]{Test}
\cfoot[]{}
\ofoot[\pagemark]{\pagemark}
\ihead[]{}
\chead[]{}
\automark[chapter]{chapter} 
\usepackage{pdfpages}
\renewcommand\nomname{List of Acronyms}


\RedeclareSectionCommand[beforeskip=12pt,afterskip=12pt]{chapter}
\setkomafont{chapter}{\sffamily\LARGE}
\RedeclareSectionCommand[beforeskip=12pt,afterskip=10pt]{section}
\RedeclareSectionCommand[beforeskip=12pt,afterskip=8pt]{subsection}
\RedeclareSectionCommand[beforeskip=-12pt,afterskip=8pt]{paragraph}
\setkomafont{paragraph}{\sffamily\normalsize}

\usepackage {blindtext} 

\setkeys{Gin}{width=\textwidth} 
\raggedbottom
\usepackage[section]{placeins} 
\usepackage {media9} 
\usepackage[hyphens]{url}
\usepackage[colorlinks=true, urlcolor=black, linkcolor=black,  citecolor=black]{hyperref} 

\@ifundefined{showcaptionsetup}{}{%
 \PassOptionsToPackage{caption=false}{subfig}}
\usepackage{subfig}
\makeatother

\usepackage{babel}
\begin{document}

\bibliographystyle{elsarticle-harv}
\nocite{*}
\bibliography{_bib}

\end{document}
1

Here is a patch file for the elsarticle-harv style:

--- /usr/share/texmf-dist/bibtex/bst/elsarticle/elsarticle-harv.bst 2016-08-03 08:15:22.000000000 +0200
+++ elsarticle-harv.bst 2016-08-26 11:28:47.873108598 +0200
@@ -67,6 +67,7 @@
     title
     type
     url
+    urldate
     volume
     year
   }
@@ -368,7 +369,14 @@
 FUNCTION {write.url}
 { url empty$
     { skip$ }
-    { "\newline\urlprefix\url{" url * "}" * write$ newline$ }
+    {
+      "\newline\urlprefix\url{" url * "}" *
+      urldate empty$
+        'skip$
+        { " (Accessed at " * urldate * ")" * }
+      if$
+      write$ newline$
+    }
   if$
 }

Copy your elsarticle-harv-bst to your project and apply this patch. If you are on unix, save the patch in patch.txt and run

cp /usr/share/texmf-dist/bibtex/bst/elsarticle/elsarticle-harv.bst . && patch < patch.txt

This patch extends the write.url function to include the date defined in the field urldate.

MWE:

bib.bib:

@article{key,
  author={foo},
  year={2016},
  url={http://example.com},
  urldate={2016-08-26}
}

test.tex:

\documentclass{article}

\usepackage{natbib}

\begin{document}

\citet{key}

\bibliographystyle{my_elsarticle-harv}
\bibliography{bib}

\end{document}
  • I am quite new to playing around with the .bst files so what exactly do you mean by appyling the patch? Do I copy in what you posted and if yes where abouts ? Thanks a lot! – KiW Aug 26 '16 at 9:54
  • the lines starting with @@ separate different chunks of changes. After the @@ are the line numbers where the changes start (in this case, 67 and 368). Then, every line preceded by a - is deleted in the original version, and you add every line starting with a +. (Lines without a + or - remain unchanged and are for context only.) — edit: on unix, you can use the patch command. – Martin Nyolt Aug 26 '16 at 9:58
  • Awesome! Thanks a lot - I will give it a try! – KiW Aug 26 '16 at 10:00
  • Just out of curiosity it looks like you can run that patch somehow, how would you do that ? EDIT: I am using Windows ;) ... I guess you just answered this one – KiW Aug 26 '16 at 10:02

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.