forked from mirrors/org-mode
oc-biblatex: Allow style customization
* lisp/oc-biblatex.el (org-cite-biblatex-styles): (org-cite-biblatex-style-shortcuts): New defcustoms. (org-cite-biblatex--expand-shortcuts): New function. (org-cite-biblatex-export-citation): Extract adequate style from defcustoms above instead of hard-coding all styles.
This commit is contained in:
parent
82bb04be22
commit
e995e069ca
|
@ -97,6 +97,12 @@ argument.
|
||||||
|
|
||||||
** Miscellaneous
|
** Miscellaneous
|
||||||
|
|
||||||
|
*** Styles are customizable in ~biblatex~ citation processor
|
||||||
|
|
||||||
|
It is now possible to add new styles or modify old ones in ~biblatex~
|
||||||
|
citation processor. See ~org-cite-biblatex-styles~ for more
|
||||||
|
information.
|
||||||
|
|
||||||
*** Citation processors can declare styles dynamically
|
*** Citation processors can declare styles dynamically
|
||||||
|
|
||||||
When a citation processor is registered, it is now possible to set
|
When a citation processor is registered, it is now possible to set
|
||||||
|
|
|
@ -81,6 +81,99 @@ If \"biblatex\" package is already required in the document, e.g., through
|
||||||
(const :tag "No option" nil))
|
(const :tag "No option" nil))
|
||||||
:safe #'string-or-null-p)
|
:safe #'string-or-null-p)
|
||||||
|
|
||||||
|
(defcustom org-cite-biblatex-styles
|
||||||
|
'(("author" "caps" "Citeauthor*" nil nil)
|
||||||
|
("author" "full" "citeauthor" nil nil)
|
||||||
|
("author" "caps-full" "Citeauthor" nil nil)
|
||||||
|
("author" nil "citeauthor*" nil nil)
|
||||||
|
("locators" "bare" "notecite" nil nil)
|
||||||
|
("locators" "caps" "Pnotecite" nil nil)
|
||||||
|
("locators" "bare-caps" "Notecite" nil nil)
|
||||||
|
("locators" nil "pnotecite" nil nil)
|
||||||
|
("noauthor" "bare" "cite*" nil nil)
|
||||||
|
("noauthor" nil "autocite*" nil nil)
|
||||||
|
("nocite" nil "nocite" nil t)
|
||||||
|
("text" "caps" "Textcite" "Textcites" nil)
|
||||||
|
("text" nil "textcite" "textcites" nil)
|
||||||
|
(nil "bare" "cite" "cites" nil)
|
||||||
|
(nil "caps" "Autocite" "Autocites" nil)
|
||||||
|
(nil "bare-caps" "Cite" "Cites" nil)
|
||||||
|
(nil nil "autocite" "autocites" nil))
|
||||||
|
"List of styles and variants, with associated BibLaTeX commands.
|
||||||
|
|
||||||
|
Each style follows the pattern
|
||||||
|
|
||||||
|
(NAME VARIANT COMMAND MULTI-COMMAND NO-OPTION)
|
||||||
|
|
||||||
|
where:
|
||||||
|
|
||||||
|
NAME is the name of the style, as a string, or nil. The nil
|
||||||
|
style is the default style. As such, it must have an entry in
|
||||||
|
the list.
|
||||||
|
|
||||||
|
VARIANT is the name of the style variant, as a string or nil.
|
||||||
|
The nil variant is the default variant for the current style.
|
||||||
|
As such, each style name must be associated to a nil variant.
|
||||||
|
|
||||||
|
COMMAND is the LaTeX command to use, as a string. It should
|
||||||
|
not contain the leading backslash character.
|
||||||
|
|
||||||
|
MULTI-COMMAND is the LaTeX command to use when a multi-cite
|
||||||
|
command is appropriate. When nil, the style is deemed
|
||||||
|
inappropriate for multi-cites. The command should not contain
|
||||||
|
the leading backslash character.
|
||||||
|
|
||||||
|
NO-OPTION is a boolean. When non-nil, no optional argument
|
||||||
|
should be added to the LaTeX command.
|
||||||
|
|
||||||
|
Each NAME-VARIANT pair should be unique in the list.
|
||||||
|
|
||||||
|
It is also possible to provide shortcuts for style and variant
|
||||||
|
names. See `org-cite-biblatex-style-shortcuts'."
|
||||||
|
:group 'org-cite
|
||||||
|
:package-version '(Org . "9.6")
|
||||||
|
:type '(repeat
|
||||||
|
(list :tag "Style/variant combination"
|
||||||
|
;; Name part.
|
||||||
|
(choice :tag "Style"
|
||||||
|
(string :tag "Name")
|
||||||
|
(const :tag "Default style" nil))
|
||||||
|
;; Variant part.
|
||||||
|
(choice :tag "Variant"
|
||||||
|
(string :tag "Name")
|
||||||
|
(const :tag "Default variant" nil))
|
||||||
|
;; Command part.
|
||||||
|
(string :tag "Command name")
|
||||||
|
(choice :tag "Multicite command"
|
||||||
|
(string :tag "Command name")
|
||||||
|
(const :tag "No multicite support" nil))
|
||||||
|
(choice :tag "Skip optional arguments"
|
||||||
|
(const :tag "Yes" t)
|
||||||
|
(const :tag "No" nil)))))
|
||||||
|
|
||||||
|
(defcustom org-cite-biblatex-style-shortcuts
|
||||||
|
'(("a" . "author")
|
||||||
|
("b" . "bare")
|
||||||
|
("c" . "caps")
|
||||||
|
("cf" . "caps-full")
|
||||||
|
("f" . "full")
|
||||||
|
("l" . "locators")
|
||||||
|
("n" . "nocite")
|
||||||
|
("na" . "noauthor")
|
||||||
|
("t" . "text"))
|
||||||
|
"List of shortcuts associated to style or variant names.
|
||||||
|
|
||||||
|
Each entry is a pair (NAME . STYLE-NAME) where NAME is the name
|
||||||
|
of the shortcut, as a string, and STYLE-NAME is the name of
|
||||||
|
a style in `org-cite-biblatex-styles'."
|
||||||
|
:group 'org-cite
|
||||||
|
:package-version '(Org . "9.6")
|
||||||
|
:type '(repeat
|
||||||
|
(cons :tag "Shortcut"
|
||||||
|
(string :tag "Name")
|
||||||
|
(string :tag "Full name")))
|
||||||
|
:safe t)
|
||||||
|
|
||||||
|
|
||||||
;;; Internal functions
|
;;; Internal functions
|
||||||
(defun org-cite-biblatex--package-options (initial style)
|
(defun org-cite-biblatex--package-options (initial style)
|
||||||
|
@ -185,6 +278,18 @@ non-nil, do not add optional arguments to the command."
|
||||||
(org-cite-biblatex--atomic-arguments
|
(org-cite-biblatex--atomic-arguments
|
||||||
(org-cite-get-references citation) info no-opt))))
|
(org-cite-get-references citation) info no-opt))))
|
||||||
|
|
||||||
|
(defun org-cite-biblatex--expand-shortcuts (style)
|
||||||
|
"Return STYLE pair with shortcuts expanded."
|
||||||
|
(pcase style
|
||||||
|
(`(,style . ,variant)
|
||||||
|
(cons (or (alist-get style org-cite-biblatex-style-shortcuts
|
||||||
|
nil nil #'equal)
|
||||||
|
style)
|
||||||
|
(or (alist-get variant org-cite-biblatex-style-shortcuts
|
||||||
|
nil nil #'equal)
|
||||||
|
variant)))
|
||||||
|
(_ (error "This should not happen"))))
|
||||||
|
|
||||||
|
|
||||||
;;; Export capability
|
;;; Export capability
|
||||||
(defun org-cite-biblatex-export-bibliography (_keys _files _style props &rest _)
|
(defun org-cite-biblatex-export-bibliography (_keys _files _style props &rest _)
|
||||||
|
@ -214,44 +319,42 @@ PROPS is the local properties of the bibliography, as a property list."
|
||||||
"Export CITATION object.
|
"Export CITATION object.
|
||||||
STYLE is the citation style, as a pair of either strings or nil.
|
STYLE is the citation style, as a pair of either strings or nil.
|
||||||
INFO is the export state, as a property list."
|
INFO is the export state, as a property list."
|
||||||
(apply
|
(pcase-let* ((`(,name . ,variant) (org-cite-biblatex--expand-shortcuts style))
|
||||||
#'org-cite-biblatex--command citation info
|
(candidates nil)
|
||||||
(pcase style
|
(style-match-flag nil))
|
||||||
;; "author" style.
|
(catch :match
|
||||||
(`(,(or "author" "a") . ,variant)
|
;; Walk `org-cite-biblatex-styles' and prioritize matching
|
||||||
(pcase variant
|
;; candidates. At the end of the process, the optimal candidate
|
||||||
((or "caps" "c") '("Citeauthor*"))
|
;; should appear in front of CANDIDATES.
|
||||||
((or "full" "f") '("citeauthor"))
|
(dolist (style org-cite-biblatex-styles)
|
||||||
((or "caps-full" "cf") '("Citeauthor"))
|
(pcase style
|
||||||
(_ '("citeauthor*"))))
|
;; A matching style-variant pair trumps anything else.
|
||||||
;; "locators" style.
|
;; Return it.
|
||||||
(`(,(or "locators" "l") . ,variant)
|
(`(,(pred (equal name)) ,(pred (equal variant)) . ,_)
|
||||||
(pcase variant
|
(throw :match (setq candidates (list style))))
|
||||||
((or "bare" "b") '("notecite"))
|
;; nil-nil style-variant is the fallback value. Consider it
|
||||||
((or "caps" "c") '("Pnotecite"))
|
;; only if nothing else matches.
|
||||||
((or "bare-caps" "bc") '("Notecite"))
|
(`(nil nil . ,_)
|
||||||
(_ '("pnotecite"))))
|
(unless candidates (push style candidates)))
|
||||||
;; "noauthor" style.
|
;; A matching style with default variant trumps a matching
|
||||||
(`(,(or "noauthor" "na") . ,variant)
|
;; variant without the adequate style. Ensure the former
|
||||||
(pcase variant
|
;; appears first in the list.
|
||||||
((or "bare" "b") '("cite*"))
|
(`(,(pred (equal name)) nil . ,_)
|
||||||
(_ '("autocite*"))))
|
(push style candidates)
|
||||||
;; "nocite" style.
|
(setq style-match-flag t))
|
||||||
(`(,(or "nocite" "n") . ,_) '("nocite" nil t))
|
(`(nil ,(pred (equal variant)) . ,_)
|
||||||
;; "text" style.
|
(unless style-match-flag (push style candidates)))
|
||||||
(`(,(or "text" "t") . ,variant)
|
;; Discard anything else.
|
||||||
(pcase variant
|
(_ nil))))
|
||||||
((or "caps" "c") '("Textcite" "Textcites"))
|
(apply
|
||||||
(_ '("textcite" "textcites"))))
|
#'org-cite-biblatex--command citation info
|
||||||
;; Default "nil" style.
|
(pcase (seq-first candidates)
|
||||||
(`(,_ . ,variant)
|
(`(,_ ,_ . ,command-parameters) command-parameters)
|
||||||
(pcase variant
|
('nil
|
||||||
((or "bare" "b") '("cite" "cites"))
|
(user-error
|
||||||
((or "caps" "c") '("Autocite" "Autocites"))
|
"Missing default style or variant in `org-cite-biblatex-styles'"))
|
||||||
((or "bare-caps" "bc") '("Cite" "Cites"))
|
(other
|
||||||
(_ '("autocite" "autocites"))))
|
(user-error "Invalid entry %S in `org-cite-biblatex-styles'" other))))))
|
||||||
;; This should not happen.
|
|
||||||
(_ (error "Invalid style: %S" style)))))
|
|
||||||
|
|
||||||
(defun org-cite-biblatex-prepare-preamble (output _keys files style &rest _)
|
(defun org-cite-biblatex-prepare-preamble (output _keys files style &rest _)
|
||||||
"Prepare document preamble for \"biblatex\" usage.
|
"Prepare document preamble for \"biblatex\" usage.
|
||||||
|
|
Loading…
Reference in a new issue