cpitclaudel / biblio.el

Browse and import bibliographic references from CrossRef, DBLP, HAL, arXiv, Dissemin, and doi.org from Emacs
GNU General Public License v3.0
180 stars 14 forks source link

Feature request: customizable citekeys #34

Closed jowens closed 4 years ago

jowens commented 4 years ago

First, this is amazing.

Is it possible to have a custom format for citekeys? My format is Lastname:YYYY:ABC, where Lastname is the last name of the first author, YYYY is the four-digit year, and ABC are the first characters of the first three words in the title. (This is the Siggraph citekey format, for the record, and I've got 20 years of bibliography built up with this.) Is there some sort of hook to be able to customize a citekey when a new entry is inserted, so that any bibtex entry I insert will also generate and use a citekey using a format I specify?

cpitclaudel commented 4 years ago

Hi John!

First, this is amazing.

:smiley:

Is there some sort of hook to be able to customize a citekey when a new entry is inserted

Yup, that's quite feasible. Biblio runs an arbitrary cleanup function biblio-cleanup-bibtex-function, which you can customize. And in fact the default one already has a flag to request a new key (it's used when generating entries for arXiv papers that don't have a DOI), so something like this in your .emacs should work:


(require 'biblio)

(defun my--biblio-cleanup-bibtex (_autokey)
  ;; Always call `biblio--cleanup-bibtex' with t, to request a new key
  (biblio--cleanup-bibtex t))

(setq biblio-cleanup-bibtex-function #'my--biblio-cleanup-bibtex)

(setq-default
 bibtex-autokey-name-year-separator ":"
 bibtex-autokey-year-title-separator ":"
 bibtex-autokey-year-length 4
 bibtex-autokey-titlewords 3
 bibtex-autokey-titleword-length -1 ;; -1 means exactly one
 bibtex-autokey-titlewords-stretch 0
 bibtex-autokey-titleword-separator ""
 bibtex-autokey-titleword-case-convert 'upcase)

Emacs' bibtex mode already support generating keys, and it is heavily configurable; I think the above does what you described. Otherwise, there are plenty of extra options described in the docstring of bibtex-generate-autokey.

As a test, when run on the first Crossref result for Accelerating DNN Inference with GraphBLAS and the GPU, I get wang:2019:ADI.

cpitclaudel commented 4 years ago

I just pushed a new option for this, so the following snippet should be enough now:

(setq-default biblio-bibtex-use-autokey t)

(setq-default
 bibtex-autokey-name-year-separator ":"
 bibtex-autokey-year-title-separator ":"
 bibtex-autokey-year-length 4
 bibtex-autokey-titlewords 3
 bibtex-autokey-titleword-length -1 ;; -1 means exactly one
 bibtex-autokey-titlewords-stretch 0
 bibtex-autokey-titleword-separator ""
 bibtex-autokey-titleword-case-convert 'upcase)
jowens commented 4 years ago

People use the word "hero" too often these days, but you, sir, are truly a hero.

jowens commented 4 years ago

MELPA has the update now and I tried it and it still does the old default citekey. Here's what I've got:

(setq-default biblio-bibtex-use-autokey t
              bibtex-autokey-name-case-convert-function 'identity
              bibtex-autokey-name-year-separator ":"
              bibtex-autokey-year-title-separator ":"
              bibtex-autokey-year-length 4
              bibtex-autokey-title-terminators "[.;]\\|--" ;; removed :!?
              bibtex-autokey-titleword-ignore '()
              bibtex-autokey-titlewords 3
              bibtex-autokey-titleword-length -1 ;; -1 means exactly one
              bibtex-autokey-titlewords-stretch 0
              bibtex-autokey-titleword-separator ""
              bibtex-autokey-titleword-case-convert 'upcase)

How can I help debug this?

cpitclaudel commented 4 years ago

How can I help debug this?

Hmm, sorry about that :) Here are the steps I took; taking the same steps and seeing whether they work would be a good start:

mkdir /tmp/sanbox
emacs -Q \
    --eval '(setq user-emacs-directory "/tmp/sandbox")' \
    -l package \
    --eval "(add-to-list 'package-archives '(\"gnu\" . \"https://elpa.gnu.org/packages/\") t)" \
    --eval "(add-to-list 'package-archives '(\"melpa\" . \"https://melpa.org/packages/\") t)" \
    --eval "(package-refresh-contents)" \
    --eval "(package-initialize)"
@Article{Wang:2019:ADI,
  author       = {Wang, Xiaoyun and Lin, Zhongyi and Yang, Carl and
                  Owens, John D.},
  title        = {Accelerating DNN Inference with GraphBLAS and the
                  GPU},
  year         = 2019,
  month        = {Sep},
  doi          = {10.1109/hpec.2019.8916498},
  url          = {http://dx.doi.org/10.1109/hpec.2019.8916498},
  isbn         = 9781728150208,
  journal      = {2019 IEEE High Performance Extreme Computing
                  Conference (HPEC)},
  publisher    = {IEEE}
}

Do you get the same results?

jowens commented 4 years ago

It works exactly as you say it should. OK. I'll figure out what's wrong on my end!

Thanks. Great debugging guidance for future issues I may have!

jowens commented 4 years ago

Ah! Here was my issue. Can doi-insert-bibtex do the same thing? Auto-generate the citekey?

cpitclaudel commented 4 years ago

Oh, good catch. Fixed and I added a test.

cpitclaudel commented 4 years ago

Thanks for the suggestions! :)

jowens commented 4 years ago

Love it. Thanks mucho.

jowens commented 4 years ago

I confirm this works. Thank you!