-** bibliography and bibliographystyle
-*** An html bibliography
-
-Reftex is no longer being developed. I want a url and doi option for formatting, so I am modifying this [[file:emacs-24.3/lisp/textmodes/reftex-cite.el::(defun%20reftex-format-citation%20(entry%20format)][function]] from reftex-cite to provide that. We need to modify the reftex-get-bib-field code a bit to remove enclosing braces and quotes so we can make nice looking links.
-
-#+BEGIN_SRC emacs-lisp :tangle org-ref.el
-(defun org-ref-reftex-get-bib-field (field entry &optional format)
- "similar to reftex-get-bib-field, but removes enclosing braces and quotes"
- (let ((result))
- (setq result (reftex-get-bib-field field entry format))
- (when (and (not (string= result "")) (string= "{" (substring result 0 1)))
- (setq result (substring result 1 -1)))
- (when (and (not (string= result "")) (string= "\"" (substring result 0 1)))
- (setq result (substring result 1 -1)))
- result))
-
-(defun org-ref-reftex-format-citation (entry format)
- "return a formatted string for the bibtex entry (from bibtex-parse-entry) according
-to the format argument. The format is a string with these percent escapes.
-
-In the format, the following percent escapes will be expanded.
-
-%l The BibTeX label of the citation.
-%a List of author names, see also `reftex-cite-punctuation'.
-%2a Like %a, but abbreviate more than 2 authors like Jones et al.
-%A First author name only.
-%e Works like %a, but on list of editor names. (%2e and %E work a well)
-
-It is also possible to access all other BibTeX database fields:
-%b booktitle %c chapter %d edition %h howpublished
-%i institution %j journal %k key %m month
-%n number %o organization %p pages %P first page
-%r address %s school %u publisher %t title
-%v volume %y year
-%B booktitle, abbreviated %T title, abbreviated
-%U url
-%D doi
-%S series
-
-Usually, only %l is needed. The other stuff is mainly for the echo area
-display, and for (setq reftex-comment-citations t).
-
-%< as a special operator kills punctuation and space around it after the
-string has been formatted.
-
-A pair of square brackets indicates an optional argument, and RefTeX
-will prompt for the values of these arguments.
-
-Beware that all this only works with BibTeX database files. When
-citations are made from the \bibitems in an explicit thebibliography
-environment, only %l is available."
- ;; Format a citation from the info in the BibTeX ENTRY
-
- (unless (stringp format) (setq format "\\cite{%l}"))
-
- (if (and reftex-comment-citations
- (string-match "%l" reftex-cite-comment-format))
- (error "reftex-cite-comment-format contains invalid %%l"))
-
- (while (string-match
- "\\(\\`\\|[^%]\\)\\(\\(%\\([0-9]*\\)\\([a-zA-Z]\\)\\)[.,;: ]*\\)"
- format)
- (let ((n (string-to-number (match-string 4 format)))
- (l (string-to-char (match-string 5 format)))
- rpl b e)
- (save-match-data
- (setq rpl
- (cond
- ((= l ?l) (concat
- (org-ref-reftex-get-bib-field "&key" entry)
- (if reftex-comment-citations
- reftex-cite-comment-format
- "")))
- ((= l ?a) (reftex-format-names
- (reftex-get-bib-names "author" entry)
- (or n 2)))
- ((= l ?A) (car (reftex-get-bib-names "author" entry)))
- ((= l ?b) (org-ref-reftex-get-bib-field "booktitle" entry "in: %s"))
- ((= l ?B) (reftex-abbreviate-title
- (org-ref-reftex-get-bib-field "booktitle" entry "in: %s")))
- ((= l ?c) (org-ref-reftex-get-bib-field "chapter" entry))
- ((= l ?d) (org-ref-reftex-get-bib-field "edition" entry))
- ((= l ?D) (org-ref-reftex-get-bib-field "doi" entry))
- ((= l ?e) (reftex-format-names
- (reftex-get-bib-names "editor" entry)
- (or n 2)))
- ((= l ?E) (car (reftex-get-bib-names "editor" entry)))
- ((= l ?h) (org-ref-reftex-get-bib-field "howpublished" entry))
- ((= l ?i) (org-ref-reftex-get-bib-field "institution" entry))
- ((= l ?j) (org-ref-reftex-get-bib-field "journal" entry))
- ((= l ?k) (org-ref-reftex-get-bib-field "key" entry))
- ((= l ?m) (org-ref-reftex-get-bib-field "month" entry))
- ((= l ?n) (org-ref-reftex-get-bib-field "number" entry))
- ((= l ?o) (org-ref-reftex-get-bib-field "organization" entry))
- ((= l ?p) (org-ref-reftex-get-bib-field "pages" entry))
- ((= l ?P) (car (split-string
- (org-ref-reftex-get-bib-field "pages" entry)
- "[- .]+")))
- ((= l ?s) (org-ref-reftex-get-bib-field "school" entry))
- ((= l ?S) (org-ref-reftex-get-bib-field "series" entry))
- ((= l ?u) (org-ref-reftex-get-bib-field "publisher" entry))
- ((= l ?U) (org-ref-reftex-get-bib-field "url" entry))
- ((= l ?r) (org-ref-reftex-get-bib-field "address" entry))
- ;; strip enclosing brackets from title if they are there
- ((= l ?t) (org-ref-reftex-get-bib-field "title" entry))
- ((= l ?T) (reftex-abbreviate-title
- (org-ref-reftex-get-bib-field "title" entry)))
- ((= l ?v) (org-ref-reftex-get-bib-field "volume" entry))
- ((= l ?y) (org-ref-reftex-get-bib-field "year" entry)))))
-
- (if (string= rpl "")
- (setq b (match-beginning 2) e (match-end 2))
- (setq b (match-beginning 3) e (match-end 3)))
- (setq format (concat (substring format 0 b) rpl (substring format e)))))
- (while (string-match "%%" format)
- (setq format (replace-match "%" t t format)))
- (while (string-match "[ ,.;:]*%<" format)
- (setq format (replace-match "" t t format)))
- ;; also replace carriage returns, tabs, and multiple whitespaces
- (setq format (replace-regexp-in-string "\n\\|\t\\|\s+" " " format))
- format)
-
-(defun org-ref-get-bibtex-entry-citation (key)
- "returns a string for the bibliography entry corresponding to key, and formatted according to the type in `org-ref-bibliography-entry-format'"
-
- (let ((org-ref-bibliography-files (org-ref-find-bibliography))
- (file) (entry) (bibtex-entry) (entry-type) (format))
-
- (setq file (catch 'result
- (loop for file in org-ref-bibliography-files do
- (if (org-ref-key-in-file-p key (file-truename file))
- (throw 'result file)
- (message "%s not found in %s" key (file-truename file))))))
-
- (with-temp-buffer
- (insert-file-contents file)
- (bibtex-search-entry key nil 0)
- (setq bibtex-entry (bibtex-parse-entry))
- (setq entry-type (downcase (cdr (assoc "=type=" bibtex-entry))))
- (setq format (cdr (assoc entry-type org-ref-bibliography-entry-format)))
- (if format
- (setq entry (org-ref-reftex-format-citation bibtex-entry format))
- (save-restriction
- (bibtex-narrow-to-entry)
- (setq entry (buffer-string)))))
- entry))
-#+END_SRC