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