emacs-citar / citar

Emacs package to quickly find and act on bibliographic references, and edit org, markdown, and latex academic documents.
GNU General Public License v3.0
479 stars 53 forks source link

citar functions to act on buffers #825

Closed ramos closed 3 months ago

ramos commented 3 months ago

Hello,

Would it be possible to use citar functions to parse a dedicated buffer? I have my own elisp functions that make dedicated searches in online databases. The result of these searches is a buffer with the BibTeX entrieas. I would like to display the results using citar (with completion, etc...)

Is there any function that accepts a buffer as argument, parses it, and uses this as completion candidates?

Many thanks for the awesome citar!

bdarcus commented 3 months ago

Is there any function that accepts a buffer as argument, parses it, and uses this as completion candidates?

There is not.

Whether that matters depends on what you precisely want to do.

How would that UX work?

ramos commented 3 months ago

How would that UX work?

Ideally I can M-x my-custom-search Then I make a custom query, that produces a buffer with BibTeX entries. Citar parses this buffer and I get completion candidates. Upon selection I get the BibTeX key as output that allows me to do two things: 1) insert this citation in the current document, and optionally 2) Download this citation to the local .bib file.

bdarcus commented 3 months ago

So to back up even further, you want to query an online db, select some subset of the results, and then insert them in a local bib file?

I kind of think that's independent of citar.

Have you considered using something like biblio.el? There, you could use its query and selection interface.

See, for example, this from the wiki.

ramos commented 3 months ago

Hi,

Typically the query returns many results (O(100)), and I would like to choose the one/two to insert as citations using completing-read. In this sense, I think that this is a perfect usecase for citar: narrowing BibTeX searches.

More concrete: The generic search can be "find author maldacena and date after 1980". This returns 87 articles and I narrow the search because I remember that the title had the work "complementary" or something similar, and the coauthor was Ellis. This last part is much more confortable to do with completing.read/citar.

The problem with biblio.el is that once you get the 100 results you have to search in that buffer by hand and this prevents the common case when you insert more than one citation. helm-bibtex was handling this very nicely, but for various reasons I moved away from helm.

bdarcus commented 3 months ago

The problem with biblio.el is that once you get the 100 results you have to search in that buffer by hand and this prevents the common case when you insert more than one citation. helm-bibtex was handling this very nicely, but for various reasons I moved away from helm.

I see.

That was its "fallback" search option?

The biblio solution on the wiki was my attempt to recreate that, but I admittedly don't really use it myself!

I'm not really sure how that might work here generally. The cache architecture we have wasn't really designed with parsing buffers, or searching online databases, in mind; it works exclusively with global and local files.

If you read through the code, you can see how those assumptions play out, and I don't see how to adjust it to handle random buffer, and not include those entries in the cache.

https://github.com/emacs-citar/citar/blob/885b86f6733fd70f42c32dd7791d3447f93db990/citar.el#L672-L690

It's possible I'm overlooking something, but my suspicion is you really need a custom completing-read interface for this piece.

I could see an external package that hooks into citar somehow (for example, by prompting the user to select which bib file to add selected results to), but likely not directly supported in the core citar package.

roshanshariff commented 3 months ago

@ramos,

I don't have a full solution for you, but if you want to code something up you might want to look at the citar--entries variable. See its documentation for details, but you should be able to let-bind it temporarily to a hash table of bibliography entries, which will then be used by all Citar functions. You'll want to use parsebib to create such a hash table from your temporary buffer.

Hope that helps!