Mendeley Latex Bibliography Two

Contents

Mendeley is a popular citation manager but it doesn’t properly export bibtex files. Bibtex files (with a .bib extension) are used to add your references to papers compiled in LaTeX. You can find many reports of these problems, including the Mendeley support page. Some of these problems haven’t been officially fixed for over 6 years! In this post I will share some code that addresses these problems, including:

  • Constraints on what you can write in the “year” field
  • Extra curly braces around titles
  • Incorrect format of “month”
  • Ability to select what types of entries include the URL (instead of only webpages)

Why Am I Using Mendeley?

First, here’s some background on how I came to using Mendeley. I was using RefWorks for citation management during grad school. Eventually, some minor annoyances piled up:

  • The website wasn’t responsive, and it was actually kind of clunky to look up papers and export Bibtex files.
  • The website was behind a subscription wall associated with my institution. This wasn’t a huge problem, but it was inconvenient to need to proxy through a campus server just to access my references.

This year, I started looking for an alternative. I tried out Zotero for a while but found it lacking (perhaps more on that in a future post). I eventually settled on Mendeley for the following reasons:

  1. Aggregate editing. I can select multiple entries to change a single field (very handy for conferences).
  2. Generally effective importing of references directly from the browser window.
  3. A useful app that lets me save a PDF annotated in Adobe reader as a separate file. I find this helpful because I do a lot of paper reading on my tablet.
  4. In-text searching. Which papers mention game theory? It’s easy to look up
  5. I can restrict what folders are backed up online so I don’t use up all of my space (2GB currently).
  6. Custom journal abbreviations.
  7. Automatic generation of bibtex files.

Problems with Bibtex Files

Overall, I think my workflow of citation management improved. However, there was one major issue, and that was how Mendeley creates bibtex files. There are a number of small bugs in how the bibtex files are formatted, and these create problems when building your bibliography in a LaTeX document. Here is a summary of the problems:

  1. Mendeley adds an extra set of curly braces to titles. This means that capitalization is always based on what you enter in Mendeley. It cannot be modified to accommodate the bibliography style. This has been a known issue since 2010.
  2. The year can only be written as 4 digits, which prevents you from writing “submitted”, “in press”, “to appear”, or similar text where it is needed. This has been a known Mendeley issue since 2009.
  3. Special characters (like “{}” or “#” inside of titles, etc) don’t work right for me when I have them escaped. Perhaps this isn’t really a problem because I can just disable the option to escape them, but selecting this option gives me weird output if I try to use curly braces to force capitalization of title characters.
  4. The only options to control what entries display URLs are “All” or “Only for Webpages”. Many of my entries have URLs that I want to keep in my database but I don’t want in the bib entry. BUT, there are non-web page entries where I DO want the bib entry, such as for journal papers that haven’t been published yet. So the options aren’t flexible enough.
  5. Months don’t appear correctly if they written in the database as words (e.g., June). The problem is that curly braces are added around the month (e.g., {jun}), so it gets converted to display as “jun” instead of “Jun.”. One fix is to store months as numbers. but this would mean I have to fix every paper when I add it to my database (since writing months with words is the default).

Correcting Bibtex Files

My initial solution was to wait until I was finished with writing a paper. Then, I would copy the bib entries from my master bibtex file into a separate file. I would fix the entries manually. This worked OK for a couple of short conference papers. However, this wasn’t practical to keep repeating. So I started looking for an automated fix.

Long story short, I wasn’t happy with what I could find. I found some solutions that used the online Mendeley reference format editor (such as for adding “in press”), but I’ve had problems getting the results to show up in bibtex files. So, I decided to work on my own solution.

I wrote some code in C that fixes my database in ~0 seconds (OK, more like 0.05 seconds). This is great because I just double-click on the executable whenever I make a change to my database and then I get a fixed copy of the bibtex file. My database has over 500 references so this function should take a database of thousands of entries and still finish before you switch back to your LaTeX editor.

What does this code do? It reads the file generated by Mendeley, fixes the entries, and writes everything to a new bib-file. It imports the default bib-file named “library.bib” and creates file “library_fixed.bib”, but these can be changed using input arguments. Here’s a list of the exact fixes:

  1. Double curly braces around the titles are changed to single curly braces.
  2. If “issn” is defined for an entry but “year” is not, then the “issn” is renamed to “year”. This let’s you use custom text for “year”, such as “in press”, by omitting the year and writing it under “issn” (my reasoning is that the ISSN is usually not included in a bibliography and it would be highly unusual for a paper to have an ISSN without a year).
  3. Escaped curly braces are changed so that you can use them around specific words in titles and they will display properly (needed for acronyms, proper names, etc.). This is an “exception” to a problem created by the removal of double curly braces for titles.
  4. Curly braces are removed around the month (this will only happen if the month appears in the format {xxx}).
  5. URLs will be removed from all entries except a list of specified types. I currently have “misc” and “unpublished” as default exceptions, and more can be added in the source. Web pages are exported as “misc”.

Your mileage may vary with your own bibtex files, but I’ve posted the code on Github. The windows executable is also posted there if you don’t want to compile it yourself.

I will update the code if I find any bugs or add other changes. If you try it out and find it helpful then I would be happy to know!

For those who are interested, here's information on LaTex and Bibtex compatibility. Sources is MIT's Zotero guide.

What is LaTeX?

LaTeX is a typesetting program that takes a plain text file with various commands in it and converts it to a formatted document based on the commands that it has been given. The source file for the document has a file extension of .tex. It is widely used at MIT for theses and other technical papers due to its prowess with mathematical and foreign characters. For more information on LaTeX, see LaTeX on Athena Basics, provided by the Athena On-Line Help system.

What is BibTeX?

BibTex is a bibliographic tool that is used with LaTeX to help organize the user's references and create a bibliography. A BibTeX user creates a bibliography file, wth a file extension of .bib, that is separate from the LaTeX source file. Each reference in the bibliography file is formatted with a certain structure and is given a "key" by which the author can refer to it in the source file. For more information on BibTeX, see MIT IS&T's page: How do I Create Bibliographies in LaTeX.

  • Zotero at MIT: Zotero with LaTeX and BibTeX

    This guide provides instructions to export all of the references in a certain citation library to BibTeX. It was written with Zotero in mind, but both Mendeley and Zotero export libraries the same way using BibTex files, Mendeley users can follow these instructions, too.

  • How compatible is Mendeley with LaTeX?

    Latex - Mendeley question and response from Mendeley Support:
    Hi,
    How compatible is Mendeley with LaTeX? I am considering using Latex to help version control my thesis and I would like to use Mendeley hand-in-hand with that. Could someone advise me? I have found a few questions relating to LaTeX in the archive - but have yet to be convinced whether Mendeley supports it or not!

    Mendeley Agent
    Mendeley can create a bibTeX file through Tools —> Options —> BibTeX syncing which can be used with LaTeX, I hope this helps!

0 Replies to “Mendeley Latex Bibliography Two”

Lascia un Commento

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *