Dealing with italics in bibtex files exported from Mendeley

TL;DR Tags for italicized text in bibtex file generated by Mendeley are not compatible with BibTeX/LaTeX. This is still an issue as of August 2015. I wrote a Python script to fix the tags from <i> and </i> to \textit{}.

I decided to write my Ph.D. thesis in LaTeX because I wanted the culmination of my years of work to beautifully presented. One blip I have encountered though is with my references in the bibtex file generated by the Mendeley reference manager I use. First, let me just say that Mendeley is awesome; I’ve used it for about 6 or 7 years now and has been incredibly useful: I collect, skim, and read a lot of journal articles so it’s been a huge time-saver with its annotation and searching functions. I also have used the plugin for citing in LibreOffice Writer, which has been great (except for this one weird glitch that I think may be related to citing within tables).

So what’s my problem? I needed species and gene names to be italicized in the article titles. This is accomplished by adding <i> and </i> tags in the title field of the Mendeley desktop application, here surrounding the genus name Bacteroides:

But these tags are unchanged in titles of the Mendeley-generated bibtex file:

Which this leads to incorrect characters in the citation of the document:

Am I the first to encounter this problem? It doesn’t seem so. Perhaps there aren’t many Biology graduate students writing their theses in LaTeX. Or perhaps those that do don’t care about proper italicization. I myself am not really a stickler for these details, but some people are and these people may be on the committees that decide the fate of lowly graduate students like me.

I corresponded with the Mendeley Support team on Twitter to see if perhaps they had a fix to this italics tag problem:

The only solution then was to repair the bibtex file myself, which though it is a bit annoying, is actually very straightforward. I wrote the Python script below to change the html-like tags to LaTeX ones*.

For this script to work as is, the following requirements must be met:

• Python version 2.7 needs to be installed (Python 3 may work; haven’t tested)
• The script needs to be in the same directory as the bibtex file it is meant to process.
• The bibtex file must be named “bibliography.bib”; a new file called “new_bibliography.bib” will be generated that has all instances of the <i> and </i> tags replaced with the LaTeX \textit{} command. (Note: be very careful that all instances of <i> and </i> are correct in the Mendeley title field!)

#!/usr/bin/python

# By: Kathy Lam
# Date: January 11, 2016
# Purpose: Replace all instances of "<i>" with "\textit{"
#          and "</i>" with "}" in bibtex file generated by Mendeley

oldbib = open("bibliography.bib", "r")
newbib = open("new_bibliography.bib", "w")

for line in oldbib:
if line.startswith("title"):
if "<i>" in line:
fixed_open_tags = line.replace("<i>", "\\textit{")
fixed_both = fixed_open_tags.replace("</i>", "}")
newbib.write(fixed_both)
else:
newbib.write(line)
else:
newbib.write(line)



In Windows, I think the script can be executed by double-clicking for those who want to avoid using the command-line. On a Mac, the file permissions must be changed to allow it to be executable, which I think has to be done through the command line using chmod +x [script_name.py]; and if you want to execute the script by double-clicking, the extension of the script should be changed from .py to .command.

Here is the reference after the italics have been fixed — huzzah!:

And, for completeness’ sake, here is the corrected bibtex file entry:

*To make the script as universal as possible, I avoided using libraries like BibtexParser. I hope that this script might be useful to someone out there trying to google a solution to this problem…

Comic Sans and the aesthetics of science

You know what is always very pretty? Autumn in Ontario. Last Saturday, it was gorgeous out, and I went for a hike with a few of my friends in the Forks of the Credit Provincial Park, which is located in Caledon. The Bruce Trail runs through there, and though it wasn’t yet peak colour in that region, it was still beautiful:

That story was a lead-in to my next question: you know what isn’t always pretty? The visual presentation of science. And to that, I say, is that really so bad…?

I’m not saying science shouldn’t be presented in a visually appealing way, or that emphasis on visual appeal is wrong. I’m not saying that. Visuals are important, of course. But can we all admit that it has gotten a bit crazy when the fuss is more about the non-science than it is about the science? Case in point: the hatred of Comic Sans. When the scientists working at CERN gave their presentation about the Higgs boson, it seemed that the media (and especially the social media) were more focused on the font in their PowerPoint presentation than on their science. It made me feel deflated. Yes, okay, fine: Comic Sans probably shouldn’t have been used. But it was. Not every person has an artistic eye, nor do all people have the same taste. Nor should they. Leave it be. Do we have to be jerks about it? We can choose not to be.

It also makes me feel a bit deflated when I hear talk of how science should be presented; that we should think of our presentation of scientific data as if it were marketing or advertising. Doesn’t that seem strange? Advertising is about convincing, persuading, manipulating an audience. While that might arguably be a good strategy, I don’t think it’s something one should do necessarily. I say this as a person who does spend hours and hours and days and days fixing slides and posters. I’ve gotten much better over the years, and when I see presentations now, I can’t help but notice when things aren’t aligned, when there are extra spaces between words, when weird colours and fonts are used, and when images are pixelated. But I also think that that these things are secondary to the science. I try not to be distracted by them, and I envy those whose attention is not mercilessly seized by these aesthetic details — details which, I think, we should actively try not to pay too much attention to. “Too much attention” I would define as the level at which attention must be taken away from the science — in one’s own thoughts, in conversation with others, whatever.

To me, a science presentation is like a painting. Should we stand here and criticize the painter’s technique, the choice of colour, and the quality of the paint? We could easily do that, sure. But shouldn’t we try to see what artist has tried to convey, through his or her painting? The message in the painting is the important thing. We need to forget about the Comic Sans. It’s not easy, but, for the message, I think it’s worth trying our best. Plus, we wouldn’t be jerks, and that’s a good thing, too, because the world has enough of those.

Karma, intuition, and the impotence of science

Karma, destiny, and related ideas aren’t things that I have thought a whole lot about in my time spent being alive. For most of my life, I’ve held a scientific worldview — one in which ideas like karma don’t really have a place, due to a lack of observable evidence (to me). I think it is generally accepted that these ideas are outside the domain of science;  because these ideas are not falsifiable, science cannot not address them. I would even go as far as to say that science is powerless to address them. That seems like a better description, because science — the scientific method that many of us use to understand the universe and our place in the universe — fails us when it comes to the metaphysical. And there are many important metaphysical questions that all of us think about.

I recently came back from a trip to Asia. Among the places I visited was Vietnam, where my parents are from. I had visited Vietnam once before, in the mid-’90s, but I was too young to truly appreciate my experiences. A little before, a lot during, and now after this trip, I am starting to really ponder ideas like karma. I started thinking about karma because my mother holds Bhuddhist beliefs, and during our trip, she took time to make donations to a village elementary school, and also to give out rice and medicine to the poor:

My mom, Luyen, standing under a banner, holding a plaque for her donation to a Vietnamese elementary school.

My mom purchased hundreds of kilograms of rice to give away.

My mom giving away rice and medicine.

In my head and in my day-to-day life, I think that there is no such thing as karma or other similar ideas. But to my self, upon reflection, somehow that doesn’t make a whole lot of sense. It’s not only that the emptiness is unsatisfying in an existential way; it’s also that it feels intuitively inadequate in a way that is difficult to describe. As someone who considers themself scientific, I feel distrustful of this kind of intuiting (even when it is done by me), but there is much “intuiting” done (read: instinct behaviour) by creatures on earth that is powerful and that plays an important role in the existence of said creatures in their place in the universe. Isn’t that true? Then intuition, even about “wild” ideas, shouldn’t be entirely disregarded… should it?

Maybe science won’t be so powerless in the end. Perhaps quantum physicists or cosmologists who study dark matter will be able to give us answers to our metaphysical questions eventually.

Conferences, seminars, and journal clubs, oh my!

I’ve heard a lot of people say that travelling is one perk of being in science, referring to the travelling done for multi-day conferences. I think I disagree more than I agree. Conferences usually have tight schedules, and there’s not much time for exploring a new place, unless one sacrifices some scheduled talks or takes additional days off after the conference is over. When I think of travelling for ‘fun’, I imagine spending a few weeks sampling bits and pieces of a foreign place at a peaceful pace… but, usually, conferences involve sitting in overly air-conditioned rooms, listening to research talk after research talk, scarfing down not-too-healthy food, scrambling from room to room, and tracking down a few (potentially) interesting posters in giant venues, a la ASM 2011, in New Orleans:

I coudn’t resist taking that picture from the balcony that overlooked the poster “room”. In short, conferences are kind of crazy and hectic — and ASM is especially crazy because it involves so many people.

All that being said, I really, really like conferences. I guess I like science discourse — even when I can’t contribute in a meaningful way. I am puzzled by (and sort of suspicious of) people who don’t invest time in meetings, seminars, and journal clubs. Obviously, these can get dry… but still. I guess I’m constantly learning new things that I think I should know, or things that I’m doing or have done wrong, that I find these things useful. Also, I guess it just seems like doing science without doing all of this other stuff is like… painting in a room without immersing oneself in the  world one is trying to paint. You could still be a great painter, but that behaviour somehow seems incongruous with the love of the art.

Anyway, speaking of conferences, my lab is going to CSM this year. My supervisor sent us all some advice on how to make posters, and I wanted to share it because it was good advice as well as entertaining. I was pretty proud of my poster for ASM (design-wise, not results-wise), but I think now that it had too much text:

I’ll have to work on that. Live and learn. (And do science, and make time to enjoy the other science that is in the world. And paint?)

The tragedy of the commons

Having worked in multiple molecular biology laboratories, it’s not hard to notice that science generates a lot of waste. Some labs are worse than others. I’m lucky to be in a lab in which, due to financial and environmental awareness on the part of both students and staff, we really try to reduce waste. We wash and re-use our weigh boats, plastic syringes, our glass culture tubes, sometimes even plastic conical tubes. Many labs don’t do this; many find this practice laughable. There is also the argument that it costs more in time to wash these things (or in money to pay someone to wash them), than it costs to simply buy more. Herein lies the tragedy of the commons… from the small laboratory to global environmental issues.

The paper The Tragedy of the Commons was published in Science by Garrett Hardin in 1968. I do not remember the exact context in which this piece was recommended to me, but only because it is so applicable to everything and I therefore think about it often. It is something that everyone should read. It discusses the population problem, and obvious related problems. I leave you with a rather long excerpt:

Where does the mind meet the heart?

I’m currently reading a book called, “The Universe in a Single Atom: The Convergence of Science and Spirituality”, written by the 14th Dalai Lama. Increasingly, it seems that Bhuddism is the only (popular) religion that is compatible with science, and I am discovering that more and more people I know — who share my scientific worldview — also find some appeal in Bhuddism.

Scientific writing: writing that bores, confuses, and frustrates

Lately, I have been pondering (a friend of mine might call it “internally lamenting”) the way science is presented in the written form. That is, why must scientific writing be so terrible to read? Why are certain practices — probably bad practices — encouraged?

I tweeted several links yesterday about scientific writing. Appropriately, today I stumbled across a post in the Science Careers section of Science, called How to Write Like a Scientist. It made me laugh… but also sad.

I don’t think that we should write as if we are trying desperately to captivate or move an audience (for example, poetically), but I also don’t think we should write in a manner that induces sleep… or the desire to stab oneself in the eye with the nearest sharp object. And why is the passive “It was concluded that…” preferable to the active “We concluded that…”? And on that note, I leave you with a few opinion pieces concerning use of the passive voice in technical writing, submitted to Nature in the mid-’90s.