Skip to content

Commit

Permalink
Merge pull request #157 from andras-simonyi/154-Do_not_apply_textual_…
Browse files Browse the repository at this point in the history
…mode_to_no-author_style_citations

154 do not apply textual mode to no author style citations
  • Loading branch information
andras-simonyi authored Mar 7, 2024
2 parents 9ef8ccc + 74abfff commit cb2d3e7
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 10 deletions.
5 changes: 4 additions & 1 deletion citeproc-cite.el
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
23 changes: 14 additions & 9 deletions citeproc-style.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,16 +50,15 @@ 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
anonymous rendering functions,
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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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'."
Expand Down
97 changes: 97 additions & 0 deletions test/human/citation_TextualDontApplyForNumericOrLabel.txt
Original file line number Diff line number Diff line change
@@ -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 =====>>
<style
xmlns="http://purl.org/net/xbiblio/csl"
class="note"
version="1.0">
<info>
<id />
<title />
<updated>2009-08-10T04:49:00+09:00</updated>
<category citation-format="numeric"/>
</info>
<citation>
<sort>
<key variable="citation-number"/>
</sort>
<layout delimiter=", ">
<group prefix="[" suffix="]" delimiter=", ">
<text variable="citation-number"/>
</group>
</layout>
</citation>
</style>
<<===== CSL =====<<


>>===== INPUT =====>>
[
{
"author": [
{
"family": "Smith",
"given": "John"
}
],
"issued": {
"date-parts": [
[
1986
]
]
},
"type": "book",
"id": "ITEM-1"
}
]
<<===== INPUT =====<<

0 comments on commit cb2d3e7

Please sign in to comment.