From e3911d8893758af6ff2fdd5992945cbf37fc0111 Mon Sep 17 00:00:00 2001 From: Andras Simonyi Date: Thu, 7 Mar 2024 09:21:00 +0100 Subject: [PATCH 1/3] Replace cite-note style structure slot with category --- citeproc-style.el | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/citeproc-style.el b/citeproc-style.el index e7dd4c7..e2e6ca0 100644 --- a/citeproc-style.el +++ b/citeproc-style.el @@ -37,6 +37,7 @@ (cl-defstruct (citeproc-style (:constructor citeproc-style--create)) "A struct representing a parsed and localized CSL style. +CATEGORY is the style's category as a string, INFO is the style's general info (currently simply the corresponding fragment of the parsed xml), OPTS, BIB-OPTS, CITE-OPTS and LOCALE-OPTS are alists of general @@ -49,7 +50,6 @@ BIB-SORT-ORDERS and CITE-SORT-ORDERS are the lists of sort orders the n-th key should be in ascending or desending order, CITE-LAYOUT-ATTRS contains the attributes of the citation layout as an alist, -CITE-NOTE is non-nil iff the style's citation-format is \"note\", DATE-TEXT and DATE-NUMERIC are the style's date formats, LOCALE contains the locale to be used or nil if not set, MACROS is an alist with macro names as keys and corresponding @@ -57,8 +57,8 @@ MACROS is an alist with macro names as keys and corresponding TERMS is the style's parsed term-list, USES-YS-VAR is non-nil iff the style uses the YEAR-SUFFIX CSL-variable." - info opts bib-opts bib-sort bib-sort-orders - bib-layout cite-opts cite-note cite-sort cite-sort-orders + category info opts bib-opts bib-sort bib-sort-orders + bib-layout cite-opts cite-sort cite-sort-orders cite-layout cite-layout-attrs locale-opts macros terms uses-ys-var date-text date-numeric locale) @@ -98,12 +98,13 @@ in-style locale information will be loaded (if available)." (--each (cddr parsed-style) (pcase (car it) ('info - (let ((info-lst (cddr it))) - (setf (citeproc-style-info style) info-lst - (citeproc-style-cite-note style) - (not (not (member '(category - ((citation-format . "note"))) - info-lst)))))) + (let* ((info-lst (cddr it)) + (category-info (cl-find-if + (lambda (x) (and (eq 'category (car x)) + (eq 'citation-format (caaadr x)))) + info-lst)) + (category (cdaadr category-info))) + (setf (citeproc-style-category style) category))) ('locale (let ((lang (alist-get 'lang (cadr it)))) (when (and (citeproc-locale--compatible-p lang locale) @@ -312,6 +313,10 @@ position and before the (possibly empty) body." ;; Handle `author' citation mode by stopping if needed (citeproc-lib-maybe-stop-rendering 'names context final))))) +(defun citeproc-style-cite-note (style) + "Return whether csl STYLE is a note style." + (string= (citeproc-style-category style) "note")) + (defun citeproc-style-global-opts (style layout) "Return the global opts in STYLE for LAYOUT. LAYOUT is either `bib' or `cite'." From 23b0ff46795394ac3e403ab363dcd0864811457c Mon Sep 17 00:00:00 2001 From: Andras Simonyi Date: Thu, 7 Mar 2024 14:40:04 +0100 Subject: [PATCH 2/3] Don't apply textual mode when citation style is numeric or label --- citeproc-cite.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/citeproc-cite.el b/citeproc-cite.el index 729ad13..731a2be 100644 --- a/citeproc-cite.el +++ b/citeproc-cite.el @@ -41,6 +41,8 @@ (require 'citeproc-sort) (require 'citeproc-subbibs) +(declare-function citeproc-style-category "citeproc-style" (style)) + (cl-defstruct (citeproc-citation (:constructor citeproc-citation-create)) "A struct representing a citation. CITES is a list of alists describing individual cites, @@ -228,7 +230,8 @@ For the optional INTERNAL-LINKS argument see (when outer-attrs (setq result (list outer-attrs result))) ;; Prepend author to textual citations - (when (eq (citeproc-citation-mode c) 'textual) + (when (and (eq (citeproc-citation-mode c) 'textual) + (not (member (citeproc-style-category style) '("numeric" "label")))) (let* ((first-elt (car cites)) ;; First elt is either a cite or a cite group. ;; If the latter then we need to locate the ;; first cite as the 2nd element of the first From 74abfffcafa6072388e9e6a7e9c5f74759a3eb86 Mon Sep 17 00:00:00 2001 From: Andras Simonyi Date: Thu, 7 Mar 2024 14:54:28 +0100 Subject: [PATCH 3/3] Add test for style category based textual citation formatting --- ...tion_TextualDontApplyForNumericOrLabel.txt | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 test/human/citation_TextualDontApplyForNumericOrLabel.txt diff --git a/test/human/citation_TextualDontApplyForNumericOrLabel.txt b/test/human/citation_TextualDontApplyForNumericOrLabel.txt new file mode 100644 index 0000000..a1aa06e --- /dev/null +++ b/test/human/citation_TextualDontApplyForNumericOrLabel.txt @@ -0,0 +1,97 @@ +>>===== MODE =====>> +citation +<<===== MODE =====<< + + +>>===== RESULT =====>> +[1] +[1] +<<===== RESULT =====<< + + +>>===== CITATIONS =====>> +[ + [ + { + "citationID": "CITATION-1", + "citationItems": [ + { + "id": "ITEM-1" + } + ], + "properties": { + "noteIndex": 0, + "mode": "textual" + } + }, + [], + [] + ], + [ + { + "citationID": "CITATION-2", + "citationItems": [ + { + "id": "ITEM-1" + } + ], + "properties": { + "noteIndex": 1 + } + }, + [], + [] + ] + +] +<<===== CITATIONS =====<< + + + +>>===== CSL =====>> + +<<===== CSL =====<< + + +>>===== INPUT =====>> +[ + { + "author": [ + { + "family": "Smith", + "given": "John" + } + ], + "issued": { + "date-parts": [ + [ + 1986 + ] + ] + }, + "type": "book", + "id": "ITEM-1" + } +] +<<===== INPUT =====<< +