FlamingTempura / bibtex-tidy

Cleaner and Formatter for BibTeX files
https://flamingtempura.github.io/bibtex-tidy/
MIT License
832 stars 63 forks source link

[bug] Incorrect braces match with double brace enclosure #406

Closed MvWouden closed 1 year ago

MvWouden commented 1 year ago

Hi,

I encountered an issue while tidying bibtex files with the double braces option, both using the cli and online interface. This issue keeps breaking my bibliography upon each tidy. I'm assuming this has to do with the escaped ampersand \&.

To reproduce, use the cli or online interface to tidy the following reference, using the "Enclose values in double braces" option:

@article{mohammadi2021smart,
  title={Smart fashion: a review of AI applications in virtual try-on \& fashion synthesis},
  author={Mohammadi, Seyed Omid and Kalhor, Ahmad},
  journal={Journal of Artificial Intelligence},
  volume={3},
  number={4},
  pages={284},
  year={2021}
}

After the first time, it'll look somewhat along the lines of:

@article{mohammadi2021smart,
    title        = {{Smart fashion: a review of AI applications in virtual try-on \& fashion synthesis}},
    author       = {Mohammadi, Seyed Omid and Kalhor, Ahmad},
    year         = 2021,
    journal      = {Journal of Artificial Intelligence},
    volume       = 3,
    number       = 4,
    pages        = 284
}

If you perform another tidy, the following occurs:

@article{mohammadi2021smart,
    title        = {{Smart fashion: a review of AI applications in virtual try-on \& fashion synthesis}}},
    author       = {Mohammadi, Seyed Omid and Kalhor, Ahmad},
    year         = 2021,
    journal      = {Journal of Artificial Intelligence},
    volume       = 3,
    number       = 4,
    pages        = 284
}

Note that an extra closing brace is inserted in the title. This additional brace is incorrect and breaks the bibliography.

An even smaller reproduction can be done by tidying the following snippet with the same options:

@article{foo,
    title        = {{bar \& baz}}
}
@article{foo,
    title        = {{bar and baz}}
}

Which will lead to:

@article{foo,
    title        = {{bar \& baz}}}
}
@article{foo,
    title        = {{bar and baz}}
}
FlamingTempura commented 1 year ago

Many thanks for investigating this and posting a minimal working example.

This was caused by a bug in the latex parser which wasn't handling escaped characters correctly.

Fixed in v1.11.0 / current web UI.

MvWouden commented 1 year ago

Many thanks for investigating this and posting a minimal working example.

This was caused by a bug in the latex parser which wasn't handling escaped characters correctly.

Fixed in v1.11.0 / current web UI.

Thanks for taking the time!

MvWouden commented 1 year ago

Can confirm, tried out the new version (CLI) and it is fixed now.