Link Twitter Facebook LinkedIn Github Email

Quick BibTeX capitalization-preserving one-liner

While writing my thesis, I realized that I need to preserve the capitalization of some words like proper or gene names in the titles of references that I imported from the Pubmed database, but having to manually comb through my BibTeX file and surround everything with curly braces was not my idea of fun. vim to the rescue!

This regex is a bit hairy, but it works and it's idempotent. Every once in a while, I just rerun the command to make sure all the capitalizations in the titles are "protected". One side effect that I didn't feel was worth correcting is that it add braces around the first word of every title, but it seems like a relatively harmless effect that isn't worth the effort to fix, since it can be hairy to eliminate the false negatives for names appearing at the beginning.

Anyway, here is the one-liner:


Currently, I limited its substitutions to the title field, but you can substitute any other field name for Title (note it appears twice) as long as that field is all in one line, as it is with my BibTeX file.