joostkremers / ebib

A BibTeX database manager for Emacs.
https://joostkremers.github.io/ebib/
BSD 3-Clause "New" or "Revised" License
276 stars 37 forks source link

Custom/complex field types? (question) #118

Closed thblt closed 5 years ago

thblt commented 7 years ago

Hi,

My PhD bibliography falls under a certain number of edge cases, and I wonder if ebib could help me handle at least some of them. In most cases, the solution I've found is to modify the behavior of some fields so they can handle complex situations, and I wonder if Ebib could be able to handle such quirks. Here are two significant examples:

I'm not asking if Ebib supports any of these features (virtually nothing does :), of course, nor is this a feature request, but I'd be grateful for pointers on how to start looking to add support for the special kind of weirdness I need to manage my bibliography.

Also, sorry in advance if some answers are in the manual, I've looked and found nothing.

Thanks in advance, and sorry about the length.

joostkremers commented 7 years ago

Hi,

sorry for the late reply. I suspect some things may be doable with Ebib, if you are willing to write some Elisp.

  • For this case, I'd like my reference manager to consider "Author" a "compound" field, and return the reference above on a search on author = Romain Gary. In a perfect world, the "author" column in the list view would also display something like "Romain Gary [as Émile Ajar]

The second should be doable right now, by customising the option ebib-field-transformation-functions. You'd have to come up with a name for the column (you can even call it "Author", since user-define columns override the default ones), and then write a function that extracts the relevant information from the database and returns it in a way that you want it displayed in the index view. Check out the default value of ebib-field-transformation-functions for some examples. (This option doesn't seem to be documented right now, I should probably fix that...)

Searching is a different matter. If you're talking about simple searches with /, then a search for "Romain Gary" will return the entry you provide, because / isn't restricted to certain fields. Using search filters in Ebib, you can create a filter that searches two fields, e.g., Author and Author-Canonical. But you'd have to do that every time you want to execute a search for author names. A better alternative would be to write a special filter, plus a function that invokes it, and then bind that function to some key. There is an example on how to do this in the manual (section Special Filters). (The interface for creating such special filters is rather messy and could stand improvement, but given my schedule, that won't happen any time soon...)

Lastly, if you use ebib-insert-citation in combination with ivy from a LaTeX (or Markdown, or Org) mode buffer and you want your entry to show up when you type Romain Gary, then you'll need to modify ebib--ivy-create-collection, which extracts the field values that the user can use to select an entry. This function isn't currently customisable, but it uses the same function ebib--get-field-value-for-display that is used to create the list view in the index buffer, so you'll probably only need to change the line (ebib--get-field-value-for-display "Author/Editor" key db) in ebib--ivy-create-collection to the column that you define to display the author name in your preferred format. (A more general solution, and I'd accept a PR to that effect, would be to create a new user option that allows the user to define the fields to be used here.)

  • Same situation with publication date, with the origyear field. Recent publications of ancient works should be considered published the year of the origyear field, if present.

I suspect it should be possible to handle that in the same way.

  • Hierarchical categories rather than keywords. I'd like to order my references in hierarchical categories, in a fashion similar to BibDesk.

Not sure what you mean here. I've never used BibDesk, so I'm not familiar with the way it works.

  • More generally, where should I look for documentation on how to programmatically access the open ebib db? The manual seems a bit terse on that topic.

Yeah, the manual is really a user manual. :smile: I'm afraid that when it comes to programming Ebib, there's only the source. I always make a point of documenting my functions, though, so hopefully it shouldn't be too difficult to dive in.

For accessing databases, you can use the functions defined in ebib-db.el. These all take (a reference to) a database object as one of their arguments. The current database in Ebib is stored in (or rather pointed to by) the variable ebib--cur-db, so to get data from the current database, you can pass that. Other databases are accessible through the list ebib-databases.

I've also defined some helper functions here and there to access the current database directly, but I wouldn't rely on them, because unlike with ebib-db.el, I never bothered to create a decent API for that.

Thanks in advance, and sorry about the length.

You're welcome, and no worries. I hope I've been able to help a bit.