X-Git-Url: https://git.donarmstrong.com/?p=org-ref.git;a=blobdiff_plain;f=org-ref.org;h=d2982c2cf224337e2713be87cd34e9d7b972d476;hp=62e9804063331dbce20da913f39b412f6f265c76;hb=dd5c516e7c1c1787bfd3b4968d6ec6cce2a6f7c3;hpb=297199fb6db3f6c253a8cc53b6cfdfc1e2b69ddd diff --git a/org-ref.org b/org-ref.org index 62e9804..d2982c2 100644 --- a/org-ref.org +++ b/org-ref.org @@ -92,8 +92,15 @@ There are some variables needed later to tell this library where you store your :group 'org-ref) (defcustom org-ref-bibliography-entry-format - "%a, %t, %j, %v(%n), %p (%y). link. doi." - "string to format an entry. Just the reference, no numbering at the beginning, etc..." + '(("article" . "%a, %t, %j, %v(%n), %p (%y). link. doi.") + + ("book" . "%a, %t, %u (%y).") + + ("proceedings" . "%e, %t in %S, %u (%y).") + + ("inproceedings" . "%a, %t, %p, in %b, edited by %e, %u (%y)")) + + "string to format an entry. Just the reference, no numbering at the beginning, etc... see the `org-ref-reftex-format-citation' docstring for the escape codes." :type 'string :group 'org-ref) #+END_SRC @@ -263,6 +270,7 @@ It is also possible to access all other BibTeX database fields: %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). @@ -324,6 +332,7 @@ environment, only %l is available." (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)) @@ -347,10 +356,10 @@ environment, only %l is available." format) (defun org-ref-get-bibtex-entry-citation (key) - "returns a string for the bibliography entry corresponding to key, and formatted according to `org-ref-bibliography-entry-format'" + "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)) + (file) (entry) (bibtex-entry) (entry-type) (format)) (setq file (catch 'result (loop for file in org-ref-bibliography-files do @@ -361,7 +370,14 @@ environment, only %l is available." (with-temp-buffer (insert-file-contents file) (bibtex-search-entry key nil 0) - (setq entry (org-ref-reftex-format-citation (bibtex-parse-entry) org-ref-bibliography-entry-format))) + (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 @@ -379,7 +395,7 @@ Here is how to use the function. You call it with point in an entry in a bibtex I am not sure why full author names are not used. -This code provides some functions to generate a simple sorted bibliography in html. First we get all the keys in the bufer. +This code provides some functions to generate a simple sorted bibliography in html. First we get all the keys in the buffer. #+BEGIN_SRC emacs-lisp :tangle org-ref.el (defun org-ref-get-bibtex-keys () @@ -1002,30 +1018,34 @@ to get a comma, or the beginning of the link. that delimits the keyword we clicked on. We also strip the text properties." (interactive) (let* ((object (org-element-context)) - (link-string (org-element-property :path object))) - - ;; we need the link path start and end - (save-excursion - (goto-char (org-element-property :begin object)) - (search-forward link-string nil nil 1) - (setq link-string-beginning (match-beginning 0)) - (setq link-string-end (match-end 0))) + (link-string (org-element-property :path object))) - ;; The key is the text between commas, or the link boundaries - (save-excursion - (if (search-forward "," link-string-end t 1) - (setq key-end (- (match-end 0) 1)) ; we found a match - (setq key-end link-string-end))) ; no comma found so take the end - ;; and backward to previous comma from point which defines the start character - (save-excursion - (if (search-backward "," link-string-beginning 1 1) - (setq key-beginning (+ (match-beginning 0) 1)) ; we found a match - (setq key-beginning link-string-beginning))) ; no match found - ;; save the key we clicked on. - (setq bibtex-key (org-ref-strip-string (buffer-substring key-beginning key-end))) - (set-text-properties 0 (length bibtex-key) nil bibtex-key) - bibtex-key - )) + (if (not (org-element-property :contents-begin object)) + ;; this means no description in the link + (progn + ;; we need the link path start and end + (save-excursion + (goto-char (org-element-property :begin object)) + (search-forward link-string nil nil 1) + (setq link-string-beginning (match-beginning 0)) + (setq link-string-end (match-end 0))) + + ;; The key is the text between commas, or the link boundaries + (save-excursion + (if (search-forward "," link-string-end t 1) + (setq key-end (- (match-end 0) 1)) ; we found a match + (setq key-end link-string-end))) ; no comma found so take the end + ;; and backward to previous comma from point which defines the start character + (save-excursion + (if (search-backward "," link-string-beginning 1 1) + (setq key-beginning (+ (match-beginning 0) 1)) ; we found a match + (setq key-beginning link-string-beginning))) ; no match found + ;; save the key we clicked on. + (setq bibtex-key (org-ref-strip-string (buffer-substring key-beginning key-end))) + (set-text-properties 0 (length bibtex-key) nil bibtex-key) + bibtex-key) + ;; link with description. assume only one key + link-string))) #+END_SRC We also need to find which bibliography file that key is in. For that, we need to know which bibliography files are referred to in the file. If none are specified with a bibliography link, we use the default bibliography. This function searches for a bibliography link, and then the LaTeX bibliography link. We also consider the addbibresource link which is used with biblatex. @@ -1492,55 +1512,6 @@ org-mode already defines a store link function for bibtex entries. It does not s (car org-stored-links))) #+END_SRC -** An html bibliography -This code provides some functions to generate a simple bibliography in html. - -#+BEGIN_SRC emacs-lisp :tangle org-ref.el -(defun org-ref-get-bibtex-keys () - "return a list of unique keys in the buffer" - (interactive) - (let ((keys '())) - (org-element-map (org-element-parse-buffer) 'link - (lambda (link) - (let ((plist (nth 1 link))) - (when (-contains? org-ref-cite-types (plist-get plist ':type)) - (dolist - (key - (org-ref-split-and-strip-string (plist-get plist ':path))) - (when (not (-contains? keys key)) - (setq keys (append keys (list key))))))))) - keys)) -#+END_SRC - - -#+BEGIN_SRC emacs-lisp :tangle org-ref.el -(defun org-ref-get-bibtex-entry-html (key) - (let ((org-ref-bibliography-files (org-ref-find-bibliography)) - (file) (entry)) - - (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))))) - (if file (with-temp-buffer - (insert-file-contents file) - (prog1 - (bibtex-search-entry key nil 0) - (setq entry (org-ref-bib-html-citation))) - (format "
  • [%s] %s
  • " key key entry))))) -#+END_SRC - - -#+BEGIN_SRC emacs-lisp :tangle org-ref.el -(defun org-ref-get-html-bibliography () - "Create an html bibliography when there are keys" - (let ((keys (org-ref-get-bibtex-keys))) - (when keys - (concat "

    Bibliography

    -")))) -#+END_SRC * Utilities ** create simple text citation from bibtex entry