[Tex/LaTex] Redundancy in bib file: conditionally suppress url if same as doi

bibliographiesbibtexconditionalsdoiurls

Mathscinet gives bibtex entries with both a doi and a url field included. Typically they look something like

@article {some-article,
   […] 
   DOI = {10.1016/j.apal.2008.12.003},
   URL = {http://dx.doi.org/10.1016/j.apal.2008.12.003},
}

I'm using amsalpha.bst, modified with urlbst to process both these fields. Of course, this means that they both appear, completely redundantly, in my bibliography!

My question is: what's the principled way to deal with this? Here are the options I've thought of so far:

  • Modify the bib file so it checks for this redundancy, and doesn't typeset the url in such cases. This seems ideal if it's possible; has anyone already done something like this? If not, is it likely to be doable by someone with a little programming experience but no existing understanding of .bst files?

  • Use a bibstyle that typesets one of url and doi but not both. Not ideal: other bib entries might have only one but not both, or might have a url different from the doi.

  • Comment out (or delete) the `url' field by hand, in the bib file, in these cases. This is what I'm currently doing. Seems a little clunky; also, somewhat violates “separation of form from content”: having the fields the same is correct as content, it’s just inappropriate for them then to both be typeset.

Related question: How to get DOI links in bibliography

Best Answer

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.