I'm using apacite
package, and I've been trying to suppress the url
when the doi
is available, following the solution provided by Linebreak in url:
\documentclass[11pt,a4paper]{article}
\usepackage{hyperref}
\usepackage{apacite}
\usepackage{etoolbox}
\usepackage{environ}
\newtoggle{bibdoi}
\newtoggle{biburl}
\makeatletter
\undef{\APACrefURL}
\undef{\endAPACrefURL}
\undef{\APACrefDOI}
\undef{\endAPACrefDOI}
\long\def\collect@url#1{\global\def\bib@url{#1}}
\long\def\collect@doi#1{\global\def\bib@doi{#1}}
\newenvironment{APACrefURL}{\global\toggletrue{biburl}\Collect@Body\collect@url}{\unskip\unskip}
\newenvironment{APACrefDOI}{\global\toggletrue{bibdoi}\Collect@Body\collect@doi}{}
\AtBeginEnvironment{thebibliography}{
\pretocmd{\PrintBackRefs}{%
\iftoggle{bibdoi}
{\iftoggle{biburl}{\unskip\unskip doi:\bib@doi}{}}
{\iftoggle{biburl}{Retrieved from\bib@url}{}}
\togglefalse{bibdoi}\togglefalse{biburl}%
}{}{}
}
\begin{document}
\nocite{*}
\bibliographystyle{apacite}
\bibliography{references}
\end{document}
In the references.bib
have the following citation:
@misc{american_cancer_society_melanoma_2018,
title = {Melanoma {skin} {cancer}},
url = {https://www.cancer.org/cancer/melanoma-skin-cancer},
urldate = {2018-02-20},
author = {{American Cancer Society}},
year = {2018}
}
I'm facing the same problem pointed out at the end of the thread, which was not answered:
The solution does not seem to work well if the entry urldate (or lastchecked) is defined (and the DOI is not). The reference would show up as Retrieved from [2018-12-20]http://www.example.com
So after using the code provided, I would come to this:
Is there a way to suppress or reformat the urldate
?