def together(children, data, last_tie=True): """ Try to keep words together, like BibTeX does. >>> print together ['very', 'long', 'road'].format().plaintext() very long<nbsp>road >>> print together ['a', 'very', 'long', 'road'].format().plaintext() a<nbsp>very long<nbsp>road """ from pybtex.bibtex.names import tie_or_space tie = richtext.Text(richtext.nbsp) space = richtext.Text(' ') parts = [part for part in _format_list(children, data) if part] if not parts: return richtext.Text() if len(parts) <= 2: tie2 = tie if last_tie else tie_or_space(parts[0], tie, space) return tie2.join(parts) else: last_tie = tie if last_tie else tie_or_space(parts[-1], tie, space) return richtext.Text(parts[0], tie_or_space(parts[0], tie, space), space.join(parts[1:-1]), last_tie, parts[-1])
def together(children, data, last_tie=True): """ Try to keep words together, like BibTeX does. >>> print(together ['very', 'long', 'road'].format().plaintext()) very long<nbsp>road >>> print(together ['a', 'very', 'long', 'road'].format().plaintext()) a<nbsp>very long<nbsp>road """ from pybtex.bibtex.names import tie_or_space tie = richtext.Text(richtext.nbsp) space = richtext.Text(' ') parts = [part for part in _format_list(children, data) if part] if not parts: return richtext.Text() if len(parts) <= 2: tie2 = tie if last_tie else tie_or_space(parts[0], tie, space) return tie2.join(parts) else: last_tie = tie if last_tie else tie_or_space(parts[-1], tie, space) return richtext.Text(parts[0], tie_or_space(parts[0], tie, space), space.join(parts[1:-1]), last_tie, parts[-1])