Bug 460316 - Command-Line tool for auto-formatting BibTeX file
Summary: Command-Line tool for auto-formatting BibTeX file
Status: RESOLVED WORKSFORME
Alias: None
Product: KBibTeX
Classification: Applications
Component: Loading/saving files (other bugs)
Version First Reported In: 0.10
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Thomas Fischer
URL:
Keywords:
Depends on: 460315
Blocks:
  Show dependency treegraph
 
Reported: 2022-10-12 14:43 UTC by nobodyinperson
Modified: 2022-12-22 21:33 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed/Implemented In: 0.11
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description nobodyinperson 2022-10-12 14:43:13 UTC
SUMMARY

A command-line tool to auto-format a BibTeX file according to KBibTeX's style would be very handy.

BENEFITS

- Auto-linting of BibTeX files according to styles (incl. auto-generation of IDs)
- Application in CI to assert BibTeX file style adherence
- Consistency when working with multiple people on a BibTeX file
- See also output file sorting: Bug # 460315
Comment 1 nobodyinperson 2022-10-12 14:44:33 UTC
Proposed CLI:

kbibtex --format bibliography.bib
# outputs formatted BibTeX

kbibtex --format bibliography.bib -o bibliography-formatted.bib
# writes to bibliography-formatted.bib

kbibtex --format --inplace bibliography.bib
# formats in-place
Comment 2 Thomas Fischer 2022-10-15 21:40:33 UTC
Rudimentary implementation of this request is available in this commit:
https://invent.kde.org/thomasfischer/kbibtex/commit/93bfb10deb49e0c688b3625e3a1a4301a4797425
As of now, it just loads a bibliographic file and writes its back out to stdout or a file (file formats determined by filenames). "inplace" is technically possible by providing the same filename both for input and output (not tested but should work as input file is closed before output file is written).
Formatting is implicit, as the output is build from an internal representation of the bibliography, not the input file directly.

The code does not contain any changes proposed for bug 460315, so no sorting yet, only once both bugfix branches are merged back into the main branch.

As "kbibtex-cli" is a command line tool, it should have a man page ("kbibtex-cli.1"). This may be something for you to contribute ...
Comment 3 nobodyinperson 2022-10-15 23:47:25 UTC
Very nice, awesome little cli program! When I rebase branch bugs/kde460316 onto this branch bugs/kde460315, even the sorting behaviour is applied to the files, which is exactly what I need 🎉

Would it be very difficult to have the normal 'kbibtex' executable provide this functionality? Just for the sake of having less executables flying around... Otherwise, kbibtex-cli is also fine 🙂

Many thanks for your work on kbibtex!!!
Comment 4 Thomas Fischer 2022-10-21 21:38:51 UTC
> Would it be very difficult to have the normal 'kbibtex' executable provide
> this functionality? Just for the sake of having less executables flying
> around...
I am favoring two separate binaries. First 'kbibtex' and 'kbibtex-cli' may have different arguments and options for various operations that may be in conflict if the "command line" gets more elaborate.
Second, the latest commit (6d94c8f836ca6ce33, unless I force-push) contains a refactored build system that allows to build just 'kbibtex-cli' without any graphical libraries. That means to compile only 60 instead of about 200 code files and less dependencies. Viable for server or container deployments where automated processing of BibTeX files is required.
Please test for yourself by switching on option BUILD_APP_COMMAND_LINE and disabling options BUILD_APP_DESKTOP and BUILD_KPART.
Comment 5 nobodyinperson 2022-10-24 11:40:24 UTC
👍 Would is also be possible to make a cli flag for auto-generating the IDs? That would be awesome!
Comment 6 Bug Janitor Service 2022-11-08 05:11:05 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 7 Thomas Fischer 2022-11-13 19:52:39 UTC
(In reply to nobodyinperson from comment #5)
> 👍 Would is also be possible to make a cli flag for auto-generating the IDs?
> That would be awesome!
https://invent.kde.org/thomasfischer/kbibtex/commit/2c60618d2fd1a74009d4f89eb0f75ffbe62a1749

The format string is found in the Preferences -> Id Suggestions -> select one -> Edit -> See top of editing dialog.
Comment 8 nobodyinperson 2022-11-13 20:55:31 UTC
Absolutely awesome, the --format-id option! 🎉🎉 Thank you very much, Thomas!

With this one huge BibTeX file (which I can't disclose here atm) i am running into a bistable cycle where the formatting is not idempotent and oscillates between appending (and removing) a '-2' after duplicate IDs. Interestingly, I cannot reproduce this with a smaller example. I guess this is another issue anyway as it also applies to the GUI. I'll open another bug report if I can reproduce this.
Comment 9 Thomas Fischer 2022-12-22 21:33:12 UTC
Git commit cd0875e0a8dcb3670e6ae9cf1f8213efffa162ac by Thomas Fischer.
Committed on 22/12/2022 at 20:37.
Pushed by thomasfischer into branch 'master'.

Adding command line program

Adding a command line program that offers basic functionality of KBibTeX
without a user interface and without many dependencies (basically just
Qt::Core and some KBibTeX libraries).

Initial implementation can only load a bibliographic file of any
recognized file format and write it back to another file or the standard
output.

M  +28   -0    src/program/CMakeLists.txt
A  +105  -0    src/program/commandline.cpp     [License: GPL(v2.0+)]

https://invent.kde.org/office/kbibtex/commit/cd0875e0a8dcb3670e6ae9cf1f8213efffa162ac