Skip to content

Instantly share code, notes, and snippets.

@bdarcus
Last active April 20, 2022 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdarcus/996fd6271e149c9c457e37d5f0a7e885 to your computer and use it in GitHub Desktop.
Save bdarcus/996fd6271e149c9c457e37d5f0a7e885 to your computer and use it in GitHub Desktop.
experiment with an org-cite style select UI that optionally presents biblatex commands for completion instead
;; (org-cite-parse-objects "[cite:@doe]")
(require 'oc-biblatex)
(defcustom style-ui 'csl
"Style select UI; each with a preview."
:type '(choice (const :tag "CSL output" 'csl)
(const :tag "biblatex commands" 'biblatex)
(const :tag "natbib commands" 'natbib)))
(defcustom style-select-latex-commands nil
"Whether to use latex commands for style selection."
:group 'style
:type '(boolean))
(defun style-latex-alist (&optional swap)
"Return org-cite-biblatex-styles as alist.
By default, each car is the latex command, and the cdr the
org-cite style with variant. With SWAP, they are reversed."
(let ((raw-styles org-cite-biblatex-styles))
(mapcar
(lambda (s)
(let* ((style (elt s 0))
(variant (elt s 1))
(command (elt s 2))
(cstyle (concat style (when variant "/") variant)))
(if swap
(cons cstyle command)
(cons command cstyle))))
raw-styles)))
(defun style-select ()
"Select oc style."
(let* ((latex-commands style-select-latex-commands)
(styles
(if latex-commands (style-latex-alist)
(style-latex-alist t)))
(choice
(completing-read
(if latex-commands "Biblatex command: "
"Style: ") styles)))
(cdr
(if style-select-latex-commands (assoc choice (style-latex-alist))
(rassoc choice (style-latex-alist))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment