X-Git-Url: https://git.donarmstrong.com/?p=org-ref.git;a=blobdiff_plain;f=org-ref.org;h=098dc5760eae7513282a0206fa34e881127f2857;hp=5a861776feb9307a605f82221392b29606a23ffc;hb=7a7f858f40db07de575c341218b915be772adb30;hpb=c40a50d52e4e81d0bc172a639f0b9437671b9c01 diff --git a/org-ref.org b/org-ref.org index 5a86177..098dc57 100644 --- a/org-ref.org +++ b/org-ref.org @@ -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) @@ -166,12 +179,16 @@ We need a hook variable to store user-defined bibtex entry cleaning functions We setup reftex here. We use a custom insert cite link function defined here: [[*org-ref-insert-cite-link][org-ref-insert-cite-link]]. We setup reftex to use our org citation format. #+BEGIN_SRC emacs-lisp :tangle org-ref.el +(require 'reftex) (defun org-mode-reftex-setup () - (load-library "reftex") (and (buffer-file-name) (file-exists-p (buffer-file-name)) (global-auto-revert-mode t) - (reftex-parse-all)) + ;; I do not remember why I put this next line in. It doesn't + ;; work for org-files. Nothing very bad happens, but it gives + ;; an annoying error. Commenting it out for now. + ;(reftex-parse-all) + ) (make-local-variable 'reftex-cite-format) (setq reftex-cite-format 'org) (define-key org-mode-map (kbd org-ref-insert-cite-key) 'org-ref-insert-cite-link)) @@ -567,8 +584,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 +968,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) @@ -879,7 +978,18 @@ At the moment, ref links are not usable for section links. You need [[#CUSTOM_ID (format "\\ref{%s}" keyword))))) #+END_SRC -It would be nice to use completion to enter a ref link, where a list of labels is provided. The following code searches the buffer for labels, custom_ids, and table names as potential items to make a ref link to. +It would be nice to use completion to enter a ref link, where a list of labels is provided. The following code searches the buffer for org and latex labels, custom_ids, and table names as potential items to make a ref link to. + +#+BEGIN_SRC emacs-lisp :tangle org-ref.el +(defun org-ref-get-org-labels () + "find #+LABEL: labels" + (save-excursion + (goto-char (point-min)) + (let ((matches '())) + (while (re-search-forward "^#\\+label:\\s-+\\(.*\\)\\b" (point-max) t) + (add-to-list 'matches (match-string-no-properties 1) t)) +matches))) +#+END_SRC #+BEGIN_SRC emacs-lisp :tangle org-ref.el (defun org-ref-get-custom-ids () @@ -896,7 +1006,7 @@ results)) Here we get a list of the labels defined as raw latex labels, e.g. \label{eqtre}. #+BEGIN_SRC emacs-lisp :tangle org-ref.el (defun org-ref-get-latex-labels () -(save-excursion + (save-excursion (goto-char (point-min)) (let ((matches '())) (while (re-search-forward "\\\\label{\\([a-zA-z0-9:-]*\\)}" (point-max) t) @@ -925,7 +1035,7 @@ Now, we can put all the labels together which will give us a list of candidates. (let ((matches '())) (while (re-search-forward "label:\\([a-zA-z0-9:-]*\\)" (point-max) t) (add-to-list 'matches (match-string-no-properties 1) t)) - (append matches (org-ref-get-latex-labels) (org-ref-get-tblnames) (org-ref-get-custom-ids)))))) + (append matches (org-ref-get-org-labels) (org-ref-get-latex-labels) (org-ref-get-tblnames) (org-ref-get-custom-ids)))))) #+END_SRC Now we create the completion function. This works from the org-machinery, e.g. if you type C-c C-l to insert a link, and use completion by pressing tab. @@ -1078,7 +1188,6 @@ This is just the LaTeX ref for equations. On export, the reference is enclosed i (format "\\eqref{%s}" keyword))))) #+END_SRC - ** cite This is the main reason this library exists. We want the following behavior. A cite link should be able to contain multiple bibtex keys. You should be able to click on the link, and get a brief citation of the entry for that key, and a menu of options to open the bibtex file, open a pdf if you have it, open your notes on the entry, or open a url if it exists. You should be able to insert new references onto an existing cite link, or create new ones easily. The following code implements these features. @@ -1096,7 +1205,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 @@ -1252,11 +1370,15 @@ we check to see if there is pdf, and if the key actually exists in the bibliogra (with-temp-buffer (insert-file-contents bibfile) (bibtex-search-entry key) - (org-ref-bib-citation)))) + (concat + (org-ref-bib-citation) + "\n" + "in: " bibfile) + ))) citation) "no key found")) - (setq menu-string (mapconcat 'identity (list m2 "\n" m1 m3 m4 m5 "(q)uit") " ")) + (setq menu-string (mapconcat 'identity (list m2 "\n" m1 m3 m4 m5 "(m)enu" "(q)uit") " ")) menu-string)) #+END_SRC @@ -1303,6 +1425,7 @@ We need some convenience functions to open act on the citation at point. These w (browse-url (format "http://dx.doi.org/%s" doi))) (throw 'done nil)))))))) + (defun org-ref-open-notes-at-point () "open the notes for bibtex key under point." (interactive) @@ -1315,6 +1438,7 @@ We need some convenience functions to open act on the citation at point. These w (bibtex-search-entry key) (org-ref-open-bibtex-notes))))) + (defun org-ref-citation-at-point () "give message of current citation at point" (interactive) @@ -1328,6 +1452,7 @@ We need some convenience functions to open act on the citation at point. These w (bibtex-search-entry key) (org-ref-bib-citation)))))) + (defun org-ref-open-citation-at-point () "open bibtex file to key at point" (interactive) @@ -1363,8 +1488,7 @@ you select your option with a single key press." ;; cite ((= choice ?c) - (org-ref-citation-at-point)) - + (org-ref-citation-at-point)) ;; quit ((or @@ -1385,9 +1509,16 @@ you select your option with a single key press." ((= choice ?u) (org-ref-open-url-at-point)) + ;; jmax-bibtex menu + ((= choice ?m) + (save-window-excursion + (set-buffer (find-file-noselect bibfile)) + ;; get to bibtex entry and use menu there + (bibtex-search-entry key) + (jmax-bibtex))) + ;; anything else we just quit. - (t (message ""))))) - + (t (message ""))))) #+END_SRC *** A function to format a cite link @@ -1600,6 +1731,273 @@ org-mode already defines a store link function for bibtex entries. It does not s (car org-stored-links))) #+END_SRC +** Index entries +org-ref minimally supports index entries. To make an index in a file, you should put in the LaTeX header these lines + + +#+LATEX_HEADER: \usepackage{makeidx} +#+LATEX_HEADER: \makeindex + + +Finally, put \makeindex at the end of the document where you want the index to appear. You will need to run the makeindex program at an appropriate point in your LaTeX to pdf, or use ox-manuscript, which will do it for you. + + +Use index links to create entries (see http://en.wikibooks.org/wiki/LaTeX/Indexing). Clicking on an index link runs occur on the buffer for the entry. The link exports to LaTeX. Some links may need to be enclosed in double brackets if they have spaces in them. + + +index:hello +index:hello!Peter +[[index:hello!Sam@\textsl{Sam}]] +[[index:Lin@\textbf{Lin}]] +[[index:Joe|textit]] +[[index:Lin@\textbf{Lin}]] +[[index:Peter|see {hello}]] +[[index:Jen|seealso{Jenny}]] + +index:encodings!input!cp850 + +#+BEGIN_SRC emacs-lisp :tangle org-ref.el +(org-add-link-type + "index" + (lambda (path) + (occur path)) + + (lambda (path desc format) + (cond + ((eq format 'latex) + (format "\\index{%s}" path))))) + +;; this will generate a temporary index of entries in the file. +(org-add-link-type + "printindex" + (lambda (path) + (let ((*index-links* '()) + (*initial-letters* '())) + + ;; get links + (org-element-map (org-element-parse-buffer) 'link + (lambda (link) + (let ((type (nth 0 link)) + (plist (nth 1 link))) + + (when (equal (plist-get plist ':type) "index") + (add-to-list + '*index-links* + (cons (plist-get plist :path) + (format + "[[elisp:(progn (switch-to-buffer \"%s\") (goto-char %s))][%s]]" +(current-buffer) + (plist-get plist :begin) ;; position of link + ;; grab a description + (save-excursion + (goto-char (plist-get plist :begin)) + (if (thing-at-point 'sentence) + ;; get a sentence + (replace-regexp-in-string + "\n" "" (thing-at-point 'sentence)) + ;; or call it a link + "link"))))))))) + + ;; sort the links + (setq *index-links* (cl-sort *index-links* 'string-lessp :key 'car)) + + ;; now first letters + (dolist (link *index-links*) + (add-to-list '*initial-letters* (substring (car link) 0 1) t)) + + ;; now create the index + (switch-to-buffer (get-buffer-create "*index*")) + (org-mode) + (erase-buffer) + (insert "#+TITLE: Index\n\n") + (dolist (letter *initial-letters*) + (insert (format "* %s\n" (upcase letter))) + ;; now process the links + (while (and + ,*index-links* + (string= letter (substring (car (car *index-links*)) 0 1))) + (let ((link (pop *index-links*))) + (insert (format "%s %s\n\n" (car link) (cdr link)))))) + (switch-to-buffer "*index*"))) + ;; formatting + (lambda (path desc format) + (cond + ((eq format 'latex) + (format "\\printindex"))))) +#+END_SRC + +#+RESULTS: +| lambda | (path) | (let ((*index-links* (quote nil)) (*initial-letters* (quote nil))) (org-element-map (org-element-parse-buffer) (quote link) (lambda (link) (let ((type (nth 0 link)) (plist (nth 1 link))) (when (equal (plist-get plist (quote :type)) index) (add-to-list (quote *index-links*) (cons (plist-get plist :path) (format [[elisp:(progn (switch-to-buffer "%s") (goto-char %s))][%s]] (current-buffer) (plist-get plist :begin) (save-excursion (goto-char (plist-get plist :begin)) (if (thing-at-point (quote sentence)) (replace-regexp-in-string \n (thing-at-point (quote sentence))) link))))))))) (setq *index-links* (cl-sort *index-links* (quote string-lessp) :key (quote car))) (dolist (link *index-links*) (add-to-list (quote *initial-letters*) (substring (car link) 0 1) t)) (switch-to-buffer (get-buffer-create *index*)) (org-mode) (erase-buffer) (insert #+TITLE: Index\n\n) (dolist (letter *initial-letters*) (insert (format * %s\n (upcase letter))) (while (and *index-links* (string= letter (substring (car (car *index-links*)) 0 1))) (let ((link (pop *index-links*))) (insert (format %s %s\n\n (car link) (cdr link)))))) (switch-to-buffer *index*)) | +| lambda | (path desc format) | (cond ((eq format (quote latex)) (format \printindex))) | + +** Glossary +org-ref provides some minimal support for a glossary. See http://en.wikibooks.org/wiki/LaTeX/Glossary for details. You need to put these lines in the header. + +#+LATEX_HEADER: \usepackage{glossaries} +#+LATEX_HEADER: \makeglossaries + +And at the end of the document put \makeglossaries. + +#+BEGIN_SRC emacs-lisp :tangle org-ref.el +(org-add-link-type + "newglossaryentry" + nil ;; no follow action + (lambda (path desc format) + (cond + ((eq format 'latex) + (format "\\newglossaryentry{%s}{%s}" path desc))))) + + +;; link to entry +(org-add-link-type + "gls" + nil ;; no follow action + (lambda (path desc format) + (cond + ((eq format 'latex) + (format "\\gls{%s}" path))))) + +;; plural +(org-add-link-type + "glspl" + nil ;; no follow action + (lambda (path desc format) + (cond + ((eq format 'latex) + (format "\\glspl{%s}" path))))) + +;; capitalized link +(org-add-link-type + "Gls" + nil ;; no follow action + (lambda (path desc format) + (cond + ((eq format 'latex) + (format "\\Gls{%s}" path))))) + +;; capitalized link +(org-add-link-type + "Glspl" + nil ;; no follow action + (lambda (path desc format) + (cond + ((eq format 'latex) + (format "\\Glspl{%s}" path))))) +#+END_SRC + +#+RESULTS: +| Glspl | nil | (lambda (path desc format) (cond ((eq format (quote latex)) (format \Glspl{%s} path)))) | +| Gls | nil | (lambda (path desc format) (cond ((eq format (quote latex)) (format \Gls{%s} path)))) | +| glspl | nil | (lambda (path desc format) (cond ((eq format (quote latex)) (format \glspl{%s} path)))) | +| gls | nil | (lambda (path desc format) (cond ((eq format (quote latex)) (format \gls{%s} path)))) | +| newglossaryentry | nil | (lambda (path desc format) (cond ((eq format (quote latex)) (format \newglossaryentry{%s}{%s} path desc)))) | +| google | (lambda (link-string) (browse-url (format http://www.google.com/search?q=%s (url-hexify-string link-string)))) | nil | +| ResearcherID | (lambda (link-string) (browse-url (format http://www.researcherid.com/rid/%s link-string))) | nil | +| orcid | (lambda (link-string) (browse-url (format http://orcid.org/%s link-string))) | nil | +| message | org-mac-message-open | nil | +| mac-outlook | org-mac-outlook-message-open | nil | +| skim | org-mac-skim-open | nil | +| addressbook | org-mac-addressbook-item-open | nil | +| x-together-item | org-mac-together-item-open | nil | +| ans | (lambda (path) (let* ((fields (split-string path ::)) (label (nth 0 fields)) (data (nth 1 fields)) (data-file (format %s-%s.dat tq-userid label))) (let ((temp-file data-file) (temp-buffer (get-buffer-create (generate-new-buffer-name *temp file*)))) (unwind-protect (prog1 (save-current-buffer (set-buffer temp-buffer) (insert data)) (save-current-buffer (set-buffer temp-buffer) (write-region nil nil temp-file nil 0))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))) (mygit (format git add %s data-file)) (mygit (format git commit -m "%s" data-file)) (mygit git push origin master))) | nil | +| mc | (lambda (link) (org-entry-put (point) ANSWER link) (save-restriction (save-excursion (org-narrow-to-subtree) (goto-char (point-max)) (if (bolp) nil (insert \n)) (insert (format # you chose %s link))))) | nil | +| exercise | (lambda (arg) (tq-check-internet) (tq-get-assignment arg)) | nil | +| solution | (lambda (label) (tq-check-internet) (let ((default-directory (file-name-as-directory (expand-file-name tq-root-directory)))) (if (file-exists-p solutions) nil (make-directory solutions)) (let ((default-directory (file-name-as-directory (expand-file-name solutions)))) (if (file-exists-p label) (progn (find-file (concat label / label .org)) (tq-update)) (mygit (format git clone %s@%s:solutions/%s tq-current-course tq-git-server label)) (find-file (concat label / label .org)))))) | nil | +| assignment | (lambda (arg) (tq-check-internet) (tq-get-assignment arg)) | nil | +| doi | doi-link-menu | nil | +| bibentry | org-ref-cite-onclick-minibuffer-menu | org-ref-format-bibentry | +| Autocites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Autocites | +| autocites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-autocites | +| supercites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-supercites | +| Textcites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Textcites | +| textcites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-textcites | +| Smartcites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Smartcites | +| smartcites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-smartcites | +| footcitetexts | org-ref-cite-onclick-minibuffer-menu | org-ref-format-footcitetexts | +| footcites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-footcites | +| Parencites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Parencites | +| parencites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-parencites | +| Cites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Cites | +| cites | org-ref-cite-onclick-minibuffer-menu | org-ref-format-cites | +| fnotecite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-fnotecite | +| Pnotecite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Pnotecite | +| pnotecite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-pnotecite | +| Notecite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Notecite | +| notecite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-notecite | +| footfullcite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-footfullcite | +| fullcite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-fullcite | +| citeurl | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citeurl | +| citedate* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citedate* | +| citedate | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citedate | +| citetitle* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citetitle* | +| citetitle | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citetitle | +| Citeauthor* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Citeauthor* | +| Autocite* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Autocite* | +| autocite* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-autocite* | +| Autocite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Autocite | +| autocite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-autocite | +| supercite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-supercite | +| parencite* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-parencite* | +| cite* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-cite* | +| Smartcite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Smartcite | +| smartcite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-smartcite | +| Textcite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Textcite | +| textcite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-textcite | +| footcitetext | org-ref-cite-onclick-minibuffer-menu | org-ref-format-footcitetext | +| footcite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-footcite | +| Parencite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Parencite | +| parencite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-parencite | +| Cite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Cite | +| Citeauthor | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Citeauthor | +| Citealp | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Citealp | +| Citealt | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Citealt | +| Citep | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Citep | +| Citet | org-ref-cite-onclick-minibuffer-menu | org-ref-format-Citet | +| citeyear* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citeyear* | +| citeyear | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citeyear | +| citeauthor* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citeauthor* | +| citeauthor | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citeauthor | +| citetext | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citetext | +| citenum | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citenum | +| citealp* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citealp* | +| citealp | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citealp | +| citealt* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citealt* | +| citealt | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citealt | +| citep* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citep* | +| citep | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citep | +| citet* | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citet* | +| citet | org-ref-cite-onclick-minibuffer-menu | org-ref-format-citet | +| nocite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-nocite | +| cite | org-ref-cite-onclick-minibuffer-menu | org-ref-format-cite | +| eqref | (lambda (label) on clicking goto the label. Navigate back with C-c & (org-mark-ring-push) (widen) (goto-char (point-min)) (if (or (re-search-forward (format label:%s label) nil t) (re-search-forward (format \label{%s} label) nil t) (re-search-forward (format ^#\+label:\s-*\(%s\)\b label) nil t)) nil (org-mark-ring-goto) (error %s not found label)) (message go back with (org-mark-ring-goto) `C-c &`)) | (lambda (keyword desc format) (cond ((eq format (quote html)) (format (%s) path)) ((eq format (quote latex)) (format \eqref{%s} keyword)))) | +| nameref | (lambda (label) on clicking goto the label. Navigate back with C-c & (org-mark-ring-push) (widen) (if (or (progn (goto-char (point-min)) (re-search-forward (format \label{%s} label) nil t))) nil (org-mark-ring-goto) (error %s not found label)) (message go back with (org-mark-ring-goto) `C-c &`)) | (lambda (keyword desc format) (cond ((eq format (quote html)) (format (%s) path)) ((eq format (quote latex)) (format \nameref{%s} keyword)))) | +| pageref | (lambda (label) on clicking goto the label. Navigate back with C-c & (org-mark-ring-push) (widen) (if (or (progn (goto-char (point-min)) (re-search-forward (format label:%s\b label) nil t)) (progn (goto-char (point-min)) (re-search-forward (format \label{%s} label) nil t)) (progn (goto-char (point-min)) (re-search-forward (format ^#\+label:\s-*\(%s\)\b label) nil t)) (progn (goto-char (point-min)) (re-search-forward (format ^#\+tblname:\s-*\(%s\)\b label) nil t))) nil (org-mark-ring-goto) (error %s not found label)) (message go back with (org-mark-ring-goto) `C-c &`)) | (lambda (keyword desc format) (cond ((eq format (quote html)) (format (%s) path)) ((eq format (quote latex)) (format \pageref{%s} keyword)))) | +| ref | (lambda (label) on clicking goto the label. Navigate back with C-c & (org-mark-ring-push) (widen) (if (or (progn (goto-char (point-min)) (re-search-forward (format label:%s\b label) nil t)) (progn (goto-char (point-min)) (re-search-forward (format \label{%s} label) nil t)) (progn (goto-char (point-min)) (re-search-forward (format ^#\+label:\s-*\(%s\)\b label) nil t)) (progn (goto-char (point-min)) (re-search-forward (format ^#\+tblname:\s-*\(%s\)\b label) nil t))) nil (org-mark-ring-goto) (error %s not found label)) (org-show-entry) (message go back with (org-mark-ring-goto) `C-c &`)) | (lambda (keyword desc format) (cond ((eq format (quote html)) (format (%s) path)) ((eq format (quote latex)) (format \ref{%s} keyword)))) | +| label | (lambda (label) on clicking count the number of label tags used in the buffer. A number greater than one means multiple labels! (message (format %s occurences (+ (count-matches (format label:%s\b[^-:] label) (point-min) (point-max) t) (count-matches (format ^#\+tblname:\s-*%s\b[^-:] label) (point-min) (point-max) t) (count-matches (format \label{%s}\b label) (point-min) (point-max) t) (count-matches (format ^#\+label:\s-*%s\b[^-:] label) (point-min) (point-max) t))))) | (lambda (keyword desc format) (cond ((eq format (quote html)) (format () path)) ((eq format (quote latex)) (format \label{%s} keyword)))) | +| list-of-tables | org-ref-list-of-tables | (lambda (keyword desc format) (cond ((eq format (quote latex)) (format \listoftables)))) | +| list-of-figures | org-ref-list-of-figures | (lambda (keyword desc format) (cond ((eq format (quote latex)) (format \listoffigures)))) | +| addbibresource | (lambda (link-string) (let* ((bibfile) (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))) (set (make-local-variable (quote reftex-default-addbibresource)) (split-string (org-element-property :path object) ,)) (save-excursion (if (search-forward , link-string-end 1 1) (setq key-end (- (match-end 0) 1)) (setq key-end (point)))) (save-excursion (if (search-backward , link-string-beginning 1 1) (setq key-beginning (+ (match-beginning 0) 1)) (setq key-beginning (point)))) (setq bibfile (org-ref-strip-string (buffer-substring key-beginning key-end))) (find-file bibfile))) | (lambda (keyword desc format) (cond ((eq format (quote html)) (format )) ((eq format (quote latex)) (format \addbibresource{%s} keyword)))) | +| bibliographystyle | (lambda (arg) (message Nothing implemented for clicking here.)) | (lambda (keyword desc format) (cond ((eq format (quote latex)) (format \bibliographystyle{%s} keyword)))) | +| printbibliography | (lambda (arg) (message Nothing implemented for clicking here.)) | (lambda (keyword desc format) (cond ((eq format (quote org)) (org-ref-get-org-bibliography)) ((eq format (quote html)) (org-ref-get-html-bibliography)) ((eq format (quote latex)) \printbibliography))) | +| nobibliography | (lambda (link-string) (let* ((bibfile) (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))) (set (make-local-variable (quote reftex-default-bibliography)) (split-string (org-element-property :path object) ,)) (save-excursion (if (search-forward , link-string-end 1 1) (setq key-end (- (match-end 0) 1)) (setq key-end (point)))) (save-excursion (if (search-backward , link-string-beginning 1 1) (setq key-beginning (+ (match-beginning 0) 1)) (setq key-beginning (point)))) (setq bibfile (org-ref-strip-string (buffer-substring key-beginning key-end))) (find-file bibfile))) | (lambda (keyword desc format) (cond ((eq format (quote org)) (org-ref-get-org-bibliography)) ((eq format (quote ascii)) (org-ref-get-ascii-bibliography)) ((eq format (quote html)) (org-ref-get-html-bibliography)) ((eq format (quote latex)) (format \nobibliography{%s} (replace-regexp-in-string \.bib (mapconcat (quote identity) (mapcar (quote expand-file-name) (split-string keyword ,)) ,)))))) | +| bibliography | (lambda (link-string) (let* ((bibfile) (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))) (set (make-local-variable (quote reftex-default-bibliography)) (split-string (org-element-property :path object) ,)) (save-excursion (if (search-forward , link-string-end 1 1) (setq key-end (- (match-end 0) 1)) (setq key-end (point)))) (save-excursion (if (search-backward , link-string-beginning 1 1) (setq key-beginning (+ (match-beginning 0) 1)) (setq key-beginning (point)))) (setq bibfile (org-ref-strip-string (buffer-substring key-beginning key-end))) (find-file bibfile))) | (lambda (keyword desc format) (cond ((eq format (quote org)) (org-ref-get-org-bibliography)) ((eq format (quote ascii)) (org-ref-get-ascii-bibliography)) ((eq format (quote html)) (org-ref-get-html-bibliography)) ((eq format (quote latex)) (format \bibliography{%s} (replace-regexp-in-string \.bib (mapconcat (quote identity) (mapcar (quote expand-file-name) (split-string keyword ,)) ,)))))) | +| rmail | org-rmail-open | nil | +| mhe | org-mhe-open | nil | +| irc | org-irc-visit | nil | +| info | org-info-open | nil | +| gnus | org-gnus-open | nil | +| docview | org-docview-open | org-docview-export | +| bibtex | org-bibtex-open | nil | +| bbdb | org-bbdb-open | org-bbdb-export | +| pydoc | (lambda (link-string) (shell-command (format python -m pydoc %s link-string))) | nil | +| index | (lambda (path) (tq-index) (occur path)) | nil | +| attachfile | (lambda (link-string) (org-open-file link-string)) | (lambda (keyword desc format) (cond ((eq format (quote html)) (format )) ((eq format (quote latex)) (format \attachfile{%s} keyword)))) | +| msx | org-msx-open | nil | +| id | org-id-open | nil | +| file+emacs | org-open-file-with-emacs | nil | +| file+sys | org-open-file-with-system | nil | + + * Utilities ** create simple text citation from bibtex entry @@ -1716,15 +2114,13 @@ 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. (if (re-search-forward (format ":Custom_ID: %s$" key) nil 'end) - (progn - (show-subtree) - (outline-previous-visible-heading 1)) + (funcall org-ref-open-notes-function) ;; no entry found, so add one (insert (format "\n** TODO %s - %s" year title)) (insert (format" @@ -1743,6 +2139,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]]. @@ -2201,7 +2616,7 @@ Sometimes it may be helpful to manually change the order of citations. These fun (org-ref-swap-keys i (- i 1) keys)) (setq keys (mapconcat 'identity keys ",")) ;; and replace the link with the sorted keys - (cl--set-buffer-substring begin end (concat type ":" keys)) + (cl--set-buffer-substring begin end (concat type ":" keys " ")) ;; now go forward to key so we can move with the key (re-search-forward key) (goto-char (match-beginning 0))))) @@ -2219,6 +2634,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) @@ -2232,11 +2648,13 @@ I like convenience. Here are some aliases for faster typing. (provide 'org-ref) #+END_SRC - * Build :noexport: +This code will tangle the elisp code out to org-ref.el and load it. [[elisp:(progn (org-babel-tangle) (load-file "org-ref.el"))]] +Alternatively you may use: + [[elisp:(org-babel-load-file "org-ref.org")]]