Would it be possible to have this write out a .bib file in the current directory?
For managing citations it's often useful to maintain a handful of topic specific bibtex files, it would then be useful if the keys that are used in the current file could be then be exported to a local .bib file to maintain documents with only the keys in that are being used. As an example, I've recently started using this extension with tectonic in the hopes of being able to bundle only the relevant files together for distribution, it would be useful to not have to bundle very large bibtex files.
I can see your use-case, but this might be beyond what this plugin is designed to do. It only uses some parsing to get the entry in the format that is needed for a tex or md file. However, there is an option to get the whole entry and paste it instead of just the ref, so maybe that could be tweaked to add the entry to a file when it is referenced in the code. This would not extract anything, so it would have to be done "as you write". I will give this some thought.
There are a few BibTeX utilities that do what you are asking based on the aux file. For example, bibtool does it, but there are others. See
- https://github.com/ge-ne/bibtool
- https://ctan.org/topic/bibtex-util