Read and write BibTeX in exactly the same order (including author)

Issue #162 new
Tom de Geus created an issue

I want to read (modify) and write a BibTeX file all while preserving the order of all fields (to help version management).

Here is my bib-file:

@article{foo2022,
  title = {I want to preserve all order to help version management},
  author = {Foo, B.},
  year = {2022},
  journal = {Bitbucket},
  volume = {1},
  pages = {1--2},
}

Now

from pybtex.database import parse_file
bib_data = parse_file('library.bib')
print(bib_data)

indeed preserves order

BibliographyData(
  entries=OrderedCaseInsensitiveDict([
    ('foo2022', Entry('article',
      fields=[
        ('title', 'I want to preserve all order to help version management'),
        ('year', '2022'),
        ('journal', 'Bitbucket'),
        ('volume', '1'),
        ('pages', '1--2')],
      persons=OrderedCaseInsensitiveDict([('author', [Person('Foo, B.')])])))]),

  preamble=[])

However

print(bib_data.to_string('bibtex'))

brings forward author

@article{foo2022,
    author = "Foo, B.",
    title = "I want to preserve all order to help version management",
    year = "2022",
    journal = "Bitbucket",
    volume = "1",
    pages = "1--2"
}

(there might be options for this, there is an argument **kwargs but I could not find what options I can use)

Comments (2)

  1. Log in to comment