Feature request: customizable citekeys
jowens opened this issue · comments
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?
Hi John!
First, this is amazing.
😃
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
.
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)
People use the word "hero" too often these days, but you, sir, are truly a hero.
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?
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:
- Start a clean emacs in
/tmp
:
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)"
- Install biblio:
M-x package-install biblio
- Configure it:
M-:
, then paste this:
(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)
- Try it out:
M-x biblio-crossref-lookup RET Accelerating DNN Inference with GraphBLAS and the GPU RET
, then pressi
on the first result. I get this:
@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?
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!
Ah! Here was my issue. Can doi-insert-bibtex
do the same thing? Auto-generate the citekey?
Oh, good catch. Fixed and I added a test.
Thanks for the suggestions! :)
Love it. Thanks mucho.
I confirm this works. Thank you!