Пример #1
0
def _customizations_latex(record):
    """
    This function curstumizes record for bibtex.
    See bibtexparser lib for more info.
    """
    record = customization.page_double_hyphen(record)
    record = customization.homogeneize_latex_encoding(record)
    record = customization.author(record)
    return record
 def test_homogeneize(self):
     record = {'toto': 'à {\`a} \`{a}'}
     result = homogeneize_latex_encoding(record)
     expected = {'toto': '{\`a} {\`a} {\`a}'}
     self.assertEqual(result, expected)
Пример #3
0
 def cust2(record):
     record = customization.author(record)
     record = customization.page_double_hyphen(record)
     record = customization.homogeneize_latex_encoding(record)
     return record
 def _mixed_customization(record):
     record = homogeneize_latex_encoding(record)
     record = convert_to_unicode(record)
     record = bc.author(record)
     return record
Пример #5
0
 def test_homogeneize(self):
     record = {'toto': 'à {\`a} \`{a}'}
     result = homogeneize_latex_encoding(record)
     expected = {'toto': '{\`a} {\`a} {\`a}'}
     self.assertEqual(result, expected)
 def cust2(record):
     record = customization.author(record)
     record = customization.page_double_hyphen(record)
     record = customization.homogeneize_latex_encoding(record)
     return record
Пример #7
0
def work_to_bibtex_entry(work, name=None, homogeneize=True, acronym=False):
    """Convert work to BibTeX entry dict for bibtexparser

    Doctest:

    .. doctest::

        >>> reload()
        >>> murta2014a = work_by_varname("murta2014a")
        >>> result = work_to_bibtex_entry(murta2014a)
        >>> list(result)
        ['ID', 'address', 'publisher', 'pages', 'booktitle', 'author', 'title', 'year', 'ENTRYTYPE']
        >>> result['ID']
        'murta2014a'
        >>> result['address']
        'Cologne, Germany'
        >>> result['publisher']
        'Springer'
        >>> result['pages']
        '71--83'
        >>> result['booktitle']
        'International Provenance and Annotation Workshop'
        >>> result['author']  # doctest: +ELLIPSIS
        'Murta, Leonardo and Braganholo, Vanessa and ... and Freire, Juliana'
        >>> result['title']
        'no{W}orkflow: capturing and analyzing provenance of scripts'
        >>> result['year']
        '2014'
        >>> result['ENTRYTYPE']
        'inproceedings'

        Custom name:
        >>> result = work_to_bibtex_entry(murta2014a, name="other")
        >>> list(result)
        ['ID', 'address', 'publisher', 'pages', 'booktitle', 'author', 'title', 'year', 'ENTRYTYPE']
        >>> result['ID']
        'other'

        Use acronym for place name:
        >>> result = work_to_bibtex_entry(murta2014a, acronym=True)
        >>> list(result)
        ['ID', 'address', 'publisher', 'pages', 'booktitle', 'author', 'title', 'year', 'ENTRYTYPE']
        >>> result['booktitle']
        'IPAW'
    """
    options = config.WORK_FIELDS
    ignore = config.BIBTEX_IGNORE_FIELDS
    mapa = config.WORK_BIBTEX_MAP
    if not name:
        if hasattr(work, 'metakey'):
            name = work.metakey
        else:
            split = work.authors.split()
            name = split[0].replace(",", "") if split else "a"
            name += str(work.year)

    if config.DEBUG_FIELDS:
        for key in dir(work):
            if not match_any(key, options) and not match_any(key, ignore):
                print(work.display, work.year, key)

    result = OrderedDict()
    result["ID"] = name
    for key in reversed(options):
        if hasattr(work, key) and not match_any(key, ignore):
            value = getattr(work, key)
            is_conference = (key == "place" and acronym
                             and value.type == "Conference"
                             and not value.acronym.startswith("<"))
            if is_conference:
                value = value.acronym
            name = mapa.get(key, lambda x: key)(work)
            if name:
                result[name] = str(value)
    if not "ENTRYTYPE" in result:
        result["ENTRYTYPE"] = "misc"
    if hasattr(work, "notes"):
        result["year"] += " [{}]".format(work.notes)
    if homogeneize:
        result = homogeneize_latex_encoding(result)
    return result