Translate

Sunday 30 November 2014

LaTeX style files

Prelude

Since nearly all funding for particle physics comes from tax payers around the globe, I am proud to say that particle physicist have been steadily improving at making their work public and open to all. Since the beginning of this year, a consortium sponsors open access to publications in particle physics. This funds the important peer-review process, which is how journals maintain the quality of their contributions. Of course, everybody is free to disseminate their opinion in blog articles, twitter messages, and to upload notes of their studies to online archives, but without verification by an independent reviewer, the quality of this information is questionable. The peer review process is of course no silver bullet, but it's the best method we have to qualify research as worthy of distribution to others, so that they can build upon the results.

Bibtex in particle physics

This long-winded introduction brings me to the crux of this post: We are submitting our current draft to EPJC. They provide LaTeX templates including a bibtex style file. (It would be great if they could arrive in this decade and allow biblatex, but most of them require natbib, which precludes the use of biblatex...) We usually cite references from various sources, so being able to use a bibtex database and a style file to get them all formatted consistently is a great bonus. The journals do a reasonable job of formatting their citations consistently, and they use the right fields for author, year, edition, pages, etc. Unfortunately for us, many contributions in the linear collider community did not go through a peer review, and the online repository we use for most of our work contains both, links to peer-reviewed journal articles, as well as private uploads of notes were not subject to the same scrutiny. This also means that the bibtex entries are somewhat inconsistent, to say the least. So some adjustment of the bibtex file (easy) and the bibtex style file (not easy) is needed.

Editing the style file

Adding fields from your bibtex database

As mentioned, most of our sources, peer-reviewed or not, can be found on the online archive, which gives them an "eprint" field in the bibtex database. Unfortunately, the style file distributed by EPJC ignores this field. The first course of action is to add an "eprint" field under the ENTRY section of the bst file (most likely near the top of the file).

Adding a document type

Bibtex allows to specify individual formatting rules for each document type: For a @book, you might want to mention editors and an ISBN, while for a published @article, the journal edition and page numbers are more relevant. For our current draft submission, I decided to format peer-reviewed articles differently from non peer-reviewed ones. Bibtex uses functions with the same names as the document type to specify formatting rules, so an @article is formatted by FUNCTION{article}{...}, while a book is formatted by FUNCTION{book}{...}. Unlike the formatting of individual fields, specifying a new document type does not need to be declared anywhere, other than writing a function for it.
I came up with this for formatting my new "arxiv" document type for articles uploaded to the online repository, but not published in a journal:
 FUNCTION {arxiv}  
 { output.bibitem  
  format.authors "author" output.check  
  add.comma  
  format.date "year" output.check  
  format.eprint "eprint" output.check  
  fin.entry  
 }  
Actually, each of these lines is a call to another FUNCTION. Most of these are defined by the style file already. I just had to write the format.eprint function, which looks like this:
 FUNCTION {format.eprint}  
 { eprint "eprint" bibinfo.check  
  duplicate$ empty$ 'skip$  
   {  
    new.block  
    "arXiv:" swap$ *   
   }  
  if$  
 }  
This prints the word "arXiv:" before the eprint entry of the bibtex database. I don't want to go into more detail about the different lines here. Mostly, because I don't understand every detail of the language used. Read the docs if you are interested.

Summary

This post assumes that you have at least cursory familiarity with bibtex and are faced with a somewhat constrained problem. As you can see, it's not a lot of code that needed writing, but finding out what to put where was somewhat time-consuming.
If you start from scratch, I suggest you follow the links in this post and only use the bibtex database to collect your references. Use biblatex rather than bibtex to format them.

I haven't fully finalized my formatting, yet, but this should give you an idea of how to change an existing bst file to suit your needs. I'll be sure to submit the revised version of the bst to the journal. If they just get rid of the natbib requirement and allow the use of biblatex, this will all become much easier. In the meantime, if you want to submit an article to a journal, and are faced with a similarly incomplete template, I hope this post is useful for you. 

No comments:

Post a Comment