python-bibtexparser icon indicating copy to clipboard operation
python-bibtexparser copied to clipboard

Handle undefined bibtex strings

Open omangin opened this issue 6 years ago • 10 comments

The idea is to be able to represent undefined bibtex strings as such even if the definition does not appear in the current bibdata. This would be an alternative to including and interpolating common strings and would enable exporting bibtex files identical to the input even when they include things such as month = jan.

omangin avatar Apr 12 '18 20:04 omangin

@omangin any news on this issue? i was actually just in the process of trying to add this feature and thought that i should check the issues first to see if there was already a method for doing this.

dotnwat avatar May 02 '18 02:05 dotnwat

actually if @omangin or @sciunto could chime in on a design that'd be useful. something as simple as a "strict = False" flag on the parser could work, but we could also imagine something like passing in a function to resolve strings not in the database. That might be more general and just as easy to implement.

dotnwat avatar May 02 '18 02:05 dotnwat

just added https://github.com/sciunto-org/python-bibtexparser/pull/205 please have a look. it works for my tests, but probably needs some work to fit in more naturally.

dotnwat avatar May 02 '18 03:05 dotnwat

I've solved this by creating a BibtexParser instance with interpolate_strings=False. This leaves expressions involving strings as BibDataStringExpressions, which can be inspected or manually interpolated.

rwirth avatar Jun 28 '18 14:06 rwirth

Indeed, both solutions seem good. I believe the motivation of the issue was about being able to see string values in a way similar to using common_strings but not include them when calling the bwriter.

For that specific point, I like the implementation from @noahdesu in #205 and I think it would actually be good to advise using it instead of include_common_strings (by providing the corresponding function) in the documentation. We would keep the other one for backward compatibility.

Any though on it before moving toward merging #205?

omangin avatar Jul 24 '18 11:07 omangin

@omangin it looks you had some provided some minor feedback on the #205 changes. Let me know if / when you decide to go with that approach and I'll address those comments.

dotnwat avatar Jul 24 '18 14:07 dotnwat

@sciunto Do you have an opinion on this?

As a summary the idea is to be able to set a function that is used as a default to interpolate undefined strings. This has the advantage of handling undefined-but-common strings without having to actually add definitions into the bibdata's string dictionary.

As far as I am concerned I think it is more elegant then the current implementation and would be in favor of including it.

omangin avatar Jul 26 '18 13:07 omangin

@omangin Thanks for raising this to my attention. Yes, I like this idea. So, +1.

sciunto avatar Jul 26 '18 13:07 sciunto

Turning off string interpolation is helpful but not enough. I'd like a warning but the undefined string unchanged (so that the .bib file is still successfully parsed). Imo, a runtime crash on an undefined string seems like overkill: could you change bibdatabase.expand_string to warn instead of raise (at least until another solution is implemented)?

alan-isaac avatar Jul 29 '19 20:07 alan-isaac

Note: #205 was close to a merge (tests & docs missing) but was otherwise decided to be acceptable.

However, it was closed by the PR opener. We'd need someone to clone that branch and complete it.

MiWeiss avatar Jul 10 '22 11:07 MiWeiss

Stale PR no one is working on anymore. Seems not relevant for v2. Closing issue (#203) and PR (#205). If anyone wants to go back and look at the PR for a v1 fix, feel free.

MiWeiss avatar May 26 '23 14:05 MiWeiss