oc-csl.el: Add support for nocite citations

* lisp/oc-csl.el (org-cite-csl--rendered-citations): Collect nocite
style citations in a separate list as required by the citeproc-el
API. Set the output of all nocite citations to the empty string.
(org-cite-csl--nocite-p): New helper predicate for checking whether a
citation is a nocite.
This commit is contained in:
András Simonyi 2022-07-01 10:24:17 +02:00 committed by Ihor Radchenko
parent 0495961f36
commit b3b17cdb66
No known key found for this signature in database
GPG key ID: 6470762A7DA11D8B
2 changed files with 49 additions and 15 deletions

View file

@ -239,7 +239,18 @@ This behaviour can be changed by supplying a =:align= parameter.
The tabbing environment can be useful when generating simple tables which The tabbing environment can be useful when generating simple tables which
can be span multiple pages and when table cells are allowed to overflow. can be span multiple pages and when table cells are allowed to overflow.
*** Support for =nocite= citations in the "csl" export processor
The "csl" citation export processor now supports =nocite= style
citations that add items to the printed bibliography without visible
references in the text. Using the key =*= in a nocite citation, for
instance,
#+begin_src org
[cite/n:@*]
#+end_src
includes all available items in the printed bibliography.
** New functions and changes in function arguments ** New functions and changes in function arguments
*** New function ~org-element-cache-map~ for quick mapping across Org elements *** New function ~org-element-cache-map~ for quick mapping across Org elements

View file

@ -59,9 +59,13 @@
;; - author (a), including bare (b), caps (c), bare-caps (bc), full (f), ;; - author (a), including bare (b), caps (c), bare-caps (bc), full (f),
;; caps-full (cf), and bare-caps-full (bcf) variants, ;; caps-full (cf), and bare-caps-full (bcf) variants,
;; - noauthor (na), including bare (b), caps (c) and bare-caps (bc) variants, ;; - noauthor (na), including bare (b), caps (c) and bare-caps (bc) variants,
;; - nocite (n),
;; - year (y), including a bare (b) variant, ;; - year (y), including a bare (b) variant,
;; - text (t). including caps (c), full (f), and caps-full (cf) variants, ;; - text (t). including caps (c), full (f), and caps-full (cf) variants,
;; - default style, including bare (b), caps (c) and bare-caps (bc) variants. ;; - default style, including bare (b), caps (c) and bare-caps (bc) variants.
;;
;; Using "*" as a key in a nocite citation includes all available items in
;; the printed bibliography.
;; CSL styles recognize "locator" in citation references' suffix. For example, ;; CSL styles recognize "locator" in citation references' suffix. For example,
;; in the citation ;; in the citation
@ -103,6 +107,7 @@
(declare-function citeproc-create "ext:citeproc") (declare-function citeproc-create "ext:citeproc")
(declare-function citeproc-citation-create "ext:citeproc") (declare-function citeproc-citation-create "ext:citeproc")
(declare-function citeproc-append-citations "ext:citeproc") (declare-function citeproc-append-citations "ext:citeproc")
(declare-function citeproc-add-uncited "ext:citeproc")
(declare-function citeproc-render-citations "ext:citeproc") (declare-function citeproc-render-citations "ext:citeproc")
(declare-function citeproc-render-bib "ext:citeproc") (declare-function citeproc-render-bib "ext:citeproc")
(declare-function citeproc-hash-itemgetter-from-any "ext:citeproc") (declare-function citeproc-hash-itemgetter-from-any "ext:citeproc")
@ -296,6 +301,12 @@ INFO is the export state, as a property list."
(citeproc-proc-style (citeproc-proc-style
(org-cite-csl--processor info)))) (org-cite-csl--processor info))))
(defun org-cite-csl--nocite-p (citation info)
"Non-nil when CITATION object's style is nocite.
INFO is the export state, as a property list."
(member (car (org-cite-citation-style citation info))
'("nocite" "n")))
(defun org-cite-csl--create-structure-params (citation info) (defun org-cite-csl--create-structure-params (citation info)
"Return citeproc structure creation params for CITATION object. "Return citeproc structure creation params for CITATION object.
STYLE is the citation style, as a string or nil. INFO is the export state, as STYLE is the citation style, as a string or nil. INFO is the export state, as
@ -535,20 +546,31 @@ INFO is the export state, as a property list.
Return an alist (CITATION . OUTPUT) where CITATION object has been rendered as Return an alist (CITATION . OUTPUT) where CITATION object has been rendered as
OUTPUT using Citeproc." OUTPUT using Citeproc."
(or (plist-get info :cite-citeproc-rendered-citations) (or (plist-get info :cite-citeproc-rendered-citations)
(let* ((citations (org-cite-list-citations info)) (let ((citations (org-cite-list-citations info))
(processor (org-cite-csl--processor info)) (processor (org-cite-csl--processor info))
(structures normal-citations nocite-ids)
(mapcar (lambda (c) (org-cite-csl--create-structure c info)) (dolist (citation citations)
citations))) (if (org-cite-csl--nocite-p citation info)
(citeproc-append-citations structures processor) (setq nocite-ids (append (org-cite-get-references citation t) nocite-ids))
(let* ((rendered (push citation normal-citations)))
(citeproc-render-citations (let ((structures
processor (mapcar (lambda (c) (org-cite-csl--create-structure c info))
(org-cite-csl--output-format info) (nreverse normal-citations))))
(org-cite-csl--no-citelinks-p info))) (citeproc-append-citations structures processor))
(result (seq-mapn #'cons citations rendered))) (when nocite-ids
(plist-put info :cite-citeproc-rendered-citations result) (citeproc-add-uncited nocite-ids processor))
result)))) (let (result
(rendered (citeproc-render-citations
processor
(org-cite-csl--output-format info)
(org-cite-csl--no-citelinks-p info))))
(dolist (citation citations)
(push (cons citation
(if (org-cite-csl--nocite-p citation info) "" (pop rendered)))
result))
(setq result (nreverse result))
(plist-put info :cite-citeproc-rendered-citations result)
result))))
;;; Export capability ;;; Export capability
@ -638,7 +660,8 @@ property list."
(("noauthor" "na") ("bare" "b") ("caps" "c") ("bare-caps" "bc")) (("noauthor" "na") ("bare" "b") ("caps" "c") ("bare-caps" "bc"))
(("year" "y") ("bare" "b")) (("year" "y") ("bare" "b"))
(("text" "t") ("caps" "c") ("full" "f") ("caps-full" "cf")) (("text" "t") ("caps" "c") ("full" "f") ("caps-full" "cf"))
(("nil") ("bare" "b") ("caps" "c") ("bare-caps" "bc")))) (("nil") ("bare" "b") ("caps" "c") ("bare-caps" "bc"))
(("nocite" "n"))))
(provide 'oc-csl) (provide 'oc-csl)
;;; oc-csl.el ends here ;;; oc-csl.el ends here