plk / biblatex-apa

APA style for BibLaTeX
90 stars 48 forks source link

Punctuation after URL not suppressed in all cases #141

Closed moewew closed 2 years ago

moewew commented 3 years ago

Via https://tex.stackexchange.com/q/586383/35864.

biblatex-apa succeeds in suppressing punctuation after the URL if it comes at the end of the entry, but if the bibliography driver prints something after the URL that does not always work.

\documentclass[american]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[backend=biber, style=apa, backref=true]{biblatex}

\begin{filecontents}[overwrite]{\jobname.bib}
@techreport{liu2009role,
    title       = {The role of media in initial public offerings},
    author      = {Laura Liu and Ann E. Sherman and Yong Zhang},
    year        = {2009},
    type        = {Working Paper},
    institution = {DePaul University; Hong Kong University of Science and Technology},
    url         = {https://papers.ssrn.com/sol3/papers.cfm?abstract_id=1737544}
}
@article{malkiel2013asset,
    author      = {Burton G. Malkiel},
    title       = {{Asset management fees and the growth of finance}},
    year        = {2013},
    journal     = {Journal of Economic Perspectives},
    volume      = {27},
    number      = {2},
    pages       = {97--108},
    url         = {https://www.aeaweb.org/articles?id=10.1257/jep.27.2.97},
    addendum    = {Addendum},
}
\end{filecontents}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\begin{document}
Lorem \autocite{liu2009role,malkiel2013asset,sigfridsson}

\printbibliography
\end{document}

Not quite sure how one would resolve this properly. Controlling the punctuation after the field is always tricky I'm thinking \nopunct might help to some degree...

\DeclareFieldFormat{url}{\url{#1}\nopunct}

or \printunit...

\renewbibmacro*{doi+url}{%
  \ifboolexpr{          test {\iffieldundef{doi}}
                 or not togl {bbx:doi}}
    {\ifboolexpr{       test {\iffieldundef{url}}
                 or not togl {bbx:url}}
       {\newunit}
       {\usebibmacro{url+urldate}%
        \printunit{\addspace}}}
    {\printfield{doi}%
     \renewcommand*{\finentrypunct}{\relax}%
     \printunit{\addspace}}}