Skip to content

Citar in bibtex files with Embark

Loren Riccie edited this page May 20, 2023 · 6 revisions

Using Citar in Bibtex files with Embark

To use Citar on bibtex entries in .bib files, we can leverage Embark.

First we create a finder for Embark. This ensures that embark-act will recognize the bibtex keys.

(defun bibtex-key-embark ()  
  (save-excursion  
    (bibtex-beginning-of-entry)  
    (when (looking-at bibtex-entry-maybe-empty-head)  
      (cons 'bibtex-key
            (bibtex-key-in-head)))))

(with-eval-after-load "embark"
  (add-to-list 'embark-target-finders 'bibtex-key-embark))

`` Next, we define a keymap, include some functions & keys, and link it to this Embark type.

(with-eval-after-load "embark"
  (embark-define-keymap bibtex-key-embark-map
    "Embark keymap for Zetteldeft links"
    ("f" 'citar-open)
    ("n" 'citar-open-notes))
  (add-to-list 'embark-keymap-alist '(bibtex-key . bibtex-key-embark-map)))

That's it! Now simply call embark-act on a bibtex entry, and use the new keybindings to use Citar.

Update: since embark-define-keymap has been removed from the package, embark documentation recommends whatever method you normally use to define keymaps. embark-act will then work again on a bibtex entry of your .bib file.

Something like this:

 (with-eval-after-load "embark"
  (defun bibtex-key-target-finder ()
    (save-excursion
      (bibtex-beginning-of-entry)
      (when (looking-at bibtex-entry-maybe-empty-head)
        (cons 'bibtex-key (bibtex-key-in-head)))))

  (add-to-list 'embark-target-finders 'bibtex-key-target-finder)

  (defvar citar-embark-bibtex-map
    (let ((map (make-sparse-keymap)))
      (define-key map "o" #'citar-open)
      map)
    "Embark keymap for BibTeX entries")

(add-to-list 'embark-keymap-alist '(bibtex-key . citar-embark-bibtex-map)))
Clone this wiki locally