New plugin: Citations (with Zotero)

I keep all my references in bib. Bibdesk (which is what I use) has the super useful feature of auto-filing related pdfs. So you make an entry, drag the article there, and it renames it and puts it in whatever folder you want. When you open the entry next time, it will be a linked file.

So, my current setup:

  • Have Bibdesk autofile my pdf articles so that their name is {{citekey}}_{{n}}.pdf, where n is a unique number (it’s needed so that if you have more than 1 pdfs for one entry they can be distinguished).
  • I have the citations plugin set up so that when I create a lit note, (1) my literature notes are also named {{citekey}}, and (2) the configurable “literature note content template” puts a link to the pdf there automatically. (Well, sort of. I have typed in file:///[path to the lit. folder]/{{citekey}}_0.pdf, which works in almost every case except if there are more than one pdfs to the same entry – rarely happens in my case.)

So, this way the bibtex entry has a link to the pdf, and so does the markdown entry – and both do without me having to do anything. (I’m lazy :slight_smile: ) And of course since the .md entry has the name of the citekey, it’s very easy to refer back to the bib if needed.

Hope this helps. There are probably many different ways of doing this.

(EDIT: of course sometimes there’s no pdf because I’m taking notes on a paper book (oh yes!). Then I just delete the markdown link.)

I have a question for @jgauthier though. It seems that the loaded bib database does not reload when the bib file changes. If I add a new entry, no matter how much I wait (although I have not tried restarting Obsidian, maybe that would help, it just occurred to me, but it’s a bigger hassle than the current workaround), the new entry does not show up in the citations search.

Current workaround: Go to the settings page, cut and re-paste the citation database path.

It’s not a big hassle, but maybe it could be fixed?
(Also, my bib file is in Dropbox if that makes a difference.)

1 Like

Thanks for the reply!
This approach doesn’t work for me unfortunately, my pdfs are named as titles and organized in a hierarchy of folders, as they need to be easily accessible from multiple devices/softwares, like the pdf annotator on the iPad, OSX preview, …
I want to rely on Obsidian “find-the-link-no-matter-the-folder” feature, so whatever solution I eventually end up with should exploit that.

I see. You’ll see what works. For me, finding files by citekey (which is author+year in my case) is much easier even on the ipad than navigating folders.
Maybe in your case it would make sense to put the files into the vault into the attachment folder.

Hi @KRao, a near-future release will have support for a file variable as you describe. This is already implemented, actually, but I haven’t finished testing it yet.

FYI, if you’re using Zotero, this will require using the BibLaTeX exports – since unfortunately the PDF links aren’t retained in the JSON export.

I’m happy to announce a release with a bunch of new features – here’s 0.4.0!
As usual, the update should be available shortly within the Obsidian interface.

Improvements

  • You can now open PDFs from within the “open note” dialog – try pressing Shift-Tab! (If you’re a Zotero user, this is only possible if you use the BibLaTeX export – unfortunately the CSL-JSON format doesn’t include PDF information.)
  • Overhauled backend – file reloading issues on Windows and OS X should be resolved, and performance should be improved.
  • Overhauled templating system – you now have access to the full Handlebars expression language. You can use this template to generate a comma-separated list of Obsidian links for each of a paper’s authors, for example:
{{#each entry.author}}[[{{this.family}}, {{this.given}}]]{{#unless @last}}, {{/unless}}{{/each}}

You can find a little more information in the plugin settings dialog. Improved documentation should arrive shortly!

  • Citation search modals now display matched portions of items in bold, like other Obsidian search dialogs
  • New command “Insert literature note content in the current pane”
  • BibLaTeX loading bugfixes
  • Resolved compatibility issues with Discordian theme
13 Likes

Great, thank you for the update. Just to confirm, this did fix the re-loading problem – which is a big quality-of-life improvement here. (And the new command is also very useful!)

I realize I’m having too many wishes here… but anyway.
Would it be possible to be able to search by citekey as well?
Use-case: sometimes I have a lot of papers by a single author, and I’m very bad at remembering titles but a little better remembering when they were published. Since my citekey is author+year, I tend to remember that fairly well too.
(Of course now I just search for the author and scroll down till I find it, it’s really not a big deal.)

1 Like

@atiz no problem at all, keep the ideas coming :slight_smile:
The citekey search is very reasonable – I’m not sure why I didn’t do this from the start. On the to-do list!

5 Likes

@jgauthier thanks a lot for this great plugin! As others have said before, this was one of the last missing must-have-features in order to increase productivity within obsidian!

I have two questions:

  1. can I include the file link (link to my local pdf) directly in the template? I tried with {{file}} but that obviously doesn’t work. Is there any placeholder for this?

  2. would it be somehow possible to implement a feature that allows to include my cited reference directly in the actual note?

Let me elaborate on this second point:

Say, I have a last h2-heading in a note that is called ## References. Whenever I insert a pandoc-style citation @citekey, the full citation is added to my References chapter (like: Author (year): Title, in: xxx, p. xyz), ideally even with a direct link to the local pdf if there is any.

I think, however, this is somehow to complicated to implement…!? An easier solution would be maybe to provide a shortcut that allows to insert this information myself. So, if I press this shortcut, the plugin inserts whatever I have defined in a special template for this, using placeholders.

My individual template could then, for example, look like this:

{{author}} ({{year}}): {{title}}, in: {{containerTitle}}, p. {{page}}. [[@citekey]] [Link to pdf]({{file}})

→ where [[@citekey]] provides the link to my literature note in this example and [Link to pdf]({{file}} results in the following link: [Link to pdf](/path/to/local/file.pdf).

Any chance something like this could be implemented quite easily?

Anyway, thanks for your great work and for sharing this with us! :+1: :clap:

1 Like

Would it now be possible to check if an original-date is given and print it, if yes?

@phlind You can use the template variable {{entry.issued}} to access the date of issue, but this is not guaranteed to have meaningful data for all fields – for example, if the bibliography entry contains year and month information (say, 2003-04) but not the day of publication, entry.issued will still fill in a dummy date 2003-04-01.

(Is this what you meant by “original-date?” If so I can try to add a solution here to only retrieve meaningful date data.)

@alltagsverstand

can I include the file link (link to my local pdf) directly in the template? I tried with {{file}} but that obviously doesn’t work. Is there any placeholder for this?

If you’re using the BibLaTeX format this is possible. Here’s the magic template string – this will retrieve the first file, if any, associated with the entry:

{{entry.files.[0]}}

(also cc @KRao – this is the feature that you wanted!)

would it be somehow possible to implement a feature that allows to include my cited reference directly in the actual note?

I’m currently working on a “references pane” feature which automatically extracts and renders citations from the current document in a side pane (like the Obsidian backlinks pane). This sounds like it could match what you want. We could also certainly support rendering this as a section within the document, I suppose.

For what it’s worth – my impression is that lots of people are currently rendering bibliography sections with the Pandoc converter. (See e.g. this post: New plugin: Citations (with Zotero) - #80 by ncraig )

7 Likes

Yes, that’s even more than I was hoping! :slightly_smiling_face: This is actually the Zettlr solution and one I personally like a lot! If it would then also be possible to open the respective file link (to a local pdf) from this pane, that would be absolutely perfect! :slightly_smiling_face:

Oh, cool, will try it out immediately!

Yep, this inserts the path to my pdf; yet, I can’t click and open the file as many of my pdf file names include spaces… Is there any possibility to alter the template string so that it replaces spaces with %20? :thinking: I tried to change the export behavior in BetterBibtex, but obviously that doesn’t work (or I haven’t found out how…)

Deleted comment.
(thought I tested the feature but not, it was my old setup. Will try later.)

@atiz you deleted your comment again - but actually that works! To be honest, I have never thought about that possibility - when inserting a file link in obsidian, I manually replaced all the spaces with %20 each time…

(In my case, it doesn’t wrap the path automatically, but you can change the template accordingly)

@jgauthier Biblatex has the field origdate, where you can enter the year of a book’s first edition, for example:

"issued": {
      "date-parts": [
        [
          1975
        ]
      ]
    },
"original-date": {
      "date-parts": [
        [
          1809
        ]
      ] 
}

But of course not every entry has this. So I thought, it might be possible to include an if-statement that prints the original year in the literature note only if it was in the source file.

It works, but you may have to do it manually or adjust the template. (I just deleted the comment because it suggested that the plugin does it for you.)
Yeah, it’s easier than replacing spaces with %20’s.

Thanks a lot! :slight_smile: I can indeed now use:

---
title: {{title}}
authors: {{authorString}}
year: {{year}}
file: {{entry.files.[0]}}
---

And the file entry is correctly populated.
I am a bit puzzled as to whether I should put the file in the front matter or use instead

---
title: {{title}}
authors: {{authorString}}
year: {{year}}
---
file: [[{{entry.files.[0]}}]]

I would consider the file entry as metadata, but putting the file in the front matter does not make it clickable or findable by Obsidian (moreover, such file can be in an arbitrary sub-folder).
What is best practice here? A bit OT here I guess, probably I don’t fully grasp the meaning of the front matter…

3 Likes

Thanks for this great plug-in! I’m having trouble finding the “Citations” tab to set the “Citation export path” within Obsidian settings (I don’t see “preferences”). I’m running MacOS with the citation plugin v.0.4.1 and obsidian v.0.10.7. I’m guessing it’s right in front of me, but somehow I’m missing it. Thank you to anyone who can point me to it. Also, in case others face this issue, it might be worth adding some screenshots to the Setup section of the README

Now open the Obsidian preferences and view the “Citations” tab. Paste the path to the exported file (.bib or .json, depending on the format you chose) in the text field labeled “Citation export path.” After closing the settings dialog, you should now be able to search your references from within Obsidian!

1 Like