Thursday, January 12, 2012

Suppressing BibTeX fields for specific biblatex entry types

I use LaTeX for writing academic papers and biblatex for handling the citations and references in them. One problem I ran into is that biblatex prints out the location, address, month, and publisher for a lot of entries, which I prefer not to have in my reference list. Rather than editing the BibTeX .bib file and losing that data forever, you can tell biblatex to ignore or suppress specific pieces of it.

Below is my code. It suppresses location, address, month, etc. for all entries, and suppresses the publisher and editor field unless the entry is a book. You may need to modify this for whatever style you're using.

% Loads biblatex with clickable links from citations and the reference list, 
% with back references if the style supports them.
\usepackage[hyperref,doi,url=false,backref,style=alphabetic,maxbibnames=99]{biblatex}
\bibliography{refs.bib}

\AtEveryBibitem{% Clean up the bibtex rather than editing it
 \clearlist{address}
 \clearfield{date}
 \clearfield{eprint}
 \clearfield{isbn}
 \clearfield{issn}
 \clearlist{location}
 \clearfield{month}
 \clearfield{series}
 
 \ifentrytype{book}{}{% Remove publisher and editor except for books
  \clearlist{publisher}
  \clearname{editor}
 }
}

Edit on 2/9/2012: As @siretart helpfully points out in the comments, biblatex makes distinctions between fields, name lists, and literal lists in the source file. To see whether to use \clearfield, \clearname, or \clearlist check the biblatex manual for the data type. For example, date and series are fields, location is a literal list, and editor is a name list. I've updated the code above to reflect this.

5 comments:

  1. \clearlist{address} seems to be ineffective, as in biblatex address is according to its documentation an alias to location.

    Also, you need to check the manual if the field to clear is a "list" (then \clearlist{field} is OK) or an "entry" (then you need to use \clearfield{field})

    ReplyDelete
  2. @siretart, thank you for pointing that out. Since I made this post I had run into that problem, and worked around it by using both \clearlist and \clearfield for each one I wanted to get rid of. I didn't know about \clearname until today, though. Now that I know where to look for the type, I can write it much cleaner like the edited code above.

    However, \clearlist{address} does work for me with the alphabetic style anyway. The manual says it is a list literal, even if it is an alias.

    ReplyDelete
  3. Cody! Thanks for the post -- it came in useful today, although biblatex was conflicting with some other package.

    ReplyDelete
    Replies
    1. You're very welcome Darya! Hopefully you figure out the conflicts. Biblatex is a wonderful package.

      Delete