Skip to content

Instantly share code, notes, and snippets.

@mattions
Created March 30, 2012 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattions/2251645 to your computer and use it in GitHub Desktop.
Save mattions/2251645 to your computer and use it in GitHub Desktop.
Initial work to protect the Capital letters in latex with braces. WARNING: Does not work, but it is a start
#!/usr/bin/env python
# -*- coding: utf8 -*-
import re
def protect_with_braces(title):
new_title = ''
words = title.split()
for w in words:
#print w
m = re.search('([A-Z]\w+)', w)
if m:
if w!=words[-1]:
new_title += "{%s} " %w
else:
new_title += "{%s}" %w
else:
if w!=words[-1]:
new_title += "%s " %w
else:
new_title += "%s" %w
return new_title
import yapbib.biblist
import yapbib.biblist as biblist
b = biblist.BibList()
bibtexfile = 'biblio_library.bib'
bibtexfile_output = "biblio_library_corrected2.bib"
file_handler = open(bibtexfile_output, 'w')
b.import_bibtex(bibtexfile, normalize=False)
items = b.List()
new_bibtex = None
for item in items:
bibentry = b.get_item(item)
title = bibentry.get_field('title')
new_title = protect_with_braces(title)
print ("Old title: \n%s" % title)
print ("New title: \n%s" % new_title)
bibentry['title'] = new_title
file_handler.write(bibentry.to_bibtex())
file_handler.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment