URL field only for certain reference types with biblatex

I'm using biblatex for my references. My bib file includes many references which I have imported from different sources. Not all references have a url entry and some of them are bogus. I now like to suppress the url entries by default but use them for specific reference types, e.g. @manual, only.

Currently I use:

\usepackage[
style=numeric-comp,
sorting=none,
doi=false,
isbn=false,
url=true,
eprint=false,
maxnames=99
]{biblatex}


Is there a possibility to say url=false in general but something like manual={url=true}? I like to avoid going to my big bib file and comment out all other url entries.

-

\documentclass{article}

\usepackage{biblatex}

\AtEveryBibitem{%
\ifentrytype{manual}{%
}{%
\clearfield{url}%
\clearfield{urldate}%
}%
}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@manual{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
url = {tex.stackexchange.com},
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
url = {tex.stackexchange.com},
}
\end{filecontents}

\nocite{*}

\begin{document}

\printbibliography

\end{document}


-
 Thanks! biblatex seems very flexible. – Martin Scharrer♦ Apr 19 '12 at 17:11

I want to provide an other solution. You can work with the command \DeclareFieldFormat. In this way you can simple add new entry types or you are able to set special formation for different entry types.

The command \DeclareFieldFormat has a star version which sets the defined for every entry type. In the next step you can define a special setting for one or more entry types by using the optional argument.

\documentclass{article}

\usepackage{biblatex}

\DeclareFieldFormat*{url}{}
\DeclareFieldFormat*{urldate}{}
\DeclareFieldFormat[manual]{urldate}{\mkbibparens{\bibstring{urlseen}\space#1}}
\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@manual{A01,
author = {Author, A.},
year = {2001},
title = {Alpha},
url = {tex.stackexchange.com},
urldate={2012-04-19}
}
@misc{B02,
author = {Buthor, B.},
year = {2002},
title = {Bravo},
url = {tex.stackexchange.com},
urldate={2012-04-19}
}
\end{filecontents}

\nocite{*}

\begin{document}

\printbibliography

\end{document}


@lockstep: I hope it's ok that I take your example.

-
+1. The benefit of your method is that it avoids complicated nested conditionals if one wants to allow URL's for several types; the drawback is that one has to look up and copy the original format definitions of url and urldate. – lockstep Apr 19 '12 at 17:13
@lockstep: In my opinion the file biblatex.def is part of the documentation. However the questioner is Martin ;-) I think is able to read the file ;-) – Marco Daniel Apr 19 '12 at 17:18
@MarcoDaniel I don't think having to look at biblatex.def is a big deal, either. However some contributed styles aren't very good at managing unit punctuation. So suppressing fields with the \clearfield-type commands is generally better at avoiding spurious punctuation than an empty formatting directive. – Audrey Apr 19 '12 at 18:27
@Audrey: DO you think we should support every contributed style. I think in this way it's a bug of the package ;-) – Marco Daniel Apr 19 '12 at 18:29
@MarcoDaniel Supporting every contributed style and offering a solution robust to bugs (which are inevitably something a user must face sometimes) are two very different things. – Audrey Apr 19 '12 at 18:33
show 1 more comment

An alternative approach, if you are using biber, is to do this before biblatex sees any data at all. Put this in your biber.conf:

<?xml version="1.0" encoding="UTF-8"?>
<config>
<sourcemap>
<maps datatype="bibtex" map_overwrite="1">
<map>
<per_type>MANUAL</per_type>
<map_step map_field_set="URL" map_field_target="URL"/>
</map>
<map>
<map_step map_field_set="URL" map_null="1"/>
</map>
</maps>
</sourcemap>
</config>


You could also just use one map clause and list all the entry types you want to remove urls from, each in their own per_entrytype line.

-
+1 This reminded me to edit another biber solution I posted. urldate should be suppressed, too. I guess just with <map_step map_field_set="URLDATE" map_null="1"/> in the second map clause. – Audrey Apr 20 '12 at 15:24
Yes, you can have as many map_step items as you like and they are processed in order, seeing the results of the previous steps. The <map> sections are mainly for grouping so that you can apply some transformations only to specific entrytypes or datasources etc. – PLK Apr 20 '12 at 19:38