I would like to get the bibtex key of references in my .bib database as a string via helm-bibtex.

(defun get-bibtex-key ()
    (if (string-prefix-p "cite" (buffer-string))
        (substring (buffer-string) 5) ;; Remove "cite: " from string.

The code above correctly returns the desired value, but inserts text into the current buffer instead of storing its value within the get-bibtex-key function-variable as a string, which makes further deployment such as this impossible:

(bibtex-completion-get-entry (get-bibtex-key))

The above code when run just dumps the value returned by (get-bibtex-key) into the current buffer.

How can I get output from (helm-bibtex) behave like the code below?

  (insert "Hi!")
  • Other approaches (such as ready-made functions) to getting bibtex key from a .bib database would also be appreciated.
    – Sati
    Commented Oct 11, 2020 at 15:55
  • 1
    See bibtex-map-entries.
    – jagrg
    Commented Oct 12, 2020 at 13:28

2 Answers 2


You can also get the keys using helm-marked-candidates:

(defun get-bibtex-key (_)
  (let ((keys (helm-marked-candidates)))
    (print keys)))

(helm-add-action-to-source "Get bibtex keys" 'get-bibtex-key helm-source-bibtex 0)


  1. M-x helm-bibtex
  2. M-a
  3. RET

If I understand correctly, you can use the (bibtex-completion-candidates) function, which returns a list of bibtex items. You then get the list containing the "=key=" string using assoc, taking the cdr (last) element of the alist which is the citation key. Finally pass this list of keys through completing-read so you can select one from the list, returning it as a string:

(defun get-bibtex-key ()
  (completing-read "Citation key: "
                  (mapcar #'(lambda (x) (cdr (assoc "=key=" x)))
  • Can a search be done on the author-title instead, like what we would do in helm?
    – Sati
    Commented Oct 12, 2020 at 2:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.