emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "András Simonyi" <andras.simonyi@gmail.com>
To: Ihor Radchenko <yantar92@gmail.com>
Cc: emacs-orgmode list <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] oc-csl: Add support for nocite citations
Date: Sat, 2 Jul 2022 10:32:52 +0200	[thread overview]
Message-ID: <CAOWRwxAAhfNDzd1-PD3yZSEt7dFOAKZaveTPMPOEgXgYEXeqfg@mail.gmail.com> (raw)
In-Reply-To: <87k08wi0wu.fsf@localhost>

[-- Attachment #1: Type: text/plain, Size: 1474 bytes --]

Dear Ihor,

thanks a lot for your reply!

On Sat, 2 Jul 2022 at 06:37, Ihor Radchenko <yantar92@gmail.com> wrote:

> By "*", do you mean something like [cite/n:@*]?
> If so, will it be correctly fontified as an existing citation?

Yes I meant exactly that. As for fontification, this is a very good
question! I've checked it now with the built-in "basic"
activation processor and it shows the "*" with an "error" face,
indicating that it's not a key in the bibliography file(s), which
might not be ideal. Nonetheless, this problem is not limited to or
introduced by this patch, because the same construct and
functionality is also supported by the "biblatex" and "natbib" export
processors.  Actually, the possibility of using "*" as a key comes
simply
from a citeproc-el change, not from oc-csl, I just thought that it is
obscure enough to merit an explicit mention in the NEWS file.

> It would help to provide an example how to use "*" key.
> Also, I'd prefer if you follow doc/Documentation_Standards.org. Please
> use Org markup instead of `...' quotes.

Thanks, I have tried to address your comments in the attached new
version of the patch.
Note that the quotes around "csl" follow the manual's "Citation
handling" chapter.

> Why not simply
> (member (car (org-cite-citation-style citation info)) '("nocite" "n"))
> ?

Thanks, that is indeed simpler, I've changed the function's definition
accordingly.


best wishes,
András

[-- Attachment #2: 0001-oc-csl.el-Add-support-for-nocite-citations.patch --]
[-- Type: text/x-patch, Size: 5698 bytes --]

From 7d2c6be97258ecbca4929e302d63b760bec078ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A1s=20Simonyi?= <andras.simonyi@gmail.com>
Date: Fri, 1 Jul 2022 10:24:17 +0200
Subject: [PATCH] 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.
---
 etc/ORG-NEWS   | 11 +++++++++++
 lisp/oc-csl.el | 53 ++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 902d70256..4cda357f1 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -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
 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 function ~org-element-cache-map~ for quick mapping across Org elements
diff --git a/lisp/oc-csl.el b/lisp/oc-csl.el
index eb67092dd..a2bd6653c 100644
--- a/lisp/oc-csl.el
+++ b/lisp/oc-csl.el
@@ -59,9 +59,13 @@
 ;; - author (a), including bare (b), caps (c), bare-caps (bc), full (f),
 ;;   caps-full (cf), and bare-caps-full (bcf) variants,
 ;; - noauthor (na), including bare (b), caps (c) and bare-caps (bc) variants,
+;; - nocite (n),
 ;; - year (y), including a bare (b) variant,
 ;; - text (t). including caps (c), full (f), and caps-full (cf) 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,
 ;; in the citation
@@ -103,6 +107,7 @@
 (declare-function citeproc-create "ext:citeproc")
 (declare-function citeproc-citation-create "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-bib "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
     (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)
   "Return citeproc structure creation params for CITATION object.
 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
 OUTPUT using Citeproc."
   (or (plist-get info :cite-citeproc-rendered-citations)
-      (let* ((citations (org-cite-list-citations info))
-             (processor (org-cite-csl--processor info))
-             (structures
-              (mapcar (lambda (c) (org-cite-csl--create-structure c info))
-                      citations)))
-        (citeproc-append-citations structures processor)
-        (let* ((rendered
-                (citeproc-render-citations
-                 processor
-                 (org-cite-csl--output-format info)
-                 (org-cite-csl--no-citelinks-p info)))
-               (result (seq-mapn #'cons citations rendered)))
-          (plist-put info :cite-citeproc-rendered-citations result)
-          result))))
+      (let ((citations (org-cite-list-citations info))
+	    (processor (org-cite-csl--processor info))
+	    normal-citations nocite-ids)
+	(dolist (citation citations)
+	  (if (org-cite-csl--nocite-p citation info)
+	      (setq nocite-ids (append (org-cite-get-references citation t) nocite-ids))
+	    (push citation normal-citations)))
+	(let ((structures
+	       (mapcar (lambda (c) (org-cite-csl--create-structure c info))
+		       (nreverse normal-citations))))
+	  (citeproc-append-citations structures processor))
+	(when nocite-ids
+	  (citeproc-add-uncited nocite-ids processor))
+	(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))))
 
 \f
 ;;; Export capability
@@ -638,7 +660,8 @@ property list."
     (("noauthor" "na") ("bare" "b") ("caps" "c") ("bare-caps" "bc"))
     (("year" "y") ("bare" "b"))
     (("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)
 ;;; oc-csl.el ends here
-- 
2.25.1


  reply	other threads:[~2022-07-02  8:34 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-01  9:30 [PATCH] oc-csl: Add support for nocite citations András Simonyi
2022-07-02  4:38 ` Ihor Radchenko
2022-07-02  8:32   ` András Simonyi [this message]
2022-07-03 11:58     ` Ihor Radchenko
2022-07-03 12:26       ` Bruce D'Arcus
2022-07-03 12:35         ` Ihor Radchenko
2022-07-03 12:38           ` Bruce D'Arcus
2022-07-03 12:53           ` John Kitchin
2022-07-03 13:10             ` [BUG] @* in [cite/nocite:@*] is a valid special LaTeX bibliography key, but it is highlighted using "error" face by oc.el (was: [PATCH] oc-csl: Add support for nocite citations) Ihor Radchenko
2022-07-04  6:53               ` András Simonyi
2022-07-04 12:28                 ` Ihor Radchenko
2022-07-04 12:57                   ` András Simonyi
2022-07-04 13:16                     ` Bruce D'Arcus
2022-07-04 11:54     ` [PATCH] oc-csl: Add support for nocite citations Ihor Radchenko
2022-07-05 19:17       ` Bruce D'Arcus
2022-07-05 19:28         ` Bruce D'Arcus
2022-07-05 19:37           ` Bruce D'Arcus
2022-07-07 10:46         ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOWRwxAAhfNDzd1-PD3yZSEt7dFOAKZaveTPMPOEgXgYEXeqfg@mail.gmail.com \
    --to=andras.simonyi@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).