Archive for February, 2012

CSL & Mendeley

Citation style language (CSL) is an XML format that allows for easy mark-up of citations. This is great as tons of popular reference managers use it. My manager of choice is Mendeley as I particularly like the ability to share references within groups and, I can get my papers on all my devices. Plus Mr. Gunn (of Mendeley) is a super badass genius and why wouldn’t you want to use something that Mr. Gunn recommends?

I particularly like the PLoS citation format as it is clean looking and, presents all the relevant information that a person would need in order to find the article being referenced.

1. Maloney A, Herskowitz LJ, Koch SJ (2011) Effects of surface passivation on gliding motility assays. PloS one 6: e19522. Available:http://www.pubmedcentral.nih.gov/articlerender.fcgi?artid=3108588&tool=pmcentrez&rendertype=abstract. Accessed 23 July 2011.

It shows:

  • The authors.
  • The year.
  • The article name.
  • The Journal – Which it never gets the capitalization correct but oh well…
  • The volume number. Complete with that pesky space after the _:_.
  • The page numbers.
  • And finally, the silly Available:… even though I have a DOI for the article.

I’m not too keen having the Available:… tag as it doesn’t give relevant information for locating an article. This stems from my belief that URLs are not forever and neither are websites. Remember Geocities? What I do want to have is the DOI in place of the Available:… since DOIs have been deemed forever static as issued forth from the electronic scribes in the cloud. At least I hope so.

In order to ensure that I don’t have the Available: section in my citation and I do have the DOI, I had to change the CSL file to do what I wanted. First, I had to find where Mendeley stored the CSL files on my computer. Since I’m using a Mac, I found they needed to be stored in:

~/Library/Application Support/Mendeley Desktop/citationStyles-1.0/

Which are my user specified csl files. I downloaded a copy of the plos.csl file from here and copied it into the above folder. I then made a copy of the plos.csl file and opened it up with my text editor and started modifying it. The beginning of the file has the info tag which houses the title of the file and the author etc.

<info>
 <title>Public Library of Science (PLoS)</title>
 <id>http://www.zotero.org/styles/plos</id>
 <link href="http://www.zotero.org/styles/plos" rel="self"/>
 <author>
 <name>Julian Onions</name>
 <email>julian.onions@gmail.com</email>
 </author>
 <category citation-format="numeric"/>
 <category field="science"/>
 <updated>2011-12-23T01:16:03+00:00</updated>
 <summary>Public Library of Science Journal style.</summary>
 <link href="http://journals.plos.org/plosbiology/guidelines.php" rel="documentation"/>
 <rights>This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License: http://creativecommons.org/licenses/by-sa/3.0/</rights>
 </info>

I didn’t need all this so I shortened it to the following. This is purely aesthetic but, doing so helped me figure out how to read the code and what the tags meant. I changed the info tag to be:

<info>
 <title>custom</title>
 <id>http://www.zotero.org/styles/custom</id>
 <category citation-format="numeric"/>
 <category field="science"/>
 <summary>doi, bolded journal, italics title</summary>
 </info>

Note that I left the id tag alone. Turns out that if you get rid of it, then your word processor freaks out and says that the citation style is not available at this time. So, leave it in there and just change the URL to indicate that it is a custom style. Doesn’t seem to matter what goes there, as long as it points to the zotero styles.

The next chunks of code are the “macro” chunks. These are “functions” if you will that are reusable bits of code that you can call in the “bibliography” block. The macro blocks in the PLoS CSL are the following:

  • editor
  • author
  • access
  • publisher
  • year-date
  • edition
  • title

In the access macro, the XML looks like this:

<macro name="access">
 <group>
 <choose>
 <if variable="URL">
 <text variable="URL" prefix="Available:" suffix="."/>
 <group prefix=" " suffix=".">
 <text term="accessed" text-case="capitalize-first" suffix=" "/>
 <date variable="accessed">
 <date-part name="day" suffix=" "/>
 <date-part name="month" suffix=" "/>
 <date-part name="year"/>
 </date>
 </group>
 </if>
 <else>
 <text variable="DOI" prefix="doi:"/>
 </else>
 </choose>
 </group>
 </macro>

In this block of code, there are two variables used, the URL and the DOI. Initially I just nixed the entire block for the URL in order to get the citations to have just the DOIs in them. However, this is not entirely advantageous as sometimes I will want the URL because I do not have a DOI. It turns out that just reordering the variables so that the DOI comes in the if statement instead of the else statement will fix this problem.


<macro name="access">
 <group>
 <choose>
 <if variable="DOI">
 <text variable="DOI" prefix="http://dx.doi.org/"/>
 </if>
 <else variable="URL">
 <text variable="URL" prefix="Available:" suffix="."/>
 <group prefix=" " suffix=".">
 <text term="accessed" text-case="capitalize-first" suffix=" "/>
 <date variable="accessed">
 <date-part name="day" suffix=" "/>
 <date-part name="month" suffix=" "/>
 <date-part name="year"/>
 </date>
 </group>
 </else>
 </choose>
 </group>
 </macro>

Now my citations look like:

1. Maloney A, Herskowitz LJ, Koch SJ (2011) Effects of surface passivation on gliding motility assays. PloS one 6: e19522. http://dx.doi.org/10.1371/journal.pone.0019522.

Notice that I  replaced the “doi: ” with “http://dx.doi.org/&#8221; in order to get a URL. Unfortunately, I have not figured out how to make it into a link yet.

The next thing I wanted was to get rid of the space between the “volume: pages”. This is changed way down in line 140 of the plos.csl file. Before I show what I changed, it is important to understand a bit about the code. In this section, I’m in the actual bibliography section that will format the citation in the way that I want. Within the bibliography section is a layout tag. This is just a tag that indicates the layout of the citation. In other words, this is the way the citation will look. The flow of the code is as follows:

  • layout – Defines the layout tag.
  • citation-number – This puts a number in front of the citation.
  • group – Next is a group section that has spaces between the entries. Here, the bibliography calls the macros above to list the authors, year, and title.
  • choose – This section defines a set of markups for different types of citations . In other words, if you have a “book report”, “chapter paper-conference”, or “thesis”, the XML will style each of those entry types differently. These different styles are contained in if and else-if statements. So, if your citation is a book, then this file will tell the citation how to format it for a book etc.
  • else – At the end of the if and else-if statements is the else statement. This is how the markup for journal articles and basically everything else other than the stuff listed above is going to be formatted.

In this else statement, there is a text tag for the variable “page”. Getting rid of the space in the prefix attribute fixes the space problem.


<choose>
...
<else>
 <group delimiter=" " prefix=". ">
 <text variable="container-title" form="short" strip-periods="true" font-weight="bold"/>
 <text variable="volume"/>
 </group>
 <text variable="page" prefix=":"/>
 </else>
 </choose>

So I also decided to make the journal name bold. Hence the font-weight attribute above. I also decided to make the article title italics so back up in the first group section of the bibliography, I attached a font-type attribute. Now my citations look like the following.

1. Maloney A, Herskowitz LJ, Koch SJ (2011) Effects of surface passivation on gliding motility assays. PloS one 6:e19522. http://dx.doi.org/10.1371/journal.pone.0019522.

The only thing I can’t seem to do is actually make the doi a real link so I have to go through the bibliography to make them ones. Oh well…

Leave a comment