Skip to content

Commit 835b872

Browse files
authored
Merge pull request #6 from ReScience/ascii-only-bibtex
convert name to ASCII-only when generating bibtex label
2 parents eac3abe + e3ca139 commit 835b872

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

article.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ReScience yaml parser
22
# Released under the BSD two-clauses licence
3+
import unicodedata
34

45
import yaml
56
import dateutil.parser
@@ -155,6 +156,14 @@ def __init__(self, data):
155156
self.authors_full += self.authors[n-2].fullname + " and "
156157
self.authors_full += self.authors[n-1].fullname
157158

159+
# create ASCII bibtex label
160+
# - Try to convert unicode character to their ASCII equivalent
161+
bibtex_label_bytes = \
162+
unicodedata.normalize('NFKD', self.authors[0].lastname).encode('ascii',
163+
'ignore')
164+
self.bibtex_label = str(bibtex_label_bytes, 'ascii')
165+
166+
158167

159168

160169
def parse(self, data):

yaml-to-bibtex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
def generate_bibtex(filename, article):
66
content = (
7-
"@Article {{{_.authors[0].lastname}:{_.date_published.year},\n"
7+
"@Article {{{_.bibtex_label}:{_.date_published.year},\n"
88
" author = {{{_.authors_full}}},\n"
99
" title = {{{{{_.title}}}}},\n"
1010
" journal = {{{_.journal_name}}},\n"

0 commit comments

Comments
 (0)