serhii.net

In the middle of the desert you can say anything you want

10 Oct 2023

My current workflow for Zotero + Obsidian citations

I really wanna solve this because I want to start writing the Master thesis draft with real citations: 230928-1745 Masterarbeit draft

Previously: 230507-1620 Zotero and Obsidian

TL;DR: insert a citation primary key the first time and convert it to a markdown footnote using a vim macro; next time just insert the secondary key (=footnote). Footnote id is the citation key and can be happily parsed/regexed later on if needed.

The problem and options

  • I tried implementing https://github.com/ishnid/zotero-obsidian, in a separate obsidian vault.
    • Works as described
    • Upsides:
      • nice intuitive citation keys/links like [[citationKey2023]]
    • Downsides:
      • Need to export the papers individually
      • When citing, you have to remember the citation key, no nice dropdown like with the Citations obsidian plugin
  • Citations1 obsidian plugin which I love
    • Plus:
      • nice dropdown when picking
      • can create both citations and apparently literature note markdown files, just like the first option!
    • Downsides:
      • Unless I do literally [[citationKey2023]] it might be hard to convert manually to latex later on if needed (experience tells me it will be needed…).
      • Never gave it a chance more than my initial usage flow with the weird citation format (like this:<@benderfr (2022) z/d/>) - optimized for finding the paper when reading, but not for converting to latex
        • All the other data I want should honestly be a literature note
        • I think I can happily do this
        • But would this imply Hugo creating pages for all my literature notes for this to be usable?

What do I do?

I think I should keep my Citations usage, except:

  • Making the Markdown citation keys in obsidian easily parseable for latex in the future
    • I need clear demarkation of the citation, inside it an easily parseable citation key, and the rest later.
    • Can I somehow add footnotes to this? LIke citation key -> footnote -> all the remaining info? I could write a template for that.

HA! Just discovered primary/secondary citation key bindings in Citation’s interface! <Return> vs <Shift-Return> away! So that’s how you do it, and - It’s a game changer!

My current solution

New concept:

  • First time I cite a paper, I insert the complex primary citation key through the citation plugin’s interface.
    • Then, with an Obsidian template vim macro, I convert it into a secondary citation with footnote leading to the other information about it
  • Next time I cite a paper I just insert a primary citation, that contains a footnote to the main thing!
    • (If I never cited the paper before, the footnote won’t work but I can do the process at any point any time in the future, as long as the key isn’t changed!)
    • I don’t like the @ as part of a footnote ID but it should2 be OK (though highly dependent on the setup). For now it works both in Hugo/goldmark and Obsidian.
  • Unchanged: no citation notes in separate markdown files.

Implementation:

  • New primary markdown citation: <_(@cite_key) ..other-stuff. _>
    • The vim macro then copies everything between <> to one register and the citation key inside () to another register
    • It transforms the entire citation into [^@cite_key]
    • It creates a corresponding footnote at the end of the file: [^cite_key]: <_.. copy of the above _>
  • Secondary markdown citation template: [^@cite_key]
    • (And i can differentiate my own footnotes later by the lack of @ at the beginning! Will be chaotic to read maybe but we’ll see)

The monstrosity vim macro3:

" mark the place with mark f, so we can come back
" (temporary) ll goes inside the <> block,  I redefined T when doing
" experiments earlier,  `:source`'d' and don't feel like restarting obsidian 
" copy entire thing including < to register a, 
" copy citekey between () to register c
" replace entire <> thing with [^citekey]
" go to the end of file,  create the footnote, put entire thing in there
" go back to where we were with `'f`

nmap <F9> mfllF<"aya<lll"cyi(va<c[^]<Esc>h"cpGo[^<Esc>"cpA]:<Space><Esc>"ap''f
set clipboard=unnamed

Full primary citation key template:

<_(@{{citekey}}) "{{title}}" ({{year}}) / {{authorString}}:  [z]({{zoteroSelectURI}}) / [{{URL}}]({{URL}}) / {{DOI}} _>

Looks like this:

  • <_(@ammus) “AMMUS : A survey of transformer-based pretrained models in natural language processing” (2021) / Katikapalli Subramanyam Kalyan, Ajit Rajasekharan, Sivanesan Sangeetha: z / / _>
  • <_(@ammus) "AMMUS : A survey of transformer-based pretrained models in natural language processing" (2021) / Katikapalli Subramanyam Kalyan, Ajit Rajasekharan, Sivanesan Sangeetha: [z](zotero://select/items/@ammus) / []() / _>
  • Test:
    • first time 4
    • next time 4
    • Woohoo!

Future plans / options for improving this

  • rewrite the primary citation format to not insert empty places/links for fields that are absent. I can use the Handlebars syntax5 for conditionals in my templates.

  1. hans/obsidian-citation-plugin: Obsidian plugin which integrates your academic reference manager with the Obsidian editor. Search your references from within Obsidian and automatically create and reference literature notes for papers and books. ↩︎

  2. (Hugo uses Goldmark, which implements the PHP footnotes thing6 which says that the only valid identifiers are ones that would be valid as a HTML id= value; @ is not possible in HTML4 but possible in the less strict HTML578. We’ll see.) ↩︎

  3. (I’ll remove the llF bit later and make it T↩︎

  4. <_(@ammus) “AMMUS : A survey of transformer-based pretrained models in natural language processing” (2021) / Katikapalli Subramanyam Kalyan, Ajit Rajasekharan, Sivanesan Sangeetha: z / / _> ↩︎ ↩︎

  5. https://handlebarsjs.com/guide/expressions.html#whitespace-control ↩︎

  6. PHP Markdown Extra ↩︎

  7. HTML: Valid id attribute values? - Stack Overflow ↩︎

  8. The id attribute got more classy in HTML5 · Mathias Bynens ↩︎

Nel mezzo del deserto posso dire tutto quello che voglio.