Example #1
0
def to_bibtex(key, ref, links=False):
    # TODO: support other refs than article
    
    fields = []
    bib_authors = []
    for last,given in ref["authors"]:
        if given:
            bib_authors.append( "{%s}, {%s}" % (last,'%s.'%given[0]) )
        else:
            bib_authors.append( "{%s}" % last )
    fields.append( ("author", " and ".join( bib_authors ) ) )
    
    # export many keys as is
    for meta_key, bibtex_key in meta2bibtex:
        if meta_key in ref:
            fields.append( (bibtex_key, "%s" % ref[meta_key]) )
    
    if links and "links" in ref:
        for k,v in ref["links"].iteritems():
            fields.append( (k,v) )
    
    # build the bibtex snippet
    ret = "@article{%s" % key
    for k,v in fields:
        ret += ",\n  %s = {%s}" % (k,string_to_latex(v))
    ret += "\n}\n"
    return ret
def to_latex(record):
    """
    Convert strings to latex
    """
    for val in record:
        record[val] = string_to_latex(record[val])
    return record
Example #3
0
def homogeneize_latex_encoding(record):
    """
    Homogeneize the latex enconding style for bibtex

    This function is experimental.

    :param record: the record.
    :type record: dict
    :returns: dict -- the modified record.
    """
    # First, we convert everything to unicode
    record = convert_to_unicode(record)
    # And then, we fall back
    for val in record:
        record[val] = string_to_latex(record[val])
        if val == 'title':
            record[val] = protect_uppercase(record[val])
    return record
def homogeneize_latex_encoding(record):
    """
    Homogeneize the latex enconding style for bibtex

    This function is experimental.

    :param record: the record.
    :type record: dict
    :returns: dict -- the modified record.
    """
    # First, we convert everything to unicode
    record = convert_to_unicode(record)
    # And then, we fall back
    for val in record:
        record[val] = string_to_latex(record[val])
        if val == 'title':
            record[val] = protect_uppercase(record[val])
    return record
Example #5
0
def homogenize_latex_encoding(record):
    """
    Homogenize the latex enconding style for bibtex

    This function is experimental.

    :param record: the record.
    :type record: dict
    :returns: dict -- the modified record.
    """
    # First, we convert everything to unicode
    record = convert_to_unicode(record)
    # And then, we fall back
    for val in record:
        if val not in ('ID', ):
            logger.debug('Apply string_to_latex to: %s', val)
            record[val] = string_to_latex(record[val])
            if val == 'title':
                logger.debug('Protect uppercase in title')
                logger.debug('Before: %s', record[val])
                record[val] = protect_uppercase(record[val])
                logger.debug('After: %s', record[val])
    return record
def homogeneize_latex_encoding(record):
    """
    Homogeneize the latex enconding style for bibtex

    This function is experimental.

    :param record: the record.
    :type record: dict
    :returns: dict -- the modified record.
    """
    # First, we convert everything to unicode
    record = convert_to_unicode(record)
    # And then, we fall back
    for val in record:
        if val not in ('ID',):
            logger.debug('Apply string_to_latex to: %s', val)
            record[val] = string_to_latex(record[val])
            if val == 'title':
                logger.debug('Protect uppercase in title')
                logger.debug('Before: %s', record[val])
                record[val] = protect_uppercase(record[val])
                logger.debug('After: %s', record[val])
    return record
Example #7
0
 def test_special_caracter(self):
     string = 'ç'
     result = string_to_latex(string)
     expected = '{\c c}'
     self.assertEqual(result, expected)
Example #8
0
 def test_accent(self):
     string = 'à é è ö'
     result = string_to_latex(string)
     expected = "{\`a} {\\\'e} {\`e} {\\\"o}"
     self.assertEqual(result, expected)
 def test_special_caracter(self):
     string = 'ç'
     result = string_to_latex(string)
     expected = '{\c c}'
     self.assertEqual(result, expected)
 def test_accent(self):
     string = 'à é è ö'
     result = string_to_latex(string)
     expected = "{\`a} {\\\'e} {\`e} {\\\"o}"
     self.assertEqual(result, expected)
Example #11
0
def cleanbib(bibtex_entry):
    return {d: string_to_latex(bibtex_entry[d]) for d in bibtex_entry.keys()}