Klimi's new dotfiles with stow.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

132 行
4.8 KiB

  1. ;;; x2bib.el --- Bibliography conversion to Bibtex
  2. ;;; Header:
  3. ;;; Commentary:
  4. ;; This module is more for my convenience to convert bibliography files to
  5. ;; bibtex. This can be done at the command line, for example, but I want to do
  6. ;; it in Emacs. There are a few scenarios where this happens.
  7. ;; 1. Someone sends me a non-Bibtex file (Endnote, etc...)
  8. ;; 2. From some online search I select many references and there is no export to
  9. ;; Bibtex option, e.g. from Web of Science.
  10. ;; This code is mostly wrappers around the command line utilities at
  11. ;; http://sourceforge.net/p/bibutils/home/Bibutils.
  12. ;; Here are the commands that are available.
  13. ;; bib2xml - convert BibTeX to MODS XML intermediate
  14. ;; biblatex2xml - convert BibLaTeX to MODS XML intermediate
  15. ;; copac2xml - convert COPAC format references to MODS XML intermediate
  16. ;; end2xml - convert EndNote (Refer format) to MODS XML intermediate
  17. ;; endx2xml - convert EndNote XML to MODS XML intermediate
  18. ;; isi2xml - convert ISI web of science to MODS XML intermediate
  19. ;; med2xml - convert Pubmed XML references to MODS XML intermediate
  20. ;; modsclean - a MODS to MODS converter for testing puposes mostly
  21. ;; ris2xml - convert RIS format to MODS XML intermediate
  22. ;; xml2ads - convert MODS XML intermediate into Smithsonian Astrophysical
  23. ;; Observatory (SAO)/National Aeronautics and Space
  24. ;; Administration (NASA) Astrophyics Data System or ADS
  25. ;; reference format (converter submitted by Richard Mathar)
  26. ;; xml2bib - convert MODS XML intermediate into BibTeX
  27. ;; xml2end - convert MODS XML intermediate into format for EndNote
  28. ;; xml2isi - convert MODS XML intermediate to ISI format
  29. ;; xml2ris - convert MODS XML intermediate into RIS format
  30. ;; xml2wordbib - convert MODS XML intermediate into Word 2007 bibliography format
  31. ;;; Code:
  32. (require 'bibtex)
  33. (require 'org-ref-core)
  34. ;;* RIS to bibtex
  35. ;; RIS can be pretty easily exported from Endnote. Here is a function to read an
  36. ;; RIS file and convert it to bibtex which is inserted at point. Note that there
  37. ;; is often other output from the commands. We try to comment them out here, but
  38. ;; you should probably inspect the entries, and do other bibtex file compliance
  39. ;; checks.
  40. ;;;###autoload
  41. (defun ris2bib (risfile &optional verbose)
  42. "Convert RISFILE to bibtex and insert at point.
  43. Without a prefix arg, stderr is diverted.
  44. If VERBOSE is non-nil show command output."
  45. (interactive
  46. (list (read-file-name "RIS file:")
  47. (prefix-numeric-value current-prefix-arg)))
  48. (let ((result (shell-command-to-string
  49. (concat
  50. (format
  51. "ris2xml %s | xml2bib -w"
  52. risfile)
  53. (unless verbose " 2> /dev/null")))))
  54. ;; make some lines into comments.
  55. (setq result (replace-regexp-in-string
  56. "^xml2bib:"
  57. "% xml2bib:"
  58. result))
  59. (setq result (replace-regexp-in-string
  60. "^ris2xml:"
  61. "% ris2xml"
  62. result))
  63. (setq result (replace-regexp-in-string
  64. "^ Defaulting"
  65. "% Defaulting"
  66. result))
  67. (insert result)))
  68. ;;* Pubmed XML to bibtex
  69. ;; In http://www.ncbi.nlm.nih.gov/pubmed/ you can select entries, and then send
  70. ;; them to a file. If you choose Pubmed XML as the format, then you can use this
  71. ;; function to convert it to bibtex.
  72. ;;;###autoload
  73. (defun medxml2bib (medfile &optional verbose)
  74. "Convert MEDFILE (in Pubmed xml) to bibtex and insert at point.
  75. Without a prefix arg, stderr is diverted.
  76. Display output if VERBOSE is non-nil."
  77. (interactive
  78. (list (read-file-name "MED file:")
  79. (prefix-numeric-value current-prefix-arg)))
  80. (let ((result (shell-command-to-string
  81. (concat
  82. (format
  83. "med2xml %s | xml2bib -w"
  84. medfile)
  85. (unless verbose " 2> /dev/null")))))
  86. ;; make some lines into comments.
  87. (setq result (replace-regexp-in-string
  88. "^xml2bib:"
  89. "% xml2bib:"
  90. result))
  91. (setq result (replace-regexp-in-string
  92. "^med2xml:"
  93. "% med2xml"
  94. result))
  95. (setq result (replace-regexp-in-string
  96. "^ Defaulting"
  97. "% Defaulting"
  98. result))
  99. (insert result)))
  100. ;;* Clean up all the entries
  101. ;; Finally, after you put the new entries in, you probably need to do some clean
  102. ;; up actions. This little function does that.
  103. ;;;###autoload
  104. (defun clean-entries ()
  105. "Map over bibtex entries and clean them."
  106. (interactive)
  107. (bibtex-map-entries
  108. (lambda (a b c)
  109. (ignore-errors
  110. (org-ref-clean-bibtex-entry)))))
  111. (provide 'x2bib)
  112. ;;; x2bib.el ends here