update packages

This commit is contained in:
2025-11-25 19:52:03 +01:00
parent 14ba373378
commit dbbae92267
280 changed files with 13451 additions and 11207 deletions

View File

@@ -39,18 +39,36 @@
;; export is your goal, you may want to use org-ref-refproc.el to handle
;; cross-references.
;;
;;; Formatting Limitations:
;;
;; Different export backends have different formatting capabilities. HTML and
;; LaTeX support full CSL formatting including small caps, italics, bold, etc.
;;
;; The org-mode backend has limitations because org-mode syntax does not support
;; small caps. Many CSL citation styles use small caps for author names, so these
;; will not render correctly when exporting to formats that use the org backend
;; (like DOCX by default).
;;
;; For DOCX export with better formatting support, set
;; `org-ref-docx-use-html-backend' to t. This causes citations to be rendered
;; as HTML which pandoc can convert to DOCX while preserving formatting.
;;
;; See `org-ref-backend-csl-formats' to customize backend mappings for different
;; export formats.
;;
;;; Code:
(eval-when-compile
(require 'hydra))
(require 'transient)
(require 'org-ref-utils)
(require 'org-ref-citation-links)
(defvar hfy-user-sheet-assoc) ; to quiet compiler
(require 'ox-org)
(if (executable-find "pandoc")
(require 'ox-pandoc))
(when (executable-find "pandoc")
(ignore-errors (require 'ox-pandoc)))
(require 'citeproc)
(ignore-errors (require 'citeproc))
(defvar org-cite-csl-styles-dir)
@@ -62,7 +80,24 @@
(ascii . plain)
(odt . org-odt)
(docx . org))
"Mapping of export backend to csl-backends."
"Mapping of export backend to csl-backends.
Each entry maps an org export backend symbol to a citeproc-el backend
format used for rendering citations and bibliographies.
Note: The 'org backend has formatting limitations because org-mode
syntax does not support small caps. CSL styles that use small caps
(common for author names) will not render correctly when using the
'org backend. For DOCX export, consider setting
`org-ref-docx-use-html-backend' to t to use HTML formatting which
pandoc can convert while preserving small caps and other formatting.
Available citeproc backends:
- html: Full HTML formatting with CSS styles
- latex: Full LaTeX formatting with commands like \\textsc{}
- org: Org-mode markup (limited, no small caps support)
- org-odt: ODT-specific XML formatting
- plain: Plain text with no formatting"
:type '(alist :key-type (symbol) :value-type (symbol))
:group 'org-ref)
@@ -92,6 +127,30 @@ Should be a csl filename, or an absolute path to a csl filename."
:group 'org-ref)
(defcustom org-ref-docx-use-html-backend nil
"Use HTML backend for DOCX export to preserve CSL formatting.
When non-nil, citations exported to DOCX will be rendered using the
HTML backend, which preserves formatting like small caps and italics
that pandoc can convert to DOCX.
When nil (default), uses the org backend which has limited formatting
support due to org-mode syntax limitations. Specifically, org-mode has
no native syntax for small caps, so CSL styles that use small caps
(common for author names in many citation styles) will not render
correctly in DOCX output.
Note: This option only affects DOCX export via pandoc. Other export
formats (HTML, LaTeX, ODT) are not affected.
See also `org-ref-backend-csl-formats' to customize backend mappings
for other export formats.
Related to issue #981: https://github.com/jkitchin/org-ref/issues/981"
:type 'boolean
:group 'org-ref)
(defcustom org-ref-csl-label-aliases
'((("app" "apps") . "appendix")
(("art" "arts") . "article-locator")
@@ -128,7 +187,7 @@ See https://github.com/citation-style-language/documentation/blob/master/specifi
:group 'org-ref)
(defcustom org-ref-export-suppress-affix-types
(defcustom org-ref-export-suppress-affix-types
'("citet"
"citet*"
"citetitle"
@@ -141,6 +200,68 @@ See https://github.com/citation-style-language/documentation/blob/master/specifi
:group 'org-ref)
;;; Footnote citation support (issue #993)
(defvar org-ref-footnote-counter 0
"Counter for footnote citations during export.
Reset to 0 at the start of each export process.")
(defcustom org-ref-footnote-cite-types
'("footcite"
"footfullcite"
"footcitetext"
"footcites"
"footcitetexts"
"smartcite"
"Smartcite")
"List of citation types that should be rendered as footnotes.
These citation types will be given a :note-index parameter when
passed to citeproc-el, which causes them to be rendered as notes/footnotes
when using CSL styles that support note formatting."
:type '(repeat string)
:group 'org-ref)
(defun org-ref-footnote-cite-type-p (cite-type)
"Return non-nil if CITE-TYPE should be rendered as a footnote.
CITE-TYPE is a string like \"footcite\" or \"cite\"."
(member cite-type org-ref-footnote-cite-types))
(defun org-ref-get-next-footnote-number ()
"Get the next footnote number and increment the counter.
Returns the next sequential footnote number (1, 2, 3, ...)."
(setq org-ref-footnote-counter (1+ org-ref-footnote-counter)))
(defun org-ref-csl-style-supports-notes-p (csl-style-file)
"Return non-nil if CSL-STYLE-FILE supports note/footnote formatting.
CSL-STYLE-FILE is a filename like \"chicago-fullnote-bibliography.csl\".
This function checks if the CSL style file contains note-related
class attributes, which indicate it supports footnote formatting."
(or
;; Check filename for common note-style indicators
;; Match: -note-, -note.csl, fullnote, footnote
(string-match-p "\\(\\bnote\\b\\|fullnote\\|footnote\\)" csl-style-file)
;; If we have the actual file, check its contents
(when (file-exists-p csl-style-file)
(with-temp-buffer
(insert-file-contents csl-style-file)
(goto-char (point-min))
;; Look for class="note" in the CSL XML
(re-search-forward "class=\"note\"" nil t)))))
(defun org-ref-get-citation-note-index (citation-link)
"Get the note-index for CITATION-LINK if it's a footnote citation type.
CITATION-LINK is an org-element link object.
Returns a footnote number if this is a footnote citation, nil otherwise."
(when (org-ref-footnote-cite-type-p
(org-element-property :type citation-link))
(org-ref-get-next-footnote-number)))
(defun org-ref-dealias-label (alias)
"Return the full, de-aliased label for ALIAS.
Looked up from `org-ref-csl-label-aliases'.
@@ -234,10 +355,17 @@ REF is a plist data structure returned from `org-ref-parse-cite-path'."
"Process the citations and bibliography in the org-buffer.
Usually run on a copy of the buffer during export.
BACKEND is the org export backend."
;; Reset footnote counter for this export
(setq org-ref-footnote-counter 0)
(save-restriction
(when subtreep
(org-narrow-to-subtree))
(let* ((csl-backend (or (cdr (assoc backend org-ref-backend-csl-formats)) 'plain))
;; Use HTML backend for DOCX if requested for better formatting
(csl-backend (if (and (eq backend 'docx) org-ref-docx-use-html-backend)
'html
csl-backend))
(style (or (cadr (assoc "CSL-STYLE"
(org-collect-keywords
@@ -248,6 +376,24 @@ BACKEND is the org export backend."
'("CSL-LOCALE"))))
org-ref-csl-default-locale))
;; Determine the actual style file path for checking note support
(style-file (cond
((file-exists-p style)
style)
((and (bound-and-true-p org-cite-csl-styles-dir)
(file-exists-p (org-ref--file-join org-cite-csl-styles-dir style)))
(org-ref--file-join org-cite-csl-styles-dir style))
((file-exists-p (expand-file-name style
(org-ref--file-join (file-name-directory
(locate-library "org-ref"))
"citeproc/csl-styles")))
(expand-file-name style (org-ref--file-join
(file-name-directory
(locate-library "org-ref"))
"citeproc/csl-styles")))
(t
style))) ; Fallback to style name itself
(proc (citeproc-create
;; The style
(cond
@@ -255,14 +401,14 @@ BACKEND is the org export backend."
style)
;; In a user-dir
((and (bound-and-true-p org-cite-csl-styles-dir)
(file-exists-p (f-join org-cite-csl-styles-dir style)))
(f-join org-cite-csl-styles-dir style))
(file-exists-p (org-ref--file-join org-cite-csl-styles-dir style)))
(org-ref--file-join org-cite-csl-styles-dir style))
;; provided by org-ref
((file-exists-p (expand-file-name style
(f-join (file-name-directory
(org-ref--file-join (file-name-directory
(locate-library "org-ref"))
"citeproc/csl-styles")))
(expand-file-name style (f-join
(expand-file-name style (org-ref--file-join
(file-name-directory
(locate-library "org-ref"))
"citeproc/csl-styles")))
@@ -274,7 +420,7 @@ BACKEND is the org export backend."
;; locale getter
(citeproc-locale-getter-from-dir (if (bound-and-true-p org-cite-csl-locales-dir)
org-cite-csl-locales-dir
(f-join (file-name-directory
(org-ref--file-join (file-name-directory
(locate-library "org-ref"))
"citeproc/csl-locales")))
;; the actual locale
@@ -338,8 +484,15 @@ BACKEND is the org export backend."
"[A-Z]"
(substring
(org-element-property :type cl) 0 1))
;; I don't know where this information would come from.
:note-index nil
;; Set note-index for footnote citation types (issue #993)
:note-index (when (org-ref-footnote-cite-type-p
(org-element-property :type cl))
;; Warn if using footnote citations with non-note style
(unless (org-ref-csl-style-supports-notes-p style-file)
(warn "Citation type '%s' is a footnote citation but CSL style '%s' may not support notes. Consider using a note-based style like chicago-fullnote-bibliography.csl"
(org-element-property :type cl)
style))
(org-ref-get-next-footnote-number))
:ignore-et-al nil
:grouped nil))))
@@ -547,6 +700,11 @@ VISIBLE-ONLY BODY-ONLY and INFO."
(defun org-ref-export-to-docx (&optional async subtreep visible-only
body-only info)
"Export the buffer to docx via pandoc and open.
Note: By default, DOCX export uses the org backend for citations which
has formatting limitations (no small caps support). Set
`org-ref-docx-use-html-backend' to t for better formatting preservation.
See `org-export-as' for the meaning of ASYNC SUBTREEP
VISIBLE-ONLY BODY-ONLY and INFO."
(org-ref-export-to 'docx async subtreep visible-only
@@ -614,23 +772,67 @@ I am not positive on this though."
(org-at-heading-p)))))
;; A hydra exporter with preprocessors
(defhydradio org-ref ()
(natmove "natmove")
(citeproc "CSL citations")
(refproc "cross-references")
(acrossproc "Acronyms, glossary")
(idxproc "Index")
(bblproc "BBL citations"))
;; A transient exporter with preprocessors
(defvar org-ref/natmove nil
"Toggle for moving natbib citations before export.")
(defvar org-ref/citeproc nil
"Toggle for running citeproc before export.")
(defvar org-ref/refproc nil
"Toggle for running refproc before export.")
(defvar org-ref/acrossproc nil
"Toggle for running acrossproc before export.")
(defvar org-ref/idxproc nil
"Toggle for running idxproc before export.")
(defvar org-ref/bblproc nil
"Toggle for running bblproc before export.")
(defun org-ref-export--toggle (var)
(set var (not (symbol-value var)))
(message "%s %s"
(capitalize (replace-regexp-in-string "/" " " (symbol-name var)))
(if (symbol-value var) "enabled" "disabled"))
(symbol-value var))
(defun org-ref-export-toggle-natmove ()
(interactive)
(org-ref-export--toggle 'org-ref/natmove))
(defun org-ref-export-toggle-citeproc ()
(interactive)
(org-ref-export--toggle 'org-ref/citeproc))
(defun org-ref-export-toggle-refproc ()
(interactive)
(org-ref-export--toggle 'org-ref/refproc))
(defun org-ref-export-toggle-acrossproc ()
(interactive)
(org-ref-export--toggle 'org-ref/acrossproc))
(defun org-ref-export-toggle-idxproc ()
(interactive)
(org-ref-export--toggle 'org-ref/idxproc))
(defun org-ref-export-toggle-bblproc ()
(interactive)
(org-ref-export--toggle 'org-ref/bblproc))
(defun org-ref-export--toggle-description (label var)
(format "%s %s" label (if (symbol-value var) "[on]" "[off]")))
(defun org-ref-export-from-hydra (&optional arg)
"Run the export dispatcher with the desired hooks selected in `org-ref-export/body'."
(defun org-ref-export-dispatch (&optional arg)
"Run the export dispatcher with the desired hooks selected in the export menu."
(interactive "P")
(when (and org-ref/citeproc org-ref/bblproc)
(error "You cannot use CSL and BBL at the same time."))
(let ((org-export-before-parsing-functions org-export-before-parsing-functions))
(when org-ref/citeproc
(cl-pushnew 'org-ref-csl-preprocess-buffer org-export-before-parsing-functions))
@@ -648,28 +850,37 @@ I am not positive on this though."
(unless (featurep 'org-ref-natbib-bbl-citeproc)
(require 'org-ref-natbib-bbl-citeproc))
(cl-pushnew 'org-ref-bbl-preprocess org-export-before-parsing-functions))
;; this goes last since it moves cites before they might get replaced.
(when org-ref/natmove
(cl-pushnew 'org-ref-cite-natmove org-export-before-parsing-functions))
(org-export-dispatch arg)))
(transient-define-prefix org-ref-export-menu ()
"Select export preprocessors and dispatch export."
[["Preprocessors"
("n" org-ref-export-toggle-natmove :transient t
:description (lambda () (org-ref-export--toggle-description "natmove" 'org-ref/natmove)))
("c" org-ref-export-toggle-citeproc :transient t
:description (lambda () (org-ref-export--toggle-description "citeproc" 'org-ref/citeproc)))
("r" org-ref-export-toggle-refproc :transient t
:description (lambda () (org-ref-export--toggle-description "refproc" 'org-ref/refproc)))
("a" org-ref-export-toggle-acrossproc :transient t
:description (lambda () (org-ref-export--toggle-description "acrossproc" 'org-ref/acrossproc)))
("i" org-ref-export-toggle-idxproc :transient t
:description (lambda () (org-ref-export--toggle-description "idxproc" 'org-ref/idxproc)))
("b" org-ref-export-toggle-bblproc :transient t
:description (lambda () (org-ref-export--toggle-description "bblproc" 'org-ref/bblproc)))]
["Actions"
("e" "Export" org-ref-export-dispatch)
("q" "Quit" transient-quit-one)]])
(defhydra org-ref-export (:color red)
"
_C-n_: natmove % -15`org-ref/natmove _C-c_: citeproc % -15`org-ref/citeproc^^^ _C-r_: refproc % -15`org-ref/refproc^^^
_C-a_: acrossproc % -15`org-ref/acrossproc _C-i_: idxproc % -15`org-ref/idxproc^^^ _C-b_: bblproc % -15`org-ref/bblproc^^^
"
("C-n" (org-ref/natmove) nil)
("C-c" (org-ref/citeproc) nil)
("C-r" (org-ref/refproc) nil)
("C-a" (org-ref/acrossproc) nil)
("C-i" (org-ref/idxproc) nil)
("C-b" (org-ref/bblproc) nil)
(define-obsolete-function-alias 'org-ref-export/body
#'org-ref-export-menu "3.1")
("e" org-ref-export-from-hydra "Export" :color blue)
("q" nil "quit"))
(define-obsolete-function-alias 'org-ref-export-from-hydra
#'org-ref-export-dispatch "3.1")
(provide 'org-ref-export)