Citing BibTeX entries generated by Mendeley

When Mendeley generates BibTeX files for entries with more than one URL, it concatenates the various URLs in a single BibTeX url field. That’s a problem because it means the URLs will be wrongly formatted when you cite the entry in your LaTeX document.


I use Mendeley intensively for my bibliographic needs. I use it to keep references to all bibliography that I need in my work, I use as a PDF database, I use it to keep my own publications and as my main academic profile on the web, I use it when writing papers on Word or LaTeX. One nice thing about Mendeley, is that is allows you to associate several files and URLs with a single publication. I often take advantage of this in my own publications (see Figure 1) to publish the PDF of a paper, along with any presentations, posters, and other stuff (usually as references to a Figshare item).

Figure 1. Mendeley entry with two URLs.


Mendeley can generate BibTeX files automatically (it also has plugins for Word and OpenOffice…), however, BibTeX conversion is not very flexible and it has a few problems. One of those problems occurs when entries have more that one URL associated. For example, the entry highlighted in Figure 1, would result in the BibTeX code of Figure 2. Notice that the two URLs have been concatenated in a single ‘url’ field in BibTeX.

Figure 2. BibTeX code for the entry in Figure 1.

If you use that BibTeX code in a LaTeX file the resulting reference will be rendered as Figure 3, which is not what you would want because both URLs were concatenated together.

Figure 3. Rendering the reference of Figure 2.

In my case, what I wanted was to simply render one of the URLs – the one that references the paper itself. My solution was to redefine the \url command to detect the cases where the passed URL has a space in it, and print only the first URL. For this, I use the xstring LaTeX package:


  % I use a custom reference style


  % I use a custom reference style

  % Split the URL string using the space character and take only
  % the first part.
  % Because the entry is formatted by default using the \url command
  % we need to first give it another name, and then redefine
  % the \url command to our own implementation.
  \IfSubStr{#1}{ }{%
  \StrPosition{#1}{ }[\Result]



This will produce something like:

Figure 4. Rendering the reference of Figure 2, with the new `\url` command.

comments powered by Disqus