I am trying to migrate from Zotero to org-ref, and got stuck when trying to use the doi-utils-add-bibtex-entry-from-doi command. After reading the Automatic Reference Key Generation section and searching online couldn't find an answer to this question. Can I change the order of the auto-generated entries (author, year, title), for example, to have an author_title_year bibtex key? Thank you in advance.
Add a comment |
1 Answer
The order of the components of the key are hard-coded, so you can't change them with a user option. However, you can re-write the function to set the order you want. You need to load your modified function after the original version, so your modification will replace it. The following code does this:
(eval-after-load "bibtex" '(defun bibtex-generate-autokey () (let* ((names (bibtex-autokey-get-names)) (year (bibtex-autokey-get-year)) (title (bibtex-autokey-get-title)) (autokey (concat bibtex-autokey-prefix-string ;; optional prefix string names (unless (or (equal names "") (equal title "")) "_") ;; string to separate names from title title (unless (or (and (equal names "") (equal title "")) (equal year "")) bibtex-autokey-year-title-separator) year))) (if bibtex-autokey-before-presentation-function (funcall bibtex-autokey-before-presentation-function autokey) autokey)))) - 1Works perfectly. I am surprised that this option does not exist by default. Thanks!Ajned– Ajned2018-12-25 16:22:28 +00:00Commented Dec 25, 2018 at 16:22
- If you ever revisit this you might enjoy converting the approach to use advice instead of replacing the function directly. It worked well for me to manage this function. gnu.org/software/emacs/manual/html_node/elisp/…grettke– grettke2024-10-13 00:14:35 +00:00Commented Oct 13, 2024 at 0:14