Thanks Nicolas! That looks quite good already.

Your test cases give good results for German.
I've also added another language property for when you want to switch to an in-text citation style:

(defun org-test--language-to-rule (info)
  (pcase (plist-get info :language)
    ("en-us" '(inside outside after))
    ((or "en" "de" "en-gb") '(strict outside after))
    ("de-author-year" '(outside outside before))
    ("fr" '(strict inside before))
    (_ nil)))

Exporting your example with #+language: de-author-year gives me:

=========================
"This is a complete sentence"[1].

"This is an incomplete sentence"[2].

"This is an incomplete sentence"[3].

This is a complete sentence[4].

This is an incomplete sentence[5].
=========================

The only quirk here is that you'll obviously want spaces before the citaitons, but I guess this is because citation end up in footnotes. With an in-text style spaces won't be collapsed here, right?

Again, thanks for all your work on this one.

Denis

Am 13.05.2021 um 23:33 schrieb Nicolas Goaziou:
Hello,

Following discussion with Bruce D'Arcus and Denis Maier, I pushed, in
the "wip-cite-new" branch, the first version of a tool for adjusting the
location of the citation and surrounding punctuation according to fixed
rules. The name is `org-cite-adjust-punctuation' and its docstring is:

   Adjust punctuation around CITATION object.

   When CITATION follows a quotation, or when there is punctuation next to it,
   the function tries to normalize the location of punctuation and citation
   according to some RULE.

   RULE is a triplet of symbols (PUNCT POSITION RELATIVE):

     PUNCT is the desired location of the punctuation with regards to the
     quotation, if any.  It may be `inside', `outside', or`strict', the latter
     meaning the punctuation should not be moved.

     POSITION is the desired location of the citation with regards to the
     quotation, if any.  It may be `inside' or `outside'.

     RELATIVE is the relative position of the citation with regards to the 
closest
     punctuation.  It may be `after' or `before'.

   For example,

     (inside outside after) corresponds to American typography;
     (strict outside after) corresponds to German typography;
     (strict inside before) corresponds to French typography.

   INFO is the export state, as a property list.

   Optional argument PUNCT is a list of punctuation marks to be considered.
   When nil, it includes the following: \".\" \",\" \";\" \":\" \"!\" and \"?\".

   Parse tree is modified by side-effect.

   Note: if you are calling both `org-cite-adjust-punctuation' and
   `org-cite-wrap-citation' on the same object, call 
`org-cite-adjust-punctuation'
   first.

Citation processors focused on export may choose to use it, particularly
when using note style.

As an example, the following code implements a processor named `test'
that uses note style, and adjust punctuation according to the language
specified for the document.

--8<---------------cut here---------------start------------->8---
(defun org-test--language-to-rule (info)
   (pcase (plist-get info :language)
     ("en-us" '(inside outside after))
     ((or "en" "de" "en-gb") '(strict outside after))
     ("fr" '(strict inside before))
     (_ nil)))

(defun org-test-export-citation (citation _style _backend info)
   (pcase (org-test--language-to-rule info)
     (`nil nil)
     (rule (org-cite-adjust-punctuation citation rule info)))
   (unless (org-cite-inside-footnote-p citation)
     (org-cite-wrap-citation citation info))
   "...")

(org-cite-register-processor 'test
   :export-citation #'org-test-export-citation)
--8<---------------cut here---------------end--------------->8---

Once evaluated, you can test it, for example, by exporting the following
document:

--8<---------------cut here---------------start------------->8---
#+language: de
#+cite_export: test

"This is a complete sentence." [cite:@key]

"This is an incomplete sentence" [cite:@key].

This is a complete sentence. [cite:@key]

This is an incomplete sentence [cite:@key].
--8<---------------cut here---------------end--------------->8---

and changing language value.

WDYT?

Regards,



Reply via email to