TransWikia.com

Suppress urldate (apacite)

TeX - LaTeX Asked by ECorrales on March 21, 2021

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}

longdefcollect@url#1{globaldefbib@url{#1}}
longdefcollect@doi#1{globaldefbib@doi{#1}}
newenvironment{APACrefURL}{globaltoggletrue{biburl}Collect@Bodycollect@url}{unskipunskip}
newenvironment{APACrefDOI}{globaltoggletrue{bibdoi}Collect@Bodycollect@doi}{}

AtBeginEnvironment{thebibliography}{
 pretocmd{PrintBackRefs}{%
  iftoggle{bibdoi}
    {iftoggle{biburl}{unskipunskip doi:bib@doi}{}}
    {iftoggle{biburl}{Retrieved frombib@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:

reference

Is there a way to suppress or reformat the urldate?

One Answer

Yes, @pablos' and @Guido's solutions don't account for the optional urldate. To make it work, insert this (the original definition of the APACrefURL environment in apacite.sty):

newcommand{APAurl}[1][]{%
  ifx@empty#1@empty
    BRetrievedFrom%  Retrieved from
  else
    BRetrieved{#1}%  Retrieved <date>, from
  fi}%

and replace this line:

{iftoggle{biburl}{Retrieved frombib@url}{}}

with this:

{iftoggle{biburl}{expandafterAPAurlbib@url}{}}

I also spotted a bug in the previous solutions, which resulted in not printing the DOI if no URL is available (weird, right?). For this, you simply need to replace this line:

{iftoggle{biburl}{unskipunskip doi:bib@doi}{}}

with this:

{unskipunskip doi:bib@doi}

Answered by BottleNick on March 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP