[Tex/LaTex] Ignore specific URL fields in biber

biberbibtex

I am using Biber for my literature. Usually the URL should be printed out but some entries have "ugly" URLs like "http://dx.doi.org/…" etc. Is it possible to not print the URL if the URL field contains a specific string? I don't want to clean my bib file because maybe I want to use all URLs later.

I have tried the advice from karlkoeller, but it still doesn't work. Why the following code doesn't work?

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=url,
        match=\regexp{dx.doi.org|dl.acm.org(.+)}, null=true
        ]
    }
  }
}

Best Answer

The solution for you is to use biblatex and biber's sourcemap features.

Add the following code snippet to your preamble.

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=url, match=\regexp{http://(dx.doi.org/|dl.acm.org/)}, final]
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
  }
}

You can extend the list of URLs to be deleted by specifying the URL in match=\regexp{http://(dx.doi.org/|dl.acm.org/)}. To filter example.com, make the line match=\regexp{http://(dx.doi.org/|dl.acm.org/|example.com)}, though you should probably use match=\regexp{http://(www.)?(dx.doi.org/|dl.acm.org/|example.com)} to also catch www.example.com.

biber uses Perl's Regular Expressions, you can read more about them here.

If biber finds a match, the url and urldate are purged, otherwise nothing happens.

The MWE

\documentclass{article}
\usepackage[style=authoryear,backend=biber]{biblatex}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=url, match=\regexp{http://(dx.doi.org/|dl.acm.org/)}, final]
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
  }
}

\begin{filecontents}{\jobname.bib}
@article{testarto,
  author        = {Arnold Uthor},
  title         = {L'Article},
  date          = {2013},
  journal       = {Journal of Interesting Articles},
  volume        = {42},
  url           = {http://dx.doi.org/10.234/56789},
  urldate       = {2013-09-18},
}
@article{testartt,
  author        = {William Riter},
  title         = {Research},
  date          = {2012},
  journal       = {Journal of Interesting Articles},
  volume        = {12},
  url           = {http://dx.doi.org/10.234/56789},
  urldate       = {2013-09-18},
}
@article{testartf,
  author        = {Steve C. Ientist},
  title         = {Some Paper},
  date          = {2012},
  journal       = {Journal of the ACM},
  volume        = {12},
  url           = {http://dl.acm.org/citation.cfm?id=2487241&picked=prox&CFID=362895712&CFTOKEN=85933440},
  urldate       = {2013-09-19},
}
@online{blog,
  author        = {Bernie Logger},
  title         = {A Very Opinionated Blogpost},
  date          = {2013-09-12},
  url           = {http://www.example.com/blog/2013/09/12/opinion},
  urldate       = {2013-09-19},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

yields enter image description here


Edit

biber's features enable us to implement a more sophisticated handling of those URLs.

The following MWE will map DOIs, stable JSTOR identifiers and arXiv links to the appropriate doi or eprintfields. If you do not want to have those displayed, just add doi=false and eprint=false to biblatex's options.

\documentclass{article}
\usepackage{hyperref}
\usepackage[style=authoryear,backend=biber]{biblatex}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{% JSTOR stable
      \step[fieldsource=url, match=\regexp{https?://(www.)?jstor.org/stable/}, final]
      \step[fieldset=eprint, origfieldval]
      \step[fieldsource=eprint, match=\regexp{https?://(www.)?jstor.org/stable/}, replace={}]
      \step[fieldset=eprinttype, fieldvalue={jstor}]
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
    \map{% arXiv
      \step[fieldsource=url, match=\regexp{https?://arxiv.org/(abs|pdf|ps|format)/}, final]
      \step[fieldset=eprint, origfieldval]
      \step[fieldsource=eprint, match=\regexp{https?://arxiv.org/(abs|pdf|ps|format)/}, replace={}]
      \step[fieldset=eprinttype, fieldvalue={arxiv}]
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
    \map{% DOIs
      \step[fieldsource=url, match=\regexp{https?://dx.doi.org/}, final]
      \step[fieldset=doi, origfieldval]
      \step[fieldsource=doi, match=\regexp{https?://dx.doi.org/}, replace={}]
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
    \map{% get rid of
      \step[fieldsource=url, match=\regexp{https?://(dl.acm.org/)}, final]
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
  }
}

\begin{filecontents}{\jobname.bib}
@article{testarto,
  author        = {Arnold Uthor},
  title         = {L'Article},
  date          = {2013},
  journal       = {Journal of Interesting Articles},
  volume        = {42},
  url           = {http://dx.doi.org/10.234/56789},
  urldate       = {2013-09-18},
}
@article{testartt,
  author        = {William Riter},
  title         = {Research},
  date          = {2012},
  journal       = {Journal of Interesting Articles},
  volume        = {12},
  url           = {http://dx.doi.org/10.234/56789},
  urldate       = {2013-09-18},
}
@article{testartf,
  author        = {Steve C. Ientist},
  title         = {Some Paper},
  date          = {2012},
  journal       = {Journal of the ACM},
  volume        = {12},
  url           = {http://dl.acm.org/citation.cfm?id=2487241&picked=prox&CFID=362895712&CFTOKEN=85933440},
  urldate       = {2013-09-19},
}
@online{blog,
  author        = {Bernie Logger},
  title         = {A Very Opinionated Blogpost},
  date          = {2013-09-12},
  url           = {http://www.example.com/blog/2013/09/12/opinion/},
  urldate       = {2013-09-19},
}
@online{HawSpT,
  author        = {S. W. Hawking},
  title         = {The Nature of Space and Time},
  date          = {1994-09-30},
  url           = {http://arxiv.org/abs/hep-th/9409195},
  urldate       = {2013-09-19},
}
@online{HelfGold,
  author        = {H. A. Helfgott},
  title         = {Major arcs for Goldbach's theorem},
  date          = {2013-06-14},
  url           = {http://arxiv.org/abs/1305.2897v2},
  urldate       = {2013-09-19},
}
@article{FregeNumber,
  author        = {G. Frege},
  title         = {The Whole Number},
  journal       = {Mind},
  series        = {newseries},
  volume        = {79},
  number        = {316},
  pages         = {481-486},
  date          = {1970-10},
  url           = {http://www.jstor.org/stable/2252434},
  urldate       = {2013-09-19},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

enter image description here

Related Question