Support formatting a BibTex file

Issue #156 new
Nils Vu created an issue

Using pybtex-convert I can read in a BibTeX file and write it out as another, which essentially formats the file in a style that Pybtex deems suitable. This would be a very useful feature if it worked better and was more customizable. Here’s a “wish list”:

  • Support writing the formatted file back into the input file. Currently this throws an error, but AFAICT the assert can just be removed.
  • Support writing the diff or the formatted file to stdout. This is standard behavior of formatters such as [yapf](https://github.com/google/yapf). They usually provide a -i flag that formats the file in-place.
  • Support some basic configuration options for the output format, e.g. indentation.
  • Sort the BibTex entries.
  • Preserve comments, or at least a leading comment such as a license header.

Would this be reasonable to add? I can help with the implementation if there’s agreement on this.

Comments (2)

  1. Johann Petrak

    Note that this command is broken as a consequence of this issue: https://bitbucket.org/pybtex-devs/pybtex/issues/153/backslashes-accumulate-when-saving-loading

    If you have a file with fields that contain underscores or “#” or other protected characters, then each time the file is saved, pybtex wil add another backslash in front. I have posted this issue which I think is a very fundamental and sever flaw quite a while ago and there was no response at all.

  2. Log in to comment