Created
March 30, 2012 13:43
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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