def get_authoryear_from_entry(entry, paren=False):
def _format_last(person):<EOL><INDENT>"""<STR_LIT>"""<EOL>return '<STR_LIT:U+0020>'.join([n.strip('<STR_LIT:{}>') for n in person.last_names])<EOL><DEDENT>if len(entry.persons['<STR_LIT>']) > <NUM_LIT:0>:<EOL><INDENT>persons = entry.persons['<STR_LIT>']<EOL><DEDENT>elif len(entry.persons['<STR_LIT>']) > <NUM_LIT:0>:<EOL><INDENT>persons = entry.persons['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>raise AuthorYearError<EOL><DEDENT>try:<EOL><INDENT>year = entry.fields['<STR_LIT>']<EOL><DEDENT>except KeyError:<EOL><INDENT>raise AuthorYearError<EOL><DEDENT>if paren and len(persons) == <NUM_LIT:1>:<EOL><INDENT>template = '<STR_LIT>'<EOL>return template.format(author=_format_last(persons[<NUM_LIT:0>]),<EOL>year=year)<EOL><DEDENT>elif not paren and len(persons) == <NUM_LIT:1>:<EOL><INDENT>template = '<STR_LIT>'<EOL>return template.format(author=_format_last(persons[<NUM_LIT:0>]),<EOL>year=year)<EOL><DEDENT>elif paren and len(persons) == <NUM_LIT:2>:<EOL><INDENT>template = '<STR_LIT>'<EOL>return template.format(author1=_format_last(persons[<NUM_LIT:0>]),<EOL>author2=_format_last(persons[<NUM_LIT:1>]),<EOL>year=year)<EOL><DEDENT>elif not paren and len(persons) == <NUM_LIT:2>:<EOL><INDENT>template = '<STR_LIT>'<EOL>return template.format(author1=_format_last(persons[<NUM_LIT:0>]),<EOL>author2=_format_last(persons[<NUM_LIT:1>]),<EOL>year=year)<EOL><DEDENT>elif not paren and len(persons) > <NUM_LIT:2>:<EOL><INDENT>template = '<STR_LIT>'<EOL>return template.format(author=_format_last(persons[<NUM_LIT:0>]),<EOL>year=year)<EOL><DEDENT>elif paren and len(persons) > <NUM_LIT:2>:<EOL><INDENT>template = '<STR_LIT>'<EOL>return template.format(author=_format_last(persons[<NUM_LIT:0>]),<EOL>year=year)<EOL><DEDENT>
Get and format author-year text from a pybtex entry to emulate
    natbib citations.

    Parameters
    ----------
    entry : `pybtex.database.Entry`
        A pybtex bibliography entry.
    parens : `bool`, optional
        Whether to add parentheses around the year. Default is `False`.

    Returns
    -------
    authoryear : `str`
        The author-year citation text.