3

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
3

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{bad,
  title={With link we don't want},
  url={http://books.google.se/books?id=SNeHkMXHcd8C},
}
@book{good,
  title={With link we want},
  url={http://tex.stackexchange.com/},
}
\end{filecontents}
\documentclass{article}

\usepackage{biblatex}
\addbibresource{\jobname.bib}
\DeclareSourcemap{
  \maps{
    \map{
      \step[fieldsource=url,
            match=\regexp{/books\.google\.},
            fieldset=url, null]
    }
  }
}
\begin{document}
\nocite{good, bad}
\printbibliography
\end{document}
  • I have to admit I'm having a bit of trouble making it work, I thought adding [overwrite=true] would sort it but no - I'll keep trying when I'm on a machine that compiles at a reasonable speed. – Chris H Mar 20 '14 at 16:40
  • I don't know what that's about. I've changed my answer to include a complete example that works for me to compare with. – pst Mar 20 '14 at 23:24
  • 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
0

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

  • I actually did this first before getting @pst's answer working, but pst's approach is better. – Chris H Mar 21 '14 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.