Beispiel #1
0
    def format(self, person, abbr=False):
        r"""
        Format names similarly to {ff~}{vv~}{ll}{, jj} in BibTeX.  

        >>> from pybtex.database import Person
        >>> name = Person(string=r"Charles Louis Xavier Joseph de la Vall{\'e}e Poussin")
        >>> plain = NameStyle().format
        >>> print(plain(name).format().plaintext())
        Charles Louis Xavier<nbsp>Joseph de<nbsp>la Vall{\'e}e<nbsp>Poussin
        >>> print(plain(name, abbr=True).format().plaintext())
        C.<nbsp>L. X.<nbsp>J. de<nbsp>la Vall{\'e}e<nbsp>Poussin

        >>> name = Person(first='First', last='Last', middle='Middle')
        >>> print(plain(name).format().plaintext())
        First<nbsp>Middle Last
        >>> print(plain(name, abbr=True).format().plaintext())
        F.<nbsp>M. Last
        >>> print(plain(Person('de Last, Jr., First Middle')).format().plaintext())
        First<nbsp>Middle de<nbsp>Last, Jr.
        """
        return join[name_part(tie=True)[person.first(abbr) +
                                        person.middle(abbr)],
                    name_part(tie=True)[person.prelast()],
                    name_part[person.last()],
                    name_part(before=', ')[person.lineage()]]
Beispiel #2
0
    def format(self, person, abbr=False):
        ur"""
        Format names similarly to {vv~}{ll}{, jj}{, f.} in BibTeX.

        >>> from pybtex.database import Person
        >>> name = Person(string=r"Charles Louis Xavier Joseph de la Vall{\'e}e Poussin")
        >>> lastfirst = NameStyle().format

        >>> print lastfirst(name).format().render_as('latex')
        de~la Vall{é}e~Poussin, Charles Louis Xavier~Joseph
        >>> print lastfirst(name).format().render_as('html')
        de&nbsp;la Vall<span class="bibtex-protected">é</span>e&nbsp;Poussin, Charles Louis Xavier&nbsp;Joseph

        >>> print lastfirst(name, abbr=True).format().render_as('latex')
        de~la Vall{é}e~Poussin, C.~L. X.~J.
        >>> print lastfirst(name, abbr=True).format().render_as('html')
        de&nbsp;la Vall<span class="bibtex-protected">é</span>e&nbsp;Poussin, C.&nbsp;L. X.&nbsp;J.

        >>> name = Person(first='First', last='Last', middle='Middle')
        >>> print lastfirst(name).format().render_as('latex')
        Last, First~Middle
        >>> print lastfirst(name, abbr=True).format().render_as('latex')
        Last, F.~M.

        """
        return join[
            name_part(tie=True)[person.rich_prelast_names],
            name_part[person.rich_last_names],
            name_part(before=', ')[person.rich_lineage_names],
            name_part(before=', ', abbr=abbr)[person.rich_first_names +
                                              person.rich_middle_names], ]
Beispiel #3
0
    def format(self, person, abbr=False):
        r"""
        Format names similarly to {vv~}{ll}{, jj}{, f.} in BibTeX.

        >>> from pybtex.database import Person
        >>> name = Person(string=r"Charles Louis Xavier Joseph de la Vall{\'e}e Poussin")
        >>> lastfirst = NameStyle().format
        >>> print lastfirst(name).format().plaintext()
        de<nbsp>la Vall{\'e}e<nbsp>Poussin, Charles Louis Xavier<nbsp>Joseph
        >>> print lastfirst(name, abbr=True).format().plaintext()
        de<nbsp>la Vall{\'e}e<nbsp>Poussin, C.<nbsp>L. X.<nbsp>J.

        >>> name = Person(first='First', last='Last', middle='Middle')
        >>> print lastfirst(name).format().plaintext()
        Last, First<nbsp>Middle
        >>> print lastfirst(name, abbr=True).format().plaintext()
        Last, F.<nbsp>M.

        """
        return join [
            name_part(tie=True) [person.prelast()],
            name_part [person.last()],
            name_part(before=', ') [person.lineage()],
            name_part(before=', ') [person.first(abbr) + person.middle(abbr)],
        ]
Beispiel #4
0
    def format(self, person, abbr=False):
        ur"""
        Format names similarly to {ff~}{vv~}{ll}{, jj} in BibTeX.  

        >>> from pybtex.database import Person
        >>> name = Person(string=r"Charles Louis Xavier Joseph de la Vall{\'e}e Poussin")
        >>> plain = NameStyle().format

        >>> print plain(name).format().render_as('latex')
        Charles Louis Xavier~Joseph de~la Vall{é}e~Poussin
        >>> print plain(name).format().render_as('html')
        Charles Louis Xavier&nbsp;Joseph de&nbsp;la Vallée&nbsp;Poussin

        >>> print plain(name, abbr=True).format().render_as('latex')
        C.~L. X.~J. de~la Vall{é}e~Poussin
        >>> print plain(name, abbr=True).format().render_as('html')
        C.&nbsp;L. X.&nbsp;J. de&nbsp;la Vallée&nbsp;Poussin

        >>> name = Person(first='First', last='Last', middle='Middle')
        >>> print plain(name).format().render_as('latex')
        First~Middle Last

        >>> print plain(name, abbr=True).format().render_as('latex')
        F.~M. Last

        >>> print plain(Person('de Last, Jr., First Middle')).format().render_as('latex')
        First~Middle de~Last, Jr.

        """
        return join [
            name_part(tie=True, abbr=abbr) [person.rich_first_names + person.rich_middle_names],
            name_part(tie=True) [person.rich_prelast_names],
            name_part [person.rich_last_names],
            name_part(before=', ') [person.rich_lineage_names]
        ]
Beispiel #5
0
    def format(self, person, abbr=False):
        ur"""
        Format names similarly to {ff~}{vv~}{ll}{, jj} in BibTeX.  

        >>> from pybtex.database import Person
        >>> name = Person(string=r"Charles Louis Xavier Joseph de la Vall{\'e}e Poussin")
        >>> plain = NameStyle().format

        >>> print plain(name).format().render_as('latex')
        Charles Louis Xavier~Joseph de~la Vall{é}e~Poussin
        >>> print plain(name).format().render_as('html')
        Charles Louis Xavier&nbsp;Joseph de&nbsp;la Vallée&nbsp;Poussin

        >>> print plain(name, abbr=True).format().render_as('latex')
        C.~L. X.~J. de~la Vall{é}e~Poussin
        >>> print plain(name, abbr=True).format().render_as('html')
        C.&nbsp;L. X.&nbsp;J. de&nbsp;la Vallée&nbsp;Poussin

        >>> name = Person(first='First', last='Last', middle='Middle')
        >>> print plain(name).format().render_as('latex')
        First~Middle Last

        >>> print plain(name, abbr=True).format().render_as('latex')
        F.~M. Last

        >>> print plain(Person('de Last, Jr., First Middle')).format().render_as('latex')
        First~Middle de~Last, Jr.

        """
        return join[name_part(tie=True, abbr=abbr)[person.rich_first_names +
                                                   person.rich_middle_names],
                    name_part(tie=True)[person.rich_prelast_names],
                    name_part[person.rich_last_names],
                    name_part(before=', ')[person.rich_lineage_names]]
Beispiel #6
0
 def format(self, person, *args):
     abbr = repr(person) in self._seen
     self._seen.add(repr(person))
     return join[name_part(tie=True, abbr=abbr)[person.rich_first_names +
                                                person.rich_middle_names],
                 name_part(tie=True)[person.rich_prelast_names],
                 name_part[person.rich_last_names],
                 name_part(before=", ")[person.rich_lineage_names], ]
Beispiel #7
0
 def format(self, person: Person, abbr: bool = False) -> Text:
     text_bold = [Tag("b", Text.from_latex(name)) for name in person.last_names]
     return join[
         name_part(tie=True, abbr=abbr)[
             person.rich_first_names + person.rich_middle_names
         ],
         name_part(tie=True)[person.rich_prelast_names],
         name_part[text_bold],
         name_part(before=", ")[person.rich_lineage_names],
     ]
Beispiel #8
0
    def format(self, person, abbr=False):
        r"""
        Format names similarly to {vv~}{ll}{, jj}{, f.} in BibTeX.

        >>> from pybtex.database import Person
        >>> name = Person(string=r"Charles Louis Xavier Joseph de la Vall{\'e}e Poussin")
        >>> lastfirst = NameStyle().format
        >>> print(lastfirst(name).format().plaintext())
        de<nbsp>la Vall{\'e}e<nbsp>Poussin, Charles Louis Xavier<nbsp>Joseph
        >>> print(lastfirst(name, abbr=True).format().plaintext())
        de<nbsp>la Vall{\'e}e<nbsp>Poussin, C.<nbsp>L. X.<nbsp>J.

        >>> name = Person(first='First', last='Last', middle='Middle')
        >>> print(lastfirst(name).format().plaintext())
        Last, First<nbsp>Middle
        >>> print(lastfirst(name, abbr=True).format().plaintext())
        Last, F.<nbsp>M.

        """
        return join[name_part(tie=True)[person.prelast()],
                    name_part[person.last()],
                    name_part(before=', ')[person.lineage()],
                    name_part(before=' ')[self._format_fname(person)], ]
Beispiel #9
0
    def to_python(self):
        from pybtex.style.names import name_part
        class NamePart(object):
            def __init__(self, part, abbr=False):
                self.part = part
                self.abbr = abbr
            def __repr__(self):
                abbr = 'abbr' if self.abbr else ''
                return 'person.%s(%s)' % (self.part, abbr)

        kwargs = {}
        if self.pre_text:
            kwargs['before'] = self.pre_text
        if self.tie:
            kwargs['tie'] = True

        return repr(name_part(**kwargs) [
            NamePart(self.types[self.format_char], self.abbreviate)
        ])
Beispiel #10
0
    def to_python(self):
        from pybtex.style.names import name_part
        class NamePart(object):
            def __init__(self, part, abbr=False):
                self.part = part
                self.abbr = abbr
            def __repr__(self):
                abbr = 'abbr' if self.abbr else ''
                return 'person.%s(%s)' % (self.part, abbr)

        kwargs = {}
        if self.pre_text:
            kwargs['before'] = self.pre_text
        if self.tie:
            kwargs['tie'] = True

        return repr(name_part(**kwargs) [
            NamePart(self.types[self.format_char], self.abbreviate)
        ])
Beispiel #11
0
 def format(self, person, abbr=False):
     return join [
         name_part(tie=True) [person.first(abbr) + person.middle(abbr)],
         name_part(tie=True) [person.prelast()],
         name_part [person.last()],
     ]
Beispiel #12
0
    def format(self, person, abbr=True):
        """Format last names."""

        return join[name_part(tie=True)[person.rich_prelast_names],
                    name_part[person.rich_last_names], ]