From c991e5875c0e716ad243db3f2d9c538d8abb1dac Mon Sep 17 00:00:00 2001 From: Jonas Kulhanek Date: Sat, 7 Dec 2019 14:51:40 +0100 Subject: [PATCH 01/12] change pub key --- pubs/commands/add_cmd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubs/commands/add_cmd.py b/pubs/commands/add_cmd.py index 1aa2ec7..b932a08 100644 --- a/pubs/commands/add_cmd.py +++ b/pubs/commands/add_cmd.py @@ -119,7 +119,7 @@ def command(conf, args): citekey = args.citekey if citekey is None: - base_key = bibstruct.extract_citekey(bibentry) + base_key = bibstruct.generate_citekey(bibentry) citekey = rp.unique_citekey(base_key, bibentry) elif citekey in rp: ui.error('citekey already exist {}.'.format(citekey)) From ffeeb4311b28fd768c6ab404b791d68da6701edf Mon Sep 17 00:00:00 2001 From: Jonas Kulhanek Date: Tue, 10 Dec 2019 11:25:06 +0100 Subject: [PATCH 02/12] Implement configuration for default citekey formating --- pubs/bibstruct.py | 14 +++++++++++--- pubs/commands/add_cmd.py | 5 ++++- pubs/config/spec.py | 11 +++++++++++ pubs/version.py | 2 +- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/pubs/bibstruct.py b/pubs/bibstruct.py index a8312b0..66f6ae6 100644 --- a/pubs/bibstruct.py +++ b/pubs/bibstruct.py @@ -57,7 +57,7 @@ def valid_citekey(citekey): return not '/' in citekey -def generate_citekey(bibdata): +def generate_citekey(bibdata, format_string='%A%Y'): """ Generate a citekey from bib_data. :raise ValueError: if no author nor editor is defined. @@ -72,8 +72,16 @@ def generate_citekey(bibdata): try: year = entry['year'] except KeyError: - year = '' - citekey = '{}{}'.format(''.join(author_last(first_author)), year) + raise ValueError( + "No author or editor defined: cannot generate a citekey.") + try: + first_word = entry['title'].split(' ')[0] + except KeyError: + first_word = '' + author_last_name = author_last(first_author) + citekey = format_string.replace('%Y', year).replace('%y', year[-2:]) \ + .replace('%A', author_last_name).replace('%a', author_last_name.lower()) \ + .replace('%W', first_word).replace('%w', first_word.lower()) return str2citekey(citekey) diff --git a/pubs/commands/add_cmd.py b/pubs/commands/add_cmd.py index b932a08..cf67fa9 100644 --- a/pubs/commands/add_cmd.py +++ b/pubs/commands/add_cmd.py @@ -119,7 +119,10 @@ def command(conf, args): citekey = args.citekey if citekey is None: - base_key = bibstruct.generate_citekey(bibentry) + if conf['main']['normalize_citekey']: + base_key = bibstruct.generate_citekey(bibentry, conf['main']['citekey_format']) + else: + base_key = bibstruct.extract_citekey(bibentry) citekey = rp.unique_citekey(base_key, bibentry) elif citekey in rp: ui.error('citekey already exist {}.'.format(citekey)) diff --git a/pubs/config/spec.py b/pubs/config/spec.py index 4c50f4c..a067ed4 100644 --- a/pubs/config/spec.py +++ b/pubs/config/spec.py @@ -31,6 +31,17 @@ note_extension = string(default='txt') # the full python stack is printed. debug = boolean(default=False) +# If true the citekey is normalized using the 'citekey_format' on adding new publications. +normalize_citekey = boolean(default=False) + +# String specifying how to format the citekey. The following +# substitutions are used: +# %a: last name of the first author in lowercase +# %A: last name of the first author in PascalCase +# %Y: four letter year of release (e.g. 2019) +# %y: two last letters of release year (e.g. 19) +citekey_format = string(default='%a%Y') + [formating] # Enable bold formatting, if the terminal supports it. diff --git a/pubs/version.py b/pubs/version.py index b4e3540..21320a8 100644 --- a/pubs/version.py +++ b/pubs/version.py @@ -1 +1 @@ -__version__ = '0.8.3' +__version__ = '0.8.4' From a271b9a757feed4271b499aead291177afb66fef Mon Sep 17 00:00:00 2001 From: Jonas Kulhanek Date: Tue, 10 Dec 2019 11:26:41 +0100 Subject: [PATCH 03/12] Fix config spec for citekey generation --- pubs/config/spec.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pubs/config/spec.py b/pubs/config/spec.py index a067ed4..42097ad 100644 --- a/pubs/config/spec.py +++ b/pubs/config/spec.py @@ -40,6 +40,8 @@ normalize_citekey = boolean(default=False) # %A: last name of the first author in PascalCase # %Y: four letter year of release (e.g. 2019) # %y: two last letters of release year (e.g. 19) +# %w: first word in the title in lowercase +# %W: first work in the title citekey_format = string(default='%a%Y') [formating] From fbcda0d4aa1cefb5d6fcb1af9be66d862b5680e7 Mon Sep 17 00:00:00 2001 From: Jonas Kulhanek Date: Fri, 31 Jan 2020 21:37:04 +0100 Subject: [PATCH 04/12] change bibstruct --- pubs/bibstruct.py | 67 +++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/pubs/bibstruct.py b/pubs/bibstruct.py index 66f6ae6..309a727 100644 --- a/pubs/bibstruct.py +++ b/pubs/bibstruct.py @@ -56,33 +56,56 @@ def valid_citekey(citekey): # FIXME: a bit crude, but efficient for now (and allows unicode citekeys) return not '/' in citekey - -def generate_citekey(bibdata, format_string='%A%Y'): +class CitekeyFormatter(Formatter): + def __init__(self): + super().__init__() + + def get_value(self, key, args, kwds): + if len(args) == 0: + raise ValueError('Must pass bibtex entry to the format method') + entry = args[0] + if isinstance(key, str): + okey = key + if key == 'author' and not 'author' in entry: + key = 'editor' + elif key == 'editor' and not 'editor' in entry: + key = 'author' + + if key == 'first_word' and 'title' in entry: + return CitekeyFormatter._U(entry['title'].split(' ')[0]) + if key == 'author_last_name' and 'author' in entry: + return CitekeyFormatter._U(author_last(entry['author'][0])) + else: + if key in entry: + return CitekeyFormatter._U(entry[key]) + else: + raise ValueError( + "No {} defined: cannot generate a citekey.".format(okey)) + + class _U(str): + def __init__(self, value): + super(value) + + def __format__(self, fmt): + val = self + if fmt[0] == 'u': + s = val.upper() + fmt = fmt[1:] + elif fmt[0] == 'l': + s = val.lower() + fmt = fmt[1:] + else: + s = str(val) + return s.__format__(fmt) + + +def generate_citekey(bibdata, format_string='{author_last_name:l}{year}{first_word:l}'): """ Generate a citekey from bib_data. :raise ValueError: if no author nor editor is defined. """ citekey, entry = get_entry(bibdata) - author_key = 'author' if 'author' in entry else 'editor' - try: - first_author = entry[author_key][0] - except KeyError: - raise ValueError( - "No author or editor defined: cannot generate a citekey.") - try: - year = entry['year'] - except KeyError: - raise ValueError( - "No author or editor defined: cannot generate a citekey.") - try: - first_word = entry['title'].split(' ')[0] - except KeyError: - first_word = '' - author_last_name = author_last(first_author) - citekey = format_string.replace('%Y', year).replace('%y', year[-2:]) \ - .replace('%A', author_last_name).replace('%a', author_last_name.lower()) \ - .replace('%W', first_word).replace('%w', first_word.lower()) - + citekey = CitekeyFormatter(format_string).format(entry) return str2citekey(citekey) From 01a2683700b585e2c55388e67017702f3c3e9225 Mon Sep 17 00:00:00 2001 From: Jonas Kulhanek Date: Sun, 2 Feb 2020 14:50:17 +0100 Subject: [PATCH 05/12] fix pubs --- pubs/bibstruct.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pubs/bibstruct.py b/pubs/bibstruct.py index 309a727..ce905bb 100644 --- a/pubs/bibstruct.py +++ b/pubs/bibstruct.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals import unicodedata import re +from string import Formatter from .p3 import ustr, uchr @@ -58,7 +59,7 @@ def valid_citekey(citekey): class CitekeyFormatter(Formatter): def __init__(self): - super().__init__() + super(CitekeyFormatter, self).__init__() def get_value(self, key, args, kwds): if len(args) == 0: @@ -84,14 +85,14 @@ class CitekeyFormatter(Formatter): class _U(str): def __init__(self, value): - super(value) + super(CitekeyFormatter._U, self).__init__(value) def __format__(self, fmt): val = self - if fmt[0] == 'u': + if len(fmt) > 0 and fmt[0] == 'u': s = val.upper() fmt = fmt[1:] - elif fmt[0] == 'l': + elif len(fmt) > 0 and fmt[0] == 'l': s = val.lower() fmt = fmt[1:] else: @@ -105,7 +106,7 @@ def generate_citekey(bibdata, format_string='{author_last_name:l}{year}{first_wo :raise ValueError: if no author nor editor is defined. """ citekey, entry = get_entry(bibdata) - citekey = CitekeyFormatter(format_string).format(entry) + citekey = CitekeyFormatter().format(format_string, entry) return str2citekey(citekey) From d073e607116e57749954a27ef463687ac5cb5779 Mon Sep 17 00:00:00 2001 From: Jonas Kulhanek Date: Wed, 26 Feb 2020 14:19:29 +0100 Subject: [PATCH 06/12] add tests for pubkey generation --- pubs/bibstruct.py | 39 +++++++++++++++++---------------------- pubs/config/spec.py | 22 ++++++++++++++-------- tests/test_bibstruct.py | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 30 deletions(-) diff --git a/pubs/bibstruct.py b/pubs/bibstruct.py index ce905bb..e47caae 100644 --- a/pubs/bibstruct.py +++ b/pubs/bibstruct.py @@ -61,6 +61,18 @@ class CitekeyFormatter(Formatter): def __init__(self): super(CitekeyFormatter, self).__init__() + def format_field(self, val, fmt): + if len(fmt) > 0 and fmt[0] == 'u': + s = str(val).upper() + fmt = fmt[1:] + elif len(fmt) > 0 and fmt[0] == 'l': + s = str(val).lower() + fmt = fmt[1:] + else: + s = val + return str2citekey(s.__format__(fmt)) + + def get_value(self, key, args, kwds): if len(args) == 0: raise ValueError('Must pass bibtex entry to the format method') @@ -73,41 +85,24 @@ class CitekeyFormatter(Formatter): key = 'author' if key == 'first_word' and 'title' in entry: - return CitekeyFormatter._U(entry['title'].split(' ')[0]) + return entry['title'].split(' ')[0] if key == 'author_last_name' and 'author' in entry: - return CitekeyFormatter._U(author_last(entry['author'][0])) + return author_last(entry['author'][0]) else: if key in entry: - return CitekeyFormatter._U(entry[key]) + return entry[key] else: raise ValueError( "No {} defined: cannot generate a citekey.".format(okey)) - class _U(str): - def __init__(self, value): - super(CitekeyFormatter._U, self).__init__(value) - - def __format__(self, fmt): - val = self - if len(fmt) > 0 and fmt[0] == 'u': - s = val.upper() - fmt = fmt[1:] - elif len(fmt) > 0 and fmt[0] == 'l': - s = val.lower() - fmt = fmt[1:] - else: - s = str(val) - return s.__format__(fmt) - - -def generate_citekey(bibdata, format_string='{author_last_name:l}{year}{first_word:l}'): +def generate_citekey(bibdata, format_string='{author_last_name}{year}'): """ Generate a citekey from bib_data. :raise ValueError: if no author nor editor is defined. """ citekey, entry = get_entry(bibdata) citekey = CitekeyFormatter().format(format_string, entry) - return str2citekey(citekey) + return citekey def extract_docfile(bibdata, remove=False): diff --git a/pubs/config/spec.py b/pubs/config/spec.py index 42097ad..86ed265 100644 --- a/pubs/config/spec.py +++ b/pubs/config/spec.py @@ -34,15 +34,21 @@ debug = boolean(default=False) # If true the citekey is normalized using the 'citekey_format' on adding new publications. normalize_citekey = boolean(default=False) -# String specifying how to format the citekey. The following +# String specifying how to format the citekey. All strings of +# the form '{{substitution:modifier}}' and '{{substitution}}' will +# be substituted with their appropriate values. The following # substitutions are used: -# %a: last name of the first author in lowercase -# %A: last name of the first author in PascalCase -# %Y: four letter year of release (e.g. 2019) -# %y: two last letters of release year (e.g. 19) -# %w: first word in the title in lowercase -# %W: first work in the title -citekey_format = string(default='%a%Y') +# author_last_name: last name of the first author +# year: year of publication +# first_word: first word of the title +# modifiers: +# l: converts the text to lowercase +# u: converts the text to uppercase +# examples: +# {{author_last_name:l}}{{year}} generates 'yang2020' +# {{author_last_name}}{{year}}{{first_word}} generates 'Yang2020Towards' +# {{author_last_name:u}}{{year}} generates 'YANG2020' +citekey_format = string(default='{{author_last_name:l}}{{year}}') [formating] diff --git a/tests/test_bibstruct.py b/tests/test_bibstruct.py index 05af028..d06b0d8 100644 --- a/tests/test_bibstruct.py +++ b/tests/test_bibstruct.py @@ -32,6 +32,46 @@ class TestGenerateCitekey(unittest.TestCase): key = bibstruct.generate_citekey(bibentry) self.assertEqual(key, 'Salinger1961') + def test_no_modifier(self): + template = '{author_last_name}{year}' + bibentry = copy.deepcopy(fixtures.doe_bibentry) + key = bibstruct.generate_citekey(bibentry, template) + self.assertEqual(key, 'Doe2013') + + bibentry = copy.deepcopy(fixtures.franny_bibentry) + key = bibstruct.generate_citekey(bibentry, template) + self.assertEqual(key, 'Salinger1961') + + def test_all_keys(self): + template = '{author_last_name}-{year}-{first_word}' + bibentry = copy.deepcopy(fixtures.doe_bibentry) + key = bibstruct.generate_citekey(bibentry, template) + self.assertEqual(key, 'Doe-2013-Nice') + + bibentry = copy.deepcopy(fixtures.franny_bibentry) + key = bibstruct.generate_citekey(bibentry, template) + self.assertEqual(key, 'Salinger-1961-Franny') + + def test_l_modifier(self): + template = '{author_last_name:l}{year:l}' + bibentry = copy.deepcopy(fixtures.doe_bibentry) + key = bibstruct.generate_citekey(bibentry, template) + self.assertEqual(key, 'doe2013') + + bibentry = copy.deepcopy(fixtures.franny_bibentry) + key = bibstruct.generate_citekey(bibentry, template) + self.assertEqual(key, 'salinger1961') + + def test_u_modifier(self): + template = '{author_last_name:u}{year:u}' + bibentry = copy.deepcopy(fixtures.doe_bibentry) + key = bibstruct.generate_citekey(bibentry, template) + self.assertEqual(key, 'DOE2013') + + bibentry = copy.deepcopy(fixtures.franny_bibentry) + key = bibstruct.generate_citekey(bibentry, template) + self.assertEqual(key, 'SALINGER1961', template) + if __name__ == '__main__': unittest.main() From 837392a33afc6f25c1b391ced878b9921b095e4f Mon Sep 17 00:00:00 2001 From: Jonas Kulhanek Date: Wed, 26 Feb 2020 14:42:30 +0100 Subject: [PATCH 07/12] fix pubkey generation for python2.7 --- pubs/bibstruct.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pubs/bibstruct.py b/pubs/bibstruct.py index e47caae..91b3a7d 100644 --- a/pubs/bibstruct.py +++ b/pubs/bibstruct.py @@ -73,11 +73,8 @@ class CitekeyFormatter(Formatter): return str2citekey(s.__format__(fmt)) - def get_value(self, key, args, kwds): - if len(args) == 0: - raise ValueError('Must pass bibtex entry to the format method') - entry = args[0] - if isinstance(key, str): + def get_value(self, key, args, entry): + if isinstance(key, (str, unicode)): okey = key if key == 'author' and not 'author' in entry: key = 'editor' @@ -94,6 +91,8 @@ class CitekeyFormatter(Formatter): else: raise ValueError( "No {} defined: cannot generate a citekey.".format(okey)) + else: + raise ValueError('Key must be a str instance') def generate_citekey(bibdata, format_string='{author_last_name}{year}'): """ Generate a citekey from bib_data. @@ -101,7 +100,7 @@ def generate_citekey(bibdata, format_string='{author_last_name}{year}'): :raise ValueError: if no author nor editor is defined. """ citekey, entry = get_entry(bibdata) - citekey = CitekeyFormatter().format(format_string, entry) + citekey = CitekeyFormatter().format(format_string, **entry) return citekey From efbccef2a19841ccc67e962f5b3794c73474219c Mon Sep 17 00:00:00 2001 From: Jonas Kulhanek Date: Wed, 26 Feb 2020 14:57:35 +0100 Subject: [PATCH 08/12] fix pubkey for python3.x --- pubs/bibstruct.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pubs/bibstruct.py b/pubs/bibstruct.py index 91b3a7d..de72a36 100644 --- a/pubs/bibstruct.py +++ b/pubs/bibstruct.py @@ -1,4 +1,11 @@ from __future__ import unicode_literals +try : + import __builtin__ +except: + # Python 3.x + import builtins + if 'unicode' not in builtins.__dict__.keys(): + unicode = str import unicodedata import re @@ -6,6 +13,7 @@ from string import Formatter from .p3 import ustr, uchr + # Citekey stuff TYPE_KEY = 'type' From bc802e2bab1404397fff38077cb40c38cb3d0f2f Mon Sep 17 00:00:00 2001 From: Jonas Kulhanek Date: Fri, 7 Aug 2020 14:59:02 +0200 Subject: [PATCH 09/12] fix alias --- pubs/plugs/alias/alias.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pubs/plugs/alias/alias.py b/pubs/plugs/alias/alias.py index fd9cae2..5bee03d 100644 --- a/pubs/plugs/alias/alias.py +++ b/pubs/plugs/alias/alias.py @@ -1,5 +1,6 @@ import shlex import subprocess +import argparse from pipes import quote as shell_quote from ...plugins import PapersPlugin @@ -19,7 +20,7 @@ class Alias(object): def parser(self, parser): self.parser = parser p = parser.add_parser(self.name, help=self.description) - p.add_argument('arguments', nargs='*', + p.add_argument('arguments', nargs=argparse.REMAINDER, help="arguments to be passed to %s" % self.name) return p From 9856193952d4f60a5db08bc1ec65bb54895abbec Mon Sep 17 00:00:00 2001 From: Jonas Kulhanek Date: Mon, 29 Nov 2021 09:49:39 +0100 Subject: [PATCH 10/12] Update citekey generation: "short_title" --- pubs/bibstruct.py | 29 ++++++++++++++++++++--------- pubs/config/spec.py | 11 ++++++----- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/pubs/bibstruct.py b/pubs/bibstruct.py index de72a36..5df6a98 100644 --- a/pubs/bibstruct.py +++ b/pubs/bibstruct.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals -try : +try: import __builtin__ -except: +except Exception: # Python 3.x import builtins if 'unicode' not in builtins.__dict__.keys(): @@ -63,7 +63,8 @@ def author_last(author_str): def valid_citekey(citekey): """Return if a citekey is a valid filename or not""" # FIXME: a bit crude, but efficient for now (and allows unicode citekeys) - return not '/' in citekey + return '/' not in citekey + class CitekeyFormatter(Formatter): def __init__(self): @@ -80,19 +81,18 @@ class CitekeyFormatter(Formatter): s = val return str2citekey(s.__format__(fmt)) - def get_value(self, key, args, entry): if isinstance(key, (str, unicode)): okey = key - if key == 'author' and not 'author' in entry: + if key == 'author' and 'author' not in entry: key = 'editor' - elif key == 'editor' and not 'editor' in entry: + elif key == 'editor' and 'editor' not in entry: key = 'author' - if key == 'first_word' and 'title' in entry: - return entry['title'].split(' ')[0] if key == 'author_last_name' and 'author' in entry: return author_last(entry['author'][0]) + if key == 'short_title' and 'title' in entry: + return get_first_word(entry['title']) else: if key in entry: return entry[key] @@ -102,7 +102,18 @@ class CitekeyFormatter(Formatter): else: raise ValueError('Key must be a str instance') -def generate_citekey(bibdata, format_string='{author_last_name}{year}'): + +def get_first_word(title): + """ + Returns the first word of the title as used in Google Scholar or Arxiv citekeys + """ + title = re.split(r'[^a-zA-Z0-9]', title) + word_blacklist = {'and', 'on', 'in', 'of', 'the', 'a', 'an', 'at'} + word = next((x for x in title if x and x.lower() not in word_blacklist), None) + return word + + +def generate_citekey(bibdata, format_string='{author_last_name}{year}{short_title}'): """ Generate a citekey from bib_data. :raise ValueError: if no author nor editor is defined. diff --git a/pubs/config/spec.py b/pubs/config/spec.py index 86ed265..bfbb79f 100644 --- a/pubs/config/spec.py +++ b/pubs/config/spec.py @@ -34,21 +34,22 @@ debug = boolean(default=False) # If true the citekey is normalized using the 'citekey_format' on adding new publications. normalize_citekey = boolean(default=False) -# String specifying how to format the citekey. All strings of -# the form '{{substitution:modifier}}' and '{{substitution}}' will +# String specifying how to format the citekey. All strings of +# the form '{{substitution:modifier}}' and '{{substitution}}' will # be substituted with their appropriate values. The following # substitutions are used: # author_last_name: last name of the first author # year: year of publication -# first_word: first word of the title +# short_title: first word of the title (excluding words such as "the", "an", ...) # modifiers: # l: converts the text to lowercase # u: converts the text to uppercase # examples: # {{author_last_name:l}}{{year}} generates 'yang2020' -# {{author_last_name}}{{year}}{{first_word}} generates 'Yang2020Towards' +# {{author_last_name}}{{year}}{{short_title}} generates 'Yang2020Towards' +# {{author_last_name:l}}{{year}}{{short_title:l}} generates 'yang2020towards' # {{author_last_name:u}}{{year}} generates 'YANG2020' -citekey_format = string(default='{{author_last_name:l}}{{year}}') +citekey_format = string(default='{{author_last_name:l}}{{year}}{{short_title:l}}') [formating] From 371c7ef0de43989cf03fe8c436cd364a89c72118 Mon Sep 17 00:00:00 2001 From: Jonas Kulhanek Date: Mon, 29 Nov 2021 10:06:09 +0100 Subject: [PATCH 11/12] Fix failing tests --- pubs/bibstruct.py | 2 +- pubs/config/spec.py | 4 +++- tests/test_bibstruct.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pubs/bibstruct.py b/pubs/bibstruct.py index 23c3f6a..1d19f4f 100644 --- a/pubs/bibstruct.py +++ b/pubs/bibstruct.py @@ -113,7 +113,7 @@ def get_first_word(title): return word -def generate_citekey(bibdata, format_string='{author_last_name}{year}{short_title}'): +def generate_citekey(bibdata, format_string='{author_last_name}{year}'): """ Generate a citekey from bib_data. :raise ValueError: if no author nor editor is defined. diff --git a/pubs/config/spec.py b/pubs/config/spec.py index 92a8747..95c6e75 100644 --- a/pubs/config/spec.py +++ b/pubs/config/spec.py @@ -53,7 +53,9 @@ normalize_citekey = boolean(default=False) # {{author_last_name}}{{year}}{{short_title}} generates 'Yang2020Towards' # {{author_last_name:l}}{{year}}{{short_title:l}} generates 'yang2020towards' # {{author_last_name:u}}{{year}} generates 'YANG2020' -citekey_format = string(default='{{author_last_name:l}}{{year}}{{short_title:l}}') +# +# Uncomment the following line to enable automatic citekey generation +# citekey_format = string(default='{{author_last_name:l}}{{year}}{{short_title:l}}') [formating] diff --git a/tests/test_bibstruct.py b/tests/test_bibstruct.py index d06b0d8..e3b4299 100644 --- a/tests/test_bibstruct.py +++ b/tests/test_bibstruct.py @@ -43,7 +43,7 @@ class TestGenerateCitekey(unittest.TestCase): self.assertEqual(key, 'Salinger1961') def test_all_keys(self): - template = '{author_last_name}-{year}-{first_word}' + template = '{author_last_name}-{year}-{short_title}' bibentry = copy.deepcopy(fixtures.doe_bibentry) key = bibstruct.generate_citekey(bibentry, template) self.assertEqual(key, 'Doe-2013-Nice') From 74b9c7af6032ed2adc8cbd683346307f1e97e580 Mon Sep 17 00:00:00 2001 From: Jonas Kulhanek Date: Mon, 29 Nov 2021 10:13:34 +0100 Subject: [PATCH 12/12] Update default citekey spec --- pubs/config/spec.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pubs/config/spec.py b/pubs/config/spec.py index 95c6e75..a436c93 100644 --- a/pubs/config/spec.py +++ b/pubs/config/spec.py @@ -54,8 +54,7 @@ normalize_citekey = boolean(default=False) # {{author_last_name:l}}{{year}}{{short_title:l}} generates 'yang2020towards' # {{author_last_name:u}}{{year}} generates 'YANG2020' # -# Uncomment the following line to enable automatic citekey generation -# citekey_format = string(default='{{author_last_name:l}}{{year}}{{short_title:l}}') +citekey_format = string(default='{{author_last_name:l}}{{year}}{{short_title:l}}') [formating]