Skip to content

Instantly share code, notes, and snippets.

@bdarcus
Last active June 28, 2022 12:14
Show Gist options
  • Save bdarcus/929d4d71dedd41388385bd07098e83fe to your computer and use it in GitHub Desktop.
Save bdarcus/929d4d71dedd41388385bd07098e83fe to your computer and use it in GitHub Desktop.
(require 'oc-biblatex)
(defcustom style-select-latex-commands t
"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)
(pcase-let* ((`(,style ,variant ,command ,_multi) s)
(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