]> git.donarmstrong.com Git - org-ref.git/blobdiff - org-ref.org
added new doi menu link for org-mode
[org-ref.git] / org-ref.org
index 681043513a175bd3ced6e91133b09a19da05aa3d..30bf03006a56807061533ebd416bb99e1780e794 100644 (file)
@@ -103,6 +103,17 @@ There are some variables needed later to tell this library where you store your
   "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)
+
+(defcustom org-ref-open-notes-function
+  (lambda ()
+    (org-show-entry)
+    (show-branches)
+    (show-children)
+    (org-cycle '(64))
+    ;;(org-tree-to-indirect-buffer)
+    (outline-previous-visible-heading 1)
+    (recenter-top-bottom 0))
+  "User-defined way to open a notes entry. This is excecuted after the entry is found, with the cursor at the beginning of the headline. The default setting fully expands the notes, and moves the headline to the top of the buffer") 
 #+END_SRC
 
 This next variable determines the citation types that are available in org-ref. Links for each one are automatically generated, and completion functions are automatically generated. Users may add to this list in their own init files.
@@ -140,6 +151,8 @@ This next variable determines the citation types that are available in org-ref.
     "footcites" "footcitetexts"
     "smartcites" "Smartcites" "textcites" "Textcites"
     "supercites" "autocites" "Autocites"
+    ;; for the bibentry package
+    "bibentry"
     )
   "List of citation types known in org-ref"
   :type '(repeat :tag "List of citation types" string)
@@ -567,8 +580,89 @@ We use a link for the bibliography so that we can click on it to open the biblio
                       ((eq format 'ascii) (org-ref-get-ascii-bibliography))
                      ((eq format 'html) (org-ref-get-html-bibliography))
                      ((eq format 'latex)
-                        ;; write out the latex bibliography command
-                      (format "\\bibliography{%s}" (replace-regexp-in-string  "\\.bib" "" (expand-file-name keyword)))))))
+                      ;; write out the latex bibliography command                     
+                      (format "\\bibliography{%s}" (replace-regexp-in-string  "\\.bib" "" (mapconcat 'identity
+                                                                                                     (mapcar 'expand-file-name
+                                                                                                             (split-string keyword ","))
+                                                                                                     ",")))))))
+                                                                              
+#+END_SRC
+
+Believe it or not, sometimes it makes sense /not/ to include the bibliography in a document (e.g. when you are required to submit references as a separate file). To generate the references,  in another file, you must make a little tex file with these contents, and then compile it.
+
+#+BEGIN_LaTeX
+  \input{project-description.bbl}
+#+END_LaTeX
+
+Here, we make a =nobibliography= link that acts like the bibliography, enables creation of the bbl file, but does not put an actual bibliography in the file.
+
+#+BEGIN_SRC emacs-lisp :tangle org-ref.el
+(org-add-link-type "nobibliography"
+                  ;; this code is run on clicking. The bibliography
+                  ;; may contain multiple files. this code finds the
+                  ;; one you clicked on and opens it.
+                  (lambda (link-string)        
+                      ;; get link-string boundaries
+                      ;; we have to go to the beginning of the line, and then search forward
+                      
+                    (let* ((bibfile)
+                           ;; object is the link you clicked on
+                           (object (org-element-context))
+                           (link-string-beginning) 
+                           (link-string-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)))
+
+                      ;; We set the reftex-default-bibliography
+                      ;; here. it should be a local variable only in
+                      ;; the current buffer. We need this for using
+                      ;; reftex to do citations.
+                      (set (make-local-variable 'reftex-default-bibliography) 
+                           (split-string (org-element-property :path object) ","))
+
+                      ;; now if we have comma separated bibliographies
+                      ;; we find the one clicked on. we want to
+                      ;; search forward to next comma from point
+                      (save-excursion
+                        (if (search-forward "," link-string-end 1 1)
+                            (setq key-end (- (match-end 0) 1)) ; we found a match
+                          (setq key-end (point)))) ; no comma found so take the point
+                      ;; and backward to previous comma from point
+                      (save-excursion
+                        (if (search-backward "," link-string-beginning 1 1)
+                            (setq key-beginning (+ (match-beginning 0) 1)) ; we found a match
+                          (setq key-beginning (point)))) ; no match found
+                      ;; save the key we clicked on.
+                      (setq bibfile (org-ref-strip-string (buffer-substring key-beginning key-end)))
+                      (find-file bibfile))) ; open file on click
+
+                    ;; formatting code
+                  (lambda (keyword desc format)
+                    (cond
+                     ((eq format 'org) (org-ref-get-org-bibliography))
+                      ((eq format 'ascii) (org-ref-get-ascii-bibliography))
+                     ((eq format 'html) (org-ref-get-html-bibliography))
+                     ((eq format 'latex)
+                      ;; write out the latex bibliography command                     
+
+;                     (format "{\\setbox0\\vbox{\\bibliography{%s}}}"
+;                             (replace-regexp-in-string  "\\.bib" "" (mapconcat 'identity
+;                                                                               (mapcar 'expand-file-name
+;                                                                                       (split-string keyword ","))
+;                                                                               ",")))
+
+                      (format "\\nobibliography{%s}"
+                              (replace-regexp-in-string  "\\.bib" "" (mapconcat 'identity
+                                                                                (mapcar 'expand-file-name
+                                                                                        (split-string keyword ","))
+                                                                                ",")))
+
+                      ))))                                                                            
 #+END_SRC
 
 #+BEGIN_SRC emacs-lisp :tangle org-ref.el
@@ -870,6 +964,7 @@ At the moment, ref links are not usable for section links. You need [[#CUSTOM_ID
      ;; we did not find anything, so go back to where we came
      (org-mark-ring-goto)
      (error "%s not found" label))
+   (org-show-entry)
    (message "go back with (org-mark-ring-goto) `C-c &`"))
  ;formatting
  (lambda (keyword desc format)
@@ -1096,7 +1191,16 @@ keyword we clicked on. We also strip the text properties."
   (interactive)
   (let* ((object (org-element-context))         
         (link-string (org-element-property :path object)))
-
+    ;; you may click on the part before the citations. here we make
+    ;; sure to move to the beginning so you get the first citation.
+    (let ((cp (point)))
+      (goto-char (org-element-property :begin object))
+      (search-forward link-string (org-element-property :end object))
+      (goto-char (match-beginning 0))
+      ;; check if we clicked before the path and move as needed.
+      (unless (< cp (point))
+       (goto-char cp)))
+       
     (if (not (org-element-property :contents-begin object))
        ;; this means no description in the link
        (progn    
@@ -1716,12 +1820,14 @@ construct the heading by hand."
     
     ;; now look for entry in the notes file
     (if  org-ref-bibliography-notes
-       (find-file org-ref-bibliography-notes)
+       (find-file-other-window org-ref-bibliography-notes)
       (error "org-ref-bib-bibliography-notes is not set to anything"))
     
     (goto-char (point-min))
     ;; put new entry in notes if we don't find it.
-    (unless (re-search-forward (format ":Custom_ID: %s$" key) nil 'end)
+    (if (re-search-forward (format ":Custom_ID: %s$" key) nil 'end)
+       (funcall org-ref-open-notes-function)
+      ;; no entry found, so add one    
       (insert (format "\n** TODO %s - %s" year title))
       (insert (format"
  :PROPERTIES:
@@ -1739,6 +1845,25 @@ key author journal year volume pages doi url key org-ref-pdf-directory key))
 (save-buffer))))
 #+END_SRC
 
+#+BEGIN_SRC emacs-lisp :tangle org-ref.el
+(defun org-ref-open-notes-from-reftex ()
+  "Call reftex, and open notes for selected entry."
+  (interactive)
+  (let ((bibtex-key )))
+
+    ;; now look for entry in the notes file
+    (if  org-ref-bibliography-notes
+       (find-file-other-window org-ref-bibliography-notes)
+      (error "org-ref-bib-bibliography-notes is not set to anything"))
+    
+    (goto-char (point-min))
+    
+    (re-search-forward (format
+                       ":Custom_ID: %s$"
+                       (first (reftex-citation t)) nil 'end))
+    (funcall org-ref-open-notes-function))
+#+END_SRC
+
 ** open url in browser from bibtex
 
 We bind this to a key here [[*key%20bindings%20for%20utilities][key bindings for utilities]].
@@ -2215,6 +2340,7 @@ I like convenience. Here are some aliases for faster typing.
 (defalias 'orp 'org-ref-open-pdf-at-point)
 (defalias 'oru 'org-ref-open-url-at-point)
 (defalias 'orn 'org-ref-open-notes-at-point)
+(defalias 'ornr 'org-ref-open-notes-from-reftex)
 
 (defalias 'orib 'org-ref-insert-bibliography-link)
 (defalias 'oric 'org-ref-insert-cite-link)