Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in support for a "related papers" section #272

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions doc/orb-manual.org
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,23 @@ formatted as in =:org-format=.
The =orb-section-file= section shows a link to the PDF or similar file
for a node.

** =orb-section-related=
:PROPERTIES:
:CUSTOM_ID: orb-section-related
:END:

The =orb-section-related= section shows formatted references for
papers related to the current node.

*** =orb-section-related-heuristic=
:PROPERTIES:
:CUSTOM_ID: orb-section-related-heuristic
:END:

This variable allows configuring how related papers will be selected.
It should be a function that takes in a BibTeX key, and returns a list
of related BibTeX keys. Default behavior is to match on surnames.

* Orb Anystyle - Emacs interfeace to Anystyle-CLI
:PROPERTIES:
:CUSTOM_ID: orb-anystyle
Expand Down
51 changes: 45 additions & 6 deletions orb-section.el
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,17 @@ an alist from type to format string. For formatting information,
see `bibtex-completion-display-formats'."
:type '(choice (const :tag "Use BibTeX-Completion APA Format"
'bibtex-completion-apa-format-reference)
(symbol :tag "Use a function")
(alist :key-type (choice (string :tag "Type Name :")
(const :tag "Default" t))
:value-type (string :tag "Format String:"))))
(symbol :tag "Use a function")
(alist :key-type (choice (string :tag "Type Name :")
(const :tag "Default" t))
:value-type (string :tag "Format String:"))))

(defcustom orb-section-related-heuristic
#'orb-section-related-for-key
"How related paper candidates should be collected.
This should be a function that takes a BibTeX key and returns a
list of BibTeX keys."
:type 'function)

(defcustom orb-section-abstract-format-method :org-format
"How to format ORB abstract.
Expand All @@ -76,8 +83,8 @@ A function taking a key and returning a string, or one of:
- `:pandoc-from-tex' Assume that the content is tex/latex
formatted and use `pandoc' to format accordingly."
:type '(choice (const :tag "Format as Org Text" :org-format)
(const :tag "Format from LaTeX" :pandoc-from-tex)
(symbol :tag "Use function.")))
(const :tag "Format from LaTeX" :pandoc-from-tex)
(symbol :tag "Use function.")))


;; ============================================================================
Expand All @@ -94,6 +101,27 @@ A function taking a key and returning a string, or one of:
(formatted-reference (s-format format-string 'bibtex-completion-apa-get-value entry)))
(replace-regexp-in-string "\\([.?!]\\)\\." "\\1" formatted-reference))))

(defun orb-section--get-authors (author-string)
"Parse an AUTHOR-STRING into a list of names."
(if (null author-string)
nil
(split-string (replace-regexp-in-string "[{}]" "" author-string) " and ")))

(defun orb-section-related-for-key (key)
"Default related-paper selection heuristic for KEY.

Uses the authors last names to find possibly related papers."
(when-let ((entry (bibtex-completion-get-entry key))
(author-surnames (orb-section--get-authors (cdr (assoc "author" entry))))
(authors-regexp (regexp-opt (mapcar (lambda (name) (car (split-string name ", ")))
author-surnames)
'words)))
(mapcar #'cdr (mapcar (apply-partially #'assoc "=key=")
(mapcar #'cdr
(cl-remove-if-not (lambda (entry)
(string-match authors-regexp (car entry)))
(bibtex-completion-candidates)))))))

(defun orb-section-unfill-region (beg end)
"Unfill the region from BEG to END.
Joining text paragraphs into a single logical line.
Expand Down Expand Up @@ -142,6 +170,17 @@ Taken from https://www.emacswiki.org/emacs/UnfillRegion"
(insert formatted-reference)
(insert "\n\n"))))

;;;###autoload
(defun orb-section-related (node)
"Show related BibTeX entries for NODE."
(when-let ((cite-key (orb-get-node-citekey node))
(entry-keys (funcall orb-section-related-heuristic cite-key)))
(magit-insert-section (orb-section-related)
(magit-insert-heading "Related:")
(dolist (key entry-keys)
(insert (orb-section-reference-format key) "\n"))
(insert "\n"))))

;;;###autoload
(defun orb-section-abstract (node)
"Show BibTeX entry abstract for NODE if it exists."
Expand Down