3

Analogous to this question, is there a way to show urls only for those references that do not have pages?

In my bibliography I have a number of articles or reviews where I keep the url field to know which website I got a given pdf from, but the pdf is a regularly published article, so it has page numbers, hence the url information is redundant. However, I also have some @articles from regular online journals and therefore not of the @online type, but that don't have pages where I would need to keep the url.

In short, I don't want to eliminate urls globally or per bibtex type, but rather have some if-then function do it for me based on whether or not the pages field is empty.

EDIT: It would also be great to accomplish the same for doi and urldate fields, i.e., suppress these too if page numbers are present.

Following the solution here one could do:

\documentclass{article}
\usepackage{filecontents}
\usepackage{biblatex}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=pages,final]
      \step[fieldset=url,null]
    }  
  }
}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{test1,
  author = {Antelope, Alfred},
  year = {2010},
  title = {A Title},
  url = {www.url.com},
  urldate = {2015-05-05},  
  journal = {Journal},
  volume = {1},
  number = {2},
  pages = {3--15}
}
@article{test2,
  author = {Bee, Ben},
  year = {2011},
  title = {Best Title},
  url = {www.url.com},
  urldate = {2015-05-05},  
  journal = {Journal},
  volume = {1},
  number = {2}
}
\end{filecontents}
\addbibresource{\jobname.bib}
\begin{document}
\nocite{*}
\printbibliography
\end{document}

... but it still always prints the urldate and, if present, also the doi field. Maybe someone knows a better solution?

2
  • 1
    One can certainly remove the fields with a source map. But what will you do if you run into an online journal in pdf format where the article is on page 3? Imho you should better correct your bib-file. If the url is not a real url but only a note to yourself, move it to another field. Aug 22, 2016 at 7:29
  • @UlrikeFischer Point taken!
    – jan
    Aug 22, 2016 at 9:04

1 Answer 1

3

You can extend your sourcemapping a bit to also delete dois and urldate, if pages are present.

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=pages,final]
      \step[fieldset=url,null]
      \step[fieldset=urldate,null]
      \step[fieldset=doi,null]
    }  
  }
}

With standard biblatex styles you could alternatively use

\renewbibmacro*{doi+eprint+url}{%
  \iffieldundef{pages}
    {\iftoggle{bbx:doi}
       {\printfield{doi}}
       {}%
     \newunit\newblock
     \iftoggle{bbx:eprint}
       {\usebibmacro{eprint}}
       {}%
     \newunit\newblock
     \iftoggle{bbx:url}
       {\usebibmacro{url+urldate}}
      {}}
    {}}

For biblatex-chicago's authordate the modification is

\renewbibmacro*{bib+doi+url}{% 16th ed.
  \iffieldundef{pages}
    {\ifthenelse{\iffieldundef{urlyear}\AND\iffieldundef{urlmonth}}%
       {}%
       {\printurldate}% Date fix
     \iffieldundef{addendum}%
       {\newunit\newblock}%
       {\newcunit\newblock}%
     \iftoggle{cms@doionly}%
       {\iffieldundef{doi}%
          {}%
          {\printfield{doi}%
           \setunit*{\addperiod\addspace}\newblock%
           \clearfield{url}}}%
       {\ifboolexpr{%
          togl {cms@doi}%
          and
          not test {\iffieldundef{doi}}%
        }%
          {\printfield{doi}%
           \setunit*{\addperiod\addspace}\newblock}%
          {}}%
     \ifboolexpr{%
       togl {cms@eprint}%
       and
       not test {\iffieldundef{eprint}}%
     }%
       {\usebibmacro{eprint}%
        \setunit*{\addperiod\addspace}\newblock}%
       {}%
     \ifboolexpr{%
       togl {cms@url}%
       and
       not test {\iffieldundef{url}}%
     }%
       {\printfield{url}}%
       {}}
    {}}%
1
  • That's a thorough solution! Thank you very much!
    – jan
    Aug 22, 2016 at 8:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .