Redundancy in bib file: conditionally suppress url if same as doi?

The original question is about a standard BibTeX style, but inspired by lockstep I've worked out a biblatex solution as a complement to my other answer. The method here is to add the appropriate prefix to the raw DOI, then test this for equivalence to the URL. The prefix needs to be processed with \detokenize as this is how the URL field is formatted.

\documentclass{article}

\usepackage{biblatex}

\renewbibmacro*{doi+eprint+url}{%
  \iftoggle{bbx:doi}
    {%
      \iffieldundef{doi}
        {}
        {%
          \begingroup
          \edef\URLorDOI{%
            \detokenize{http://dx.doi.org/}%
            \thefield{doi}%
          }%
          \iffieldequals{url}{\URLorDOI}
            {\endgroup}
            {%
              \endgroup
              \printfield{doi}%
            }%  
        }%
    }
    {}%
  \newunit\newblock
  \iftoggle{bbx:eprint}
    {\usebibmacro{eprint}}
    {}%
  \newunit\newblock
  \iftoggle{bbx:url}
    {\usebibmacro{url+urldate}}
    {}}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
  doi = {10.1016/j.apal.2008.12.003},
}

@misc{B02,
  author = {Buthor, B.},
  year = {2002},
  title = {Bravo},
  url = {http://dx.doi.org/10.1016/j.apal.2008.12.003},
  urldate = {2010-11-22},
}

@misc{C03,
  author = {Cuthor, C.},
  year = {2003},
  title = {Charlie},
  doi = {10.1016/j.apal.2008.12.003},
  url = {http://dx.doi.org/10.1016/j.apal.2008.12.003},
  urldate = {2010-11-22},
}
\end{filecontents}

\bibliography{\jobname}

\begin{document}

\nocite{*}

\printbibliography

\end{document}

The modifications made by urlbst are quite clear, so the change you want is actually not too hard (by BibTeX standards). If you open up your .bst files, you need to search for a function called output.web.refs. It needs modifying to read

FUNCTION {output.web.refs}
{
  new.block
  output.url
  addeprints eprint empty$ not and
    { format.eprint output.nonnull }
    'skip$
  if$
  adddoiresolver doi empty$ not and
    { 
      url empty$
        { format.doi output.nonnull }
        {
          doiurl doi * url =     
            'skip$
            { format.doi output.nonnull }
          if$  
        } 
      if$  
    }
    'skip$
  if$
  addpubmedresolver pubmed empty$ not and
    { format.pubmed output.nonnull }
    'skip$
  if$
}

All that has happened here is that I've added a test for an empty URL and a second for the URL being the same as the DOI once the prefix is added.


I didn't manage to test for "sort-of-identical" doi und url fields, but here's a solution using biblatex - url and urldate fields will only be typeset if the respective entry doesn't include a doi field.

\documentclass{article}

\usepackage{biblatex}

\DeclareFieldFormat{url}{%
  \iffieldundef{doi}{%
    \mkbibacro{URL}\addcolon\space\url{#1}%
  }{%
  }%
}

\DeclareFieldFormat{urldate}{%
  \iffieldundef{doi}{%
    \mkbibparens{\bibstring{urlseen}\space#1}%
  }{%
  }%
}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
  doi = {10.1016/j.apal.2008.12.003},
}

@misc{B02,
  author = {Buthor, B.},
  year = {2002},
  title = {Bravo},
  url = {http://dx.doi.org/10.1016/j.apal.2008.12.003},
  urldate = {2010-11-22},
}

@misc{C03,
  author = {Cuthor, C.},
  year = {2003},
  title = {Charlie},
  doi = {10.1016/j.apal.2008.12.003},
  url = {http://dx.doi.org/10.1016/j.apal.2008.12.003},
  urldate = {2010-11-22},
}
\end{filecontents}

\bibliography{\jobname}

\begin{document}

\nocite{*}

\printbibliography

\end{document}