def get_part(self, type, abbr=False): names = getattr(self, "_" + type) if abbr: from pybtex.textutils import abbreviate names = [abbreviate(name) for name in names] return names
def name_part(children, data, before='', tie=False, abbr=False): if abbr: children = [abbreviate(child) for child in children] parts = together[children].format_data(data) if not parts: return Text() if tie: return Text(before, parts, tie_or_space(parts, nbsp, ' ')) else: return Text(before, parts)
def format_lab_names(persons): # see alpha.bst format.lab.names # s = persons numnames = len(persons) if numnames > 1: if numnames > 2: namesleft = 1 else: namesleft = numnames result = "" nameptr = 1 while namesleft: person = persons[nameptr - 1] if nameptr == numnames: if str(person) == "others": result += "et al. " else: result += _strip_nonalnum( [abbreviate(name) for name in person.prelast()] + [' '] + person.last()) else: result += _strip_nonalnum( [abbreviate(name) for name in person.prelast()] + [' '] + person.last()) if numnames == 2 and nameptr == 1: result += ' and ' else: result += ' ' nameptr += 1 namesleft -= 1 if numnames > 2: result += "et al." else: person = persons[0] result = _strip_nonalnum( [abbreviate(name) for name in person.prelast()] + [' '] + person.last()) return result
def get_part(self, type, abbr=False): """Get a list of name parts by `type`. >>> knuth = Person('Donald E. Knuth') >>> knuth.get_part('first') [u'Donald'] >>> knuth.get_part('last') [u'Knuth'] """ names = getattr(self, type + '_names') if abbr: import warnings warnings.warn('Person.get_part(abbr=True) is deprecated since 0.19: use pybtex.textutils.abbreviate()', stacklevel=2) from pybtex.textutils import abbreviate names = [abbreviate(name) for name in names] return names
def get_part(self, type, abbr=False): """Get a list of name parts by `type`. >>> knuth = Person('Donald E. Knuth') >>> knuth.get_part('first') ['Donald'] >>> knuth.get_part('last') ['Knuth'] """ names = getattr(self, type + '_names') if abbr: import warnings warnings.warn('Person.get_part(abbr=True) is deprecated since 0.19: use pybtex.textutils.abbreviate()', stacklevel=2) from pybtex.textutils import abbreviate names = [abbreviate(name) for name in names] return names
def get_part(self, type, abbr=False): names = getattr(self, '_' + type) if abbr: from pybtex.textutils import abbreviate names = [abbreviate(name) for name in names] return names
def _abbr(parts): return (abbreviate(part) for part in parts)
def getparts(p, x): for part in p.get_part(x, False): if len(part) == 1: yield abbreviate(part) else: yield part
def filter_bibentry(self, entry): # # entry is a pybtex.database.Entry object # for role in self.roles: if role not in entry.persons: continue for k in range(len(entry.persons[role])): p = entry.persons[role][k] ### NO: this kills any protection, e.g., with braces, etc. # # # de-latex the person first # pstr = unicodestr(p) # # BUG: FIXME: remove space after any macros # pstr = re.sub(r'(\\[a-zA-Z]+)\s+', r'\1{}', pstr) # replace "blah\macro blah" by "blah\macro{}blah" #if (self._names_to_utf8): # pstr = latex2text.latex2text(pstr) # #p = Person(pstr) if self._names_to_utf8: # delatex everything to UTF-8, but honor names protected by braces and keep those rxmacrospace = re.compile(r'(\\[a-zA-Z]+)\s+') l2t = LatexNodes2Text(keep_braced_groups=True, strict_latex_spaces=True) protected_detex_fn = lambda x: l2t.latex_to_text(rxmacrospace.sub(r'\1{}', x)).strip() # join name again to correctly treat accents like "Fran\c cois" or "\AA berg" p = Person(protected_detex_fn(unicodestr(p))) # do_detex = lambda lst: [ protected_detex(x) for x in lst ] # p.first_names = do_detex(p.first_names) # p.middle_names = do_detex(p.middle_names) # p.prelast_names = do_detex(p.prelast_names) # p.last_names = do_detex(p.last_names) # p.lineage = do_detex(p.lineage_names) if self._only_single_letter_firsts: do_abbrev = lambda x: abbreviate(x) if len(x) == 1 else x else: do_abbrev = abbreviate first_names = p.first_names middle_names = p.middle_names if self._only_one_initial: first_names = first_names[0:1] middle_names = [] if self._strip_first_names: first_names = [] middle_names = [] pnew = Person(string='', first=" ".join([do_abbrev(x) for x in first_names]), middle=" ".join([do_abbrev(x) for x in middle_names]), prelast=" ".join(p.prelast_names), last=" ".join(p.last_names), lineage=" ".join(p.lineage_names)) entry.persons[role][k] = pnew #logger.debug("nameinitials: %r became %r" % (p, pnew)) return