(setq org-ref-ref-re
- "ref:\\([a-zA-Z0-9-_:]*,?\\)*")
+ "\\(eq\\)?ref:\\([a-zA-Z0-9-_:]*,?\\)*")
(defface org-ref-cite-face
;; write out the latex bibliography command
(format "\\bibliographystyle{%s}" keyword)))))
+
+(defun org-bibliographystyle-complete-link (&optional arg)
+ "Completion function for bibliographystyle link.
+ARG does nothing."
+ (format "bibliographystyle:%s" (ido-completing-read
+ "style: "
+ '("unsrt" "plain" "alpha"
+ ;; natbib
+ ;; https://www.sharelatex.com/learn/Natbib_bibliography_styles
+ "dinat" "humannat" "plainnat"
+ "abbrnat" "unsrtnat" "rusnat"
+ "ksfhnat"))))
+
+
(defun org-bibliography-complete-link (&optional arg)
"Completion function for bibliography link.
ARG does nothing."
(format "bibliography:%s" (read-file-name "enter file: " nil nil t)))
+
(defun org-ref-insert-bibliography-link ()
"Insert a bibliography with completion."
(interactive)
((eq format 'latex)
(format "\\listoftables")))))
+
+;; ** label link
(defun org-ref-count-labels (label)
"Counts number of matches for LABEL in the document."
(+ (count-matches (format "label:%s\\b[^-:]" label) (point-min) (point-max))
(setq custom-id-count (+ 1 custom-id-count)))))
custom-id-count)))
-;; ** label link
(org-add-link-type
"label"
(lambda (label)
:type "ref"
:link (concat "ref:" (org-element-property :name object))))
-;; it turns out this does not work. you can already store a link to a heading with a CUSTOM_ID
;; store link on heading with custom_id
-; (when (and (equal (org-element-type object) 'headline)
-; (org-entry-get (point) "CUSTOM_ID"))
-; (org-store-link-props
-; :type "ref"
-; :link (concat "ref:" (org-entry-get (point) "CUSTOM_ID"))))
+ ;; this is not a ref link, but it is still what you want
+ (when (and (equal (org-element-type object) 'headline)
+ (org-entry-get (point) "CUSTOM_ID"))
+ (org-store-link-props
+ :type "custom_id"
+ :link (format "[[#%s]]" (org-entry-get (point) "CUSTOM_ID"))))
;; and to #+label: lines
(when (and (equal (org-element-type object) 'paragraph)
(org-element-property :name object))
(org-store-link-props
:type "ref"
- :link (concat "ref:" (org-element-property :name object))))
-))
+ :link (concat "ref:" (org-element-property :name object))))))
(add-hook 'org-store-link-functions 'org-label-store-link)
choice
2))))))
-;; ** Generation of the cite links
+;; *** Generation of the cite links
(defmacro org-ref-make-completion-function (type)
"Macro to make a link completion function for a link of TYPE."
`(defun ,(intern (format "org-%s-complete-link" type)) (&optional arg)
(org-ref-open-citation-at-point)
(email-bibtex-entry)) nil)))
+;; * org-ref-help
+(defun org-ref-help ()
+ "Open the org-ref manual."
+ (interactive)
+ (find-file (expand-file-name
+ "org-ref.org"
+ (file-name-directory
+ (find-library-name "org-ref")))))
+
+;; * org-ref menu
+(defun org-ref-org-menu ()
+ "Add org-ref menu to the Org menu."
+
+ (easy-menu-change
+ '("Org") "org-ref"
+ '( ["Insert citation" org-ref-helm-insert-cite-link]
+ ["Insert ref" org-ref-helm-insert-ref-link]
+ ["Insert label" org-ref-helm-insert-label-link]
+ "--"
+ ["List of figures" org-ref-list-of-figures]
+ ["List of tables" org-ref-list-of-tables]
+ ["Extract bibtex entries" org-ref-extract-bibtex-entries]
+ ["Check org-file" org-ref]
+ "--"
+ ["Help" org-ref-help]
+ ["Customize org-ref" (customize-group 'org-ref)])
+ "Show/Hide")
+
+ (easy-menu-change '("Org") "--" nil "Show/Hide"))
+
+(add-hook 'org-mode-hook 'org-ref-org-menu)
+
;; * The end
(provide 'org-ref)