org-roam / org-roam-bibtex

Org Roam integration with bibliography management software
GNU General Public License v3.0
565 stars 47 forks source link

Insert link to reference with author and year #234

Closed Jason-S-Ross closed 2 years ago

Jason-S-Ross commented 2 years ago

When I insert a link to a cited work, I don't like using the full article title in my org files. It gets overly verbose, and when doing research on a specific subject, it's easier for me to remember author and year than the entire title.

I’d like to insert something like %^{author} (%^{year}) - %^{title}, e.g. “Simone (2007) - Partition of unity-based discontinuous finite elements: GFEM, PUFEM, XFEM” or %^{author}, (%^{year}) e.g. "Menouillard et al. (2006)" instead of the title.

bdarcus commented 2 years ago

FWIW, if one uses org-cite, this metadata is available via tooltip in the basic activate processor, or with alternative activate processors you have other options like:

https://github.com/andras-simonyi/org-cite-csl-activate

myshevchuk commented 2 years ago

Hi @Jason-S-Ross, PR #235 upgrades the option orb-insert-link-description to a proper template string. For simplicity, only wildcards of type ${field-name} are supported, e.g. ${author}, (${year}). Please check if it works for you. I'll merge it soon after I've updated the documentation.

Jason-S-Ross commented 2 years ago

FWIW, if one uses org-cite, this metadata is available via tooltip in the basic activate processor, or with alternative activate processors you have other options like:

https://github.com/andras-simonyi/org-cite-csl-activate

This works great. I'd like to know how to use the citations as links to the corresponding roam nodes, the same way setting orb-insert-link-description to 'title does. I imagine that's an org-cite question, though...

Hi @Jason-S-Ross, PR #235 upgrades the option orb-insert-link-description to a proper template string. For simplicity, only wildcards of type ${field-name} are supported, e.g. ${author}, (${year}). Please check if it works for you. I'll merge it soon after I've updated the documentation.

The pr works for me, but I notice in the documentation of orb-insert-link-description it refers to placeholders of the form %^{field}, not ${field}, which I think is what you mean.

bdarcus commented 2 years ago

This works great. I'd like to know how to use the citations as links to the corresponding roam nodes.

That's handled in an org-cite "follow" processor.

The citar package I maintain includes one, and it would be easy enough to add to ORB.

Oh, and here's a hydra example I was experimenting with (the one I mention above uses embark).

Jason-S-Ross commented 2 years ago

This works great. I'd like to know how to use the citations as links to the corresponding roam nodes.

That's handled in an org-cite "follow" processor.

The citar package I maintain includes one, and it would be easy enough to add to ORB.

Oh, and here's a hydra example I was experimenting with (the one I mention above uses embark).

I wonder if a "quick and dirty" way of getting a link to the roam node is to append the results of (org-roam-node-file (org-roam-node-from-ref key)) to the file list presented by citar-org-follow. I'm not familiar enough with citar to see if that's sensible.

myshevchuk commented 2 years ago

This works great. I'd like to know how to use the citations as links to the corresponding roam nodes, the same way setting orb-insert-link-description to 'title does. I imagine that's an org-cite question, though...

That's handled in an org-cite "follow" processor. The citar package I maintain includes one, and it would be easy enough to add to ORB.

I think there is a need for some clarification of terminology. There are sort of two type of links and consequently backlinks in Org-roam. The first one is just regular Org-mode ID links [[id:node-id][Description]]. This is what you create with org-roam-node-insert or orb-insert-link. The difference between the Org-roam and the ORB versions is that the former creates a link to any existing Org-roam node, or creates a note-node if it does not exist. The ORB version consults the bibliography file and lets you create a link to an existing note associated with a BibTeX entry or lets you create a new note for an entry that doesn't have one yet.

The second type of links are not links conceptually, although the Org-ref cite:citations are indeed based on the Org-mode link mechanism internally. They are citations. The Org-cite citations are not links even technically. Yet both Org-ref and Org-cite citations can function as links in the sense they can take you somewhere, for example to an associated Org-roam note, when you click on it. ORB already includes the necessary adaptations that allow for "following" a citation. In fact, it just properly configures the respective piece of software to do the job - Org-ref for Org-ref citations and Citar for Org-cite citations. One just needs to make sure org-roam-bibtex-mode is active. Also, make sure that the relevant software is installed (Org-ref, Citar). Typically, after activating a citation you'll be presented with a Hydra-like menu, where you'll find an option Edit notes or similar. Choosing this option will take you to the note if it exists or prompt you to create a new one if it doesn't.

There are not only conceptual differences between links and citations, but many differences in behaviour as well. During export, Org-mode links will be exported as hyperlinks, while citations will be exported as, well, citations.[^1] In the Org-roam side pane, Org-mode links on the one hand and all the different citation flavors on the other hand will be grouped under different sections.

Sorry for the wordiness, I'll reuse this piece later somewhere in the docs. The answer to your question is in the second paragraph.

[^1]: It just happens that both can function as links inside Emacs

myshevchuk commented 2 years ago

it refers to placeholders of the form %^{field}, not ${field}, which I think is what you mean.

Thank you.

Jason-S-Ross commented 2 years ago

Typically, after activating a citation you'll be presented with a Hydra-like menu, where you'll find an option Edit notes or similar. Choosing this option will take you to the note if it exists or prompt you to create a new one if it doesn't.

Took me a couple hours to find this so I'm sharing if someone else has the same problem: With citar and doom emacs, SPC a opens the menu you're referring to.

bdarcus commented 2 years ago

Oh, I didn't know you were a doom user.; glad you figured it out though.

myshevchuk commented 2 years ago

Took me a couple hours to find this

I'm not using Org-cite citations and this aspect of Citar myself. Took me some time to figure it out too, although minutes not hours. That's an Emacs thing - sometimes it just sucks up your time. I'm quite sure though it was possible earlier to activate a citation by pressing the usual C-c C-o as with Org-ref. SPC a is a Doom keybinding for embark-act. ORB does not provide any keybindings, that's the task of other packages.

Jason-S-Ross commented 2 years ago

Thank you both for your insights!