]> git.donarmstrong.com Git - org-ref.git/blob - jmax-bibtex.el
added an arxiv example
[org-ref.git] / jmax-bibtex.el
1 ;;; jmax-bibtex.el --- jmax-bibtex utilities
2
3 ;; Copyright(C) 2014 John Kitchin
4
5 ;; Author: John Kitchin <jkitchin@andrew.cmu.edu>
6 ;; URL: https://github.com/jkitchin/org-ref
7 ;; Version: 0.1
8 ;; Keywords: org-mode, bibtex
9 ;; Package-Requires: ((org-ref) (s) (dash) (doi-utils) (key-chord))
10
11 ;; This file is not currently part of GNU Emacs.
12
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 2, or (at
16 ;; your option) any later version.
17
18 ;; This program is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 ;; General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program ; see the file COPYING.  If not, write to
25 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
27
28 ;;; Commentary:
29
30 ;; jmax-bibtex-generate-longtitles
31 ;; jmax-bibtex-generate-shorttitles
32 ;; jmax-stringify-journal-name :: replace a journal name with a string in
33 ;; `jmax-bibtex-journal-abbreviations'
34 ;; jmax-set-journal-string :: in a bibtex entry run this to replace the
35 ;; journal with a string
36 ;;
37 ;; jmax-title-case-article :: title case the title in an article
38 ;; jmax-sentence-case-article :: sentence case the title in an article.
39
40 ;; jmax-replace-nonascii :: replace nonascii characters in a bibtex
41 ;; entry. Replacements are in `jmax-nonascii-latex-replacements'.
42 ;;
43 ;; jmax-title-case-article
44 ;; jmax-sentence-case-article
45 ;;
46 ;; jmax-bibtex-next-entry :: bound to M-n
47 ;; jmax-bibtex-previous-entry :: bound to M-p
48 ;;
49 ;; Functions to act on a bibtex entry or file
50 ;; jmax-bibtex-hydra/body gives a hydra menu to a lot of useful functions.
51 ;; jmax-bibtex-new-entry/body gives a hydra menu to add new bibtex entries.
52 ;; jmax-bibtex-file/body gives a hydra menu of actions for the bibtex file
53 ;;
54 ;; jmax-bibtex :: a deprecated menu of actions
55
56 (require 'hydra)
57 (require 'key-chord)
58
59 ;;; Code:
60 (defgroup jmax-bibtex nil
61   "Customization group for jmax-bibtex.")
62
63
64 (defcustom jmax-bibtex-hydra-key-chord
65   nil
66   "key-chord to run `jmax-bibtex-hydra'.
67 I like \"jj\""
68   :type 'string
69   :group 'jmax-bibtex)
70
71
72 (defcustom jmax-bibtex-hydra-key-binding
73   nil
74   "key-binding to run `jmax-bibtex-hydra'.
75 I like \C-cj."
76   :type 'string
77   :group 'jmax-bibtex)
78
79
80 (defvar jmax-bibtex-journal-abbreviations
81   '(("ACAT" "ACS Catalysis" "ACS Catal.")
82     ("AM" "Acta Materialia" "Acta Mater.")
83     ("AMM" "Acta Metallurgica et Materialia" "Acta Metall. Mater.")
84     ("AMiner" "American Mineralogist" "Am. Mineral.")
85     ("AngC" "Angewandte Chemie-International Edition" "Angew. Chem. Int. Edit.")
86     ("APLM" "APL Materials" "APL Mat.")
87     ("ACBE" "Applied Catalysis B: Environmental" "Appl. Catal. B-Environ.")
88     ("APL" "Applied Physics Letters" "Appl. Phys. Lett.")
89     ("ASS" "Applied Surface Science" "Appl. Surf. Sci.")
90     ("CL" "Catalysis Letters" "Catal. Lett.")
91     ("CST" "Catalysis Science & Technology" "Catal. Sci. Technol.")
92     ("CT" "Catalysis Today" "Catal. Today")
93     ("CPL" "Chemical Physics Letters" "Chem. Phys. Lett")
94     ("CR" "Chemical Reviews" "Chem. Rev.")
95     ("CSR" "Chemical Society Reviews" "Chem. Soc. Rev.")
96     ("CSR" "Chemical Society Reviews" "Chem. Soc. Rev.")
97     ("CM" "Chemistry of Materials" "Chem. Mater.")
98     ("CSA" "Colloids and Surfaces, A: Physicochemical and Engineering Aspects" "Colloids Surf., A")
99     ("CPMS" "Computational Materials Science" "Comp. Mater. Sci.")
100     ("CPC" "Computer Physics Communications" "Comput. Phys. Commun.")
101     ("CGD" "Crystal Growth \\& Design" "Cryst. Growth Des.")
102     ("CEC" "CrystEngComm" "CrystEngComm")
103     ("ECST" "ECS Transactions" "ECS Trans.")
104     ("EES" "Energy \\& Environmental Science" "Energy Environ. Sci.")
105     ("HPR" "High Pressure Research" "High Pressure Res.")
106     ("IC" "Inorganic Chemistry" "Inorg. Chem.")
107     ("IECR" "Industrial \\& Engineering Chemistry Research" "Ind. Eng. Chem. Res.")
108     ("JJAP" "Japanese Journal of Applied Physics" "Jpn. J. Appl. Phys.")
109     ("JMatR" "Journal of  Materials Research" "J. Mater. Res.")
110     ("JALC" "Journal of Alloys and Compounds" "J. Alloy Compd.")
111     ("JAC" "Journal of Applied Crystallography" "J. Appl. Crystallogr.")
112     ("JAP" "Journal of Applied Physics" "J. Appl. Phys.")
113     ("JC" "Journal of Catalysis" "J. Catal.")
114     ("JCP" "Journal of Chemical Physics" "J. Chem. Phys.")
115     ("JCC" "Journal of Computational Chemistry" "J. Comput. Chem.")
116     ("JCG" "Journal of Crystal Growth" "J. Crys. Growth")
117     ("JMC" "Journal of Materials Chemistry" "J. Mater. Chem.")
118     ("JMC" "Journal of Materials Chemistry" "J. Mater. Chem.")
119     ("JMSL" "Journal of Materials Science Letters" "J. Mater. Sci. Lett.")
120     ("JMS" "Journal of Membrane Science" "J. Memb. Sci.")
121     ("JPE" "Journal of Phase Equilibria" "J. Phase Equilib.")
122     ("JPCS" "Journal of Physics and Chemistry of Solids" "J. Phys. Chem. Solids")
123     ("JPCM" "Journal of Physics: Condensed Matter" "J. Phys.: Condens. Matter")
124     ("JSSC" "Journal of Solid State Chemistry" "J. Solid State Chem.")
125     ("JACerS" "Journal of the American Ceramic Society" "J. Am. Ceram. Soc.")
126     ("JACS" "Journal of the American Chemical Society" "J. Am. Chem. Soc.")
127     ("JES" "Journal of The Electrochemical Society" "J. Electrochem. Soc.")
128     ("JEaC" "Journal of Electroanalytical Chemistry" "J. Electroanal. Chem.")
129     ("JMS" "Journal of Membrane Science" "J. Memb. Sci.")
130     ("JVST" "Journal of Vacuum Science \\& Technology A" "J. Vac. Sci. Technol. A")
131     ("ML" "Materials Letters" "Mater. Lett.")
132     ("MSE-BS" "Materials Science and Engineering B" "Mat. Sci. Eng. B-Solid")
133     ("MOLSIM" "Molecular Simulation" "Mol. Sim.")
134     ("Nature" "Nature" "Nature")
135     ("NM" "Nature Materials" "Nat. Mater.")
136     ("PML" "Philosophical Magazine Letters" "Phil. Mag. Lett.")
137     ("PMA" "Philosophical Magazine A" "Phil. Mag. A")
138     ("PA" "Physica A: Statistical Mechanics and its Applications" "Physica A")
139     ("PB" "Physica B-Condensed Matter" "Physica B")
140     ("PCCP" "Physical Chemistry Chemical Physics" "Phys. Chem. Chem. Phys.")
141     ("PSSB" "physica status solidi (b)" "Phys. Status Solidi B")
142     ("PRA" "Physical Review A" "Phys. Rev. A")
143     ("PRB" "Physical Review B" "Phys. Rev. B")
144     ("PRL" "Physical Review Letters" "Phys. Rev. Lett.")
145     ("PCM" "Physics and Chemistry of Minerals" "Phys. Chem. Miner.")
146     ("PSurfSci" "Progress in Surface Science" "Prog. Surf. Sci.")
147     ("Science" "Science" "Science")
148     ("SABC" "Sensors and Actuators B: Chemical" "Sensor. Actuat. B-Chem.")
149     ("SS" "Surface Science" "Surf. Sci.")
150     ("EPJB" "The European Physical Journal B" "Eur. Phys. J. B")
151     ("JPC" "The Journal of Physical Chemistry" "J. Phys. Chem.")
152     ("JPCB" "The Journal of Physical Chemistry B" "J. Phys. Chem. B")
153     ("JPCC" "The Journal of Physical Chemistry C" "J. Phys. Chem. C")
154     ("JPCL" "The Journal of Physical Chemistry Letters" "J. Phys. Chem. Lett.")
155     ("JCP" "The Journal of Chemical Physics" "J. Chem. Phys.")
156     ("MSMSE" "Modelling and Simulation in Materials Science and Engineering" "Modell. Simul. Mater. Sci. Eng.")
157     ("TSF" "Thin Solid Films" "Thin Solid Films")
158     ("TC" "Topics in Catalysis" "Top. Catal.")
159     ("WR" "Water Research" "Water Res."))
160   "List of (string journal-full-name journal-abbreviation).  Find abbreviations at http://cassi.cas.org/search.jsp.")
161
162
163 (defun jmax-bibtex-generate-longtitles ()
164   "Generate longtitles.bib which are @string definitions.
165 The full journal names are in `jmax-bibtex-journal-abbreviations'."
166   (interactive)
167   (with-temp-file "longtitles.bib"
168     (dolist (row jmax-bibtex-journal-abbreviations)
169       (insert (format "@string{%s=\"%s\"}\n"
170                       (nth 0 row)
171                       (nth 1 row))))))
172
173
174 (defun jmax-bibtex-generate-shorttitles ()
175     "Generate shorttitles.bib which are @string definitions.
176 The abbreviated journal names in `jmax-bibtex-journal-abbreviations'."
177   (interactive)
178   (with-temp-file "shorttitles.bib"
179     (dolist (row jmax-bibtex-journal-abbreviations)
180       (insert (format "@string{%s=\"%s\"}\n"
181                       (nth 0 row)
182                       (nth 2 row))))))
183
184
185 (defun jmax-stringify-journal-name (&optional key start end)
186   "Replace journal name in a bibtex entry with a string.
187 The strings are defined in
188 `jmax-bibtex-journal-abbreviations'.  The optional arguments KEY,
189 START and END allow you to use this with `bibtex-map-entries'"
190   (interactive)
191   (bibtex-beginning-of-entry)
192   (when
193       (string= "article"
194                (downcase
195                 (cdr (assoc "=type=" (bibtex-parse-entry)))))
196     (let* ((full-names (mapcar
197                         (lambda (row)
198                           (cons  (nth 1 row) (nth 0 row)))
199                         jmax-bibtex-journal-abbreviations))
200            (abbrev-names (mapcar
201                           (lambda (row)
202                             (cons  (nth 2 row) (nth 0 row)))
203                           jmax-bibtex-journal-abbreviations))
204            (journal (s-trim (bibtex-autokey-get-field "journal")))
205            (bstring (or
206                      (cdr (assoc journal full-names))
207                      (cdr (assoc journal abbrev-names)))))
208       (when bstring
209         (bibtex-set-field "journal" bstring t)
210         (bibtex-fill-entry)))))
211
212 (defun jmax-set-journal-string (full-journal-name)
213   "Set a bibtex journal name to the string that represents FULL-JOURNAL-NAME.
214 This is defined in `jmax-bibtex-journal-abbreviations'."
215   (interactive (list
216                 (ido-completing-read
217                  "Journal: "
218                  (mapcar
219                   (lambda (x)
220                     (nth 1 x))
221                   jmax-bibtex-journal-abbreviations))))
222   ;; construct data alist for the string lookup.
223   (let ((alist (mapcar
224                 (lambda (x)
225                   (cons (nth 1 x) (nth 0 x)))
226                 jmax-bibtex-journal-abbreviations)))
227     (bibtex-set-field "journal" (cdr (assoc full-journal-name alist)) t)
228     (bibtex-fill-entry)
229     (bibtex-clean-entry)))
230
231 ;; see https://github.com/fxcoudert/tools/blob/master/doi2bib for more replacements
232 (defvar jmax-nonascii-latex-replacements
233   '()
234   "Cons list of non-ascii characters and their LaTeX representations.")
235
236 (setq jmax-nonascii-latex-replacements
237       '(("í" . "{\\\\'i}")
238         ("æ" . "{\\\\ae}")
239         ("ć" . "{\\\\'c}")
240         ("é" . "{\\\\'e}")
241         ("ä" . "{\\\\\"a}")
242         ("è" . "{\\\\`e}")
243         ("à" . "{\\\\`a}")
244         ("á" . "{\\\\'a}")
245         ("ø" . "{\\\\o}")
246         ("ë" . "{\\\\\"e}")
247         ("ü" . "{\\\\\"u}")
248         ("ñ" . "{\\\\~n}")
249         ("ņ" . "{\\\\c{n}}")
250         ("å" . "{\\\\aa}")
251         ("ö" . "{\\\\\"o}")
252         ("Á" . "{\\\\'A}")
253         ("á" . "{\\\\'a}")
254         ("í" . "{\\\\'i}")
255         ("ó" . "{\\\\'o}")
256         ("ó" . "{\\\\'o}")
257         ("ú" .  "{\\\\'u}")
258         ("ú" . "{\\\\'u}")
259         ("š" . "{\\\\v{s}}")
260         ("ř"  . "{\\\\v{r}}")
261         ("İ" . "{\\\\.I}")
262         ("ğ" . "{\\\\u{g}}")
263         ("δ" . "$\\\\delta$")
264         ("ç" . "{\\\\c{c}}")
265         ("ß" . "{\\\\ss}")
266         ("≤" . "$\\\\le$")
267         ("<" . "$\\\\lt$")
268         ("θ" . "$\\\\theta$")
269         ("μ" . "$\\\\mu$")
270         ("→" . "$\\\\rightarrow$")
271         ("⇌" . "$\\\\leftrightharpoons$")
272         ("×" . "$\\\\times$")
273         ("°" . "$\\\\deg$")
274         ("ş" . "{\\\\c{s}}")
275         ("ı" . "i")                    ; I think this is a turkish i
276         ;; I think these are non-ascii spaces. there seems to be more than one.
277         (" " . " ")
278         (" " . " ")
279         ("–" . "-")
280         ("−" . "-")
281         ("–" . "-")
282         ("—" . "-")
283         ("‘" . "'")
284         ("’" . "'")
285         ("“" . "\"")
286         ("’" . "'")
287         ("”" . "\"")))
288
289 (defun jmax-replace-nonascii ()
290   "Hook function to replace non-ascii characters in a bibtex entry."
291
292   (interactive)
293   (save-restriction
294     (bibtex-narrow-to-entry)
295     (goto-char (point-min))
296     (dolist (char (mapcar (lambda (x) (car x)) jmax-nonascii-latex-replacements))
297       (while (re-search-forward char nil t)
298         (replace-match (cdr (assoc char jmax-nonascii-latex-replacements))))
299       (goto-char (point-min))))
300   (save-buffer))
301
302 (add-hook 'org-ref-clean-bibtex-entry-hook 'jmax-replace-nonascii)
303
304
305 (defvar jmax-lower-case-words
306   '("a" "an" "on" "and" "for"
307     "the" "of" "in")
308   "List of words to keep lowercase when changing case in a title.")
309
310
311 (defun jmax-title-case-article (&optional key start end)
312   "Convert a bibtex entry article title to title-case.
313 The arguments KEY, START and END are optional, and are only there
314 so you can use this function with `bibtex-map-entries' to change
315 all the title entries in articles."
316   (interactive)
317   (bibtex-beginning-of-entry)
318
319   (let* ((title (bibtex-autokey-get-field "title"))
320          (words (split-string title))
321          (start 0))
322     (when
323         (string= "article" (downcase (cdr (assoc "=type=" (bibtex-parse-entry)))))
324       (setq words (mapcar
325                    (lambda (word)
326                      (if (or
327                           ;; match words containing {} or \ which are probably
328                           ;; LaTeX or protected words
329                           (string-match "\\$\\|{\\|}\\|\\\\" word)
330                           ;; these words should not be capitalized, unless they
331                           ;; are the first word
332                           (-contains? jmax-lower-case-words (s-downcase word)))
333                          word
334                        (s-capitalize word)))
335                    words))
336
337       ;; Check if first word should be capitalized
338       (when (-contains? jmax-lower-case-words (car words))
339         (setf (car words) (s-capitalize (car words))))
340
341       (setq title (mapconcat 'identity words " "))
342
343       ;; Capitalize letters after a dash
344       (while
345           (string-match "[a-zA-Z]-\\([a-z]\\)" title start)
346         (let ((char (substring title (match-beginning 1) (match-end 1))))
347           (setf (substring title (match-beginning 1) (match-end 1))
348                 (format "%s" (upcase char)))
349           (setq start (match-end 1))))
350
351       ;; this is defined in doi-utils
352       (bibtex-set-field
353        "title"
354        title)
355       (bibtex-fill-entry))))
356
357 (add-hook 'org-ref-clean-bibtex-entry-hook 'jmax-title-case-article)
358
359
360 (defun jmax-sentence-case-article (&optional key start end)
361   "Convert a bibtex entry article title to sentence-case.
362 The arguments KEY, START and END are optional, and are only there
363 so you can use this function with `bibtex-map-entries' to change
364 all the title entries in articles."
365   (interactive)
366   (bibtex-beginning-of-entry)
367
368   (let* ((title (bibtex-autokey-get-field "title"))
369          (words (split-string title))
370          (start 0))
371     (when
372         (string= "article" (downcase (cdr (assoc "=type=" (bibtex-parse-entry)))))
373       (setq words (mapcar
374                    (lambda (word)
375                      (if
376                          ;; match words containing {} or \ which are probably
377                          ;; LaTeX or protected words
378                          (string-match "\\$\\|{\\|}\\|\\\\" word)
379                          word
380                        (s-downcase word)))
381                    words))
382
383       ;; capitalize first word
384       (setf (car words) (s-capitalize (car words)))
385
386       ;; join the words
387       (setq title (mapconcat 'identity words " "))
388
389       ;; capitalize a word after a :, eg. a subtitle, and protect it
390       (while
391           (string-match "[a-z]:\\s-+\\([A-Z]\\)" title start)
392         (let ((char (substring title (match-beginning 1) (match-end 1))))
393           (setf (substring title (match-beginning 1) (match-end 1))
394 ;;              (format "{%s}" (upcase char)))
395                 (format "%s" (upcase char)))
396           (setq start (match-end 1))))
397
398       ;; this is defined in doi-utils
399       (bibtex-set-field
400        "title" title)
401
402       ;; clean and refill entry so it looks nice
403       (bibtex-clean-entry)
404       (bibtex-fill-entry))))
405
406
407 (defun jmax-bibtex-next-entry (&optional n)
408   "Jump to the beginning of the next bibtex entry.
409 N is a prefix argument.  If it is numeric, jump that many entries
410 forward.  Negative numbers do nothing."
411   (interactive "P")
412   ;; Note if we start at the beginning of an entry, nothing
413   ;; happens. We need to move forward a char, and call again.
414   (when (= (point) (save-excursion
415                      (bibtex-beginning-of-entry)))
416     (forward-char)
417     (jmax-bibtex-next-entry))
418
419   ;; search forward for an entry
420   (when
421       (re-search-forward bibtex-entry-head nil t (and (numberp n) n))
422     ;; go to beginning of the entry
423     (bibtex-beginning-of-entry)))
424
425
426 (defun jmax-bibtex-previous-entry (&optional n)
427   "Jump to beginning of the previous bibtex entry.
428 N is a prefix argument.  If it is numeric, jump that many entries back."
429   (interactive "P")
430   (bibtex-beginning-of-entry)
431  (when
432      (re-search-backward bibtex-entry-head nil t (and (numberp n) n))
433    (bibtex-beginning-of-entry)))
434
435
436 (defun jmax-bibtex-mode-keys ()
437   "Modify keymaps used by `bibtex-mode'."
438   (local-set-key (kbd "M-n") 'jmax-bibtex-next-entry)
439   (local-set-key (kbd "M-p") 'jmax-bibtex-previous-entry))
440
441 ;; add to bibtex-mode-hook
442 (add-hook 'bibtex-mode-hook 'jmax-bibtex-mode-keys)
443
444
445 (defun jmax-bibtex-entry-doi ()
446   "Get doi from entry at point."
447   (interactive)
448   (save-excursion
449     (bibtex-beginning-of-entry)
450     (reftex-get-bib-field "doi" (bibtex-parse-entry t))))
451
452
453 (defun jmax-bibtex-wos ()
454   "Open bibtex entry in Web Of Science if there is a DOI."
455   (interactive)
456   (doi-utils-wos (jmax-bibtex-entry-doi)))
457
458
459 (defun jmax-bibtex-wos-citing ()
460   "Open citing articles for bibtex entry in Web Of Science if there is a DOI."
461   (interactive)
462   (doi-utils-wos-citing (jmax-bibtex-entry-doi)))
463
464
465 (defun jmax-bibtex-wos-related ()
466   "Open related articles for bibtex entry in Web Of Science if there is a DOI."
467   (interactive)
468   (doi-utils-wos-related (jmax-bibtex-entry-doi)))
469
470
471 (defun jmax-bibtex-wos-citing ()
472   "Open citing articles for bibtex entry in Web Of Science if there is a DOI."
473   (interactive)
474   (doi-utils-wos-citing (jmax-bibtex-entry-doi)))
475
476
477 (defun jmax-bibtex-crossref ()
478   "Open the bibtex entry in Crossref by its doi."
479   (interactive)
480   (doi-utils-crossref (jmax-bibtex-entry-doi)))
481
482
483 (defun jmax-bibtex-google-scholar ()
484   "Open the bibtex entry at point in google-scholar by its doi."
485   (interactive)
486   (doi-utils-google-scholar (jmax-bibtex-entry-doi)))
487
488
489 (defun jmax-bibtex-pubmed ()
490   "Open the bibtex entry at point in Pubmed by its doi."
491   (interactive)
492   (doi-utils-pubmed (jmax-bibtex-entry-doi)))
493
494
495 (defun jmax-bibtex-pdf (doi)
496   "Open the pdf for the bibtex entry at point.
497 Thin wrapper to get `jmax-bibtex' to open pdf, because it calls
498 functions with a DOI argument."
499   (interactive)
500   (org-ref-open-bibtex-pdf))
501
502
503 ;; hydra menu for actions on bibtex entries
504 (defhydra jmax-bibtex-hydra (:color blue)
505    "
506 _p_: Open pdf     _y_: Copy key               _n_: New entry     _w_: WOS
507 _b_: Open url     _f_: Copy formatted entry   _o_: Copy entry    _c_: WOS citing
508 _r_: Refile entry _k_: Add keywords           _d_: delete entry  _a_: WOS related
509 _e_: Email entry  _K_: Edit keywords          _L_: clean entry   _P_: Pubmed
510 _U_: Update entry _N_: Open notes             _R_: Crossref      _g_: Google Scholar
511 _s_: Sort entry   _a_: Remove nonascii        _h_: helm-bibtex   _q_: quit
512 _u_: Update field _f_: file funcs
513 "
514    ("p" org-ref-open-bibtex-pdf)
515    ("P" jmax-bibtex-pubmed)
516    ("w" jmax-bibtex-wos)
517    ("c" jmax-bibtex-wos-citing)
518    ("a" jmax-bibtex-wos-related)
519    ("R" jmax-bibtex-crossref)
520    ("g" jmax-bibtex-google-scholar)
521    ("n" jmax-bibtex-new-entry/body)
522    ("N" org-ref-open-bibtex-notes)
523    ("o" bibtex-copy-entry-as-kill)
524    ("d" bibtex-kill-entry)
525    ("L" org-ref-clean-bibtex-entry)
526    ("y" (kill-new  (bibtex-autokey-get-field "=key=")))
527    ("f" bibtex-copy-summary-as-kill)
528    ("k" helm-tag-bibtex-entry)
529    ("K" (lambda ()
530           (interactive)
531           (org-ref-set-bibtex-keywords
532            (read-input "Keywords: "
533                        (bibtex-autokey-get-field "keywords"))
534            t)))
535    ("b" org-ref-open-in-browser)
536    ("r" (lambda () (interactive)
537           (bibtex-beginning-of-entry)
538           (bibtex-kill-entry)
539           (find-file (ido-completing-read
540                       "Bibtex file: "
541                       (f-entries "." (lambda (f) (f-ext? f "bib")))))
542           (goto-char (point-max))
543           (bibtex-yank)
544           (save-buffer)
545           (kill-buffer)))
546    ("e" email-bibtex-entry)
547    ("U" (doi-utils-update-bibtex-entry-from-doi (jmax-bibtex-entry-doi)))
548    ("u" doi-utils-update-field)
549    ("f" jmax-bibtex-file/body)
550    ("h" helm-bibtex)
551    ("a" jmax-replace-nonascii)
552    ("s" org-ref-sort-bibtex-entry)
553    ("q" nil))
554
555 ;; create key-chord and key binding for hydra
556 (when jmax-bibtex-hydra-key-chord
557   (key-chord-define-global
558    jmax-bibtex-hydra-key-chord
559    'jmax-bibtex-hydra/body))
560
561
562 (when jmax-bibtex-hydra-key-binding
563   (global-set-key jmax-bibtex-hydra-key-binding 'jmax-bibtex-hydra/body))
564
565
566 ;; A hydra for adding new bibtex entries.
567 (defhydra jmax-bibtex-new-entry (:color blue)
568   "New Bibtex entry:"
569   ("a" bibtex-Article "Article")
570   ("b" bibtex-Book "Book")
571   ("i" bibtex-InBook "In book")
572   ("l" bibtex-Booklet "Booklet")
573   ("P" bibtex-Proceedings "Proceedings")
574   ("p" bibtex-InProceedings "In proceedings")
575   ("m" bibtex-Misc "Misc.")
576   ("M" bibtex-Manual "Manual")
577   ("T" bibtex-PhdThesis "PhD Thesis")
578   ("t" bibtex-MastersThesis "MS Thesis")
579   ("R" bibtex-TechReport "Report")
580   ("u" bibtex-Unpublished "unpublished")
581   ("c" bibtex-InCollection "Article in collection")
582   ("q" nil "quit"))
583
584
585 ;; a hydra menu of functions to act on a bibtex file.
586 (defhydra jmax-bibtex-file (:color blue)
587   "Bibtex file functions: "
588   ("v" bibtex-validate "Validate entries")
589   ("s" bibtex-sort-buffer "Sort entries")
590   ("r" bibtex-reformat "Reformat entries")
591   ("c" bibtex-count-entries "Count entries")
592   ("p" org-ref-build-full-bibliography "PDF bibliography"))
593
594
595 (defvar jmax-bibtex-menu-funcs '()
596  "Functions to run in doi menu.
597 Each entry is a list of (key menu-name function).  The function
598 must take one argument, the doi.  This is somewhat deprecated, as
599 I prefer the hydra interfaces above.")
600
601 (setq jmax-bibtex-menu-funcs
602       '(("p" "df" jmax-bibtex-pdf)
603         ("C" "opy" (lambda (doi)
604                      (kill-new (org-ref-bib-citation))
605                      (bury-buffer)))
606         ("w" "os" doi-utils-wos)
607         ("c" "iting articles" doi-utils-wos-citing)
608         ("r" "elated articles" doi-utils-wos-related)
609         ("s" "Google Scholar" doi-utils-google-scholar)
610         ("P" "Pubmed" doi-utils-pubmed)
611         ("f" "CrossRef" doi-utils-crossref)))
612
613 (defun jmax-bibtex ()
614   "Menu command to run in a bibtex entry.
615 Functions from `jmax-bibtex-menu-funcs'.  They all rely on the
616 entry having a doi."
617
618   (interactive)
619   ;; construct menu string as a message
620   (message
621    (concat
622     (mapconcat
623      (lambda (tup)
624        (concat "[" (elt tup 0) "]"
625                (elt tup 1) " "))
626      jmax-bibtex-menu-funcs "") ": "))
627   (let* ((input (read-char-exclusive))
628          (choice (assoc
629                   (char-to-string input) jmax-bibtex-menu-funcs)))
630     (when choice
631       (funcall
632        (elt
633         choice
634         2)
635        (jmax-bibtex-entry-doi)
636        ))))
637
638 (defalias 'jb 'jmax-bibtex)
639
640 (provide 'jmax-bibtex)
641
642 ;;; jmax-bibtex.el ends here