New plugin: Citations (with Zotero)

@jgauthier, just in case this might be helpful in the future. The plugin could not load my bibTeX file. After x-mins of trial and error, it appears that abstracts had LaTeX elements like \mbox or \mbox{} (and probably others). I have just generated a copy of bibTeX file without abstracts and everything works now. Thanks a lot for the plugin!

@romanov.maxim thanks for the report and for doing the investigation yourself! This should be fixed in the next release.

2 Likes

What is the suggested way to handle the link to the pdf of the cited paper/book?
Basically we have 3 entities (the MarkDown note, the pdf of the cited document, the bibtex entry of such document).

To cite and have an handy link to the pdf for access convenience one could:

  1. define a file = {} field in the corresponding bibtex entry
  2. insert both the citation and the markdown link to the pdf in the markdown text where citation is needed

The first approach would require support from this plugin, but avoids things getting out of sync.
Or am I missing an obvious solution?

1 Like

And thanks a lot for the bibtex support, that’s really appreciated :slight_smile:

1 Like

Hello, maybe it’s a very stupid question, but I am still quite illiterate on markdown so please bear with me :pray:
Is there any way to export those Zotero references from Obsidian into a Word file (having the Zotero plugin installed) as footnotes/bibliography integrated with the Zotero system? Or I can only copy/paste them as plain text?

2 Likes

Markdown to “Live” Word Document

If I understand the question, I can share a workflow for going from markdown files to word or open office documents that have “live” Zotero citations. Exporting to flattened citations is also possible and doesn’t require the lua script listed below. Getting live citations is something I stumbled across relatively recently, really like, and use regularly. Following from this thread: Convert plaintext citekey to “live” MS Word citation - Zotero Forums

Dependencies:

Procedure:

  • Export the Zotero library as BetterBibTex *.bib and make sure that the export file does not have a space in the name. For example My LIbrary should be My_Library.
  • In the markdown document to be exported, fill out the appropriate yaml frontmatter described in the BetterBibTex manual Markdown/Pandoc :: Better BibTeX for Zotero
  • Export the file via pandoc using an added lua filter. I use the following code:
    pandoc -s "<path to file.md>" --lua-filter="<path to script zotero.lua>" --bibliography "C:\Users\Nathan\Nextcloud\Notes\My_Library.bib" -o "<path to output.docx>"
  • After the export is complete, open the Word document and refresh Zotero.

Presto! …at least on Win10. Good luck.

8 Likes

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…)