# Suppress certain URLS in bibliography

If you get a .bib file from google books, unsurprisingly it has a link to google books in the URL field. This is handy to have in the .bib file so I'd rather not remove it from the file, which would be easy using regex, however I don't want it to print.

Is there a way to suppress printing of the URL field based on the content of that field?

Alternatively it looks like I could disable the URL field for @books with something like \AtEveryBibitem{\ifentrytype{book}{\clearfield{url}}{}} but I'd rather fix the real issue and keep the ability to cite books with URLs .

• You can add a traditional code comment // to the beginning of the field in the bibfile (to make "//url = ..."). This is treated as a keyword of "//url" which is unknown, and thus ignored. (Note, this isn't a real comment command.) – cslstr Mar 20 '14 at 14:03
• @cslstr - or indeed a % by the look of things. So I can use a regex to comment out the field with find:(url\ ?=\ ?\{[a-z:/]*books\.google\.) replace:%\$1. – Chris H Mar 20 '14 at 14:41

You can use \DeclareSourcemap in the preamble to remove fields. Here is a complete example. (If you have the google books bibs in its own file(s) you can also use \perdatasource to make this apply to only that source. See section 4.5.2 (Dynamic Modification of Data) in the biblatex documentation!

\begin{filecontents}{\jobname.bib}
}
@book{good,
url={http://tex.stackexchange.com/},
}
\end{filecontents}
\documentclass{article}

\usepackage{biblatex}
\DeclareSourcemap{
\maps{
\map{
\step[fieldsource=url,
fieldset=url, null]
}
}
}
\begin{document}

• Found it thanks to your expanded example - \DeclareSourceMap{...} has to come after \addbibresource{...}. I had \addbibresource{...} in my master.tex file, and added your code in myutils.sty which is called earlier from master.tex. – Chris H Mar 21 '14 at 8:56
For completeness, the alternative approach set out by clstr in a comment is simply to comment out the offending lines by prefixing them with // or %. I would use a regex for this (as I've got 300 entries in my .bib) either in the editor or from a terminal: sed -r 's/(url\ ?=\ ?\{[a-z:\/]*books\.google\.)/%\1/g oldrefs.bib >newrefs.bib