Skip to content
Hugo-Heagren edited this page Jan 9, 2022 · 8 revisions

Ebib tips and tricks

This page is for tips and tricks for using Ebib, things that may be useful to others but haven't (yet) been added to Ebib. Anyone is welcome to edit this page and add tips.

Import entries from Zotero Translation Server

Contributed by wangtianshu.

Zotero translation server lets you use Zotero translators without the Zotero client which support retrieve metadata from a lot of websites or identifiers (DOI, ISBN, PMID, arXiv ID). To use it, you should have an available Zotero translation server.

  (defcustom ebib-zotero-translation-server "http://127.0.0.1:1969"
    "The address of Zotero translation server."
    :group 'ebib
    :type 'string)

  (defun ebib-zotero-translate (item server-path &optional export-format)
    "Convert item to EXPORT-FORMAT entry through `ebib-zotero-translation-server'."
    (let ((export-format (or export-format
                             (downcase (symbol-name (intern-soft bibtex-dialect))))))
      (shell-command-to-string
       (format "curl -s -d '%s' -H 'Content-Type: text/plain' '%s/%s' | curl -s -d @- -H 'Content-Type: application/json' '%s/export?format=%s'" item ebib-zotero-translation-server server-path ebib-zotero-translation-server export-format))))

  (defun ebib-zotero-import-url (url)
    "Fetch a entry from zotero translation server via a URL.
The entry is stored in the current database."
    (interactive "MURL: ")
    (with-temp-buffer
      (insert (ebib-zotero-translate url "web"))
      (ebib-import-entries ebib--cur-db)))

  (defun ebib-zotero-import-identifier (identifier)
    "Fetch a entry from zotero translation server via an IDENTIFIER.
The entry is stored in the current database,
and the identifier can be DOI, ISBN, PMID, or arXiv ID."
    (interactive "MIDENTIFIER: ")
    (with-temp-buffer
      (insert (ebib-zotero-translate identifier "search"))
      (ebib-import-entries ebib--cur-db)))

Attach PDF from Ebib to email in mu4e/Gnus

Contributed by mardukbp.

(defun ebib-attach-file ()
  "Attach file to gnus/mu4e composition buffer"
  (interactive)

  (ebib-execute-when
    ((entries)
     (let ((filename (to-raw (car (ebib-get-field-value ebib-standard-file-field
                                                        (edb-cur-entry ebib-cur-db))))))
       (if filename
           (ebib-dired-attach filename)
         (error "Field `%s' is empty" ebib-standard-file-field))))
    ((default)
     (beep))))

(defun ebib-dired-attach (file)
  "Attach FILENAME using gnus-dired-attach."
  (let ((file-full-path
            (or (locate-file file ebib-file-search-dirs)
                (locate-file (file-name-nondirectory file) ebib-file-search-dirs)
                (expand-file-name file))))
    (if (file-exists-p file-full-path)
	(progn
	  (gnus-dired-attach (cons file-full-path '()))
	  (ebib-lower))
      (error "File not found: `%s'" file-full-path))))

Zotero-like arXiv integration

Contributed by mardukbp.

One of the great features of Zotero is that with one click you get the citation and the PDF added to your library. Thanks to arxiv2bib, conkeror and emacsclient it takes one (emacs-ish) keystroke to accomplish the same thing.

The following Elisp code creates the command ebib-import-arxiv:

(setq arxiv-dir "~/Papers/arxiv/")    ; change dir as desired

(defun ebib-import-arxiv (arxiv-url)
  (interactive)

  (let ((tempbuff (get-buffer-create "*arxiv*"))
	(arxiv-id (car (cdr (split-string arxiv-url "abs/"))))
	(arxiv-pdf-url (concat (replace-regexp-in-string "abs" "pdf" arxiv-url) ".pdf")))

    (call-process-shell-command "arxiv2bib.py" nil tempbuff nil arxiv-id)

    (call-process-shell-command "links" nil nil nil
				"-source" arxiv-pdf-url "> " (concat arxiv-dir arxiv-id ".pdf"))

    (with-current-buffer tempbuff
      (ebib-import))))

The following snippet should go into ~/.conkerorrc:

function ebib_import_arxiv (url) {
    var cmd_str = 'emacsclient -ne \'(ebib-import-arxiv \"' + url + '\")\'';
    shell_command_blind(cmd_str);
}

interactive("arxiv2ebib", "Download PDF and add bibtex entry for current preprint to ebib",
            function (I) {
		ebib_import_arxiv(I.buffer.display_uri_string);
            });

define_key(content_buffer_normal_keymap, "C-c c", "arxiv2ebib");

Import bibtex from journal's website

Contributed by mardukbp.

In addition to the previous tip, here is the corresponding code for importing a paper's citation in bibtex format directly from the journal's website. The following Elisp code defines the command ebib-import-bibtex:

(require 'mm-url)

(defun ebib-import-bibtex (url)
  (interactive)

  (with-temp-buffer
    (mm-url-insert-file-contents url)
    (ebib-import)))

The following snippet should go into ~/.conkerorrc:

function ebib_import_bibtex (url) {
    var cmd_str = 'emacsclient -ne \'(ebib-import-bibtex \"' + url + '\")\'';
    shell_command_blind(cmd_str);
}

interactive("bibtex2ebib", "Download PDF and add bibtex entry for current preprint to ebib",
            function (I) {
		ebib_import_bibtex(I.buffer.display_uri_string);
            });

define_key(content_buffer_normal_keymap, "C-c f", "bibtex2ebib");

Extract Ebib links from an org subtree

Contributed by kuerzn.

The function ebib-show-from-org-subtree extracts all references (links to Ebib) from the current org subtree and filters the current database to display only those entries:

(defun ebib-show-from-org-subtree ()
  (interactive)
  (let ((keys (org-extract-references-from-subtree)))
    (ebib-db-set-filter `(contains "=key=" ,(regexp-opt keys))
                        ebib--cur-db)
    (ebib--redisplay)))

(defun org-extract-references-from-subtree ()
  (let (res)
    (org-map-tree
     (lambda ()
       (re-search-forward "^\\** \\(.*\\)$")
       (goto-char (match-beginning 1))
       (let* ((limit (match-end 1)))
         (while (re-search-forward "\\<ebib:\\(\\w+\\)\\>" limit t)
           (push (match-string-no-properties 1) res)))))
    res))

Import files directly from the internet

I often find pdf files of papers or books I want to read online. The standard workflow for saving them in ebib is to create an entry, download the file somewhere, then go the entry and ebib-import-file. This is a hassle. Instead, just turn on url-handler-mode (M-xurl-handler-mode). Emacs will treat urls as files in things like read-file prompts, so you can just copy the url of the pdf and enter it directly into ebib-file-import.