~protesilaos/denote

Re: Connecting denote with bibliographies

Details
Message ID
<87r12d2w96.fsf@protesilaos.com>
DKIM signature
missing
Download raw message
[ Just noticed we were missing the mailing list.  Adding it in cc. ]

> From: Peter Prevos <peter@prevos.net>
> Date: Fri, 22 Jul 2022 21:19:47 +1000
>
> Χαῖρε Prot,
>
> I studied some ancient Greek years ago, one of the few words I remember 
> :)

Nice!  There are at least a few other words you might recognise.  For
example, "biblio-graphy" ("book-writing", meaning "the writing on books"
or else "a record on books").

> I had a little win connecting Citar to denote using the code below, 
> which enables creating a note from within Citar.
>
> The optional entry parameter in the function is a list with the complete 
> bibtext entry that can be used to create notes, eg. "(("keywords" . 
> "Emacs") ("publisher" . "FSF") ("year" . "2022") ("author" . "Richard 
> Stalman") ("title" . "Emacs Manual") ("=type=" . "book") ("=key=" . 
> "stalman_2022_emacs"))"

This looks promising.

> Only problem now is that Citar does not recognise these files as being a 
> bibliography note. Unfortunately, the underscores in bibtex keys are 
> removed by denote.

Okay.  We will see what we can do.

To you question about pre-populating the selection, the simplest way is
this, based on the default code in Denote:

    (defun denote--keywords-crm (keywords)
      "Use `completing-read-multiple' for KEYWORDS."
      (delete-dups
       (completing-read-multiple
        "File keyword: " keywords
        nil nil "bib" 'denote--keyword-history))) ; we have nil instead of "bib"

If you want that behaviour, I can help you implement it.  But maybe you
prefer that "bib" is included automatically, without affecting
note-creation in general.  As such, it is better to expand on our custom
function by tweaking how the keywords' prompt works in this case:

    (defun my-modified-denote--keywords-prompt ()
      "Prompt for one or more keywords.
    In the case of multiple entries, those are separated by the
    `crm-sepator', which typically is a comma.  In such a case, the
    output is sorted with `string-lessp'.

    This is derived from `denote--keywords-prompt' for the purposes
    of automatically adding the bib keyword to the list of
    keywords without the user having to input it at the prompt."
      (let ((choice (append '("bib") (denote--keywords-crm (denote-keywords)))))
        (setq denote-last-keywords
              (if denote-sort-keywords
                  (sort choice #'string-lessp)
                choice))))

Notice the 'append' part.  If you ever want to replace "bib" with a list
of strings, you just do it there.  Or you define a variable which holds
a list of strings (again, I can help you).

Finally we have the wrapper function for the 'denote' command:

    (defun denote-citar-file--create-note (key &optional entry)
      "Create a bibliography note through Citar."
      (denote
       key
       (my-modified-denote--keywords-prompt)))

> Only problem now is that Citar does not recognise these files as being a 
> bibliography note. Unfortunately, the underscores in bibtex keys are 
> removed by denote.

Indeed.  Now they are stripped away as we do not allow them in the
title.  Perhaps you could replace 'key' in the above function with the
following:

    (replace-regexp-in-string "_" "-" key)

This will turn "stalman_2022_emacs" into "stalman-2022-emacs" and make
it part of the file name.  Then we can have the inverse which first
grabs the title component from the file name, replaces hyphens with
underscores, and then checks if a bibliography entry exists.

> So the other option is to create a metadata item, e.g. #+reference: 
> stalman_2022_emacs. A special Citar function should than be able to link 
> the file to my Bibex entry.

It is an option.  Though it would be easier if we can do it with just
the file name.  (I think we are getting closer.)  Otherwise we also need
to change the front matter and have extra code that checks the contents.

-- 
Protesilaos Stavrou
https://protesilaos.com
Reply to thread Export thread (mbox)