Exemplo n.º 1
0
 def test_parse_latex(self):
     for reference, string in self.MACROS:
         self.assertEqual(reference, parse_latex(string))
     for reference, string in self.ACCENT_MACROS:
         self.assertEqual(reference, parse_latex(string))
     for reference, string in self.ASSORTED:
         self.assertEqual(reference, parse_latex(string))
     for reference, string in self.MATH:
         self.assertEqual(reference, parse_latex(string))
Exemplo n.º 2
0
 def test_parse_latex(self):
     for reference, string in self.MACROS:
         self.assertEqual(reference, parse_latex(string))
     for reference, string in self.ACCENT_MACROS:
         self.assertEqual(reference, parse_latex(string))
     for reference, string in self.ASSORTED:
         self.assertEqual(reference, parse_latex(string))
     for reference, string in self.MATH:
         self.assertEqual(reference, parse_latex(string))
Exemplo n.º 3
0
 def __init__(self, filename, encoding='ascii'):
     bibtex_database = BibTeXParser(filename)
     bibtex_database.encoding = encoding
     self.preamble_macros = {}
     parse_latex(bibtex_database.preamble,
                 {'newcommand': NewCommand(self.preamble_macros),
                  'mbox': Macro(1, '{0}'),
                  'cite': Macro(1, 'CITE({0})')})
     for key, entry in bibtex_database.items():
         self.add(self.create_reference(key, entry))
Exemplo n.º 4
0
 def test_parse_latex(self):
     for reference, string in self.MACROS:
         self.assertEqual(reference, parse_latex(string))
     for reference, string in self.ACCENT_MACROS:
         self.assertEqual(reference, parse_latex(string))
     for reference, string in self.ASSORTED:
         self.assertEqual(reference, parse_latex(string))
     for reference, string, warning in self.WARNINGS:
         with self.assertWarns(UserWarning) as record:
             self.assertEqual(reference, parse_latex(string))
         message, = (rec.message.args[0] for rec in record.warnings)
         assert warning in message
     for reference, string in self.MATH:
         self.assertEqual(reference, parse_latex(string))
Exemplo n.º 5
0
 def _parse_year(self, year):
     try:
         year_str = parse_latex(year, self.preamble_macros)
     except TypeError:
         year_str = str(year)
     if EN_DASH in year_str:
         begin_year, end_year = year_str.split(EN_DASH)
         begin_len, end_len = len(begin_year), len(end_year)
         if end_len < begin_len:
             end_year = begin_year[:begin_len - end_len] + end_year
     else:
         begin_year = end_year = int(year_str)
     return begin_year, end_year
Exemplo n.º 6
0
 def _parse_author(self, authors):
     csl_authors = []
     for author in split_names(authors):
         first, von, last, jr = parse_name(author)
         csl_parts = {}
         for part, csl_label in [(first, 'given'),
                                 (von, 'non-dropping-particle'),
                                 (last, 'family'), (jr, 'suffix')]:
             if part is not None:
                 csl_parts[csl_label] = parse_latex(part,
                                                    self.preamble_macros)
         name = Name(**csl_parts)
         csl_authors.append(name)
     return csl_authors
Exemplo n.º 7
0
 def make_string(string, top_level_group=False):
     unlatexed = parse_latex(string, self.preamble_macros)
     fixed_case = top_level_group and not string.startswith('\\')
     string_cls = NoCase if fixed_case else String
     return string_cls(unlatexed)